Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #994 from code-a1/develop
Browse files Browse the repository at this point in the history
Added the "Switch to offline mode" feature
  • Loading branch information
ILIYANGERMANOV authored Jun 3, 2022
2 parents b5378de + 847803c commit 5ff2097
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ivy.frp.view.navigation.Navigation
import com.ivy.wallet.io.network.IvySession
import com.ivy.wallet.io.persistence.IvyRoomDatabase
import com.ivy.wallet.io.persistence.SharedPrefs
import com.ivy.wallet.ui.Main
import com.ivy.wallet.ui.Onboarding
import com.ivy.wallet.utils.ioThread

Expand All @@ -24,4 +25,12 @@ class LogoutLogic(
navigation.navigateTo(Onboarding)
navigation.resetBackStack()
}

suspend fun cloudLogout() {
ioThread {
ivySession.logout()
}

navigation.navigateTo(Main);
}
}
35 changes: 33 additions & 2 deletions app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ fun BoxWithConstraintsScope.SettingsScreen(screen: Settings) {
body = body
)
},
onDeleteAllUserData = viewModel::deleteAllUserData
onDeleteAllUserData = viewModel::deleteAllUserData,
onDeleteCloudUserData = viewModel::deleteCloudUserData
)
}

Expand Down Expand Up @@ -148,12 +149,15 @@ private fun BoxWithConstraintsScope.UI(
onSetHideCurrentBalance: (Boolean) -> Unit = {},
onSetStartDateOfMonth: (Int) -> Unit = {},
onRequestFeature: (String, String) -> Unit = { _, _ -> },
onDeleteAllUserData: () -> Unit = {}
onDeleteAllUserData: () -> Unit = {},
onDeleteCloudUserData: () -> Unit = {},

) {
var currencyModalVisible by remember { mutableStateOf(false) }
var nameModalVisible by remember { mutableStateOf(false) }
var chooseStartDateOfMonthVisible by remember { mutableStateOf(false) }
var requestFeatureModalVisible by remember { mutableStateOf(false) }
var deleteCloudDataModalVisible by remember { mutableStateOf(false) }
var deleteAllDataModalVisible by remember { mutableStateOf(false) }
var deleteAllDataModalFinalVisible by remember { mutableStateOf(false) }

Expand Down Expand Up @@ -394,6 +398,18 @@ private fun BoxWithConstraintsScope.UI(
) {
deleteAllDataModalVisible = true
}

if(user != null){
Spacer(Modifier.height(16.dp))

SettingsPrimaryButton(
icon = R.drawable.ic_categories,
text = stringResource(R.string.switch_to_offline_mode),
backgroundGradient = Gradient.solid(Red)
) {
deleteCloudDataModalVisible = true
}
}
}

item {
Expand Down Expand Up @@ -463,6 +479,21 @@ private fun BoxWithConstraintsScope.UI(
}
)

DeleteModal(
title = stringResource(R.string.delete_all_cloud_data_question),
description = stringResource(
R.string.delete_all_user_cloud_data_warning, user?.email ?: stringResource(
R.string.your_account
)
),
visible = deleteCloudDataModalVisible,
dismiss = { deleteCloudDataModalVisible = false },
onDelete = {
onDeleteCloudUserData()
deleteCloudDataModalVisible = false
}
)

ProgressModal(
title = stringResource(R.string.exporting_data),
description = stringResource(R.string.exporting_data_description),
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ class SettingsViewModel @Inject constructor(
}
}

fun cloudLogout() {
viewModelScope.launch {
TestIdlingResource.increment()

logoutLogic.cloudLogout()

TestIdlingResource.decrement()
}
}

fun login() {
ivyContext.googleSignIn { idToken ->
if (idToken != null) {
Expand Down Expand Up @@ -375,4 +385,15 @@ class SettingsViewModel @Inject constructor(
logout()
}
}

fun deleteCloudUserData() {
viewModelScope.launch {
try {
restClient.nukeService.deleteAllUserData()
} catch (e: Exception) {
e.printStackTrace()
}
cloudLogout()
}
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@
<string name="skip_all">تخطي الكل</string>
<string name="confirm_skip_all">تأكيد تخطي الكل</string>
<string name="confirm_skip_all_description">هل أنت متأكد من أنك تريد تخطي جميع المعاملات المخطط لها المتأخرة؟</string>
<string name="switch_to_offline_mode">Switch to offline mode</string>
<string name="delete_all_user_cloud_data_warning">WARNING! This action will delete all your cloud-stored data for %1$s PERMANENTLY, the offline data stored in your local app will remain.</string>
<string name="delete_all_cloud_data_question">Delete all cloud-stored data?</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@
<string name="skip_all">прескочете всички</string>
<string name="confirm_skip_all">Потвърдете пропускането на всички</string>
<string name="confirm_skip_all_description">Сигурни ли сте, че искате да пропуснете всички просрочени планирани операции?</string>
<string name="switch_to_offline_mode">Switch to offline mode</string>
<string name="delete_all_user_cloud_data_warning">WARNING! This action will delete all your cloud-stored data for %1$s PERMANENTLY, the offline data stored in your local app will remain.</string>
<string name="delete_all_cloud_data_question">Delete all cloud-stored data?</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@
<string name="skip_all">Saltar todo</string>
<string name="confirm_skip_all">Confirmar saltar todo</string>
<string name="confirm_skip_all_description">¿Está seguro de saltar todas las transacciones planeadas caducadas?</string>
<string name="switch_to_offline_mode">Switch to offline mode</string>
<string name="delete_all_user_cloud_data_warning">WARNING! This action will delete all your cloud-stored data for %1$s PERMANENTLY, the offline data stored in your local app will remain.</string>
<string name="delete_all_cloud_data_question">Delete all cloud-stored data?</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@
<string name="confirm_skip_all_description">Sei sicuro di voler ignorare tutti i pagamenti pianificati scaduti?</string>
<string name="confirm_skip_all">Conferma e ignora tutto</string>
<string name="skip_all">Ignora tutto</string>
<string name="switch_to_offline_mode">Switch to offline mode</string>
<string name="delete_all_user_cloud_data_warning">WARNING! This action will delete all cloud-stored data for %1$s PERMANENTLY, the offline data stored in your local app will remain.</string>
<string name="delete_all_cloud_data_question">Delete all cloud-stored data?</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@
<string name="skip_all">Пропустить все</string>
<string name="confirm_skip_all">Подтвердить пропуск всех</string>
<string name="confirm_skip_all_description">Вы уверены, что хотите пропустить все просроченные запланированные операции?</string>
<string name="switch_to_offline_mode">Switch to offline mode</string>
<string name="delete_all_user_cloud_data_warning">WARNING! This action will delete all your cloud-stored data for %1$s PERMANENTLY, the offline data stored in your local app will remain.</string>
<string name="delete_all_cloud_data_question">Delete all cloud-stored data?</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@
<string name="skip_all">Skip all</string>
<string name="confirm_skip_all">Confirm skip all</string>
<string name="confirm_skip_all_description">Are you sure that you want to skip all overdue planned payments?</string>
<string name="switch_to_offline_mode">Switch to offline mode</string>
<string name="delete_all_user_cloud_data_warning">WARNING! This action will delete all your cloud-stored data for %1$s PERMANENTLY, the offline data stored in your local app will remain.</string>
<string name="delete_all_cloud_data_question">Delete all cloud-stored data?</string>
</resources>

0 comments on commit 5ff2097

Please sign in to comment.