Replace deprecated ProgressDialog
Fixes #8223 (cherry picked from commit bae391c2c16899f5f3c04b833b1d0eb12d6b94df) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt
This commit is contained in:
parent
0eee1f1c3b
commit
cdd05c0996
@ -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
|
||||
@ -31,9 +30,17 @@ import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
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.Composable
|
||||
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
|
||||
@ -179,12 +186,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
|
||||
@ -316,8 +317,6 @@ class ReaderActivity : BaseActivity() {
|
||||
config = null
|
||||
menuToggleToast?.cancel()
|
||||
readingModeToast?.cancel()
|
||||
progressDialog?.dismiss()
|
||||
progressDialog = null
|
||||
}
|
||||
|
||||
/**
|
||||
@ -533,6 +532,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(
|
||||
@ -543,15 +557,17 @@ class ReaderActivity : BaseActivity() {
|
||||
readerPreferences = viewModel.readerPreferences,
|
||||
)
|
||||
}
|
||||
is ReaderViewModel.Dialog.Page -> ReaderPageDialog(
|
||||
is ReaderViewModel.Dialog.PageActions -> {
|
||||
ReaderPageActionsDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
onSetAsCover = viewModel::setAsCover,
|
||||
onShare = viewModel::shareImage,
|
||||
onSave = viewModel::saveImage,
|
||||
onShareCombined = viewModel::shareImages,
|
||||
onSaveCombined = viewModel::saveImages,
|
||||
hasExtraPage = (state.dialog as? ReaderViewModel.Dialog.Page)?.extraPage != null,
|
||||
hasExtraPage = (state.dialog as? ReaderViewModel.Dialog.PageActions)?.extraPage != null,
|
||||
)
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
@ -1288,13 +1304,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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ import tachiyomi.presentation.core.components.ActionButton
|
||||
import tachiyomi.presentation.core.components.material.padding
|
||||
|
||||
@Composable
|
||||
fun ReaderPageDialog(
|
||||
fun ReaderPageActionsDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
// SY -->
|
||||
onSetAsCover: (useExtraPage: Boolean) -> Unit,
|
@ -862,8 +862,12 @@ class ReaderViewModel(
|
||||
) + filenameSuffix
|
||||
}
|
||||
|
||||
fun showLoadingDialog() {
|
||||
mutableState.update { it.copy(dialog = Dialog.Loading) }
|
||||
}
|
||||
|
||||
fun openPageDialog(page: ReaderPage/* SY --> */, extraPage: ReaderPage? = null/* SY <-- */) {
|
||||
mutableState.update { it.copy(dialog = Dialog.Page(page, extraPage)) }
|
||||
mutableState.update { it.copy(dialog = Dialog.PageActions(page, extraPage)) }
|
||||
}
|
||||
|
||||
fun openColorFilterDialog() {
|
||||
@ -881,9 +885,9 @@ class ReaderViewModel(
|
||||
fun saveImage(useExtraPage: Boolean) {
|
||||
// SY -->
|
||||
val page = if (useExtraPage) {
|
||||
(state.value.dialog as? Dialog.Page)?.extraPage
|
||||
(state.value.dialog as? Dialog.PageActions)?.extraPage
|
||||
} else {
|
||||
(state.value.dialog as? Dialog.Page)?.page
|
||||
(state.value.dialog as? Dialog.PageActions)?.page
|
||||
}
|
||||
// SY <--
|
||||
if (page?.status != Page.State.READY) return
|
||||
@ -921,7 +925,7 @@ class ReaderViewModel(
|
||||
|
||||
// SY -->
|
||||
fun saveImages() {
|
||||
val (firstPage, secondPage) = (state.value.dialog as? Dialog.Page ?: return)
|
||||
val (firstPage, secondPage) = (state.value.dialog as? Dialog.PageActions ?: return)
|
||||
val viewer = state.value.viewer as? PagerViewer ?: return
|
||||
val isLTR = (viewer !is R2LPagerViewer) xor (viewer.config.invertDoublePages)
|
||||
val bg = viewer.config.pageCanvasColor
|
||||
@ -1000,9 +1004,9 @@ class ReaderViewModel(
|
||||
fun shareImage(useExtraPage: Boolean) {
|
||||
// SY -->
|
||||
val page = if (useExtraPage) {
|
||||
(state.value.dialog as? Dialog.Page)?.extraPage
|
||||
(state.value.dialog as? Dialog.PageActions)?.extraPage
|
||||
} else {
|
||||
(state.value.dialog as? Dialog.Page)?.page
|
||||
(state.value.dialog as? Dialog.PageActions)?.page
|
||||
}
|
||||
// SY <--
|
||||
if (page?.status != Page.State.READY) return
|
||||
@ -1032,7 +1036,7 @@ class ReaderViewModel(
|
||||
|
||||
// SY -->
|
||||
fun shareImages() {
|
||||
val (firstPage, secondPage) = (state.value.dialog as? Dialog.Page ?: return)
|
||||
val (firstPage, secondPage) = (state.value.dialog as? Dialog.PageActions ?: return)
|
||||
val viewer = state.value.viewer as? PagerViewer ?: return
|
||||
val isLTR = (viewer !is R2LPagerViewer) xor (viewer.config.invertDoublePages)
|
||||
val bg = viewer.config.pageCanvasColor
|
||||
@ -1069,9 +1073,9 @@ class ReaderViewModel(
|
||||
fun setAsCover(useExtraPage: Boolean) {
|
||||
// SY -->
|
||||
val page = if (useExtraPage) {
|
||||
(state.value.dialog as? Dialog.Page)?.extraPage
|
||||
(state.value.dialog as? Dialog.PageActions)?.extraPage
|
||||
} else {
|
||||
(state.value.dialog as? Dialog.Page)?.page
|
||||
(state.value.dialog as? Dialog.PageActions)?.page
|
||||
}
|
||||
// SY <--
|
||||
if (page?.status != Page.State.READY) return
|
||||
@ -1207,8 +1211,9 @@ class ReaderViewModel(
|
||||
}
|
||||
|
||||
sealed class Dialog {
|
||||
object Loading : Dialog()
|
||||
object ColorFilter : Dialog()
|
||||
data class Page(val page: ReaderPage/* SY --> */, val extraPage: ReaderPage? = null /* SY <-- */) : Dialog()
|
||||
data class PageActions(val page: ReaderPage/* SY --> */, val extraPage: ReaderPage? = null /* SY <-- */) : Dialog()
|
||||
}
|
||||
|
||||
sealed class Event {
|
||||
|
Loading…
x
Reference in New Issue
Block a user