Improve repetitive Toasts

This commit is contained in:
Ash 2022-04-24 21:01:12 +08:00
parent 2e69c7e300
commit aa6517818c
10 changed files with 37 additions and 40 deletions

View File

@ -3,7 +3,7 @@ package me.ash.reader
import android.content.Context import android.content.Context
import android.os.Looper import android.os.Looper
import android.util.Log import android.util.Log
import android.widget.Toast import me.ash.reader.ui.ext.showToastLong
import java.lang.Thread.UncaughtExceptionHandler import java.lang.Thread.UncaughtExceptionHandler
import kotlin.system.exitProcess import kotlin.system.exitProcess
@ -13,10 +13,8 @@ class CrashHandler(private val context: Context) : UncaughtExceptionHandler {
} }
override fun uncaughtException(p0: Thread, p1: Throwable) { override fun uncaughtException(p0: Thread, p1: Throwable) {
if (Looper.myLooper() == null) { Looper.myLooper() ?: Looper.prepare()
Looper.prepare() context.showToastLong(p1.message)
}
Toast.makeText(context, p1.message, Toast.LENGTH_LONG).show()
Looper.loop() Looper.loop()
p1.printStackTrace() p1.printStackTrace()
Log.e("RLog", "uncaughtException: ${p1.message}") Log.e("RLog", "uncaughtException: ${p1.message}")

View File

@ -3,6 +3,7 @@ package me.ash.reader.ui.ext
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.ContextWrapper import android.content.ContextWrapper
import android.widget.Toast
import me.ash.reader.data.entity.Version import me.ash.reader.data.entity.Version
import me.ash.reader.data.entity.toVersion import me.ash.reader.data.entity.toVersion
@ -16,3 +17,15 @@ fun Context.getCurrentVersion(): Version = packageManager
.getPackageInfo(packageName, 0) .getPackageInfo(packageName, 0)
.versionName .versionName
.toVersion() .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)
}

View File

@ -1,6 +1,5 @@
package me.ash.reader.ui.page.home.feeds.option.feed 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.Icons
import androidx.compose.material.icons.outlined.DeleteForever import androidx.compose.material.icons.outlined.DeleteForever
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi
import me.ash.reader.R import me.ash.reader.R
import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.component.Dialog
import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.showToast
@OptIn(ExperimentalPagerApi::class) @OptIn(ExperimentalPagerApi::class)
@Composable @Composable
@ -52,7 +52,7 @@ fun DeleteFeedDialog(
viewModel.dispatch(FeedOptionViewAction.Delete { viewModel.dispatch(FeedOptionViewAction.Delete {
viewModel.dispatch(FeedOptionViewAction.HideDeleteDialog) viewModel.dispatch(FeedOptionViewAction.HideDeleteDialog)
viewModel.dispatch(FeedOptionViewAction.Hide(scope)) viewModel.dispatch(FeedOptionViewAction.Hide(scope))
Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() context.showToast(toastString)
}) })
} }
) { ) {

View File

@ -26,6 +26,7 @@ import me.ash.reader.ui.component.BottomDrawer
import me.ash.reader.ui.component.TextFieldDialog import me.ash.reader.ui.component.TextFieldDialog
import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.roundClick import me.ash.reader.ui.ext.roundClick
import me.ash.reader.ui.ext.showToast
import me.ash.reader.ui.page.home.feeds.subscribe.ResultView import me.ash.reader.ui.page.home.feeds.subscribe.ResultView
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@ -139,7 +140,7 @@ fun FeedOptionDrawer(
onConfirm = { onConfirm = {
feedOptionViewModel.dispatch(FeedOptionViewAction.Rename) feedOptionViewModel.dispatch(FeedOptionViewAction.Rename)
feedOptionViewModel.dispatch(FeedOptionViewAction.Hide(scope)) feedOptionViewModel.dispatch(FeedOptionViewAction.Hide(scope))
Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() context.showToast(toastString)
} }
) )
} }

View File

