Skip to content

Commit

Permalink
fix: 使用系统默认 toast (gkd-kit#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jan 13, 2024
1 parent 5e8de4b commit 3d20fc7
Show file tree
Hide file tree
Showing 23 changed files with 128 additions and 136 deletions.
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/data/NodeInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package li.songe.gkd.data

import android.view.accessibility.AccessibilityNodeInfo
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import kotlinx.serialization.Serializable
import li.songe.gkd.service.getChildren
import li.songe.gkd.service.topActivityFlow
import li.songe.gkd.util.toast
import kotlin.system.measureTimeMillis

@Serializable
Expand Down Expand Up @@ -72,7 +72,7 @@ data class NodeInfo(
}
if (times > MAX_KEEP_SIZE) {
// https://github.com/gkd-kit/gkd/issues/28
ToastUtils.showShort("节点数量至多保留$MAX_KEEP_SIZE,丢弃后续节点")
toast("节点数量至多保留$MAX_KEEP_SIZE,丢弃后续节点")
LogUtils.w(
root.packageName, topActivityFlow.value.activityId, "节点数量过多"
)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/debug/FloatingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.material3.Icon
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.blankj.utilcode.util.ToastUtils
import com.torrydo.floatingbubbleview.FloatingBubbleListener
import com.torrydo.floatingbubbleview.service.expandable.BubbleBuilder
import kotlinx.coroutines.Dispatchers
Expand All @@ -24,6 +23,7 @@ import li.songe.gkd.notif.createNotif
import li.songe.gkd.notif.floatingChannel
import li.songe.gkd.notif.floatingNotif
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.toast
import kotlin.math.sqrt

class FloatingService : CompositionFbService({
Expand Down Expand Up @@ -66,7 +66,7 @@ class FloatingService : CompositionFbService({
// is onClick
appScope.launchTry(Dispatchers.IO) {
SnapshotExt.captureSnapshot()
ToastUtils.showShort("快照成功")
toast("快照成功")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/debug/HttpService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package li.songe.gkd.debug
import android.content.Context
import android.content.Intent
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import io.ktor.http.ContentType
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.application.call
Expand Down Expand Up @@ -49,6 +48,7 @@ import li.songe.gkd.util.launchTry
import li.songe.gkd.util.map
import li.songe.gkd.util.storeFlow
import li.songe.gkd.util.subsItemsFlow
import li.songe.gkd.util.toast
import li.songe.gkd.util.updateSubscription
import java.io.File

Expand Down Expand Up @@ -139,7 +139,7 @@ class HttpService : CompositionService({
null
}
if (server == null) {
ToastUtils.showShort("HTTP服务启动失败,您可以尝试切换端口后重新启动")
toast("HTTP服务启动失败,您可以尝试切换端口后重新启动")
stopSelf()
return@collect
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/li/songe/gkd/debug/SnapshotExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.core.graphics.set
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.ToastUtils
import com.blankj.utilcode.util.ZipUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
Expand All @@ -24,6 +23,7 @@ import li.songe.gkd.util.keepNullJson
import li.songe.gkd.util.snapshotFolder
import li.songe.gkd.util.snapshotZipDir
import li.songe.gkd.util.storeFlow
import li.songe.gkd.util.toast
import java.io.File
import kotlin.math.min

Expand Down Expand Up @@ -71,7 +71,7 @@ object SnapshotExt {
throw RpcError("正在保存快照,不可重复操作")
}
captureLoading.value = true
ToastUtils.showShort("正在保存快照...")
toast("正在保存快照...")

try {
val snapshotDef = coroutineScope { async(Dispatchers.IO) { createComplexSnapshot() } }
Expand Down Expand Up @@ -121,7 +121,7 @@ object SnapshotExt {
File(getSnapshotPath(snapshot.id)).writeText(text)
DbSet.snapshotDao.insert(snapshot.toSnapshot())
}
ToastUtils.showShort("快照捕获成功")
toast("快照捕获成功")
return snapshot
} finally {
captureLoading.value = false
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/kotlin/li/songe/gkd/debug/SnapshotTileService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ package li.songe.gkd.debug

import android.accessibilityservice.AccessibilityService
import android.service.quicksettings.TileService
import com.blankj.utilcode.util.ToastUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import li.songe.gkd.appScope
import li.songe.gkd.debug.SnapshotExt.captureSnapshot
import li.songe.gkd.service.GkdAbService
import li.songe.gkd.service.safeActiveWindow
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.toast

class SnapshotTileService : TileService() {
override fun onClick() {
super.onClick()
val service = GkdAbService.service
if (service == null) {
ToastUtils.showShort("无障碍没有开启")
toast("无障碍没有开启")
return
}
appScope.launchTry(Dispatchers.IO) {
val oldAppId = service.safeActiveWindow?.packageName
?: return@launchTry ToastUtils.showShort("获取界面信息根节点失败")
?: return@launchTry toast("获取界面信息根节点失败")
val interval = 500L
val waitTime = 3000L
var i = 0
Expand All @@ -30,7 +30,7 @@ class SnapshotTileService : TileService() {
delay(interval)
i++
if (i * interval > waitTime) {
ToastUtils.showShort("没有检测到界面切换,捕获失败")
toast("没有检测到界面切换,捕获失败")
return@launchTry
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/service/AbExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package li.songe.gkd.service
import android.accessibilityservice.AccessibilityService
import android.graphics.Rect
import android.view.accessibility.AccessibilityNodeInfo
import com.blankj.utilcode.util.ToastUtils
import li.songe.gkd.util.storeFlow
import li.songe.gkd.util.toast
import li.songe.selector.Selector
import li.songe.selector.Transform

Expand Down Expand Up @@ -194,7 +194,7 @@ fun toastClickTip() {
if (storeFlow.value.toastWhenClick) {
val t = System.currentTimeMillis()
if (t - lastToastTime > 3000) {
ToastUtils.showShort(storeFlow.value.clickToast)
toast(storeFlow.value.clickToast)
lastToastTime = t
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import android.view.accessibility.AccessibilityNodeInfo
import androidx.core.app.NotificationManagerCompat
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.ToastUtils
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText
Expand Down Expand Up @@ -55,6 +54,7 @@ import li.songe.gkd.util.map
import li.songe.gkd.util.storeFlow
import li.songe.gkd.util.subsIdToRawFlow
import li.songe.gkd.util.subsItemsFlow
import li.songe.gkd.util.toast
import li.songe.gkd.util.updateStorage
import li.songe.gkd.util.updateSubscription
import li.songe.selector.Selector
Expand Down Expand Up @@ -397,7 +397,7 @@ class GkdAbService : CompositionAbService({
aliveView = tempView
} catch (e: Exception) {
LogUtils.d("创建无障碍悬浮窗失败", e)
ToastUtils.showShort("创建无障碍悬浮窗失败")
toast("创建无障碍悬浮窗失败")
updateStorage(
storeFlow,
storeFlow.value.copy(enableAbFloatWindow = false)
Expand Down Expand Up @@ -427,7 +427,7 @@ class GkdAbService : CompositionAbService({
lastTriggerTime = t
scope.launchTry(Dispatchers.IO) {
SnapshotExt.captureSnapshot()
ToastUtils.showShort("快照成功")
toast("快照成功")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/shizuku/ShizukuApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.ActivityManager
import android.app.IActivityTaskManager
import android.view.Display
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
Expand All @@ -16,6 +15,7 @@ import li.songe.gkd.composition.CanOnDestroy
import li.songe.gkd.data.DeviceInfo
import li.songe.gkd.util.map
import li.songe.gkd.util.storeFlow
import li.songe.gkd.util.toast
import rikka.shizuku.Shizuku
import rikka.shizuku.ShizukuBinderWrapper
import rikka.shizuku.SystemServiceHelper
Expand Down Expand Up @@ -60,7 +60,7 @@ fun IActivityTaskManager.safeGetTasks(): List<ActivityManager.RunningTaskInfo>?
getTasksFcType = -1
LogUtils.d(DeviceInfo.instance)
LogUtils.d(fcs)
ToastUtils.showShort("Shizuku获取方法签名错误")
toast("Shizuku获取方法签名错误")
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ClipboardUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootNavGraph
import kotlinx.coroutines.Dispatchers
Expand All @@ -69,6 +68,7 @@ import li.songe.gkd.util.json
import li.songe.gkd.util.launchAsFn
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.navigate
import li.songe.gkd.util.toast
import li.songe.gkd.util.updateSubscription

@RootNavGraph
Expand Down Expand Up @@ -274,7 +274,7 @@ fun AppItemPage(
)
)
ClipboardUtils.copyText(groupAppText)
ToastUtils.showShort("复制成功")
toast("复制成功")
}) {
Text(text = "复制规则组")
}
Expand Down Expand Up @@ -324,7 +324,7 @@ fun AppItemPage(
DbSet.subsConfigDao.delete(
subsItemVal.id, appRawVal.id, menuGroupRaw.key
)
ToastUtils.showShort("删除成功")
toast("删除成功")
setMenuGroupRaw(null)
}
}
Expand Down Expand Up @@ -363,22 +363,22 @@ fun AppItemPage(
confirmButton = {
TextButton(onClick = {
if (oldSource == source) {
ToastUtils.showShort("规则无变动")
toast("规则无变动")
return@TextButton
}
val newGroupRaw = try {
RawSubscription.parseRawGroup(source)
} catch (e: Exception) {
LogUtils.d(e)
ToastUtils.showShort("非法规则:${e.message}")
toast("非法规则:${e.message}")
return@TextButton
}
if (newGroupRaw.key != editGroupRaw.key) {
ToastUtils.showShort("不能更改规则组的key")
toast("不能更改规则组的key")
return@TextButton
}
if (!newGroupRaw.valid) {
ToastUtils.showShort("非法规则:存在非法选择器")
toast("非法规则:存在非法选择器")
return@TextButton
}
setEditGroupRaw(null)
Expand All @@ -396,7 +396,7 @@ fun AppItemPage(
vm.viewModelScope.launchTry(Dispatchers.IO) {
updateSubscription(newSubsRaw)
DbSet.subsItemDao.update(subsItemVal.copy(mtime = System.currentTimeMillis()))
ToastUtils.showShort("更新成功")
toast("更新成功")
}
}, enabled = source.isNotEmpty()) {
Text(text = "更新")
Expand Down Expand Up @@ -438,7 +438,7 @@ fun AppItemPage(
confirmButton = {
TextButton(onClick = {
if (oldSource == source) {
ToastUtils.showShort("禁用项无变动")
toast("禁用项无变动")
return@TextButton
}
setExcludeGroupRaw(null)
Expand All @@ -451,7 +451,7 @@ fun AppItemPage(
)).copy(exclude = ExcludeData.parse(appId, source).stringify())
vm.viewModelScope.launchTry(Dispatchers.IO) {
DbSet.subsConfigDao.insert(newSubsConfig)
ToastUtils.showShort("更新成功")
toast("更新成功")
}
}) {
Text(text = "更新")
Expand Down Expand Up @@ -484,28 +484,28 @@ fun AppItemPage(
RawSubscription.parseRawGroup(source)
} catch (e: Exception) {
LogUtils.d(e)
ToastUtils.showShort("非法规则:${e.message}")
toast("非法规则:${e.message}")
return@TextButton
}
listOf(newGroupRaw)
} else {
if (newAppRaw.id != appRawVal.id) {
ToastUtils.showShort("id不一致,无法添加")
toast("id不一致,无法添加")
return@TextButton
}
if (newAppRaw.groups.isEmpty()) {
ToastUtils.showShort("不能添加空规则组")
toast("不能添加空规则组")
return@TextButton
}
newAppRaw.groups
}
if (!tempGroups.all { g -> g.valid }) {
ToastUtils.showShort("非法规则:存在非法选择器")
toast("非法规则:存在非法选择器")
return@TextButton
}
tempGroups.forEach { g ->
if (appRawVal.groups.any { g2 -> g2.name == g.name }) {
ToastUtils.showShort("存在同名规则[${g.name}]")
toast("存在同名规则[${g.name}]")
return@TextButton
}
}
Expand All @@ -525,7 +525,7 @@ fun AppItemPage(
DbSet.subsItemDao.update(subsItemVal.copy(mtime = System.currentTimeMillis()))
updateSubscription(newSubsRaw)
showAddDlg = false
ToastUtils.showShort("添加成功")
toast("添加成功")
}
}, enabled = source.isNotEmpty()) {
Text(text = "添加")
Expand Down
Loading

0 comments on commit 3d20fc7

Please sign in to comment.