Skip to content

Commit

Permalink
perf: rm Tuple3
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jan 15, 2025
1 parent 5575dcd commit d78627a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 34 deletions.
9 changes: 0 additions & 9 deletions app/src/main/kotlin/li/songe/gkd/data/Tuple.kt

This file was deleted.

11 changes: 5 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/debug/FloatingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.torrydo.floatingbubbleview.service.expandable.ExpandableBubbleService
import kotlinx.coroutines.flow.MutableStateFlow
import li.songe.gkd.app
import li.songe.gkd.appScope
import li.songe.gkd.data.Tuple3
import li.songe.gkd.notif.floatingNotif
import li.songe.gkd.notif.notifyService
import li.songe.gkd.permission.canDrawOverlaysState
Expand Down Expand Up @@ -44,20 +43,20 @@ class FloatingService : ExpandableBubbleService() {

// https://github.com/gkd-kit/gkd/issues/62
// https://github.com/gkd-kit/gkd/issues/61
val defaultFingerData = Tuple3(0L, 0f, 0f)
val defaultFingerData = Triple(0L, 0f, 0f)
var fingerDownData = defaultFingerData
val maxDistanceOffset = 50
builder.addFloatingBubbleListener(object : FloatingBubbleListener {
override fun onFingerDown(x: Float, y: Float) {
fingerDownData = Tuple3(System.currentTimeMillis(), x, y)
fingerDownData = Triple(System.currentTimeMillis(), x, y)
}

override fun onFingerMove(x: Float, y: Float) {
if (fingerDownData === defaultFingerData) {
return
}
val dx = fingerDownData.t1 - x
val dy = fingerDownData.t2 - y
val dx = fingerDownData.second - x
val dy = fingerDownData.third - y
val distance = sqrt(dx * dx + dy * dy)
if (distance > maxDistanceOffset) {
// reset
Expand All @@ -66,7 +65,7 @@ class FloatingService : ExpandableBubbleService() {
}

override fun onFingerUp(x: Float, y: Float) {
if (System.currentTimeMillis() - fingerDownData.t0 < ViewConfiguration.getTapTimeout()) {
if (System.currentTimeMillis() - fingerDownData.first < ViewConfiguration.getTapTimeout()) {
// is onClick
appScope.launchTry {
SnapshotExt.captureSnapshot()
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/kotlin/li/songe/gkd/shizuku/ShizukuApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import kotlinx.coroutines.flow.update
import li.songe.gkd.META
import li.songe.gkd.appScope
import li.songe.gkd.data.AppInfo
import li.songe.gkd.data.Tuple3
import li.songe.gkd.data.otherUserMapFlow
import li.songe.gkd.data.toAppInfo
import li.songe.gkd.util.allPackageInfoMapFlow
Expand Down Expand Up @@ -75,7 +74,7 @@ fun initShizuku() {
packageManagerFlow,
userAppInfoMapFlow,
allPackageInfoMapFlow,
) { a, b, c -> Tuple3(a, b, c) }.debounce(3000)
) { a, b, c -> Triple(a, b, c) }.debounce(3000)
.collect { (pkgManager, userAppInfoMap, allPackageInfoMap) ->
otherUserAppInfoMapFlow.update {
if (pkgManager != null) {
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/ui/ActionLogPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import li.songe.gkd.data.ActionLog
import li.songe.gkd.data.ExcludeData
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.Tuple3
import li.songe.gkd.data.stringify
import li.songe.gkd.data.switch
import li.songe.gkd.db.DbSet
Expand Down Expand Up @@ -192,7 +191,7 @@ fun ActionLogPage(
) {
items(
count = actionDataItems.itemCount,
key = actionDataItems.itemKey { c -> c.t0.id }
key = actionDataItems.itemKey { c -> c.first.id }
) { i ->
val item = actionDataItems[i] ?: return@items
val lastItem = if (i > 0) actionDataItems[i - 1] else null
Expand All @@ -204,7 +203,7 @@ fun ActionLogPage(
item = item,
lastItem = lastItem,
onClick = {
previewActionLog = item.t0
previewActionLog = item.first
},
subsId = subsId,
appId = appId,
Expand Down Expand Up @@ -363,15 +362,15 @@ fun ActionLogPage(
@Composable
private fun ActionLogCard(
i: Int,
item: Tuple3<ActionLog, RawSubscription.RawGroupProps?, RawSubscription.RawRuleProps?>,
lastItem: Tuple3<ActionLog, RawSubscription.RawGroupProps?, RawSubscription.RawRuleProps?>?,
item: Triple<ActionLog, RawSubscription.RawGroupProps?, RawSubscription.RawRuleProps?>,
lastItem: Triple<ActionLog, RawSubscription.RawGroupProps?, RawSubscription.RawRuleProps?>?,
onClick: () -> Unit,
subsId: Long?,
appId: String?,
) {
val context = LocalContext.current as MainActivity
val (actionLog, group, rule) = item
val lastActionLog = lastItem?.t0
val lastActionLog = lastItem?.first
val isDiffApp = actionLog.appId != lastActionLog?.appId
val verticalPadding = if (i == 0) 0.dp else if (isDiffApp) 12.dp else 8.dp
val subsIdToRaw by subsIdToRawFlow.collectAsState()
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/kotlin/li/songe/gkd/ui/ActionLogVm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.paging.map
import com.ramcosta.composedestinations.generated.destinations.ActionLogPageDestination
import kotlinx.coroutines.flow.combine
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.Tuple3
import li.songe.gkd.db.DbSet
import li.songe.gkd.util.subsIdToRawFlow

Expand Down Expand Up @@ -42,7 +41,7 @@ class ActionLogVm(stateHandle: SavedStateHandle) : ViewModel() {
getOrNull(c.ruleIndex)
}
}
Tuple3(c, group, rule)
Triple(c, group, rule)
}
}
.cachedIn(viewModelScope)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fun SubsPage(
val listState = rememberLazyListState()
var isFirstVisit by remember { mutableStateOf(true) }
LaunchedEffect(
key1 = appAndConfigs.mapHashCode { it.t0.id }
key1 = appAndConfigs.mapHashCode { it.first.id }
) {
if (isFirstVisit) {
isFirstVisit = false
Expand Down Expand Up @@ -261,7 +261,7 @@ fun SubsPage(
modifier = Modifier.scaffoldPadding(contentPadding),
state = listState
) {
itemsIndexed(appAndConfigs, { i, a -> i.toString() + a.t0.id }) { _, a ->
itemsIndexed(appAndConfigs, { i, a -> i.toString() + a.first.id }) { _, a ->
val (appRaw, subsConfig, enableSize) = a
SubsAppCard(
rawApp = appRaw,
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.Tuple3
import li.songe.gkd.db.DbSet
import li.songe.gkd.util.SortTypeOption
import li.songe.gkd.util.appInfoCacheFlow
Expand Down Expand Up @@ -107,7 +106,7 @@ class SubsVm(stateHandle: SavedStateHandle) : ViewModel() {
categoryConfigs.find { c -> c.categoryKey == groupToCategoryMap[g]?.key }
)
}
Tuple3(app, appSubsConfigs.find { s -> s.appId == app.id }, enableSize)
Triple(app, appSubsConfigs.find { s -> s.appId == app.id }, enableSize)
}
}.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())

Expand All @@ -117,11 +116,11 @@ class SubsVm(stateHandle: SavedStateHandle) : ViewModel() {
if (searchStr.isBlank()) {
appAndConfigs
} else {
val results = mutableListOf<Tuple3<RawSubscription.RawApp, SubsConfig?, Int>>()
val results = mutableListOf<Triple<RawSubscription.RawApp, SubsConfig?, Int>>()
val remnantList = appAndConfigs.toMutableList()
//1. 搜索已安装应用名称
remnantList.toList().apply { remnantList.clear() }.forEach { a ->
val name = appInfoCache[a.t0.id]?.name
val name = appInfoCache[a.first.id]?.name
if (name?.contains(searchStr, true) == true) {
results.add(a)
} else {
Expand All @@ -130,16 +129,16 @@ class SubsVm(stateHandle: SavedStateHandle) : ViewModel() {
}
//2. 搜索未安装应用名称
remnantList.toList().apply { remnantList.clear() }.forEach { a ->
val name = a.t0.name
if (appInfoCache[a.t0.id] == null && name?.contains(searchStr, true) == true) {
val name = a.first.name
if (appInfoCache[a.first.id] == null && name?.contains(searchStr, true) == true) {
results.add(a)
} else {
remnantList.add(a)
}
}
//3. 搜索应用 id
remnantList.toList().apply { remnantList.clear() }.forEach { a ->
if (a.t0.id.contains(searchStr, true)) {
if (a.first.id.contains(searchStr, true)) {
results.add(a)
} else {
remnantList.add(a)
Expand Down

0 comments on commit d78627a

Please sign in to comment.