diff --git a/feature/settings/src/main/java/com/mifos/feature/settings/navigation/SettingsNavigation.kt b/feature/settings/src/main/java/com/mifos/feature/settings/navigation/SettingsNavigation.kt index 26bfb012ce..e8d566b988 100644 --- a/feature/settings/src/main/java/com/mifos/feature/settings/navigation/SettingsNavigation.kt +++ b/feature/settings/src/main/java/com/mifos/feature/settings/navigation/SettingsNavigation.kt @@ -4,30 +4,25 @@ import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.compose.composable import com.mifos.feature.settings.settings.SettingsScreen +import com.mifos.feature.settings.updateServer.UpdateServerConfigScreenRoute /** * Created by Pronay Sarker on 10/08/2024 (7:52 AM) */ -const val SETTINGS_SCREEN_ROUTE = "settings_screen_route" - -fun NavController.navigateToSettingsScreen() { - this.navigate(SETTINGS_SCREEN_ROUTE) -} - fun NavGraphBuilder.settingsScreen( navigateBack: () -> Unit, navigateToLoginScreen: () -> Unit, changePasscode: (String) -> Unit, languageChanged: () -> Unit, - serverConfig: () -> Unit ) { - composable(SETTINGS_SCREEN_ROUTE) { + composable( + route = SettingsScreens.SettingsScreen.route + ) { SettingsScreen( onBackPressed = navigateBack, navigateToLoginScreen = navigateToLoginScreen, languageChanged = languageChanged, - serverConfig = serverConfig, - changePasscode = { } + changePasscode = changePasscode ) } } \ No newline at end of file diff --git a/feature/settings/src/main/java/com/mifos/feature/settings/navigation/SettingsScreens.kt b/feature/settings/src/main/java/com/mifos/feature/settings/navigation/SettingsScreens.kt new file mode 100644 index 0000000000..142e619e75 --- /dev/null +++ b/feature/settings/src/main/java/com/mifos/feature/settings/navigation/SettingsScreens.kt @@ -0,0 +1,8 @@ +package com.mifos.feature.settings.navigation + +/** + * Created by Pronay Sarker on 22/08/2024 (4:31 PM) + */ +sealed class SettingsScreens(val route: String) { + data object SettingsScreen : SettingsScreens("settings_screen") +} \ No newline at end of file diff --git a/feature/settings/src/main/java/com/mifos/feature/settings/settings/SettingsScreen.kt b/feature/settings/src/main/java/com/mifos/feature/settings/settings/SettingsScreen.kt index e7946b0659..b6562dd7b6 100644 --- a/feature/settings/src/main/java/com/mifos/feature/settings/settings/SettingsScreen.kt +++ b/feature/settings/src/main/java/com/mifos/feature/settings/settings/SettingsScreen.kt @@ -1,9 +1,15 @@ package com.mifos.feature.settings.settings +import android.content.ComponentName import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.os.CountDownTimer +import android.widget.Toast import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn @@ -11,10 +17,13 @@ import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text +import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -25,11 +34,13 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.platform.LocalAutofill import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringArrayResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.core.content.ContentProviderCompat.requireContext import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.mifos.core.common.enums.MifosAppLanguage @@ -40,6 +51,7 @@ import com.mifos.core.designsystem.component.UpdateEndpointDialogScreen import com.mifos.core.designsystem.icon.MifosIcons import com.mifos.feature.settings.R import com.mifos.feature.settings.syncSurvey.SyncSurveysDialog +import com.mifos.feature.settings.updateServer.UpdateServerConfigScreenRoute import java.util.Locale @Composable @@ -48,7 +60,6 @@ fun SettingsScreen( navigateToLoginScreen: () -> Unit, changePasscode: (String) -> Unit, languageChanged: () -> Unit, - serverConfig: () -> Unit ) { val viewModel: SettingsViewModel = hiltViewModel() val baseURL by viewModel.baseUrl.collectAsStateWithLifecycle() @@ -82,11 +93,11 @@ fun SettingsScreen( ) languageChanged() }, - serverConfig = serverConfig ) } +@OptIn(ExperimentalMaterial3Api::class) @Composable fun SettingsScreen( onBackPressed: () -> Unit, @@ -98,7 +109,6 @@ fun SettingsScreen( handleEndpointUpdate: (baseURL: String, tenant: String) -> Unit, updateTheme: (theme: AppTheme) -> Unit, updateLanguage: (language: MifosAppLanguage) -> Unit, - serverConfig: () -> Unit ) { val snackbarHostState = remember { SnackbarHostState() } @@ -106,6 +116,10 @@ fun SettingsScreen( var showEndpointUpdateDialog by rememberSaveable { mutableStateOf(false) } var showThemeUpdateDialog by rememberSaveable { mutableStateOf(false) } var showSyncSurveyDialog by rememberSaveable { mutableStateOf(false) } + var showServerConfig by rememberSaveable { mutableStateOf(false) } + + val sheetState = rememberModalBottomSheetState() + val context = LocalContext.current MifosScaffold( icon = MifosIcons.arrowBack, @@ -129,17 +143,14 @@ fun SettingsScreen( SettingsCardItem.ENDPOINT -> showEndpointUpdateDialog = true - SettingsCardItem.SERVER_CONFIG -> { - serverConfig() - - } + SettingsCardItem.SERVER_CONFIG -> showServerConfig = true } } ) } } - if( showSyncSurveyDialog ) { + if (showSyncSurveyDialog) { SyncSurveysDialog( closeDialog = { showSyncSurveyDialog = false @@ -147,6 +158,21 @@ fun SettingsScreen( ) } + if (showServerConfig) { + ModalBottomSheet( + onDismissRequest = { showServerConfig = false }, + sheetState = sheetState, + ) { + UpdateServerConfigScreenRoute( + onCloseClick = { showServerConfig = false }, + onSuccessful = { + showServerConfig = false + showRestartCountdownToast(context, 2) + } + ) + } + } + if (showLanguageUpdateDialog) { MifosRadioButtonDialog( titleResId = R.string.feature_settings_choose_language, @@ -254,6 +280,33 @@ fun updateLanguageLocale(context: Context, language: String, isSystemLanguage: B } } +private fun showRestartCountdownToast(context: Context, seconds: Int) { + val countDownTimer = object : CountDownTimer((seconds * 1000).toLong(), 1000) { + override fun onTick(millisUntilFinished: Long) { + val secondsRemaining = millisUntilFinished / 1000 + Toast.makeText( + context, + "Restarting app in $secondsRemaining seconds", + Toast.LENGTH_SHORT + ).show() + } + + override fun onFinish() { + context.restartApplication() + } + } + countDownTimer.start() +} + +fun Context.restartApplication() { + val packageManager: PackageManager = this.packageManager + val intent: Intent = packageManager.getLaunchIntentForPackage(this.packageName)!! + val componentName: ComponentName = intent.component!! + val restartIntent: Intent = Intent.makeRestartActivityTask(componentName) + this.startActivity(restartIntent) + Runtime.getRuntime().exit(0) +} + @Composable @Preview(showSystemUi = true, showBackground = true) fun PreviewSettingsScreen() { @@ -267,7 +320,6 @@ fun PreviewSettingsScreen() { updateLanguage = {}, updateTheme = {}, changePasscode = {}, - serverConfig = {} ) } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt index 684870862a..1f8e94a0fb 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt @@ -17,7 +17,7 @@ import com.mifos.feature.checker_inbox_task.navigation.CheckerInboxTaskScreens import com.mifos.feature.groups.navigation.GroupScreen import com.mifos.feature.path_tracking.navigation.PathTrackingScreens import com.mifos.feature.search.navigation.SearchScreens -import com.mifos.feature.settings.navigation.SETTINGS_SCREEN_ROUTE +import com.mifos.feature.settings.navigation.SettingsScreens sealed class HomeDestinationsScreen( val title: String = "", @@ -80,7 +80,7 @@ sealed class HomeDestinationsScreen( data object SettingsScreen : HomeDestinationsScreen( title = "Settings", - route = SETTINGS_SCREEN_ROUTE, + route = SettingsScreens.SettingsScreen.route, icon = Icons.Rounded.Settings ) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/SettingsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/SettingsFragment.kt index de544c9c48..1ec743f40c 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/SettingsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/SettingsFragment.kt @@ -55,9 +55,9 @@ class SettingsFragment : Fragment() { startActivity(intent) activity?.finish() }, - serverConfig = { - findNavController().navigate(R.id.updateServerConfigFragment) - } +// serverConfig = { +// findNavController().navigate(R.id.updateServerConfigFragment) +// } ) } } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/UpdateServerConfigFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/UpdateServerConfigFragment.kt index d1bcfb05b2..6e57347abb 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/UpdateServerConfigFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/UpdateServerConfigFragment.kt @@ -39,7 +39,7 @@ class UpdateServerConfigFragment : BottomSheetDialogFragment() { onSuccessful = { this@UpdateServerConfigFragment.dismiss() - showRestartCountdownToast(requireContext(), 2) +// showRestartCountdownToast(requireContext(), 2) } ) } @@ -47,29 +47,3 @@ class UpdateServerConfigFragment : BottomSheetDialogFragment() { } } -private fun showRestartCountdownToast(context: Context, seconds: Int) { - val countDownTimer = object : CountDownTimer((seconds * 1000).toLong(), 1000) { - override fun onTick(millisUntilFinished: Long) { - val secondsRemaining = millisUntilFinished / 1000 - Toast.makeText( - context, - "Restarting app in $secondsRemaining seconds", - Toast.LENGTH_SHORT - ).show() - } - - override fun onFinish() { - context.restartApplication() - } - } - countDownTimer.start() -} - -fun Context.restartApplication() { - val packageManager: PackageManager = this.packageManager - val intent: Intent = packageManager.getLaunchIntentForPackage(this.packageName)!! - val componentName: ComponentName = intent.component!! - val restartIntent: Intent = Intent.makeRestartActivityTask(componentName) - this.startActivity(restartIntent) - Runtime.getRuntime().exit(0) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt index 5dc1885bb8..392db004b5 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt @@ -177,11 +177,10 @@ fun Navigation( ) settingsScreen( - navigateBack = { navController.popBackStack() }, + navigateBack = navController::popBackStack, navigateToLoginScreen = {}, changePasscode = {}, languageChanged = { }, - serverConfig = {} ) aboutScreen(