From bae391c2c16899f5f3c04b833b1d0eb12d6b94df Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 1 Jul 2023 10:36:20 -0400 Subject: [PATCH] Replace deprecated ProgressDialog Fixes #8223 --- .../tachiyomi/ui/reader/ReaderActivity.kt | 54 ++++++++++++------- ...geDialog.kt => ReaderPageActionsDialog.kt} | 2 +- .../tachiyomi/ui/reader/ReaderViewModel.kt | 15 ++++-- 3 files changed, 45 insertions(+), 26 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/ui/reader/{ReaderPageDialog.kt => ReaderPageActionsDialog.kt} (99%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index e476f07b1f..696e19d028 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader import android.annotation.SuppressLint import android.annotation.TargetApi -import android.app.ProgressDialog import android.app.assist.AssistContent import android.content.Context import android.content.Intent @@ -25,8 +24,16 @@ import android.view.animation.Animation import android.view.animation.AnimationUtils import android.widget.Toast import androidx.activity.viewModels +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.Text import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp import androidx.core.graphics.ColorUtils import androidx.core.net.toUri import androidx.core.transition.doOnEnd @@ -128,12 +135,6 @@ class ReaderActivity : BaseActivity() { */ private var config: ReaderConfig? = null - /** - * Progress dialog used when switching chapters from the menu buttons. - */ - @Suppress("DEPRECATION") - private var progressDialog: ProgressDialog? = null - private var menuToggleToast: Toast? = null private var readingModeToast: Toast? = null @@ -242,8 +243,6 @@ class ReaderActivity : BaseActivity() { config = null menuToggleToast?.cancel() readingModeToast?.cancel() - progressDialog?.dismiss() - progressDialog = null } /** @@ -412,6 +411,21 @@ class ReaderActivity : BaseActivity() { val state by viewModel.state.collectAsState() val onDismissRequest = viewModel::closeDialog when (state.dialog) { + is ReaderViewModel.Dialog.Loading -> { + AlertDialog( + onDismissRequest = { /* Non dismissible */ }, + confirmButton = {}, + text = { + Row( + horizontalArrangement = Arrangement.spacedBy(16.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + CircularProgressIndicator() + Text(stringResource(R.string.loading)) + } + }, + ) + } is ReaderViewModel.Dialog.ColorFilter -> { setMenuVisibility(false) ReaderColorFilterDialog( @@ -422,12 +436,14 @@ class ReaderActivity : BaseActivity() { readerPreferences = viewModel.readerPreferences, ) } - is ReaderViewModel.Dialog.Page -> ReaderPageDialog( - onDismissRequest = onDismissRequest, - onSetAsCover = viewModel::setAsCover, - onShare = viewModel::shareImage, - onSave = viewModel::saveImage, - ) + is ReaderViewModel.Dialog.PageActions -> { + ReaderPageActionsDialog( + onDismissRequest = onDismissRequest, + onSetAsCover = viewModel::setAsCover, + onShare = viewModel::shareImage, + onSave = viewModel::saveImage, + ) + } null -> {} } } @@ -757,13 +773,11 @@ class ReaderActivity : BaseActivity() { * [show]. This is only used when the next/previous buttons on the toolbar are clicked; the * other cases are handled with chapter transitions on the viewers and chapter preloading. */ - @Suppress("DEPRECATION") private fun setProgressDialog(show: Boolean) { - progressDialog?.dismiss() - progressDialog = if (show) { - ProgressDialog.show(this, null, getString(R.string.loading), true) + if (show) { + viewModel.showLoadingDialog() } else { - null + viewModel.closeDialog() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageActionsDialog.kt similarity index 99% rename from app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageDialog.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageActionsDialog.kt index b3b07be2a3..486339ebae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageActionsDialog.kt @@ -25,7 +25,7 @@ import tachiyomi.presentation.core.components.ActionButton import tachiyomi.presentation.core.components.material.padding @Composable -fun ReaderPageDialog( +fun ReaderPageActionsDialog( onDismissRequest: () -> Unit, onSetAsCover: () -> Unit, onShare: () -> Unit, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index ec37fd9453..0c683cecf2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -718,8 +718,12 @@ class ReaderViewModel( ) + filenameSuffix } + fun showLoadingDialog() { + mutableState.update { it.copy(dialog = Dialog.Loading) } + } + fun openPageDialog(page: ReaderPage) { - mutableState.update { it.copy(dialog = Dialog.Page(page)) } + mutableState.update { it.copy(dialog = Dialog.PageActions(page)) } } fun openColorFilterDialog() { @@ -735,7 +739,7 @@ class ReaderViewModel( * There's also a notification to allow sharing the image somewhere else or deleting it. */ fun saveImage() { - val page = (state.value.dialog as? Dialog.Page)?.page + val page = (state.value.dialog as? Dialog.PageActions)?.page if (page?.status != Page.State.READY) return val manga = manga ?: return @@ -777,7 +781,7 @@ class ReaderViewModel( * image will be kept so it won't be taking lots of internal disk space. */ fun shareImage() { - val page = (state.value.dialog as? Dialog.Page)?.page + val page = (state.value.dialog as? Dialog.PageActions)?.page if (page?.status != Page.State.READY) return val manga = manga ?: return @@ -807,7 +811,7 @@ class ReaderViewModel( * Sets the image of the selected page as cover and notifies the UI of the result. */ fun setAsCover() { - val page = (state.value.dialog as? Dialog.Page)?.page + val page = (state.value.dialog as? Dialog.PageActions)?.page if (page?.status != Page.State.READY) return val manga = manga ?: return val stream = page.stream ?: return @@ -928,8 +932,9 @@ class ReaderViewModel( } sealed class Dialog { + object Loading : Dialog() object ColorFilter : Dialog() - data class Page(val page: ReaderPage) : Dialog() + data class PageActions(val page: ReaderPage) : Dialog() } sealed class Event {