Skip to content

Commit

Permalink
Fixing crashes on clicking bank acc details and editprofile (openMF#1713
Browse files Browse the repository at this point in the history
)

* Fix : App crashing on clicking BankAccount

* Fix : App crashing on clicking Editprofile

* Fix : App crashing on clicking confirm in create SI
  • Loading branch information
AdityaKumdale authored Jul 29, 2024
1 parent 7c875f8 commit c71b4ee
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,30 @@ fun NavGraphBuilder.bankAccountDetailScreen(
navArgument(Constants.INDEX) { type = NavType.IntType }
)
) { backStackEntry ->
val bankAccountDetails = backStackEntry.arguments?.getParcelable<BankAccountDetails>(Constants.BANK_ACCOUNT_DETAILS)
val bankAccountDetails =
backStackEntry.arguments?.getParcelable(Constants.BANK_ACCOUNT_DETAILS)
?: BankAccountDetails("", "", "", "", "")
val index = backStackEntry.arguments?.getInt(Constants.INDEX) ?: 0

BankAccountDetailScreen(
bankAccountDetails = bankAccountDetails!!,
onSetupUpiPin = { onSetupUpiPin(bankAccountDetails, index) },
onChangeUpiPin = {
if (bankAccountDetails.isUpiEnabled) {
onChangeUpiPin(bankAccountDetails, index)
} else {
// TODO: Use global snackbar
}
},
onForgotUpiPin = {
if (bankAccountDetails.isUpiEnabled) {
onForgotUpiPin(bankAccountDetails, index)
} else {
// TODO: Use global snackbar
}
},
navigateBack = { onBackClick(bankAccountDetails, index) }
)
BankAccountDetailScreen(
bankAccountDetails = bankAccountDetails,
onSetupUpiPin = { onSetupUpiPin(bankAccountDetails, index) },
onChangeUpiPin = {
if (bankAccountDetails.isUpiEnabled) {
onChangeUpiPin(bankAccountDetails, index)
} else {
// TODO: Use global snackbar
}
},
onForgotUpiPin = {
if (bankAccountDetails.isUpiEnabled) {
onForgotUpiPin(bankAccountDetails, index)
} else {
// TODO: Use global snackbar
}
},
navigateBack = { onBackClick(bankAccountDetails, index) }
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
Expand All @@ -45,7 +44,6 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import androidx.core.content.FileProvider
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.togitech.ccp.component.TogiCountryCodePicker
Expand All @@ -61,28 +59,24 @@ import org.mifospay.core.designsystem.icon.MifosIcons.PhotoLibrary
import org.mifospay.core.designsystem.theme.MifosTheme
import org.mifospay.core.designsystem.theme.historyItemTextStyle
import org.mifospay.core.designsystem.theme.styleMedium16sp
import org.mifospay.feature.profile.BuildConfig
import org.mifospay.feature.profile.R
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.Objects

@Composable
fun EditProfileScreenRoute(
viewModel: EditProfileViewModel = hiltViewModel(),
onBackClick: () -> Unit,
getUri:(context: Context, file: File) -> Uri
) {
val editProfileUiState by viewModel.editProfileUiState.collectAsStateWithLifecycle()
val updateSuccess by viewModel.updateSuccess.collectAsStateWithLifecycle()

val context = LocalContext.current
val file = createImageFile(context)
val uri = FileProvider.getUriForFile(
Objects.requireNonNull(context),
BuildConfig.LIBRARY_PACKAGE_NAME + ".provider", file
)
val uri = getUri(context,file)

LaunchedEffect(key1 = true) {
viewModel.fetchProfileDetails()
Expand Down Expand Up @@ -286,7 +280,7 @@ fun EditProfileScreenContent(
} else {
TogiCountryCodePicker(
modifier = Modifier,
initialPhoneNumber = mobile,
initialPhoneNumber = " ",
autoDetectCode = true,
shape = RoundedCornerShape(3.dp),
colors = TextFieldDefaults.outlinedTextFieldColors(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package org.mifospay.feature.profile.navigation

import android.content.Context
import android.net.Uri
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import org.mifospay.feature.profile.edit.EditProfileScreenRoute
import java.io.File

const val EDIT_PROFILE_ROUTE = "edit_profile_route"
fun NavController.navigateToEditProfile(navOptions: NavOptions? = null) = navigate(EDIT_PROFILE_ROUTE, navOptions)

fun NavGraphBuilder.editProfileScreen(
onBackPress: () -> Unit,
getUri:(context: Context, file: File) -> Uri
) {
composable(route = EDIT_PROFILE_ROUTE) {
EditProfileScreenRoute(
onBackClick = onBackPress
onBackClick = onBackPress,
getUri = getUri
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,22 @@ fun ConfirmTransfer(
.width(150.dp)
.padding(top = 16.dp),
onClick = {
confirm.invoke(
clientId,
amount.toDouble(),
recurrenceInterval.toInt(),
validTill
)
if (amount.isNotEmpty()) {
confirm.invoke(
clientId,
amount.toDouble(),
recurrenceInterval.toInt(),
validTill
)
} else {
// Handle the case when the amount is empty
Toast.makeText(
context,
R.string.feature_standing_instruction_failed_to_save_changes,
Toast.LENGTH_SHORT
)
.show()
}
if (updateSuccess) {
Toast.makeText(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ fun NavGraphBuilder.setupUpiPinScreen() {
navArgument(Constants.TYPE) { type = NavType.StringType }
)
) { backStackEntry ->
val bankAccountDetails = backStackEntry.arguments?.getParcelable<BankAccountDetails>(Constants.BANK_ACCOUNT_DETAILS)
val bankAccountDetails =
backStackEntry.arguments?.getParcelable(Constants.BANK_ACCOUNT_DETAILS)
?: BankAccountDetails("", "", "", "", "")
val index = backStackEntry.arguments?.getInt(Constants.INDEX) ?: 0
val type = backStackEntry.arguments?.getString(Constants.TYPE) ?: ""

SetupUpiPinScreenRoute(
bankAccountDetails = bankAccountDetails!!,
bankAccountDetails = bankAccountDetails,
type = type,
index = index
)
}
}

fun NavController.navigateToSetupUpiPin(bankAccountDetails: BankAccountDetails, index: Int, type: String) {
fun NavController.navigateToSetupUpiPin(
bankAccountDetails: BankAccountDetails,
index: Int,
type: String
) {
val bundle = Bundle().apply {
putParcelable(Constants.BANK_ACCOUNT_DETAILS, bankAccountDetails)
}
Expand Down
18 changes: 17 additions & 1 deletion mifospay/src/main/java/org/mifospay/navigation/MifosNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.net.Uri
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.FileProvider
import androidx.core.os.bundleOf
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
Expand Down Expand Up @@ -60,6 +61,8 @@ import org.mifospay.feature.standing.instruction.navigateToNewSiScreen
import org.mifospay.feature.standing.instruction.newSiScreen
import org.mifospay.feature.upi_setup.navigation.navigateToSetupUpiPin
import org.mifospay.feature.upi_setup.navigation.setupUpiPinScreen
import java.io.File
import java.util.Objects

/**
* Top-level navigation graph. Navigation is organized as explained at
Expand Down Expand Up @@ -177,7 +180,12 @@ fun MifosNavHost(
kycLevel3Screen()
newSiScreen(onBackClick = navController::popBackStack)

editProfileScreen(onBackPress = navController::popBackStack)
editProfileScreen(
onBackPress = navController::popBackStack,
getUri = { context, file ->
getUri(context, file)
},
)

faqScreen(
navigateBack = { navController.popBackStack() }
Expand Down Expand Up @@ -289,4 +297,12 @@ fun Context.openPassCodeActivity(deepLinkURI: Uri) {
Pair(PassCodeConstants.PASSCODE_INITIAL_LOGIN, true)
),
)
}

fun getUri(context: Context, file: File): Uri {
val uri = FileProvider.getUriForFile(
Objects.requireNonNull(context),
org.mifospay.BuildConfig.APPLICATION_ID + ".provider", file
)
return uri
}

0 comments on commit c71b4ee

Please sign in to comment.