Skip to content

Commit

Permalink
feat: tow line text, inner disable explain,
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jun 14, 2024
1 parent 6f2d47e commit eaa7ee0
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 64 deletions.
51 changes: 42 additions & 9 deletions app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package li.songe.gkd.ui

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -19,6 +20,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.automirrored.filled.Sort
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FloatingActionButton
Expand All @@ -30,6 +32,7 @@ import androidx.compose.material3.RadioButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -177,6 +180,7 @@ fun AppConfigPage(appId: String) {
}
val checked = getChecked(excludeData, g.group, appId, appInfo)
AppGroupCard(
vm = vm,
group = g.group,
checked = checked,
onClick = {
Expand Down Expand Up @@ -211,15 +215,20 @@ fun AppConfigPage(appId: String) {
}
}
items(appGroups) { g ->
AppGroupCard(g.group, g.enable, onClick = {
navController.navigate(
AppItemPageDestination(
g.subsItem.id,
appId,
g.group.key,
AppGroupCard(
vm = vm,
group = g.group,
checked = g.enable,
onClick = {
navController.navigate(
AppItemPageDestination(
g.subsItem.id,
appId,
g.group.key,
)
)
)
}) {
}
) {
vm.viewModelScope.launchTry {
DbSet.subsConfigDao.insert(
g.config?.copy(enable = it) ?: SubsConfig(
Expand Down Expand Up @@ -248,10 +257,28 @@ fun AppConfigPage(appId: String) {
}
}
}

val innerDisabledDlg by vm.innerDisabledDlgFlow.collectAsState()
if (innerDisabledDlg) {
AlertDialog(
title = { Text(text = "内置禁用") },
text = {
Text(text = "此规则组已经在其 apps 字段中配置对当前应用的禁用, 因此无法手动开启规则组\n\n提示: 这种情况一般在此全局规则无法适配/跳过适配当前应用时出现")
},
onDismissRequest = { vm.innerDisabledDlgFlow.value = false },
confirmButton = {
TextButton(onClick = { vm.innerDisabledDlgFlow.value = false }) {
Text(text = "我知道了")
}
}
)

}
}

@Composable
private fun AppGroupCard(
vm: AppConfigVm,
group: RawSubscription.RawGroupProps,
checked: Boolean?,
onClick: () -> Unit,
Expand Down Expand Up @@ -313,7 +340,13 @@ private fun AppGroupCard(
Switch(
checked = false,
enabled = false,
onCheckedChange = onCheckedChange
onCheckedChange = null,
modifier = Modifier.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
) {
vm.innerDisabledDlgFlow.value = true
}
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ class AppConfigVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel
}
}.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())

val innerDisabledDlgFlow = MutableStateFlow(false)

}

18 changes: 5 additions & 13 deletions app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.stringify
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.component.getDialogResult
import li.songe.gkd.ui.destinations.GroupItemPageDestination
import li.songe.gkd.ui.style.itemPadding
Expand Down Expand Up @@ -132,19 +133,10 @@ fun AppItemPage(
)
}
}, title = {
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,
)
}
TowLineText(
title = subsRaw?.name ?: subsItemId.toString(),
subTitle = appInfoCache[appId]?.name ?: appRaw.name ?: appId
)
}, actions = {})
}, floatingActionButton = {
if (editable) {
Expand Down
14 changes: 5 additions & 9 deletions app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ 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
Expand All @@ -50,6 +49,7 @@ import kotlinx.coroutines.Dispatchers
import li.songe.gkd.data.CategoryConfig
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.component.getDialogResult
import li.songe.gkd.ui.style.itemPadding
import li.songe.gkd.util.EnableGroupOption
Expand Down Expand Up @@ -94,14 +94,10 @@ fun CategoryPage(subsItemId: Long) {
)
}
}, title = {
Column {
Text(
text = subsRaw?.name ?: subsItemId.toString(),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Text(text = "规则类别", style = MaterialTheme.typography.bodyMedium)
}
TowLineText(
title = subsRaw?.name ?: subsItemId.toString(),
subTitle = "规则类别"
)
}, actions = {})
}, floatingActionButton = {
if (editable) {
Expand Down
18 changes: 5 additions & 13 deletions app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import li.songe.gkd.data.stringify
import li.songe.gkd.db.DbSet
import li.songe.gkd.service.launcherAppId
import li.songe.gkd.ui.component.AppBarTextField
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.style.appItemPadding
import li.songe.gkd.ui.style.menuPadding
import li.songe.gkd.util.LocalNavController
Expand Down Expand Up @@ -129,19 +130,10 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) {
modifier = Modifier.focusRequester(focusRequester)
)
} else {
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
)
}
TowLineText(
title = rawSubs?.name ?: subsItemId.toString(),
subTitle = (group?.name ?: groupKey.toString())
)
}
}, actions = {
if (showSearchBar) {
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import kotlinx.coroutines.Dispatchers
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.component.getDialogResult
import li.songe.gkd.ui.destinations.GlobalRuleExcludePageDestination
import li.songe.gkd.ui.destinations.GroupItemPageDestination
Expand Down Expand Up @@ -116,14 +117,10 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) {
)
}
}, title = {
Column {
Text(
text = rawSubs?.name ?: subsItemId.toString(),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Text(text = "全局规则", style = MaterialTheme.typography.bodyMedium)
}
TowLineText(
title = rawSubs?.name ?: subsItemId.toString(),
subTitle = "全局规则"
)
})
},
floatingActionButton = {
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package li.songe.gkd.ui

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand Down Expand Up @@ -46,7 +45,6 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
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
Expand All @@ -58,6 +56,7 @@ import li.songe.gkd.data.SubsConfig
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.AppBarTextField
import li.songe.gkd.ui.component.SubsAppCard
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.component.getDialogResult
import li.songe.gkd.ui.destinations.AppItemPageDestination
import li.songe.gkd.ui.style.menuPadding
Expand Down Expand Up @@ -150,14 +149,10 @@ fun SubsPage(
modifier = Modifier.focusRequester(focusRequester)
)
} else {
Column {
Text(
text = subsRaw?.name ?: subsItemId.toString(),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Text(text = "应用规则", style = MaterialTheme.typography.bodyMedium)
}
TowLineText(
title = subsRaw?.name ?: subsItemId.toString(),
subTitle = "应用规则",
)
}
}, actions = {
if (showSearchBar) {
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/ui/component/TowLineText.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package li.songe.gkd.ui.component

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.style.TextOverflow

@Composable
fun TowLineText(
title: String,
subTitle: String
) {
Column {
Text(
text = title,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.titleMedium
)
Text(
text = subTitle,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.titleSmall
)
}
}
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/util/SubsState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ val ruleSummaryFlow by lazy {
val subGlobalGroupToRules =
mutableMapOf<RawSubscription.RawGlobalGroup, List<GlobalRule>>()
rawSubs.globalGroups.filter { g ->
g.valid && (subGlobalSubsConfigs.find { c -> c.groupKey == g.key }?.enable
?: g.enable ?: true)
(subGlobalSubsConfigs.find { c -> c.groupKey == g.key }?.enable
?: g.enable ?: true) && g.valid
}.forEach { groupRaw ->
val config = subGlobalSubsConfigs.find { c -> c.groupKey == groupRaw.key }
val g = ResolvedGlobalGroup(
Expand Down

0 comments on commit eaa7ee0

Please sign in to comment.