Skip to content

Commit ad7d313

Browse files
committed
fix: clean queue on timed sheet dismiss and reapply critical navigation
1 parent 601f0b6 commit ad7d313

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

app/src/main/java/to/bitkit/ui/ContentView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fun ContentView(
409409
TimedSheetType.NOTIFICATIONS -> {
410410
BackgroundPaymentsIntroSheet(
411411
onContinue = {
412-
appViewModel.dismissTimedSheet(skipQueue = true)
412+
appViewModel.dismissTimedSheet()
413413
navController.navigate(Routes.BackgroundPaymentsSettings)
414414
settingsViewModel.setBgPaymentsIntroSeen(true)
415415
},
@@ -419,7 +419,7 @@ fun ContentView(
419419
TimedSheetType.QUICK_PAY -> {
420420
QuickPayIntroSheet(
421421
onContinue = {
422-
appViewModel.dismissTimedSheet(skipQueue = true)
422+
appViewModel.dismissTimedSheet()
423423
navController.navigate(Routes.QuickPaySettings)
424424
},
425425
)
@@ -432,7 +432,7 @@ fun ContentView(
432432
val intent =
433433
Intent(Intent.ACTION_VIEW, Env.STORING_BITCOINS_URL.toUri())
434434
context.startActivity(intent)
435-
appViewModel.dismissTimedSheet(skipQueue = true)
435+
appViewModel.dismissTimedSheet()
436436
}
437437
)
438438
}

app/src/main/java/to/bitkit/utils/timedsheets/TimedSheetManager.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,20 @@ class TimedSheetManager(private val scope: CoroutineScope) {
4242
checkJob = null
4343
}
4444

45-
fun dismissCurrentSheet(skipQueue: Boolean = false) {
45+
fun dismissCurrentSheet() {
46+
if (currentTimedSheet == null) return
47+
4648
scope.launch {
4749
currentTimedSheet?.onDismissed()
50+
_currentSheet.value = null
51+
currentTimedSheet = null
4852

49-
if (skipQueue) {
50-
Logger.debug("Clearing timed sheet queue", context = TAG)
51-
_currentSheet.value = null
52-
currentTimedSheet = null
53-
} else {
54-
checkAndShowNextSheet()
55-
}
53+
Logger.debug("Clearing timed sheet queue", context = TAG)
5654
}
5755
}
5856

5957
private suspend fun checkAndShowNextSheet() {
58+
Logger.debug("Registered sheets: ${registeredSheets.map { it.type.name }}")
6059
for (sheet in registeredSheets.toList()) {
6160
if (sheet.shouldShow()) {
6261
Logger.debug(

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import org.lightningdevkit.ldknode.Event
4848
import org.lightningdevkit.ldknode.PaymentId
4949
import org.lightningdevkit.ldknode.SpendableUtxo
5050
import org.lightningdevkit.ldknode.Txid
51+
import to.bitkit.BuildConfig
5152
import to.bitkit.R
5253
import to.bitkit.data.CacheStore
5354
import to.bitkit.data.SettingsStore
@@ -93,6 +94,7 @@ import to.bitkit.repositories.LightningRepo
9394
import to.bitkit.repositories.PreActivityMetadataRepo
9495
import to.bitkit.repositories.TransferRepo
9596
import to.bitkit.repositories.WalletRepo
97+
import to.bitkit.services.AppUpdaterService
9698
import to.bitkit.ui.Routes
9799
import to.bitkit.ui.components.Sheet
98100
import to.bitkit.ui.shared.toast.ToastEventBus
@@ -131,6 +133,7 @@ class AppViewModel @Inject constructor(
131133
private val activityRepo: ActivityRepo,
132134
private val preActivityMetadataRepo: PreActivityMetadataRepo,
133135
private val blocktankRepo: BlocktankRepo,
136+
private val appUpdaterService: AppUpdaterService,
134137
private val notifyPaymentReceivedHandler: NotifyPaymentReceivedHandler,
135138
private val cacheStore: CacheStore,
136139
private val transferRepo: TransferRepo,
@@ -238,15 +241,11 @@ class AppViewModel @Inject constructor(
238241
}
239242
}
240243
}
241-
242-
observeLdkNodeEvents()
243-
observeSendEvents()
244-
245244
viewModelScope.launch {
246-
walletRepo.balanceState.collect {
247-
checkTimedSheets()
248-
}
245+
checkCriticalAppUpdate()
249246
}
247+
observeLdkNodeEvents()
248+
observeSendEvents()
250249
}
251250

252251
private fun observeLdkNodeEvents() {
@@ -1805,8 +1804,31 @@ class AppViewModel @Inject constructor(
18051804

18061805
fun onLeftHome() = timedSheetManager.onHomeScreenExited()
18071806

1808-
fun dismissTimedSheet(skipQueue: Boolean = false) =
1809-
timedSheetManager.dismissCurrentSheet(skipQueue)
1807+
fun dismissTimedSheet() = timedSheetManager.dismissCurrentSheet()
1808+
1809+
private suspend fun checkCriticalAppUpdate() = withContext(bgDispatcher) {
1810+
delay(SCREEN_TRANSITION_DELAY_MS)
1811+
1812+
runCatching {
1813+
val androidReleaseInfo = appUpdaterService.getReleaseInfo().platforms.android
1814+
val currentBuildNumber = BuildConfig.VERSION_CODE
1815+
1816+
if (androidReleaseInfo.buildNumber <= currentBuildNumber) return@withContext
1817+
1818+
if (androidReleaseInfo.isCritical) {
1819+
mainScreenEffect(
1820+
MainScreenEffect.Navigate(
1821+
route = Routes.CriticalUpdate,
1822+
navOptions = navOptions {
1823+
popUpTo(0) { inclusive = true }
1824+
}
1825+
)
1826+
)
1827+
}
1828+
}.onFailure { e ->
1829+
Logger.warn("Failure fetching new releases", e = e, context = TAG)
1830+
}
1831+
}
18101832

18111833
companion object {
18121834
private const val TAG = "AppViewModel"

app/src/test/java/to/bitkit/utils/timedsheets/TimedSheetManagerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class TimedSheetManagerTest : BaseUnitTest() {
103103

104104
assertEquals(TimedSheetType.APP_UPDATE, sut.currentSheet.value)
105105

106-
sut.dismissCurrentSheet(skipQueue = true)
106+
sut.dismissCurrentSheet()
107107
testScope.advanceTimeBy(100)
108108

109109
assertNull(sut.currentSheet.value)
@@ -139,7 +139,7 @@ class TimedSheetManagerTest : BaseUnitTest() {
139139

140140
assertEquals(TimedSheetType.BACKUP, sut.currentSheet.value)
141141

142-
sut.dismissCurrentSheet(skipQueue = false)
142+
sut.dismissCurrentSheet()
143143
testScope.advanceTimeBy(100)
144144

145145
assertNull(sut.currentSheet.value)

0 commit comments

Comments
 (0)