mirror of https://github.com/Ashinch/ReadYou.git
Improve repetitive Toasts
This commit is contained in:
parent
2e69c7e300
commit
aa6517818c
|
@ -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}")
|
||||
|
|
|
@ -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()
|
||||
.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)
|
||||
}
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
)
|
||||
}
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
) {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
) {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
) {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue