diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index be65ddfdf..fb7203cc2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -22,7 +22,7 @@ import java.util.Locale import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values -fun Preference.asImmediateFlow(block: (value: T) -> Unit): Flow { +fun Preference.asImmediateFlow(block: (T) -> Unit): Flow { block(get()) return asFlow() .onEach { block(it) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 78ce1c78b..11576c697 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -43,6 +43,7 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchUI +import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.delay import kotlinx.coroutines.flow.launchIn import timber.log.Timber @@ -301,11 +302,8 @@ class MainActivity : BaseViewBindingActivity() { private suspend fun resetExitConfirmation() { isConfirmingExit = true - val toast = Toast.makeText(this, R.string.confirm_exit, Toast.LENGTH_LONG) - toast.show() - + val toast = toast(R.string.confirm_exit, Toast.LENGTH_LONG) delay(2000) - toast.cancel() isConfirmingExit = false } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 947d5b68d..48f286172 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -551,9 +551,8 @@ class ReaderActivity : BaseRxActivity() private fun showReadingModeToast(mode: Int) { val strings = resources.getStringArray(R.array.viewers_selector) readingModeToast?.cancel() - readingModeToast = Toast.makeText(this, strings[mode], Toast.LENGTH_SHORT).also { + readingModeToast = toast(strings[mode]) { it.setGravity(Gravity.CENTER_VERTICAL or Gravity.CENTER_HORIZONTAL, 0, 0) - it.show() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index de7c5b413..ed83778f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -42,8 +42,8 @@ import kotlin.math.roundToInt * @param resource the text resource. * @param duration the duration of the toast. Defaults to short. */ -fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT): Toast { - return Toast.makeText(this, resource, duration).also { it.show() } +fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast { + return toast(getString(resource), duration, block) } /** @@ -52,8 +52,11 @@ fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT): * @param text the text to display. * @param duration the duration of the toast. Defaults to short. */ -fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT): Toast { - return Toast.makeText(this, text.orEmpty(), duration).also { it.show() } +fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast { + return Toast.makeText(this, text.orEmpty(), duration).also { + block(it) + it.show() + } } /** diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7eb63a290..a6a73aa0c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -253,7 +253,7 @@ Fullscreen Show navigation layout overlay - Briefly show tap zones when reader is opened + Show tap zones when reader is opened Dual page split Invert dual page split placement If the placement of the dual page split doesn\'t match reading direction