Convert CookieSignInScene to use a suspend dialog
This commit is contained in:
1 parent
d30837665a
commit
681be33fed
3 files changed
+19
-60
No files matched your search
@@ -18,7 +18,6 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Cookie
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
@@ -57,6 +56,7 @@ import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.ui.widget.rememberDialogState
|
||||
import com.hippo.util.ExceptionUtils
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
|
||||
@@ -84,8 +84,8 @@ fun CookieSignInScene(windowSizeClass: WindowSizeClass) {
|
||||
|
||||
var signInJob by remember { mutableStateOf<Job?>(null) }
|
||||
|
||||
var showErrorDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var loginErrorException by remember { mutableStateOf<Throwable?>(null) }
|
||||
val dialogState = rememberDialogState()
|
||||
dialogState.Handler()
|
||||
|
||||
val noCookies = stringResource(R.string.from_clipboard_error)
|
||||
|
||||
@@ -134,8 +134,19 @@ fun CookieSignInScene(windowSizeClass: WindowSizeClass) {
|
||||
}
|
||||
}.onFailure {
|
||||
EhCookieStore.signOut()
|
||||
loginErrorException = it
|
||||
showErrorDialog = true
|
||||
dialogState.show(
|
||||
confirmText = R.string.get_it,
|
||||
title = R.string.sign_in_failed,
|
||||
text = {
|
||||
Text(
|
||||
text =
|
||||
"""
|
||||
${ExceptionUtils.getReadableString(it)}
|
||||
${stringResource(R.string.wrong_cookie_warning)}
|
||||
""".trimIndent(),
|
||||
)
|
||||
},
|
||||
)
|
||||
isProgressIndicatorVisible = false
|
||||
}
|
||||
}
|
||||
@@ -294,32 +305,6 @@ fun CookieSignInScene(windowSizeClass: WindowSizeClass) {
|
||||
if (isProgressIndicatorVisible) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
if (showErrorDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
showErrorDialog = false
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
showErrorDialog = false
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.get_it))
|
||||
}
|
||||
},
|
||||
title = {
|
||||
Text(text = stringResource(id = R.string.sign_in_failed))
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text =
|
||||
"""
|
||||
${ExceptionUtils.getReadableString(loginErrorException!!)}
|
||||
${stringResource(R.string.wrong_cookie_warning)}
|
||||
""".trimIndent(),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
WindowWidthSizeClass.Expanded -> Box(
|
||||
@@ -442,32 +427,6 @@ fun CookieSignInScene(windowSizeClass: WindowSizeClass) {
|
||||
if (isProgressIndicatorVisible) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
if (showErrorDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
showErrorDialog = false
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
showErrorDialog = false
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.get_it))
|
||||
}
|
||||
},
|
||||
title = {
|
||||
Text(text = stringResource(id = R.string.sign_in_failed))
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text =
|
||||
"""
|
||||
${ExceptionUtils.getReadableString(loginErrorException!!)}
|
||||
${stringResource(R.string.wrong_cookie_warning)}
|
||||
""".trimIndent(),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class HistoryScene : BaseScene() {
|
||||
val clear = dialogState.show(
|
||||
confirmText = R.string.clear_all,
|
||||
dismissText = android.R.string.cancel,
|
||||
text = R.string.clear_all_history,
|
||||
text = { Text(text = stringResource(id = R.string.clear_all_history)) },
|
||||
)
|
||||
if (clear) EhDB.clearHistoryInfo()
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class DialogState : DialogScope {
|
||||
@StringRes confirmText: Int? = null,
|
||||
@StringRes dismissText: Int? = null,
|
||||
@StringRes title: Int? = null,
|
||||
@StringRes text: Int? = null,
|
||||
text: (@Composable () -> Unit)? = null,
|
||||
): Boolean {
|
||||
return suspendCancellableCoroutine { cont ->
|
||||
cont.invokeOnCancellation { dismiss() }
|
||||
@@ -69,7 +69,7 @@ class DialogState : DialogScope {
|
||||
}
|
||||
},
|
||||
title = title?.let { { Text(text = stringResource(id = title)) } },
|
||||
text = text?.let { { Text(text = stringResource(id = text)) } },
|
||||
text = text,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user