feat: subs settings action
Some checks are pending
Build-Apk / build (push) Waiting to run

This commit is contained in:
lisonge 2024-08-18 20:53:51 +08:00
parent 8e3246a9a6
commit b4474f5041
5 changed files with 66 additions and 18 deletions

View File

@ -24,6 +24,7 @@ import li.songe.gkd.util.allSubObject
@Composable
fun <T> TextMenu(
modifier: Modifier = Modifier,
title: String,
option: Option<T>,
onOptionChange: ((Option<T>) -> Unit),
@ -34,8 +35,13 @@ fun <T> TextMenu(
.clickable {
expanded = true
}
.fillMaxWidth()
.itemPadding(),
.fillMaxWidth().let {
if (modifier == Modifier) {
it.itemPadding()
} else {
it.then(modifier)
}
},
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {

View File

@ -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 = "打开应用时检测新版本",

View File

@ -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("正在刷新订阅,请稍后操作")

View File

@ -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
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M710,810Q647,810 603.5,766.5Q560,723 560,660Q560,597 603.5,553.5Q647,510 710,510Q773,510 816.5,553.5Q860,597 860,660Q860,723 816.5,766.5Q773,810 710,810ZM710,730Q739,730 759.5,709.5Q780,689 780,660Q780,631 759.5,610.5Q739,590 710,590Q681,590 660.5,610.5Q640,631 640,660Q640,689 660.5,709.5Q681,730 710,730ZM160,700L160,620L480,620L480,700L160,700ZM250,450Q187,450 143.5,406.5Q100,363 100,300Q100,237 143.5,193.5Q187,150 250,150Q313,150 356.5,193.5Q400,237 400,300Q400,363 356.5,406.5Q313,450 250,450ZM250,370Q279,370 299.5,349.5Q320,329 320,300Q320,271 299.5,250.5Q279,230 250,230Q221,230 200.5,250.5Q180,271 180,300Q180,329 200.5,349.5Q221,370 250,370ZM480,340L480,260L800,260L800,340L480,340ZM710,660Q710,660 710,660Q710,660 710,660Q710,660 710,660Q710,660 710,660Q710,660 710,660Q710,660 710,660Q710,660 710,660Q710,660 710,660ZM250,300Q250,300 250,300Q250,300 250,300Q250,300 250,300Q250,300 250,300Q250,300 250,300Q250,300 250,300Q250,300 250,300Q250,300 250,300Z"/>
</vector>