Skip to content

Commit

Permalink
fix(deps): update dependency dev.chrisbanes.compose:compose-bom to v2…
Browse files Browse the repository at this point in the history
…024.06.00-alpha01 (#60)

* feat(ui): Add restoring & syncing banner

* fix(deps): update dependency dev.chrisbanes.compose:compose-bom to v2024.06.00-alpha01

---------

Co-authored-by: Cuong-Tran <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
renovate[bot] and cuong-tran authored Jul 6, 2024
1 parent b53b099 commit d5cf010
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 4 deletions.
26 changes: 23 additions & 3 deletions app/src/main/java/eu/kanade/presentation/components/Banners.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ fun AppStateBanners(
downloadedOnlyMode: Boolean,
incognitoMode: Boolean,
indexing: Boolean,
// KMK -->
restoring: Boolean,
syncing: Boolean,
// KMK <--
modifier: Modifier = Modifier,
) {
val density = LocalDensity.current
Expand All @@ -71,12 +75,21 @@ fun AppStateBanners(
SubcomposeLayout(modifier = modifier) { constraints ->
val indexingPlaceable = subcompose(0) {
AnimatedVisibility(
visible = indexing,
// KMK -->
visible = indexing || restoring || syncing,
// KMK <--
enter = expandVertically(),
exit = shrinkVertically(),
) {
IndexingDownloadBanner(
modifier = Modifier.windowInsetsPadding(mainInsets),
// KMK -->
text = when {
syncing -> stringResource(MR.strings.syncing_library)
restoring -> stringResource(MR.strings.restoring_backup)
else -> stringResource(MR.strings.download_notifier_cache_renewal)
},
// KMK <--
)
}
}.fastMap { it.measure(constraints) }
Expand Down Expand Up @@ -155,7 +168,12 @@ private fun IncognitoModeBanner(modifier: Modifier = Modifier) {
}

@Composable
private fun IndexingDownloadBanner(modifier: Modifier = Modifier) {
private fun IndexingDownloadBanner(
modifier: Modifier = Modifier,
// KMK -->
text: String = stringResource(MR.strings.download_notifier_cache_renewal),
// KMK <--
) {
val density = LocalDensity.current
Row(
modifier = Modifier
Expand All @@ -173,7 +191,9 @@ private fun IndexingDownloadBanner(modifier: Modifier = Modifier) {
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = stringResource(MR.strings.download_notifier_cache_renewal),
// KMK -->
text = text,
// KMK <--
color = MaterialTheme.colorScheme.onSecondary,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.labelMedium,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ import logcat.LogPriority
import tachiyomi.core.common.i18n.stringResource
import tachiyomi.core.common.util.system.logcat
import tachiyomi.i18n.MR
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

class BackupRestoreJob(private val context: Context, workerParams: WorkerParameters) :
CoroutineWorker(context, workerParams) {

private val notifier = BackupNotifier(context)

// KMK -->
private val backupRestoreStatus: BackupRestoreStatus = Injekt.get()
// KMK <--

override suspend fun doWork(): Result {
val uri = inputData.getString(LOCATION_URI_KEY)?.toUri()
val options = inputData.getBooleanArray(OPTIONS_KEY)?.let { RestoreOptions.fromBooleanArray(it) }
Expand All @@ -36,6 +42,10 @@ class BackupRestoreJob(private val context: Context, workerParams: WorkerParamet
return Result.failure()
}

// KMK -->
backupRestoreStatus.start()
// KMK <--

val isSync = inputData.getBoolean(SYNC_KEY, false)

setForegroundSafely()
Expand All @@ -54,6 +64,9 @@ class BackupRestoreJob(private val context: Context, workerParams: WorkerParamet
}
} finally {
context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
// KMK -->
backupRestoreStatus.stop()
// KMK <--
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eu.kanade.tachiyomi.data.backup.restore

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.stateIn

class BackupRestoreStatus {
private val scope = CoroutineScope(Dispatchers.IO)

private val _isRunning = MutableStateFlow(false)

val isRunning = _isRunning
.debounce(1000L) // Don't notify if it finishes quickly enough
.stateIn(scope, SharingStarted.WhileSubscribed(), false)

suspend fun start() {
_isRunning.emit(true)
}

suspend fun stop() {
_isRunning.emit(false)
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters)

private val notifier = SyncNotifier(context)

// KMK -->
private val syncStatus: SyncStatus = Injekt.get()
// KMK <--

override suspend fun doWork(): Result {
if (tags.contains(TAG_AUTO)) {
// Find a running manual worker. If exists, try again later
Expand All @@ -37,6 +41,10 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters)
}
}

// KMK -->
syncStatus.start()
// KMK <--

setForegroundSafely()

return try {
Expand All @@ -48,6 +56,9 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters)
Result.success() // try again next time
} finally {
context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
// KMK -->
syncStatus.stop()
// KMK <--
}
}

Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncStatus.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eu.kanade.tachiyomi.data.sync

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.stateIn

class SyncStatus {
private val scope = CoroutineScope(Dispatchers.IO)

private val _isRunning = MutableStateFlow(false)

val isRunning = _isRunning
.debounce(1000L) // Don't notify if it finishes quickly enough
.stateIn(scope, SharingStarted.WhileSubscribed(), false)

suspend fun start() {
_isRunning.emit(true)
}

suspend fun stop() {
_isRunning.emit(false)
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import app.cash.sqldelight.driver.android.AndroidSqliteDriver
import eu.kanade.domain.track.store.DelayedTrackingStore
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.backup.restore.BackupRestoreStatus
import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.cache.PagePreviewCache
import eu.kanade.tachiyomi.data.download.DownloadCache
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.data.saver.ImageSaver
import eu.kanade.tachiyomi.data.sync.SyncStatus
import eu.kanade.tachiyomi.data.sync.service.GoogleDriveService
import eu.kanade.tachiyomi.data.track.TrackerManager
import eu.kanade.tachiyomi.extension.ExtensionManager
Expand Down Expand Up @@ -172,6 +174,11 @@ class AppModule(val app: Application) : InjektModule {
addSingletonFactory { PagePreviewCache(app) }
// SY <--

// KMK -->
addSingletonFactory { BackupRestoreStatus() }
addSingletonFactory { SyncStatus() }
// KMK <--

// Asynchronously init expensive components for a faster cold start
ContextCompat.getMainExecutor(app).execute {
get<NetworkHelper>()
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ import eu.kanade.presentation.more.settings.screen.data.RestoreBackupScreen
import eu.kanade.presentation.util.AssistContentScreen
import eu.kanade.presentation.util.DefaultNavigatorScreenTransition
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.data.backup.restore.BackupRestoreStatus
import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.coil.MangaCoverMetadata
import eu.kanade.tachiyomi.data.download.DownloadCache
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.sync.SyncStatus
import eu.kanade.tachiyomi.data.updater.AppUpdateChecker
import eu.kanade.tachiyomi.extension.api.ExtensionApi
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
Expand Down Expand Up @@ -122,6 +124,11 @@ class MainActivity : BaseActivity() {
private val unsortedPreferences: UnsortedPreferences by injectLazy()
// SY <--

// KMK -->
private val backupRestoreStatus: BackupRestoreStatus by injectLazy()
private val syncStatus: SyncStatus by injectLazy()
// KMK <--

private val downloadCache: DownloadCache by injectLazy()
private val chapterCache: ChapterCache by injectLazy()

Expand Down Expand Up @@ -189,6 +196,10 @@ class MainActivity : BaseActivity() {
val incognito by preferences.incognitoMode().collectAsState()
val downloadOnly by preferences.downloadedOnly().collectAsState()
val indexing by downloadCache.isInitializing.collectAsState()
// KMK -->
val syncing by syncStatus.isRunning.collectAsState()
val restoring by backupRestoreStatus.isRunning.collectAsState()
// KMK <--

// Set status bar color considering the top app state banner
val systemUiController = rememberSystemUiController()
Expand Down Expand Up @@ -260,6 +271,10 @@ class MainActivity : BaseActivity() {
downloadedOnlyMode = downloadOnly,
incognitoMode = incognito,
indexing = indexing,
// KMK -->
restoring = restoring,
syncing = syncing,
// KMK <--
modifier = Modifier.windowInsetsPadding(scaffoldInsets),
)
},
Expand Down
4 changes: 3 additions & 1 deletion gradle/compose.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[versions]
compose-bom = "2024.05.00-alpha03"
compiler = "1.5.14"
# 2024.04.00-alpha01 & above has several bugs with the new animateItem() modifier
compose-bom = "2024.06.00-alpha01"
accompanist = "0.35.1-alpha"

[libraries]
Expand Down

0 comments on commit d5cf010

Please sign in to comment.