Skip to content

Commit

Permalink
feat: ActivityLogPage
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Dec 25, 2024
1 parent 9b1851f commit db0565c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 38 deletions.
116 changes: 78 additions & 38 deletions app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package li.songe.gkd.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -11,39 +15,43 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.paging.LoadState
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemKey
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import li.songe.gkd.MainActivity
import li.songe.gkd.data.ActivityLog
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.AppNameText
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.StartEllipsisText
import li.songe.gkd.ui.component.waitResult
import li.songe.gkd.ui.style.EmptyHeight
import li.songe.gkd.ui.style.itemHorizontalPadding
import li.songe.gkd.ui.style.scaffoldPadding
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.ProfileTransitions
import li.songe.gkd.util.appInfoCacheFlow
import li.songe.gkd.util.copyText
import li.songe.gkd.util.launchAsFn
import li.songe.gkd.util.throttle

Expand All @@ -57,7 +65,6 @@ fun ActivityLogPage() {

val logCount by vm.logCountFlow.collectAsState()
val list = vm.pagingDataFlow.collectAsLazyPagingItems()
val appInfoCache by appInfoCacheFlow.collectAsState()

val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
Scaffold(modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = {
Expand Down Expand Up @@ -101,46 +108,79 @@ fun ActivityLogPage() {
count = list.itemCount,
key = list.itemKey { it.id }
) { i ->
val activityLog = list[i] ?: return@items
if (i > 0) {
HorizontalDivider()
}
Column(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp)
) {
Row {
Text(text = activityLog.date)
Spacer(modifier = Modifier.width(10.dp))
val appInfo = appInfoCache[activityLog.appId]
val appShowName = appInfo?.name ?: activityLog.appId
Text(
text = appShowName,
style = LocalTextStyle.current.let {
if (appInfo?.isSystem == true) {
it.copy(textDecoration = TextDecoration.Underline)
} else {
it
}
}
)
}
Spacer(modifier = Modifier.width(10.dp))
val showActivityId = activityLog.showActivityId
if (showActivityId != null) {
StartEllipsisText(text = showActivityId)
} else {
Text(text = "null", color = LocalContentColor.current.copy(alpha = 0.5f))
}
}
val actionLog = list[i] ?: return@items
val lastActionLog = if (i > 0) list[i - 1] else null
ActivityLogCard(i = i, actionLog = actionLog, lastActionLog = lastActionLog)
}
item {
Spacer(modifier = Modifier.height(EmptyHeight))
if (logCount == 0) {
if (logCount == 0 && list.loadState.refresh !is LoadState.Loading) {
EmptyText(text = "暂无记录")
}
}
}
}
}

@Composable
private fun ActivityLogCard(
i: Int,
actionLog: ActivityLog,
lastActionLog: ActivityLog?,
) {
val isDiffApp = actionLog.appId != lastActionLog?.appId
val verticalPadding = if (i == 0) 0.dp else if (isDiffApp) 12.dp else 8.dp
Column(
modifier = Modifier
.fillMaxWidth()
.padding(
start = itemHorizontalPadding,
end = itemHorizontalPadding,
top = verticalPadding
)
) {
if (isDiffApp) {
AppNameText(appId = actionLog.appId)
}
Row(
modifier = Modifier
.clickable(onClick = throttle {
copyText(actionLog.showActivityId.toString())
})
.fillMaxWidth()
.height(IntrinsicSize.Min)
) {
Spacer(modifier = Modifier.width(2.dp))
Spacer(
modifier = Modifier
.fillMaxHeight()
.width(2.dp)
.background(MaterialTheme.colorScheme.primaryContainer),
)
Spacer(modifier = Modifier.width(8.dp))
Column(
modifier = Modifier.weight(1f)
) {
Text(
text = actionLog.date,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.secondary,
)
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyMedium) {
val showActivityId = actionLog.showActivityId
if (showActivityId != null) {
StartEllipsisText(
text = showActivityId,
modifier = Modifier.height(LocalTextStyle.current.lineHeight.value.dp),
)
} else {
Text(
text = "null",
color = LocalContentColor.current.copy(alpha = 0.5f),
)
}
}
}
}
}
}
8 changes: 8 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/util/Copy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package li.songe.gkd.util

import com.blankj.utilcode.util.ClipboardUtils

fun copyText(text: String) {
ClipboardUtils.copyText(text)
toast("复制成功")
}

0 comments on commit db0565c

Please sign in to comment.