diff --git a/app/src/main/kotlin/li/songe/gkd/ui/component/TextMenu.kt b/app/src/main/kotlin/li/songe/gkd/ui/component/TextMenu.kt index f8d1da7..a4bf7b1 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/component/TextMenu.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/component/TextMenu.kt @@ -24,6 +24,7 @@ import li.songe.gkd.util.allSubObject @Composable fun TextMenu( + modifier: Modifier = Modifier, title: String, option: Option, onOptionChange: ((Option) -> Unit), @@ -34,8 +35,13 @@ fun TextMenu( .clickable { expanded = true } - .fillMaxWidth() - .itemPadding(), + .fillMaxWidth().let { + if (modifier == Modifier) { + it.itemPadding() + } else { + it.then(modifier) + } + }, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween ) { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt index dab07a3..ec12b27 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt @@ -56,7 +56,6 @@ import li.songe.gkd.util.DarkThemeOption import li.songe.gkd.util.LocalMainViewModel import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.UpdateChannelOption -import li.songe.gkd.util.UpdateTimeOption import li.songe.gkd.util.checkUpdate import li.songe.gkd.util.findOption import li.songe.gkd.util.launchAsFn @@ -313,21 +312,14 @@ fun useSettingsPage(): ScaffoldExt { }) } - Text( - text = "更新", - modifier = Modifier.titleItemPadding(), - style = MaterialTheme.typography.titleSmall, - color = MaterialTheme.colorScheme.primary, - ) - - TextMenu( - title = "更新订阅", - option = UpdateTimeOption.allSubObject.findOption(store.updateSubsInterval) - ) { - storeFlow.update { s -> s.copy(updateSubsInterval = it.value) } - } - if (BuildConfig.ENABLED_UPDATE) { + Text( + text = "更新", + modifier = Modifier.titleItemPadding(), + style = MaterialTheme.typography.titleSmall, + color = MaterialTheme.colorScheme.primary, + ) + TextSwitch( name = "自动更新", desc = "打开应用时检测新版本", diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt index c575f73..abf92ad 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt @@ -51,6 +51,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog import androidx.hilt.navigation.compose.hiltViewModel @@ -58,6 +59,7 @@ import androidx.lifecycle.viewModelScope import com.dylanc.activityresult.launcher.launchForResult import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import li.songe.gkd.MainActivity import li.songe.gkd.data.Value @@ -66,16 +68,22 @@ import li.songe.gkd.data.exportData import li.songe.gkd.data.importData import li.songe.gkd.db.DbSet import li.songe.gkd.ui.component.SubsItemCard +import li.songe.gkd.ui.component.TextMenu import li.songe.gkd.ui.component.waitResult +import li.songe.gkd.ui.style.itemVerticalPadding import li.songe.gkd.util.LOCAL_SUBS_ID import li.songe.gkd.util.LocalLauncher import li.songe.gkd.util.LocalMainViewModel +import li.songe.gkd.util.SafeR +import li.songe.gkd.util.UpdateTimeOption import li.songe.gkd.util.checkSubsUpdate +import li.songe.gkd.util.findOption import li.songe.gkd.util.isSafeUrl import li.songe.gkd.util.launchAsFn import li.songe.gkd.util.launchTry import li.songe.gkd.util.saveFileToDownloads import li.songe.gkd.util.shareFile +import li.songe.gkd.util.storeFlow import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow import li.songe.gkd.util.subsRefreshingFlow @@ -181,6 +189,29 @@ fun useSubsManagePage(): ScaffoldExt { }) } + var showSettingsDlg by remember { mutableStateOf(false) } + if (showSettingsDlg) { + AlertDialog( + onDismissRequest = { showSettingsDlg = false }, + title = { Text("订阅设置") }, + text = { + val store by storeFlow.collectAsState() + TextMenu( + modifier = Modifier.padding(0.dp, itemVerticalPadding), + title = "更新订阅", + option = UpdateTimeOption.allSubObject.findOption(store.updateSubsInterval) + ) { + storeFlow.update { s -> s.copy(updateSubsInterval = it.value) } + } + }, + confirmButton = { + TextButton(onClick = { showSettingsDlg = false }) { + Text("关闭") + } + } + ) + } + ShareDataDialog(vm) val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() @@ -254,6 +285,14 @@ fun useSubsManagePage(): ScaffoldExt { ) } } else { + IconButton(onClick = { + showSettingsDlg = true + }) { + Icon( + painter = painterResource(id = SafeR.ic_page_info), + contentDescription = null, + ) + } IconButton(onClick = { if (subsRefreshingFlow.value) { toast("正在刷新订阅,请稍后操作") diff --git a/app/src/main/kotlin/li/songe/gkd/util/SafeR.kt b/app/src/main/kotlin/li/songe/gkd/util/SafeR.kt index 12d7bc1..1015eb5 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/SafeR.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/SafeR.kt @@ -5,8 +5,9 @@ import li.songe.gkd.R /** * ![image](https://github.com/gkd-kit/gkd/assets/38517192/c9325110-d90f-4041-a01d-404d14c5d34d) */ -@Suppress("UNRESOLVED_REFERENCE") +@Suppress("UNRESOLVED_REFERENCE") // fix android studio can't find R object SafeR { val app_name: Int = R.string.app_name val ic_status: Int = R.drawable.ic_status + val ic_page_info: Int = R.drawable.ic_page_info } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_page_info.xml b/app/src/main/res/drawable/ic_page_info.xml new file mode 100644 index 0000000..10b22ce --- /dev/null +++ b/app/src/main/res/drawable/ic_page_info.xml @@ -0,0 +1,10 @@ + + +