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

Commit

Permalink
Implement option to delete all user data
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliyan Germanov committed Jan 3, 2022
1 parent b5338b3 commit badb0d0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/ivy/wallet/network/RestClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,5 @@ class RestClient private constructor(
retrofit.create(BankIntegrationsService::class.java)
}
val githubService: GithubService by lazy { retrofit.create(GithubService::class.java) }
val nukeService: NukeService by lazy { retrofit.create(NukeService::class.java) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.ivy.wallet.network.service

import retrofit2.http.POST

interface NukeService {
@POST("wallet/nuke/delete-all-user-data")
suspend fun deleteAllUserData()
}
57 changes: 49 additions & 8 deletions app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ import com.ivy.wallet.ui.theme.components.IvyButton
import com.ivy.wallet.ui.theme.components.IvyIcon
import com.ivy.wallet.ui.theme.components.IvySwitch
import com.ivy.wallet.ui.theme.components.IvyToolbar
import com.ivy.wallet.ui.theme.modal.ChooseStartDateOfMonthModal
import com.ivy.wallet.ui.theme.modal.CurrencyModal
import com.ivy.wallet.ui.theme.modal.NameModal
import com.ivy.wallet.ui.theme.modal.RequestFeatureModal
import com.ivy.wallet.ui.theme.modal.*
import java.util.*

@ExperimentalFoundationApi
Expand Down Expand Up @@ -93,7 +90,8 @@ fun BoxWithConstraintsScope.SettingsScreen(screen: Screen.Settings) {
title = title,
body = body
)
}
},
onDeleteAllUserData = viewModel::deleteAllUserData
)
}

Expand All @@ -119,12 +117,16 @@ private fun BoxWithConstraintsScope.UI(
onExportToCSV: () -> Unit = {},
onSetLockApp: (Boolean) -> Unit = {},
onSetStartDateOfMonth: (Int) -> Unit = {},
onRequestFeature: (String, String) -> Unit = { _, _ -> }
onRequestFeature: (String, String) -> Unit = { _, _ -> },
onDeleteAllUserData: () -> 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 deleteAllDataModalVisible by remember { mutableStateOf(false) }
var deleteAllDataModalFinalVisible by remember { mutableStateOf(false) }

LazyColumn(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -289,6 +291,23 @@ private fun BoxWithConstraintsScope.UI(
TCAndPrivacyPolicy()
}

item {
SettingsSectionDivider(
text = "Danger zone",
color = Red
)

Spacer(Modifier.height(16.dp))

SettingsPrimaryButton(
icon = R.drawable.ic_delete,
text = "Delete all user data",
backgroundGradient = Gradient.solid(Red)
) {
deleteAllDataModalVisible = true
}
}

item {
Spacer(modifier = Modifier.height(120.dp)) //last item spacer
}
Expand Down Expand Up @@ -326,6 +345,27 @@ private fun BoxWithConstraintsScope.UI(
},
onSubmit = onRequestFeature
)

DeleteModal(
title = "Delete all user data?",
description = "WARNING! This action will delete all data for ${user?.email ?: "your account"} PERMANENTLY and you won't be able to recover it.",
visible = deleteAllDataModalVisible,
dismiss = { deleteAllDataModalVisible = false },
onDelete = {
deleteAllDataModalVisible = false
deleteAllDataModalFinalVisible = true
}
)

DeleteModal(
title = "Confirm permanent deletion for '${user?.email ?: "all of your data"}'",
description = "FINAL WARNING! After clicking \"Delete\" your data will be gone forever.",
visible = deleteAllDataModalFinalVisible,
dismiss = { deleteAllDataModalFinalVisible = false },
onDelete = {
onDeleteAllUserData()
}
)
}

@Composable
Expand Down Expand Up @@ -946,15 +986,16 @@ private fun CurrencyButton(

@Composable
private fun SettingsSectionDivider(
text: String
text: String,
color: Color = Gray
) {
Spacer(Modifier.height(32.dp))

Text(
modifier = Modifier.padding(start = 32.dp),
text = text,
style = Typo.body2.style(
color = Gray,
color = color,
fontWeight = FontWeight.Bold
)
)
Expand Down
11 changes: 11 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 @@ -273,4 +273,15 @@ class SettingsViewModel @Inject constructor(
TestIdlingResource.decrement()
}
}

fun deleteAllUserData() {
viewModelScope.launch {
try {
restClient.nukeService.deleteAllUserData()
} catch (e: Exception) {
e.printStackTrace()
}
logout()
}
}
}

0 comments on commit badb0d0

Please sign in to comment.