@ -1,6 +1,5 @@
package me.ash.reader.ui.page.home.feeds.option.group 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.Icons
import androidx.compose.material.icons.outlined.Notifications import androidx.compose.material.icons.outlined.Notifications
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi
import me.ash.reader.R import me.ash.reader.R
import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.component.Dialog
import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.showToast
@OptIn(ExperimentalPagerApi::class) @OptIn(ExperimentalPagerApi::class)
@Composable @Composable
@ -53,7 +53,7 @@ fun AllAllowNotificationDialog(
viewModel.dispatch(GroupOptionViewAction.AllAllowNotification(true) { viewModel.dispatch(GroupOptionViewAction.AllAllowNotification(true) {
viewModel.dispatch(GroupOptionViewAction.HideAllAllowNotificationDialog) viewModel.dispatch(GroupOptionViewAction.HideAllAllowNotificationDialog)
viewModel.dispatch(GroupOptionViewAction.Hide(scope)) 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.AllAllowNotification(false) {
viewModel.dispatch(GroupOptionViewAction.HideAllAllowNotificationDialog) viewModel.dispatch(GroupOptionViewAction.HideAllAllowNotificationDialog)
viewModel.dispatch(GroupOptionViewAction.Hide(scope)) viewModel.dispatch(GroupOptionViewAction.Hide(scope))
Toast.makeText(context, denyToastString, Toast.LENGTH_SHORT).show() context.showToast(denyToastString)
}) })
} }
) { ) {

View File

@ -1,6 +1,5 @@
package me.ash.reader.ui.page.home.feeds.option.group 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.Icons
import androidx.compose.material.icons.outlined.DriveFileMove import androidx.compose.material.icons.outlined.DriveFileMove
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi
import me.ash.reader.R import me.ash.reader.R
import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.component.Dialog
import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.showToast
@OptIn(ExperimentalPagerApi::class) @OptIn(ExperimentalPagerApi::class)
@Composable @Composable
@ -59,7 +59,7 @@ fun AllMoveToGroupDialog(
viewModel.dispatch(GroupOptionViewAction.AllMoveToGroup { viewModel.dispatch(GroupOptionViewAction.AllMoveToGroup {
viewModel.dispatch(GroupOptionViewAction.HideAllMoveToGroupDialog) viewModel.dispatch(GroupOptionViewAction.HideAllMoveToGroupDialog)
viewModel.dispatch(GroupOptionViewAction.Hide(scope)) viewModel.dispatch(GroupOptionViewAction.Hide(scope))
Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() context.showToast(toastString)
}) })
} }
) { ) {

View File

@ -1,6 +1,5 @@
package me.ash.reader.ui.page.home.feeds.option.group 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.Icons
import androidx.compose.material.icons.outlined.Article import androidx.compose.material.icons.outlined.Article
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi
import me.ash.reader.R import me.ash.reader.R
import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.component.Dialog
import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.showToast
@OptIn(ExperimentalPagerApi::class) @OptIn(ExperimentalPagerApi::class)
@Composable @Composable
@ -53,7 +53,7 @@ fun AllParseFullContentDialog(
viewModel.dispatch(GroupOptionViewAction.AllParseFullContent(true) { viewModel.dispatch(GroupOptionViewAction.AllParseFullContent(true) {
viewModel.dispatch(GroupOptionViewAction.HideAllParseFullContentDialog) viewModel.dispatch(GroupOptionViewAction.HideAllParseFullContentDialog)
viewModel.dispatch(GroupOptionViewAction.Hide(scope)) 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.AllParseFullContent(false) {
viewModel.dispatch(GroupOptionViewAction.HideAllParseFullContentDialog) viewModel.dispatch(GroupOptionViewAction.HideAllParseFullContentDialog)
viewModel.dispatch(GroupOptionViewAction.Hide(scope)) viewModel.dispatch(GroupOptionViewAction.Hide(scope))
Toast.makeText(context, denyToastString, Toast.LENGTH_SHORT).show() context.showToast(denyToastString)
}) })
} }
) { ) {

View File

@ -1,6 +1,5 @@
package me.ash.reader.ui.page.home.feeds.option.group 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.Icons
import androidx.compose.material.icons.outlined.DeleteForever import androidx.compose.material.icons.outlined.DeleteForever
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -16,6 +15,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi
import me.ash.reader.R import me.ash.reader.R
import me.ash.reader.ui.component.Dialog import me.ash.reader.ui.component.Dialog
import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.showToast
@OptIn(ExperimentalPagerApi::class) @OptIn(ExperimentalPagerApi::class)
@Composable @Composable
@ -52,7 +52,7 @@ fun DeleteGroupDialog(
viewModel.dispatch(GroupOptionViewAction.Delete { viewModel.dispatch(GroupOptionViewAction.Delete {
viewModel.dispatch(GroupOptionViewAction.HideDeleteDialog) viewModel.dispatch(GroupOptionViewAction.HideDeleteDialog)
viewModel.dispatch(GroupOptionViewAction.Hide(scope)) viewModel.dispatch(GroupOptionViewAction.Hide(scope))
Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() context.showToast(toastString)
}) })
} }
) { ) {

View File

@ -1,7 +1,6 @@
package me.ash.reader.ui.page.home.feeds.option.group package me.ash.reader.ui.page.home.feeds.option.group
import android.content.Context import android.content.Context
import android.widget.Toast
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.animation.animateContentSize import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.layout.* 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.SelectionChip
import me.ash.reader.ui.component.Subtitle import me.ash.reader.ui.component.Subtitle
import me.ash.reader.ui.component.TextFieldDialog import me.ash.reader.ui.component.TextFieldDialog
import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.*
import me.ash.reader.ui.ext.currentAccountId
import me.ash.reader.ui.ext.getDefaultGroupId
import me.ash.reader.ui.ext.roundClick
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@Composable @Composable
@ -149,7 +145,7 @@ fun GroupOptionDrawer(
onConfirm = { onConfirm = {
groupOptionViewModel.dispatch(GroupOptionViewAction.Rename) groupOptionViewModel.dispatch(GroupOptionViewAction.Rename)
groupOptionViewModel.dispatch(GroupOptionViewAction.Hide(scope)) groupOptionViewModel.dispatch(GroupOptionViewAction.Hide(scope))
Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show() context.showToast(toastString)
} }
) )
} }

