[DO NOT USE] Implement DownloadScreen part 2

This commit is contained in:
tarsin committed 2023-06-05 15:55:07 +08:00
1 parent 9b4477766c
commit 281154be7a
3 files changed
+47 -7

No files matched your search

@@ -56,10 +56,10 @@ object Settings : DataStorePreferences(null) {
var favCount by intArrayPref("fav_count", 10)
var archivePasswds by stringSetOrNullPref("archive_passwds")
val downloadDelay by intFromStrPref("download_delay", 0)
var downloadDelay by intFromStrPref("download_delay", 0)
var gallerySite by intFromStrPref(KEY_GALLERY_SITE, 0)
val multiThreadDownload by intFromStrPref("download_thread", 3)
val preloadImage by intFromStrPref("preload_image", 5)
var multiThreadDownload by intFromStrPref("download_thread", 3)
var preloadImage by intFromStrPref("preload_image", 5)
val theme by intFromStrPref(KEY_THEME, -1)
val listMode by intFromStrPref(KEY_LIST_MODE, 0)
val detailSize by intFromStrPref(KEY_DETAIL_SIZE, 0)
@@ -76,7 +76,7 @@ object Settings : DataStorePreferences(null) {
val meteredNetworkWarning by boolPref("cellular_network_warning", false)
var appLinkVerifyTip by boolPref("app_link_verify_tip", false)
var enabledSecurity by boolPref("enable_secure", false)
val mediaScan by boolPref(KEY_MEDIA_SCAN, false)
var mediaScan by boolPref(KEY_MEDIA_SCAN, false)
var hasDefaultDownloadLabel by boolPref("has_default_download_label", false)
var qSSaveProgress by boolPref("qs_save_progress", true)
var saveParseErrorBody by boolPref("save_parse_error_body", true)
@@ -89,7 +89,7 @@ object Settings : DataStorePreferences(null) {
val blackDarkTheme by boolPref(KEY_BLACK_DARK_THEME, false)
var preloadThumbAggressively by boolPref("preload_thumb_aggressively", false)
var dF by boolPref(KEY_DOMAIN_FRONTING, false)
val downloadOriginImage by boolPref("download_origin_image", false)
var downloadOriginImage by boolPref("download_origin_image", false)
var bypassVpn by boolPref(KEY_BYPASS_VPN, true)
val thumbSizeDp by intPref(KEY_THUMB_SIZE, 120)
@@ -24,6 +24,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.download.downloadLocation
import com.hippo.ehviewer.ui.keepNoMediaFileStatus
import com.hippo.ehviewer.ui.login.LocalNavController
@@ -76,6 +77,45 @@ fun DownloadScreen() {
title = stringResource(id = R.string.settings_download_download_location),
summary = downloadLocation.uri.toString(),
) { selectDownloadDirLauncher.launch(downloadLocation.uri) }
SwitchPreference(
title = stringResource(id = R.string.settings_download_media_scan),
summary = if (Settings.mediaScan) stringResource(id = R.string.settings_download_media_scan_summary_on) else stringResource(id = R.string.settings_download_media_scan_summary_off),
value = Settings::mediaScan,
)
SimpleMenuPreferenceInt(
title = stringResource(id = R.string.settings_download_concurrency),
summary = stringResource(id = R.string.settings_download_concurrency_summary, Settings.multiThreadDownload),
entry = R.array.multi_thread_download_entries,
entryValueRes = R.array.multi_thread_download_entry_values,
value = Settings::multiThreadDownload,
)
SimpleMenuPreferenceInt(
title = stringResource(id = R.string.settings_download_download_delay),
summary = stringResource(id = R.string.settings_download_download_delay_summary, Settings.downloadDelay),
entry = R.array.download_delay_entries,
entryValueRes = R.array.download_delay_entry_values,
value = Settings::downloadDelay,
)
SimpleMenuPreferenceInt(
title = stringResource(id = R.string.settings_download_preload_image),
summary = stringResource(id = R.string.settings_download_preload_image_summary, Settings.preloadImage),
entry = R.array.preload_image_entries,
entryValueRes = R.array.preload_image_entry_values,
value = Settings::preloadImage,
)
SwitchPreference(
title = stringResource(id = R.string.settings_download_download_origin_image),
summary = stringResource(id = R.string.settings_download_download_origin_image_summary),
value = Settings::downloadOriginImage,
)
Preference(
title = stringResource(id = R.string.settings_download_restore_download_items),
summary = stringResource(id = R.string.settings_download_restore_download_items_summary),
)
Preference(
title = stringResource(id = R.string.settings_download_clean_redundancy),
summary = stringResource(id = R.string.settings_download_clean_redundancy_summary),
)
}
}
}
@@ -86,7 +86,7 @@ fun HtmlPreference(title: String, summary: AnnotatedString? = null, onClick: ()
}
@Composable
fun SimpleMenuPreferenceInt(title: String, @ArrayRes entry: Int, @ArrayRes entryValueRes: Int, value: KMutableProperty0<Int>) {
fun SimpleMenuPreferenceInt(title: String, summary: String? = null, @ArrayRes entry: Int, @ArrayRes entryValueRes: Int, value: KMutableProperty0<Int>) {
val entryArray = stringArrayResource(id = entry)
val valuesArray = stringArrayResource(id = entryValueRes)
val map = remember {
@@ -96,7 +96,7 @@ fun SimpleMenuPreferenceInt(title: String, @ArrayRes entry: Int, @ArrayRes entry
var v by remember { mutableIntStateOf(value.get()) }
fun set(new: String) = value.set(new.toInt().also { v = it })
check(entryArray.size == valuesArray.size)
DropDownPref(title = title, defaultValue = v.toString(), onValueChange = ::set, useSelectedAsSummary = true, entries = map)
DropDownPref(title = title, summary = summary, defaultValue = v.toString(), onValueChange = ::set, useSelectedAsSummary = summary.isNullOrBlank(), entries = map)
}
@Composable