Replace deprecated ProgressDialog

Fixes #8223
This commit is contained in:
arkon 2023-07-01 10:36:20 -04:00
parent 0ac5f3b93c
commit bae391c2c1
3 changed files with 45 additions and 26 deletions

View File

@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.annotation.TargetApi import android.annotation.TargetApi
import android.app.ProgressDialog
import android.app.assist.AssistContent import android.app.assist.AssistContent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -25,8 +24,16 @@ import android.view.animation.Animation
import android.view.animation.AnimationUtils import android.view.animation.AnimationUtils
import android.widget.Toast import android.widget.Toast
import androidx.activity.viewModels 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.collectAsState
import androidx.compose.runtime.getValue 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.graphics.ColorUtils
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.core.transition.doOnEnd import androidx.core.transition.doOnEnd
@ -128,12 +135,6 @@ class ReaderActivity : BaseActivity() {
*/ */
private var config: ReaderConfig? = null 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 menuToggleToast: Toast? = null
private var readingModeToast: Toast? = null private var readingModeToast: Toast? = null
@ -242,8 +243,6 @@ class ReaderActivity : BaseActivity() {
config = null config = null
menuToggleToast?.cancel() menuToggleToast?.cancel()
readingModeToast?.cancel() readingModeToast?.cancel()
progressDialog?.dismiss()
progressDialog = null
} }
/** /**
@ -412,6 +411,21 @@ class ReaderActivity : BaseActivity() {
val state by viewModel.state.collectAsState() val state by viewModel.state.collectAsState()
val onDismissRequest = viewModel::closeDialog val onDismissRequest = viewModel::closeDialog
when (state.dialog) { 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 -> { is ReaderViewModel.Dialog.ColorFilter -> {
setMenuVisibility(false) setMenuVisibility(false)
ReaderColorFilterDialog( ReaderColorFilterDialog(
@ -422,12 +436,14 @@ class ReaderActivity : BaseActivity() {
readerPreferences = viewModel.readerPreferences, readerPreferences = viewModel.readerPreferences,
) )
} }
is ReaderViewModel.Dialog.Page -> ReaderPageDialog( is ReaderViewModel.Dialog.PageActions -> {
onDismissRequest = onDismissRequest, ReaderPageActionsDialog(
onSetAsCover = viewModel::setAsCover, onDismissRequest = onDismissRequest,
onShare = viewModel::shareImage, onSetAsCover = viewModel::setAsCover,
onSave = viewModel::saveImage, onShare = viewModel::shareImage,
) onSave = viewModel::saveImage,
)
}
null -> {} null -> {}
} }
} }
@ -757,13 +773,11 @@ class ReaderActivity : BaseActivity() {
* [show]. This is only used when the next/previous buttons on the toolbar are clicked; the * [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. * other cases are handled with chapter transitions on the viewers and chapter preloading.
*/ */
@Suppress("DEPRECATION")
private fun setProgressDialog(show: Boolean) { private fun setProgressDialog(show: Boolean) {
progressDialog?.dismiss() if (show) {
progressDialog = if (show) { viewModel.showLoadingDialog()
ProgressDialog.show(this, null, getString(R.string.loading), true)
} else { } else {
null viewModel.closeDialog()
} }
} }

View File

@ -25,7 +25,7 @@ import tachiyomi.presentation.core.components.ActionButton
import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.components.material.padding
@Composable @Composable
fun ReaderPageDialog( fun ReaderPageActionsDialog(
onDismissRequest: () -> Unit, onDismissRequest: () -> Unit,
onSetAsCover: () -> Unit, onSetAsCover: () -> Unit,
onShare: () -> Unit, onShare: () -> Unit,

View File

@ -718,8 +718,12 @@ class ReaderViewModel(
) + filenameSuffix ) + filenameSuffix
} }
fun showLoadingDialog() {
mutableState.update { it.copy(dialog = Dialog.Loading) }
}
fun openPageDialog(page: ReaderPage) { fun openPageDialog(page: ReaderPage) {
mutableState.update { it.copy(dialog = Dialog.Page(page)) } mutableState.update { it.copy(dialog = Dialog.PageActions(page)) }
} }
fun openColorFilterDialog() { fun openColorFilterDialog() {
@ -735,7 +739,7 @@ class ReaderViewModel(
* There's also a notification to allow sharing the image somewhere else or deleting it. * There's also a notification to allow sharing the image somewhere else or deleting it.
*/ */
fun saveImage() { 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 if (page?.status != Page.State.READY) return
val manga = manga ?: 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. * image will be kept so it won't be taking lots of internal disk space.
*/ */
fun shareImage() { 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 if (page?.status != Page.State.READY) return
val manga = manga ?: 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. * Sets the image of the selected page as cover and notifies the UI of the result.
*/ */
fun setAsCover() { 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 if (page?.status != Page.State.READY) return
val manga = manga ?: return val manga = manga ?: return
val stream = page.stream ?: return val stream = page.stream ?: return
@ -928,8 +932,9 @@ class ReaderViewModel(
} }
sealed class Dialog { sealed class Dialog {
object Loading : Dialog()
object ColorFilter : Dialog() object ColorFilter : Dialog()
data class Page(val page: ReaderPage) : Dialog() data class PageActions(val page: ReaderPage) : Dialog()
} }
sealed class Event { sealed class Event {