Skip to content

Commit

Permalink
Merge branch 'release/3.3.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitletondor committed Dec 7, 2024
2 parents 1a4fc40 + c3469b1 commit 9c99cc5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Android/EasyBudget/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
compileSdk = 35
minSdk = 23
targetSdk = 35
versionCode = 161
versionName = "3.3.12"
versionCode = 162
versionName = "3.3.13"
vectorDrawables.useSupportLibrary = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import io.realm.kotlin.log.RealmLogger
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
Expand Down Expand Up @@ -416,60 +417,64 @@ class EasyBudget : Application(), Configuration.Provider {
val componentActivity = activity as? ComponentActivity ?: throw IllegalStateException("Activity is not a ComponentActivity")

componentActivity.lifecycleScope.launch(Dispatchers.IO) {
iab.iabStatusFlow.flatMapLatest { iabStatusFlow ->
when(iabStatusFlow) {
PremiumCheckStatus.INITIALIZING,
PremiumCheckStatus.CHECKING,
PremiumCheckStatus.ERROR,
PremiumCheckStatus.NOT_PREMIUM -> emptyFlow()
PremiumCheckStatus.LEGACY_PREMIUM,
PremiumCheckStatus.PREMIUM_SUBSCRIBED,
PremiumCheckStatus.PRO_SUBSCRIBED -> {
if (parameters.isBackupEnabled()) {
auth.state
.mapLatest { authState ->
when(authState) {
is AuthState.Authenticated -> {
fun backupDiffDays(lastBackupDate: Date?): Long? {
if (lastBackupDate == null) {
return null
iab.iabStatusFlow
.flatMapLatest { iabStatusFlow ->
when(iabStatusFlow) {
PremiumCheckStatus.INITIALIZING,
PremiumCheckStatus.CHECKING,
PremiumCheckStatus.ERROR,
PremiumCheckStatus.NOT_PREMIUM -> emptyFlow()
PremiumCheckStatus.LEGACY_PREMIUM,
PremiumCheckStatus.PREMIUM_SUBSCRIBED,
PremiumCheckStatus.PRO_SUBSCRIBED -> {
if (parameters.isBackupEnabled()) {
auth.state
.mapLatest { authState ->
when(authState) {
is AuthState.Authenticated -> {
fun backupDiffDays(lastBackupDate: Date?): Long? {
if (lastBackupDate == null) {
return null
}

val now = Date()
val diff = now.time - lastBackupDate.time
val diffInDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS)

return diffInDays
}

val now = Date()
val diff = now.time - lastBackupDate.time
val diffInDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS)

return diffInDays
}

val lastBackupDate = parameters.getLastBackupDate()
val backupDiffDaysValue = backupDiffDays(lastBackupDate)
if (backupDiffDaysValue != null && backupDiffDaysValue >= 14) {
try {
onBackupIsLate(backupDiffDaysValue)
} catch (e: Exception) {
if (e is CancellationException) throw e

Logger.error("Error while calling onBackupIsLate", e)
val lastBackupDate = parameters.getLastBackupDate()
val backupDiffDaysValue = backupDiffDays(lastBackupDate)
if (backupDiffDaysValue != null && backupDiffDaysValue >= 14) {
try {
onBackupIsLate(backupDiffDaysValue)
} catch (e: Exception) {
if (e is CancellationException) throw e

Logger.error("Error while calling onBackupIsLate", e)
}
} else {
Logger.warning("Backup is active but never happened")
}
} else {
Logger.warning("Backup is active but never happened")
}
is AuthState.NotAuthenticated -> {
Logger.warning("Backup is active but user is not authenticated", LateBackupWithUnauthUserException("Backup is active but user is not authenticated"))
}
is AuthState.Authenticating -> {
// No-op
}
}
is AuthState.NotAuthenticated -> {
Logger.warning("Backup is active but user is not authenticated", LateBackupWithUnauthUserException("Backup is active but user is not authenticated"))
}
is AuthState.Authenticating -> {
// No-op
}
}
}
} else {
Logger.debug("Backup is inactive")
emptyFlow()
}
} else {
Logger.debug("Backup is inactive")
emptyFlow()
}
}
}
}
.collectLatest {
// No-op
}
}
} catch (e: Exception) {
Expand Down

0 comments on commit 9c99cc5

Please sign in to comment.