mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-21 14:01:51 +01:00
parent
0ac5f3b93c
commit
bae391c2c1
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user