Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update password module #2650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dependencies {
implementation(projects.feature.location)
implementation(projects.feature.about)
implementation(projects.feature.settings)
implementation(projects.feature.updatePassword)


implementation("androidx.legacy:legacy-support-v4:1.0.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.mifos.mobile.core.model.enums.BeneficiaryState
import org.mifos.mobile.ui.fragments.base.BaseFragment
import com.google.zxing.Result
import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary
import org.mifos.mobile.ui.qr_code_import.QrCodeImportScreen
import org.mifos.mobile.feature.qr.qr_code_import.QrCodeImportScreen

@AndroidEntryPoint
class QrCodeImportComposeFragment : BaseFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import dagger.hilt.android.AndroidEntryPoint
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.core.ui.component.mifosComposeView
import org.mifos.mobile.feature.update_password.UpdatePasswordScreen
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.fragments.base.BaseFragment

Expand All @@ -22,17 +21,12 @@ class UpdatePasswordFragment : BaseFragment() {
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
MifosMobileTheme {
UpdatePasswordScreen(
navigateBack = {
requireActivity().onBackPressedDispatcher.onBackPressed()
}
)
return mifosComposeView(requireContext()) {
UpdatePasswordScreen(
navigateBack = {
requireActivity().onBackPressedDispatcher.onBackPressed()
}
}
)
}
}

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@
<string name="change_passcode">Change Passcode</string>
<string name="change_app_passcode">Change App Passcode</string>
<string name="change_password">Change Password</string>
<string name="change_account_password">Change your Account Password</string>
<string name="current_password">Current Password</string>
<string name="new_password">New Password</string>
<string name="string_changed_successfully">%1$s changed successfully</string>

<string name="account_not_active_to_perform_deposit">Account should to be Active to perform a
Expand Down Expand Up @@ -630,7 +627,6 @@
</string-array>
<string name="app_info">App Info</string>
<string name="login_failed">Login Failed, Please Try Again Later.</string>
<string name="could_not_update_password_error">We were unable to update password.</string>
<string name="password_changed_successfully">Password changed successfully</string>
<string name="could_not_register_user_error">We were unable to register the user.</string>
<string name="no_questions_found">No Questions Found</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.junit.*
import org.junit.runner.RunWith
import org.mifos.mobile.core.data.repositories.ClientRepository
import org.mifos.mobile.core.data.repositories.UserAuthRepository
import org.mifos.mobile.ui.update_password.UpdatePasswordViewModel
import org.mifos.mobile.feature.update_password.UpdatePasswordViewModel
import org.mifos.mobile.util.RxSchedulersOverrideRule
import org.mifos.mobile.feature.registration.utils.RegistrationState
import org.mockito.Mock
Expand Down Expand Up @@ -40,13 +40,16 @@ class UpdatePasswordViewModelTest {
@Mock
lateinit var clientRepositoryImp: ClientRepository

private lateinit var updatePasswordViewModel: UpdatePasswordViewModel
private lateinit var updatePasswordViewModel: org.mifos.mobile.feature.update_password.UpdatePasswordViewModel

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
updatePasswordViewModel =
UpdatePasswordViewModel(userAuthRepositoryImp, clientRepositoryImp)
org.mifos.mobile.feature.update_password.UpdatePasswordViewModel(
userAuthRepositoryImp,
clientRepositoryImp
)
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion feature/about/src/main/res/drawable/ic_source_code.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="@color/primary_text"
android:fillColor="#212121"
android:pathData="M24.9316,8.0001 L19,40.0001h4.0684L29,8.0001ZM14,14.0001l-10,10 10,10 2.8008,-2.8008 -7.2012,-7.1992 7.2012,-7.1992zM34,14.0001 L31.1992,16.8009 38.4004,24.0001 31.1992,31.1993 34,34.0001 44,24.0001z"
android:strokeWidth="2" />
</vector>
2 changes: 1 addition & 1 deletion feature/about/src/main/res/drawable/ic_website.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/primary_text"
android:fillColor="#212121"
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z" />
</vector>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.qr_code_import
package org.mifos.mobile.feature.qr.qr_code_import

import android.Manifest
import android.graphics.Bitmap
Expand Down Expand Up @@ -43,8 +43,6 @@ import org.mifos.mobile.core.ui.component.MFScaffold
import org.mifos.mobile.core.ui.component.MifosErrorComponent
import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay
import org.mifos.mobile.feature.qr.R
import org.mifos.mobile.feature.qr.qr_code_import.PermissionBox
import org.mifos.mobile.feature.qr.qr_code_import.convertToMutableBitmap

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.qr_code_import
package org.mifos.mobile.feature.qr.qr_code_import

import android.graphics.Bitmap
import androidx.lifecycle.ViewModel
Expand Down
1 change: 1 addition & 0 deletions feature/update-password/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
20 changes: 20 additions & 0 deletions feature/update-password/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
}


android {
namespace = "org.mifos.mobile.feature.update.password"
}

dependencies {
implementation(projects.ui)
implementation(projects.core.common)
implementation(projects.core.model)
implementation(projects.core.data)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}
Empty file.
21 changes: 21 additions & 0 deletions feature/update-password/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.mifos.mobile.feature.update_password

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("org.mifos.mobile.feature.update_password.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions feature/update-password/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.update_password
package org.mifos.mobile.feature.update_password

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -22,7 +22,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
Expand All @@ -33,10 +32,9 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import org.mifos.mobile.R
import org.mifos.mobile.core.ui.component.MifosOutlinedTextField
import org.mifos.mobile.feature.update.password.R

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun UpdatePasswordContent(
viewModel: UpdatePasswordViewModel = hiltViewModel(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.update_password
package org.mifos.mobile.feature.update_password

import android.content.Context
import android.widget.Toast
Expand All @@ -23,15 +23,14 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.mifos.mobile.R
import org.mifos.mobile.core.ui.component.MifosProgressIndicator
import org.mifos.mobile.core.ui.component.MifosTopBar
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.core.common.Network
import org.mifos.mobile.feature.savings.savings_account_withdraw.UiStatesParameterProvider
import org.mifos.mobile.feature.registration.utils.RegistrationState
import org.mifos.mobile.feature.update.password.R


@Composable
Expand All @@ -49,7 +48,7 @@ fun UpdatePasswordScreen(

@Composable
fun UpdatePasswordScreen(
uiState: RegistrationState,
uiState: UpdatePasswordUiState,
navigateBack: () -> Unit
) {
val context = LocalContext.current
Expand All @@ -76,15 +75,15 @@ fun UpdatePasswordScreen(
)

when (uiState) {
is RegistrationState.Loading -> {
is UpdatePasswordUiState.Loading -> {
MifosProgressIndicator(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background.copy(0.8f))
)
}

is RegistrationState.Error -> {
is UpdatePasswordUiState.Error -> {
if (updatePasswordButtonClicked) {
LaunchedEffect(snackbarHostState) {
snackbarHostState.showSnackbar(
Expand All @@ -96,9 +95,9 @@ fun UpdatePasswordScreen(
}
}

is RegistrationState.Initial -> Unit
is UpdatePasswordUiState.Initial -> Unit

is RegistrationState.Success -> {
is UpdatePasswordUiState.Success -> {
LaunchedEffect(snackbarHostState) {
snackbarHostState.showSnackbar(
context.getString(R.string.password_changed_successfully),
Expand All @@ -113,10 +112,20 @@ fun UpdatePasswordScreen(
}
}

class UiStatesParameterProvider : PreviewParameterProvider<UpdatePasswordUiState> {
override val values: Sequence<UpdatePasswordUiState>
get() = sequenceOf(
UpdatePasswordUiState.Initial,
UpdatePasswordUiState.Error(1),
UpdatePasswordUiState.Loading,
UpdatePasswordUiState.Success
)
}

@Composable
@Preview(showSystemUi = true, showBackground = true)
fun UpdatePasswordScreenPreview(
@PreviewParameter(UiStatesParameterProvider::class) registrationUiState: RegistrationState
@PreviewParameter(UiStatesParameterProvider::class) updatePasswordUiState: UpdatePasswordUiState
) {
MifosMobileTheme {
UpdatePasswordScreen(navigateBack = {})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.update_password
package org.mifos.mobile.feature.update_password

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand All @@ -7,10 +7,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.launch
import org.mifos.mobile.R
import org.mifos.mobile.core.data.repositories.ClientRepository
import org.mifos.mobile.core.data.repositories.UserAuthRepository
import org.mifos.mobile.feature.registration.utils.RegistrationState
import org.mifos.mobile.feature.update.password.R
import javax.inject.Inject

@HiltViewModel
Expand All @@ -19,19 +18,27 @@ class UpdatePasswordViewModel @Inject constructor(
private val clientRepositoryImp: ClientRepository,
) : ViewModel() {

private val _updatePasswordUiState = MutableStateFlow<RegistrationState>(RegistrationState.Initial)
val updatePasswordUiState: StateFlow<RegistrationState> get() = _updatePasswordUiState
private val _updatePasswordUiState = MutableStateFlow<UpdatePasswordUiState>(UpdatePasswordUiState.Initial)
val updatePasswordUiState: StateFlow<UpdatePasswordUiState> get() = _updatePasswordUiState

fun updateAccountPassword(newPassword: String, confirmPassword: String) {
viewModelScope.launch {
_updatePasswordUiState.value = RegistrationState.Loading
_updatePasswordUiState.value = UpdatePasswordUiState.Loading
userAuthRepositoryImp.updateAccountPassword(newPassword, confirmPassword).catch {
_updatePasswordUiState.value =
RegistrationState.Error(R.string.could_not_update_password_error)
UpdatePasswordUiState.Error(R.string.could_not_update_password_error)
}.collect {
_updatePasswordUiState.value = RegistrationState.Success
_updatePasswordUiState.value = UpdatePasswordUiState.Success
clientRepositoryImp.updateAuthenticationToken(newPassword)
}
}
}
}


sealed class UpdatePasswordUiState {
data class Error(val exception: Int) : UpdatePasswordUiState()
data object Success : UpdatePasswordUiState()
data object Loading : UpdatePasswordUiState()
data object Initial: UpdatePasswordUiState()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z" />
</vector>
Empty file.
Loading
Loading