refactor: move it into it's own function and use data and storage label.

Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh 2023-11-20 05:53:22 +11:00
parent 1a185375b7
commit 389336b823
No known key found for this signature in database
GPG Key ID: 14D73B142042BBA9
4 changed files with 40 additions and 27 deletions

View File

@ -144,7 +144,7 @@ fun MoreScreen(
}
item {
TextPreferenceWidget(
title = stringResource(MR.strings.label_backup_and_sync),
title = stringResource(MR.strings.label_data_storage),
icon = Icons.Outlined.Storage,
onPreferenceClick = onClickDataAndStorage,
)

View File

@ -65,7 +65,7 @@ object SettingsDataScreen : SearchableSettings {
@ReadOnlyComposable
@Composable
override fun getTitleRes() = MR.strings.label_backup_and_sync
override fun getTitleRes() = MR.strings.label_data_storage
@Composable
override fun getPreferences(): List<Preference> {
@ -79,23 +79,7 @@ object SettingsDataScreen : SearchableSettings {
return listOf(
getBackupAndRestoreGroup(backupPreferences = backupPreferences),
getDataGroup(),
) + listOf(
Preference.PreferenceGroup(
title = stringResource(MR.strings.label_sync),
preferenceItems = listOf(
Preference.PreferenceItem.ListPreference(
pref = syncPreferences.syncService(),
title = stringResource(MR.strings.pref_sync_service),
entries = mapOf(
SyncManager.SyncService.NONE.value to stringResource(MR.strings.off),
SyncManager.SyncService.SYNCYOMI.value to stringResource(MR.strings.syncyomi),
SyncManager.SyncService.GOOGLE_DRIVE.value to stringResource(MR.strings.google_drive),
),
onValueChanged = { true },
),
),
),
) + getSyncServicePreferences(syncPreferences, syncService)
) + getSyncPreferences(syncPreferences = syncPreferences, syncService = syncService)
}
@Composable
@ -342,21 +326,51 @@ object SettingsDataScreen : SearchableSettings {
)
}
}
@Composable
private fun getSyncPreferences(syncPreferences: SyncPreferences, syncService: Int): List<Preference> {
return listOf(
Preference.PreferenceItem.ListPreference(
pref = syncPreferences.syncService(),
title = stringResource(MR.strings.pref_sync_service),
entries = mapOf(
SyncManager.SyncService.NONE.value to stringResource(MR.strings.off),
SyncManager.SyncService.SYNCYOMI.value to stringResource(MR.strings.syncyomi),
SyncManager.SyncService.GOOGLE_DRIVE.value to stringResource(MR.strings.google_drive),
),
onValueChanged = { true },
),
) + getSyncServicePreferences(syncPreferences, syncService)
}
}
@Composable
private fun getSyncServicePreferences(syncPreferences: SyncPreferences, syncService: Int): List<Preference> {
val syncServiceType = SyncManager.SyncService.fromInt(syncService)
val basePreferences = getBasePreferences(syncServiceType, syncPreferences)
return if (syncServiceType != SyncManager.SyncService.NONE) {
basePreferences + getAdditionalPreferences(syncPreferences)
} else {
basePreferences
}
}
@Composable
private fun getBasePreferences(syncServiceType: SyncManager.SyncService, syncPreferences: SyncPreferences): List<Preference> {
return when (syncServiceType) {
SyncManager.SyncService.NONE -> emptyList()
SyncManager.SyncService.SYNCYOMI -> getSelfHostPreferences(syncPreferences)
SyncManager.SyncService.GOOGLE_DRIVE -> getGoogleDrivePreferences()
} +
if (syncServiceType == SyncManager.SyncService.NONE) {
emptyList()
} else {
listOf(getSyncNowPref(), getAutomaticSyncGroup(syncPreferences))
}
}
}
@Composable
private fun getAdditionalPreferences(syncPreferences: SyncPreferences): List<Preference> {
return listOf(getSyncNowPref(), getAutomaticSyncGroup(syncPreferences))
}
@Composable

View File

@ -209,7 +209,7 @@ object SettingsMainScreen : Screen() {
screen = SettingsBrowseScreen,
),
Item(
titleRes = MR.strings.label_backup_and_sync,
titleRes = MR.strings.label_data_storage,
subtitleRes = MR.strings.pref_backup_summary,
icon = Icons.Outlined.Storage,
screen = SettingsDataScreen,

View File

@ -30,7 +30,6 @@
<string name="label_sources">Sources</string>
<string name="label_data_storage">Data and storage</string>
<string name="label_backup">Backup</string>
<string name="label_backup_and_sync">Backup and Sync</string>
<string name="label_sync">Sync</string>
<string name="label_stats">Statistics</string>
<string name="label_migration">Migrate</string>