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

Add monthly backup reminder #1280

Merged
merged 6 commits into from
Nov 12, 2024
Merged

Conversation

yevhen1sec
Copy link
Collaborator

Fixes #1266

@yevhen1sec yevhen1sec requested a review from yvebe October 31, 2024 18:52
@yevhen1sec yevhen1sec marked this pull request as draft October 31, 2024 18:52
@yevhen1sec yevhen1sec marked this pull request as ready for review November 8, 2024 19:52
navigator.navigate(Destination.BackupPassword(vaultId!!))
}
}

fun dismissBackupReminder() = viewModelScope.launch {
uiState.update { it.copy(showMonthlyBackupReminder = false) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update is not a suspend method, so it doesn't need to be inside of launch

@@ -201,8 +216,17 @@ internal class VaultAccountsViewModel @Inject constructor(
@Suppress("ReplaceNotNullAssertionWithElvisReturn")
fun backupVault() {
viewModelScope.launch {
uiState.update { it.copy(showMonthlyBackupReminder = false) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest reusing dismissBackupReminder() method for all of the code which hides reminder (after launch will be removed from dismiss)

@@ -61,6 +64,8 @@ internal class VaultAccountsViewModel @Inject constructor(
private val vaultDataStoreRepository: VaultDataStoreRepository,
private val accountsRepository: AccountsRepository,
private val balanceVisibilityRepository: BalanceVisibilityRepository,
private val getGlobalBackupReminderStatus: GetGlobalBackupReminderStatus,
private val neverShowGlobalBackupReminder: NeverShowGlobalBackupReminder,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private val neverShowGlobalBackupReminder: NeverShowGlobalBackupReminder,
private val setNeverShowGlobalBackupReminder: NeverShowGlobalBackupReminder,

actions require imperative names

onDismiss: () -> Unit,
onBackup: () -> Unit,
onDoNotRemind: () -> Unit,
){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
){
) {

👾


object VultiDate {
fun getEpochMonth(): Int {
val localDate = java.time.LocalDate.now()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use kotlinx.datetime

object VultiDate {
fun getEpochMonth(): Int {
val localDate = java.time.LocalDate.now()
return localDate.minusYears(1970).year * 12 + localDate.monthValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is rather weird, look into kotlinx.datetime

import kotlinx.coroutines.flow.first
import javax.inject.Inject

interface GetGlobalBackupReminderStatus : suspend () -> Boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status, which is boolean, is not really informative about what that status means. if you use boolean as return, prefer to name a check somehow e.g. IsGlobalBackupReminderRequired (UseCase)
also, do not forget to postfix that with UseCase

Comment on lines 16 to 32
when (shownMonth) {
0 -> {
vaultDataStoreRepository.setGlobalBackupReminderStatus(currentEpochMonth)
return true
}
-1 -> {
return false
}
currentEpochMonth -> {
vaultDataStoreRepository.setGlobalBackupReminderStatus(currentEpochMonth)
return false
}
else -> {
vaultDataStoreRepository.setGlobalBackupReminderStatus(currentEpochMonth)
return true
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually do not understand what happens here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here logic that do 2 things

  • depends on record in ds should we show reminder
  • rewrite ds if needed

interface NeverShowGlobalBackupReminder : suspend () -> Unit

internal class NeverShowGlobalBackupReminderImpl @Inject constructor(
val vaultDataStoreRepository: VaultDataStoreRepository,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val vaultDataStoreRepository: VaultDataStoreRepository,
private val vaultDataStoreRepository: VaultDataStoreRepository,

val vaultDataStoreRepository: VaultDataStoreRepository,
) : NeverShowGlobalBackupReminder {
override suspend fun invoke() {
vaultDataStoreRepository.setGlobalBackupReminderStatus(-1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 is a magic constant

@yevhen1sec yevhen1sec requested a review from yvebe November 12, 2024 09:52
@yevhen1sec yevhen1sec merged commit 2895492 into main Nov 12, 2024
1 check passed
@yevhen1sec yevhen1sec deleted the enhancement/monthly-backup-reminder branch November 12, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ADD] monthly backup reminder
3 participants