From 747a20ac3cfcf57a1f7f0998d000298fb5bc8c68 Mon Sep 17 00:00:00 2001 From: lisonge Date: Wed, 29 May 2024 20:00:08 +0800 Subject: [PATCH] feat: two column title text --- .../kotlin/li/songe/gkd/ui/AppItemPage.kt | 22 ++++++------ .../kotlin/li/songe/gkd/ui/CategoryPage.kt | 36 +++++++++++-------- .../li/songe/gkd/ui/GlobalRuleExcludePage.kt | 19 ++++++---- .../kotlin/li/songe/gkd/ui/GlobalRulePage.kt | 9 ++++- .../main/kotlin/li/songe/gkd/ui/SubsPage.kt | 16 +++++---- 5 files changed, 65 insertions(+), 37 deletions(-) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt index 871827a..ac699a9 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt @@ -129,17 +129,19 @@ fun AppItemPage( ) } }, title = { - val text = if (subsRaw == null) { - "订阅文件缺失" - } else { - "${appInfoCache[appId]?.name ?: appRaw.name ?: appId}/${subsRaw.name}" + Column { + Text( + text = subsRaw?.name ?: subsItemId.toString(), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + Text( + text = appInfoCache[appId]?.name ?: appRaw.name ?: appId, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + style = MaterialTheme.typography.bodyMedium, + ) } - Text( - text = text, - maxLines = 1, - softWrap = false, - overflow = TextOverflow.Ellipsis, - ) }, actions = {}) }, floatingActionButton = { if (editable) { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt index a51cf64..60b29ea 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt @@ -40,6 +40,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope @@ -92,7 +93,16 @@ fun CategoryPage(subsItemId: Long) { contentDescription = null, ) } - }, title = { Text(text = "规则类别/${subsRaw?.name ?: subsItemId}") }, actions = {}) + }, title = { + Column { + Text( + text = subsRaw?.name ?: subsItemId.toString(), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + Text(text = "规则类别", style = MaterialTheme.typography.bodyMedium) + } + }, actions = {}) }, floatingActionButton = { if (editable) { FloatingActionButton(onClick = { showAddDlg = true }) { @@ -260,14 +270,13 @@ fun CategoryPage(subsItemId: Long) { vm.viewModelScope.launchTry(Dispatchers.IO) { subsItem?.apply { updateSubscription( - subsRawVal.copy(categories = categories.toMutableList() - .apply { - val i = - categories.indexOfFirst { c -> c.key == editNameCategory.key } - if (i >= 0) { - set(i, editNameCategory.copy(name = source)) - } - }) + subsRawVal.copy(categories = categories.toMutableList().apply { + val i = + categories.indexOfFirst { c -> c.key == editNameCategory.key } + if (i >= 0) { + set(i, editNameCategory.copy(name = source)) + } + }) ) DbSet.subsItemDao.update(copy(mtime = System.currentTimeMillis())) } @@ -305,11 +314,10 @@ fun CategoryPage(subsItemId: Long) { vm.viewModelScope.launchTry(Dispatchers.IO) { subsItem?.apply { updateSubscription( - subsRawVal.copy(categories = categories.toMutableList() - .apply { - add(RawSubscription.RawCategory(key = (categories.maxOfOrNull { c -> c.key } - ?: -1) + 1, name = source, enable = null)) - }) + subsRawVal.copy(categories = categories.toMutableList().apply { + add(RawSubscription.RawCategory(key = (categories.maxOfOrNull { c -> c.key } + ?: -1) + 1, name = source, enable = null)) + }) ) DbSet.subsItemDao.update(copy(mtime = System.currentTimeMillis())) toast("添加成功") diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt index a18ec5b..b871d80 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt @@ -129,12 +129,19 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) { modifier = Modifier.focusRequester(focusRequester) ) } else { - Text( - text = "${rawSubs?.name ?: subsItemId}/${group?.name ?: groupKey}", - maxLines = 1, - softWrap = false, - overflow = TextOverflow.Ellipsis, - ) + Column { + Text( + text = rawSubs?.name ?: subsItemId.toString(), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + Text( + text = (group?.name ?: groupKey.toString()), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + style = MaterialTheme.typography.bodyMedium + ) + } } }, actions = { if (showSearchBar) { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt index 4370b56..5021101 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt @@ -116,7 +116,14 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { ) } }, title = { - Text(text = "全局规则/${rawSubs?.name ?: subsItemId}") + Column { + Text( + text = rawSubs?.name ?: subsItemId.toString(), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + Text(text = "全局规则", style = MaterialTheme.typography.bodyMedium) + } }) }, floatingActionButton = { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt index a478616..e492073 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt @@ -1,6 +1,7 @@ package li.songe.gkd.ui import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -24,6 +25,7 @@ import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.RadioButton import androidx.compose.material3.Scaffold @@ -149,12 +151,14 @@ fun SubsPage( modifier = Modifier.focusRequester(focusRequester) ) } else { - Text( - text = "应用规则/${subsRaw?.name ?: subsItemId}", - maxLines = 1, - softWrap = false, - overflow = TextOverflow.Ellipsis, - ) + Column { + Text( + text = subsRaw?.name ?: subsItemId.toString(), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + Text(text = "应用规则", style = MaterialTheme.typography.bodyMedium) + } } }, actions = { if (showSearchBar) {