View File

@ -4,7 +4,6 @@ import android.content.Intent
import android.net.Uri import android.net.Uri
import android.view.HapticFeedbackConstants import android.view.HapticFeedbackConstants
import android.view.SoundEffectConstants import android.view.SoundEffectConstants
import android.widget.Toast
import androidx.compose.animation.animateContentSize import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
@ -111,11 +110,7 @@ fun TipsAndSupport(
pressAMP = 16f pressAMP = 16f
}, },
onTap = { onTap = {
Toast.makeText( context.showToast(checkingUpdates)
context,
checkingUpdates,
Toast.LENGTH_SHORT
).show()
scope.launch { scope.launch {
updateViewModel.dispatch( updateViewModel.dispatch(
UpdateViewAction.CheckUpdate( UpdateViewAction.CheckUpdate(
@ -126,13 +121,7 @@ fun TipsAndSupport(
) )
}, },
{ {
if (!it) { if (!it) context.showToast(isLatestVersion)
Toast.makeText(
context,
isLatestVersion,
Toast.LENGTH_SHORT
).show()
}
} }
) )
) )
@ -197,7 +186,7 @@ fun TipsAndSupport(
) { ) {
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
view.playSoundEffect(SoundEffectConstants.CLICK) view.playSoundEffect(SoundEffectConstants.CLICK)
Toast.makeText(context, comingSoon, Toast.LENGTH_SHORT).show() context.showToast(comingSoon)
}) })
Spacer(modifier = Modifier.width(16.dp)) Spacer(modifier = Modifier.width(16.dp))
@ -237,7 +226,7 @@ fun TipsAndSupport(
) { ) {
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
view.playSoundEffect(SoundEffectConstants.CLICK) view.playSoundEffect(SoundEffectConstants.CLICK)
Toast.makeText(context, comingSoon, Toast.LENGTH_SHORT).show() context.showToast(comingSoon)
}) })
} }
Spacer(modifier = Modifier.height(48.dp)) Spacer(modifier = Modifier.height(48.dp))