diff --git a/app/src/main/java/me/ash/reader/CrashHandler.kt b/app/src/main/java/me/ash/reader/CrashHandler.kt index fce71a2..73f05f6 100644 --- a/app/src/main/java/me/ash/reader/CrashHandler.kt +++ b/app/src/main/java/me/ash/reader/CrashHandler.kt @@ -3,7 +3,7 @@ package me.ash.reader import android.content.Context import android.os.Looper import android.util.Log -import android.widget.Toast +import me.ash.reader.ui.ext.showToastLong import java.lang.Thread.UncaughtExceptionHandler import kotlin.system.exitProcess @@ -13,10 +13,8 @@ class CrashHandler(private val context: Context) : UncaughtExceptionHandler { } override fun uncaughtException(p0: Thread, p1: Throwable) { - if (Looper.myLooper() == null) { - Looper.prepare() - } - Toast.makeText(context, p1.message, Toast.LENGTH_LONG).show() + Looper.myLooper() ?: Looper.prepare() + context.showToastLong(p1.message) Looper.loop() p1.printStackTrace() Log.e("RLog", "uncaughtException: ${p1.message}") diff --git a/app/src/main/java/me/ash/reader/ui/ext/ContextExt.kt b/app/src/main/java/me/ash/reader/ui/ext/ContextExt.kt index c2a12aa..1085a9a 100644 --- a/app/src/main/java/me/ash/reader/ui/ext/ContextExt.kt +++ b/app/src/main/java/me/ash/reader/ui/ext/ContextExt.kt @@ -3,6 +3,7 @@ package me.ash.reader.ui.ext import android.app.Activity import android.content.Context import android.content.ContextWrapper +import android.widget.Toast import me.ash.reader.data.entity.Version import me.ash.reader.data.entity.toVersion @@ -15,4 +16,16 @@ fun Context.findActivity(): Activity? = when (this) { fun Context.getCurrentVersion(): Version = packageManager .getPackageInfo(packageName, 0) .versionName - .toVersion() \ No newline at end of file + .toVersion() + +private var toast: Toast? = null + +fun Context.showToast(message: String?, duration: Int = Toast.LENGTH_SHORT) { + toast?.cancel() + toast = Toast.makeText(this, message, duration) + toast?.show() +} + +fun Context.showToastLong(message: String?) { + showToast(message, Toast.LENGTH_LONG) +} \ No newline at end of file diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/DeleteFeedDialog.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/DeleteFeedDialog.kt index 192ec41..bee258e 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/DeleteFeedDialog.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/DeleteFeedDialog.kt @@ -1,6 +1,5 @@ package me.ash.reader.ui.page.home.feeds.option.feed -import android.widget.Toast import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.DeleteForever import androidx.compose.material3.Icon @@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi import me.ash.reader.R import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.ext.collectAsStateValue +import me.ash.reader.ui.ext.showToast @OptIn(ExperimentalPagerApi::class) @Composable @@ -52,7 +52,7 @@ fun DeleteFeedDialog( viewModel.dispatch(FeedOptionViewAction.Delete { viewModel.dispatch(FeedOptionViewAction.HideDeleteDialog) viewModel.dispatch(FeedOptionViewAction.Hide(scope)) - Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() + context.showToast(toastString) }) } ) { diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionDrawer.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionDrawer.kt index 3931912..61ba69b 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionDrawer.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionDrawer.kt @@ -26,6 +26,7 @@ import me.ash.reader.ui.component.BottomDrawer import me.ash.reader.ui.component.TextFieldDialog import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.roundClick +import me.ash.reader.ui.ext.showToast import me.ash.reader.ui.page.home.feeds.subscribe.ResultView @OptIn(ExperimentalMaterialApi::class) @@ -139,7 +140,7 @@ fun FeedOptionDrawer( onConfirm = { feedOptionViewModel.dispatch(FeedOptionViewAction.Rename) feedOptionViewModel.dispatch(FeedOptionViewAction.Hide(scope)) - Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() + context.showToast(toastString) } ) } \ No newline at end of file diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllAllowNotificationDialog.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllAllowNotificationDialog.kt index 50757ac..4375629 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllAllowNotificationDialog.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllAllowNotificationDialog.kt @@ -1,6 +1,5 @@ package me.ash.reader.ui.page.home.feeds.option.group -import android.widget.Toast import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Notifications import androidx.compose.material3.Icon @@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi import me.ash.reader.R import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.ext.collectAsStateValue +import me.ash.reader.ui.ext.showToast @OptIn(ExperimentalPagerApi::class) @Composable @@ -53,7 +53,7 @@ fun AllAllowNotificationDialog( viewModel.dispatch(GroupOptionViewAction.AllAllowNotification(true) { viewModel.dispatch(GroupOptionViewAction.HideAllAllowNotificationDialog) viewModel.dispatch(GroupOptionViewAction.Hide(scope)) - Toast.makeText(context, allowToastString, Toast.LENGTH_SHORT).show() + context.showToast(allowToastString) }) } ) { @@ -68,7 +68,7 @@ fun AllAllowNotificationDialog( viewModel.dispatch(GroupOptionViewAction.AllAllowNotification(false) { viewModel.dispatch(GroupOptionViewAction.HideAllAllowNotificationDialog) viewModel.dispatch(GroupOptionViewAction.Hide(scope)) - Toast.makeText(context, denyToastString, Toast.LENGTH_SHORT).show() + context.showToast(denyToastString) }) } ) { diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllMoveToGroupDialog.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllMoveToGroupDialog.kt index b0027af..8898407 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllMoveToGroupDialog.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllMoveToGroupDialog.kt @@ -1,6 +1,5 @@ package me.ash.reader.ui.page.home.feeds.option.group -import android.widget.Toast import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.DriveFileMove import androidx.compose.material3.Icon @@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi import me.ash.reader.R import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.ext.collectAsStateValue +import me.ash.reader.ui.ext.showToast @OptIn(ExperimentalPagerApi::class) @Composable @@ -59,7 +59,7 @@ fun AllMoveToGroupDialog( viewModel.dispatch(GroupOptionViewAction.AllMoveToGroup { viewModel.dispatch(GroupOptionViewAction.HideAllMoveToGroupDialog) viewModel.dispatch(GroupOptionViewAction.Hide(scope)) - Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() + context.showToast(toastString) }) } ) { diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllParseFullContentDialog.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllParseFullContentDialog.kt index 059c0b6..f71799f 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllParseFullContentDialog.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/AllParseFullContentDialog.kt @@ -1,6 +1,5 @@ package me.ash.reader.ui.page.home.feeds.option.group -import android.widget.Toast import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Article import androidx.compose.material3.Icon @@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi import me.ash.reader.R import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.ext.collectAsStateValue +import me.ash.reader.ui.ext.showToast @OptIn(ExperimentalPagerApi::class) @Composable @@ -53,7 +53,7 @@ fun AllParseFullContentDialog( viewModel.dispatch(GroupOptionViewAction.AllParseFullContent(true) { viewModel.dispatch(GroupOptionViewAction.HideAllParseFullContentDialog) viewModel.dispatch(GroupOptionViewAction.Hide(scope)) - Toast.makeText(context, allowToastString, Toast.LENGTH_SHORT).show() + context.showToast(allowToastString) }) } ) { @@ -68,7 +68,7 @@ fun AllParseFullContentDialog( viewModel.dispatch(GroupOptionViewAction.AllParseFullContent(false) { viewModel.dispatch(GroupOptionViewAction.HideAllParseFullContentDialog) viewModel.dispatch(GroupOptionViewAction.Hide(scope)) - Toast.makeText(context, denyToastString, Toast.LENGTH_SHORT).show() + context.showToast(denyToastString) }) } ) { diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/DeleteGroupDialog.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/DeleteGroupDialog.kt index 497aa6b..6f0793d 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/DeleteGroupDialog.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/DeleteGroupDialog.kt @@ -1,6 +1,5 @@ package me.ash.reader.ui.page.home.feeds.option.group -import android.widget.Toast import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.DeleteForever import androidx.compose.material3.Icon @@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi import me.ash.reader.R import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.ext.collectAsStateValue +import me.ash.reader.ui.ext.showToast @OptIn(ExperimentalPagerApi::class) @Composable @@ -52,7 +52,7 @@ fun DeleteGroupDialog( viewModel.dispatch(GroupOptionViewAction.Delete { viewModel.dispatch(GroupOptionViewAction.HideDeleteDialog) viewModel.dispatch(GroupOptionViewAction.Hide(scope)) - Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() + context.showToast(toastString) }) } ) { diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/GroupOptionDrawer.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/GroupOptionDrawer.kt index 20099b2..3742131 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/GroupOptionDrawer.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/group/GroupOptionDrawer.kt @@ -1,7 +1,6 @@ package me.ash.reader.ui.page.home.feeds.option.group import android.content.Context -import android.widget.Toast import androidx.activity.compose.BackHandler import androidx.compose.animation.animateContentSize import androidx.compose.foundation.layout.* @@ -38,10 +37,7 @@ import me.ash.reader.ui.component.BottomDrawer import me.ash.reader.ui.component.SelectionChip import me.ash.reader.ui.component.Subtitle import me.ash.reader.ui.component.TextFieldDialog -import me.ash.reader.ui.ext.collectAsStateValue -import me.ash.reader.ui.ext.currentAccountId -import me.ash.reader.ui.ext.getDefaultGroupId -import me.ash.reader.ui.ext.roundClick +import me.ash.reader.ui.ext.* @OptIn(ExperimentalMaterialApi::class) @Composable @@ -149,7 +145,7 @@ fun GroupOptionDrawer( onConfirm = { groupOptionViewModel.dispatch(GroupOptionViewAction.Rename) groupOptionViewModel.dispatch(GroupOptionViewAction.Hide(scope)) - Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() + context.showToast(toastString) } ) } diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/TipsAndSupport.kt b/app/src/main/java/me/ash/reader/ui/page/settings/TipsAndSupport.kt index 649ef64..ccd18fb 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/TipsAndSupport.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/TipsAndSupport.kt @@ -4,7 +4,6 @@ import android.content.Intent import android.net.Uri import android.view.HapticFeedbackConstants import android.view.SoundEffectConstants -import android.widget.Toast import androidx.compose.animation.animateContentSize import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween @@ -111,11 +110,7 @@ fun TipsAndSupport( pressAMP = 16f }, onTap = { - Toast.makeText( - context, - checkingUpdates, - Toast.LENGTH_SHORT - ).show() + context.showToast(checkingUpdates) scope.launch { updateViewModel.dispatch( UpdateViewAction.CheckUpdate( @@ -126,13 +121,7 @@ fun TipsAndSupport( ) }, { - if (!it) { - Toast.makeText( - context, - isLatestVersion, - Toast.LENGTH_SHORT - ).show() - } + if (!it) context.showToast(isLatestVersion) } ) ) @@ -197,7 +186,7 @@ fun TipsAndSupport( ) { view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) view.playSoundEffect(SoundEffectConstants.CLICK) - Toast.makeText(context, comingSoon, Toast.LENGTH_SHORT).show() + context.showToast(comingSoon) }) Spacer(modifier = Modifier.width(16.dp)) @@ -237,7 +226,7 @@ fun TipsAndSupport( ) { view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) view.playSoundEffect(SoundEffectConstants.CLICK) - Toast.makeText(context, comingSoon, Toast.LENGTH_SHORT).show() + context.showToast(comingSoon) }) } Spacer(modifier = Modifier.height(48.dp))