From 465a4c0a37c3009b4cff5fed928d96a9cfbdd68b Mon Sep 17 00:00:00 2001 From: lisonge Date: Fri, 1 Mar 2024 18:00:51 +0800 Subject: [PATCH] perf: show full activityId --- .../main/kotlin/li/songe/gkd/data/ClickLog.kt | 25 ++++++++++-- .../kotlin/li/songe/gkd/ui/ClickLogPage.kt | 40 +++++-------------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/app/src/main/kotlin/li/songe/gkd/data/ClickLog.kt b/app/src/main/kotlin/li/songe/gkd/data/ClickLog.kt index 42ed897..6b4b2e3 100644 --- a/app/src/main/kotlin/li/songe/gkd/data/ClickLog.kt +++ b/app/src/main/kotlin/li/songe/gkd/data/ClickLog.kt @@ -1,6 +1,5 @@ package li.songe.gkd.data -import android.os.Parcelable import androidx.paging.PagingSource import androidx.room.ColumnInfo import androidx.room.Dao @@ -11,12 +10,11 @@ import androidx.room.PrimaryKey import androidx.room.Query import androidx.room.Update import kotlinx.coroutines.flow.Flow -import kotlinx.parcelize.Parcelize +import li.songe.gkd.util.format @Entity( tableName = "click_log", ) -@Parcelize data class ClickLog( @PrimaryKey @ColumnInfo(name = "id") val id: Long = System.currentTimeMillis(), @ColumnInfo(name = "app_id") val appId: String? = null, @@ -27,7 +25,26 @@ data class ClickLog( @ColumnInfo(name = "group_type", defaultValue = "2") val groupType: Int, @ColumnInfo(name = "rule_index") val ruleIndex: Int, @ColumnInfo(name = "rule_key") val ruleKey: Int? = null, -) : Parcelable { +) { + + val showActivityId by lazy { + if (activityId != null) { + if (appId != null && activityId.startsWith( + appId + ) + ) { + activityId.substring(appId.length) + } else { + activityId + } + } else { + null + } + } + + val date by lazy { id.format("MM-dd HH:mm:ss") } + + @Dao interface TriggerLogDao { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt index 43025e3..d2897e7 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt @@ -36,14 +36,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemKey -import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootNavGraph import kotlinx.coroutines.Dispatchers @@ -63,7 +61,6 @@ import li.songe.gkd.ui.destinations.GlobalRulePageDestination import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.appInfoCacheFlow -import li.songe.gkd.util.format import li.songe.gkd.util.launchAsFn import li.songe.gkd.util.navigate import li.songe.gkd.util.subsIdToRawFlow @@ -108,10 +105,6 @@ fun ClickLogPage() { mutableStateOf(false) } - LaunchedEffect(key1 = clickDataItems.itemSnapshotList.items, block = { - LogUtils.d(clickDataItems.itemSnapshotList.items.size) - }) - val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior() Scaffold(modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = { TopAppBar( @@ -154,36 +147,21 @@ fun ClickLogPage() { .padding(10.dp)) { Row { Text( - text = clickLog.id.format("MM-dd HH:mm:ss"), + text = clickLog.date, fontFamily = FontFamily.Monospace ) Spacer(modifier = Modifier.width(10.dp)) - Text( - text = appInfoCache[clickLog.appId]?.name ?: clickLog.appId ?: "" - ) + val appShowName = appInfoCache[clickLog.appId]?.name ?: clickLog.appId + if (appShowName != null) { + Text(text = appShowName) + } } Spacer(modifier = Modifier.width(10.dp)) - val showActivityId = if (clickLog.activityId != null) { - if (clickLog.appId != null && clickLog.activityId.startsWith( - clickLog.appId - ) - ) { - clickLog.activityId.substring(clickLog.appId.length) - } else { - clickLog.activityId - } - } else { - null + clickLog.showActivityId?.let { showActivityId -> + Text(text = showActivityId) } - if (showActivityId != null) { - Text( - text = showActivityId, - overflow = TextOverflow.Ellipsis, - maxLines = 1, - ) - } - if (group?.name != null) { - Text(text = group.name) + group?.name?.let { name -> + Text(text = name) } if (rule?.name != null) { Text(text = rule.name ?: "")