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.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
|
||||||
@ -31,9 +30,17 @@ import android.widget.RelativeLayout
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
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.Composable
|
import androidx.compose.runtime.Composable
|
||||||
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
|
||||||
@ -179,12 +186,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
|
||||||
@ -316,8 +317,6 @@ class ReaderActivity : BaseActivity() {
|
|||||||
config = null
|
config = null
|
||||||
menuToggleToast?.cancel()
|
menuToggleToast?.cancel()
|
||||||
readingModeToast?.cancel()
|
readingModeToast?.cancel()
|
||||||
progressDialog?.dismiss()
|
|
||||||
progressDialog = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -533,6 +532,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(
|
||||||
@ -543,15 +557,17 @@ 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,
|
||||||
onShareCombined = viewModel::shareImages,
|
onSave = viewModel::saveImage,
|
||||||
onSaveCombined = viewModel::saveImages,
|
onShareCombined = viewModel::shareImages,
|
||||||
hasExtraPage = (state.dialog as? ReaderViewModel.Dialog.Page)?.extraPage != null,
|
onSaveCombined = viewModel::saveImages,
|
||||||
)
|
hasExtraPage = (state.dialog as? ReaderViewModel.Dialog.PageActions)?.extraPage != null,
|
||||||
|
)
|
||||||
|
}
|
||||||
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
|
* [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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,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,
|
||||||
// SY -->
|
// SY -->
|
||||||
onSetAsCover: (useExtraPage: Boolean) -> Unit,
|
onSetAsCover: (useExtraPage: Boolean) -> Unit,
|
@ -862,8 +862,12 @@ class ReaderViewModel(
|
|||||||
) + filenameSuffix
|
) + filenameSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showLoadingDialog() {
|
||||||
|
mutableState.update { it.copy(dialog = Dialog.Loading) }
|
||||||
|
}
|
||||||
|
|
||||||
fun openPageDialog(page: ReaderPage/* SY --> */, extraPage: ReaderPage? = null/* SY <-- */) {
|
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() {
|
fun openColorFilterDialog() {
|
||||||
@ -881,9 +885,9 @@ class ReaderViewModel(
|
|||||||
fun saveImage(useExtraPage: Boolean) {
|
fun saveImage(useExtraPage: Boolean) {
|
||||||
// SY -->
|
// SY -->
|
||||||
val page = if (useExtraPage) {
|
val page = if (useExtraPage) {
|
||||||
(state.value.dialog as? Dialog.Page)?.extraPage
|
(state.value.dialog as? Dialog.PageActions)?.extraPage
|
||||||
} else {
|
} else {
|
||||||
(state.value.dialog as? Dialog.Page)?.page
|
(state.value.dialog as? Dialog.PageActions)?.page
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
if (page?.status != Page.State.READY) return
|
if (page?.status != Page.State.READY) return
|
||||||
@ -921,7 +925,7 @@ class ReaderViewModel(
|
|||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
fun saveImages() {
|
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 viewer = state.value.viewer as? PagerViewer ?: return
|
||||||
val isLTR = (viewer !is R2LPagerViewer) xor (viewer.config.invertDoublePages)
|
val isLTR = (viewer !is R2LPagerViewer) xor (viewer.config.invertDoublePages)
|
||||||
val bg = viewer.config.pageCanvasColor
|
val bg = viewer.config.pageCanvasColor
|
||||||
@ -1000,9 +1004,9 @@ class ReaderViewModel(
|
|||||||
fun shareImage(useExtraPage: Boolean) {
|
fun shareImage(useExtraPage: Boolean) {
|
||||||
// SY -->
|
// SY -->
|
||||||
val page = if (useExtraPage) {
|
val page = if (useExtraPage) {
|
||||||
(state.value.dialog as? Dialog.Page)?.extraPage
|
(state.value.dialog as? Dialog.PageActions)?.extraPage
|
||||||
} else {
|
} else {
|
||||||
(state.value.dialog as? Dialog.Page)?.page
|
(state.value.dialog as? Dialog.PageActions)?.page
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
if (page?.status != Page.State.READY) return
|
if (page?.status != Page.State.READY) return
|
||||||
@ -1032,7 +1036,7 @@ class ReaderViewModel(
|
|||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
fun shareImages() {
|
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 viewer = state.value.viewer as? PagerViewer ?: return
|
||||||
val isLTR = (viewer !is R2LPagerViewer) xor (viewer.config.invertDoublePages)
|
val isLTR = (viewer !is R2LPagerViewer) xor (viewer.config.invertDoublePages)
|
||||||
val bg = viewer.config.pageCanvasColor
|
val bg = viewer.config.pageCanvasColor
|
||||||
@ -1069,9 +1073,9 @@ class ReaderViewModel(
|
|||||||
fun setAsCover(useExtraPage: Boolean) {
|
fun setAsCover(useExtraPage: Boolean) {
|
||||||
// SY -->
|
// SY -->
|
||||||
val page = if (useExtraPage) {
|
val page = if (useExtraPage) {
|
||||||
(state.value.dialog as? Dialog.Page)?.extraPage
|
(state.value.dialog as? Dialog.PageActions)?.extraPage
|
||||||
} else {
|
} else {
|
||||||
(state.value.dialog as? Dialog.Page)?.page
|
(state.value.dialog as? Dialog.PageActions)?.page
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
if (page?.status != Page.State.READY) return
|
if (page?.status != Page.State.READY) return
|
||||||
@ -1207,8 +1211,9 @@ class ReaderViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
sealed class Dialog {
|
sealed class Dialog {
|
||||||
|
object Loading : Dialog()
|
||||||
object ColorFilter : 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 {
|
sealed class Event {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user