Skip to content

Commit

Permalink
Improve general settings
Browse files Browse the repository at this point in the history
  • Loading branch information
geekygecko committed Nov 1, 2024
1 parent 55026c1 commit fe12a85
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import au.com.shiftyjelly.pocketcasts.compose.components.DialogFrame
import au.com.shiftyjelly.pocketcasts.compose.components.SettingRadioDialogRow
import au.com.shiftyjelly.pocketcasts.compose.components.SettingRow
import au.com.shiftyjelly.pocketcasts.compose.components.SettingRowToggle
import au.com.shiftyjelly.pocketcasts.compose.components.SettingSection
import au.com.shiftyjelly.pocketcasts.compose.components.SettingSectionHeader
import au.com.shiftyjelly.pocketcasts.compose.theme
import au.com.shiftyjelly.pocketcasts.images.R
import au.com.shiftyjelly.pocketcasts.models.to.PodcastGrouping
Expand Down Expand Up @@ -118,7 +118,7 @@ class PlaybackSettingsFragment : BaseFragment() {
val listState = rememberLazyListState()
val settingsItemsKey = SettingsItems.entries

val sleepTimerIndex = settingsItemsKey.indexOf(SettingsItems.SETTINGS_GENERAL_SLEEP_TIMER)
val sleepTimerIndex = settingsItemsKey.indexOf(SettingsItems.SETTINGS_HEADER_SLEEP_TIMER)
LaunchedEffect(scrollToSleepTimer) {
if (scrollToSleepTimer) {
listState.animateScrollToItem(index = sleepTimerIndex)
Expand All @@ -143,27 +143,32 @@ class PlaybackSettingsFragment : BaseFragment() {
) {
items(settingsItemsKey.size) { item ->
when (settingsItemsKey[item]) {
SettingsItems.SETTINGS_GENERAL_DEFAULTS -> {
SettingSection(heading = stringResource(LR.string.settings_general_defaults)) {
RowAction(
saved = settings.streamingMode.flow.collectAsState().value,
onSave = {
analyticsTracker.track(
AnalyticsEvent.SETTINGS_GENERAL_ROW_ACTION_CHANGED,
mapOf(
"value" to when (it) {
true -> "play"
false -> "download"
},
),
)
settings.streamingMode.set(it, updateModifiedAt = true)
},
)
}
SettingsItems.SETTINGS_HEADER_DEFAULTS -> {
SettingSectionHeader(
text = stringResource(LR.string.settings_general_defaults),
indent = false,
)
}

SettingsItems.SETTINGS_GENERAL_UP_NEXT -> {
SettingsItems.SETTINGS_ROW_ACTION -> {
RowAction(
saved = settings.streamingMode.flow.collectAsState().value,
onSave = {
analyticsTracker.track(
AnalyticsEvent.SETTINGS_GENERAL_ROW_ACTION_CHANGED,
mapOf(
"value" to when (it) {
true -> "play"
false -> "download"
},
),
)
settings.streamingMode.set(it, updateModifiedAt = true)
},
)
}

SettingsItems.SETTINGS_UP_NEXT_SWIPE -> {
UpNextSwipe(
saved = settings.upNextSwipe.flow.collectAsState().value,
onSave = {
Expand All @@ -181,7 +186,7 @@ class PlaybackSettingsFragment : BaseFragment() {
)
}

SettingsItems.SETTINGS_GENERAL_EPISODE -> {
SettingsItems.SETTINGS_EPISODE_GROUPING -> {
PodcastEpisodeGrouping(
saved = settings.podcastGroupingDefault.flow.collectAsState().value,
onSave = {
Expand All @@ -203,7 +208,7 @@ class PlaybackSettingsFragment : BaseFragment() {
)
}

SettingsItems.SETTINGS_GENERAL_ARCHIVED_EPISODES -> {
SettingsItems.SETTINGS_ARCHIVED_EPISODES -> {
ShowArchived(
saved = settings.showArchivedDefault.flow.collectAsState().value,
onSave = {
Expand All @@ -229,25 +234,31 @@ class PlaybackSettingsFragment : BaseFragment() {
modifier = Modifier.clickable {
(activity as? FragmentHostListener)?.addFragment(MediaActionsFragment())
},
indent = false,
)
}

SettingsItems.SETTINGS_GENERAL_PLAYER -> {
SettingSection(heading = stringResource(LR.string.settings_general_player)) {
SkipTime(
primaryText = stringResource(LR.string.settings_skip_forward_time),
saved = settings.skipForwardInSecs.flow
.collectAsState()
.value,
onSave = {
analyticsTracker.track(
AnalyticsEvent.SETTINGS_GENERAL_SKIP_FORWARD_CHANGED,
mapOf("value" to it),
)
settings.skipForwardInSecs.set(it, updateModifiedAt = true)
},
)
}
SettingsItems.SETTINGS_HEADER_PLAYER -> {
SettingSectionHeader(
text = stringResource(LR.string.settings_general_player),
indent = false,
)
}

SettingsItems.SETTINGS_SKIP_FORWARD_TIME -> {
SkipTime(
primaryText = stringResource(LR.string.settings_skip_forward_time),
saved = settings.skipForwardInSecs.flow
.collectAsState()
.value,
onSave = {
analyticsTracker.track(
AnalyticsEvent.SETTINGS_GENERAL_SKIP_FORWARD_CHANGED,
mapOf("value" to it),
)
settings.skipForwardInSecs.set(it, updateModifiedAt = true)
},
)
}

SettingsItems.SETTINGS_SKIP_BACK_TIME -> {
Expand All @@ -264,7 +275,7 @@ class PlaybackSettingsFragment : BaseFragment() {
)
}

SettingsItems.SETTINGS_GENERAL_KEEP_SCREEN_AWAKE -> {
SettingsItems.SETTINGS_KEEP_SCREEN_AWAKE -> {
KeepScreenAwake(
saved = settings.keepScreenAwake.flow.collectAsState().value,
onSave = {
Expand All @@ -277,7 +288,7 @@ class PlaybackSettingsFragment : BaseFragment() {
)
}

SettingsItems.SETTINGS_GENERAL_OPEN_PLAYER_AUTOMATICALLY -> {
SettingsItems.SETTINGS_OPEN_PLAYER_AUTOMATICALLY -> {
OpenPlayerAutomatically(
saved = settings.openPlayerAutomatically.flow.collectAsState().value,
onSave = {
Expand All @@ -290,7 +301,7 @@ class PlaybackSettingsFragment : BaseFragment() {
)
}

SettingsItems.SETTINGS_GENERAL_INTELLIGENT_PLAYBACK -> {
SettingsItems.SETTINGS_INTELLIGENT_PLAYBACK -> {
IntelligentPlaybackResumption(
saved = settings.intelligentPlaybackResumption.flow.collectAsState().value,
onSave = {
Expand All @@ -303,7 +314,7 @@ class PlaybackSettingsFragment : BaseFragment() {
)
}

SettingsItems.SETTINGS_GENERAL_PLAY_UP_NEXT -> {
SettingsItems.SETTINGS_PLAY_UP_NEXT_EPISODE -> {
PlayUpNextOnTap(
saved = settings.tapOnUpNextShouldPlay.flow.collectAsState().value,
onSave = {
Expand All @@ -316,8 +327,8 @@ class PlaybackSettingsFragment : BaseFragment() {
)
}

SettingsItems.SETTINGS_USE_REAL_TIME_FOR_PLAYBACK_REMAINING_TIME -> {
UseRealTimeForPlaybackRemaingingTime(
SettingsItems.SETTINGS_ADJUST_REMAINING_TIME -> {
UseRealTimeForPlaybackRemainingTime(
saved = settings.useRealTimeForPlaybackRemaingTime.flow.collectAsState().value,
onSave = {
analyticsTracker.track(
Expand All @@ -329,30 +340,37 @@ class PlaybackSettingsFragment : BaseFragment() {
)
}

SettingsItems.SETTINGS_GENERAL_SLEEP_TIMER -> {
SettingSection(heading = stringResource(LR.string.settings_general_sleep_timer)) {
AutoSleepTimerRestart(
saved = settings.autoSleepTimerRestart.flow.collectAsState().value,
onSave = {
analyticsTracker.track(
AnalyticsEvent.SETTINGS_GENERAL_AUTO_SLEEP_TIMER_RESTART_TOGGLED,
mapOf("enabled" to it),
)
settings.autoSleepTimerRestart.set(it, updateModifiedAt = true)
},
)

ShakeToResetSleepTimer(
saved = settings.shakeToResetSleepTimer.flow.collectAsState().value,
onSave = {
analyticsTracker.track(
AnalyticsEvent.SETTINGS_GENERAL_SHAKE_TO_RESET_SLEEP_TIMER_TOGGLED,
mapOf("enabled" to it),
)
settings.shakeToResetSleepTimer.set(it, updateModifiedAt = true)
},
)
}
SettingsItems.SETTINGS_HEADER_SLEEP_TIMER -> {
SettingSectionHeader(
text = stringResource(LR.string.settings_general_sleep_timer),
indent = false,
)
}

SettingsItems.SETTINGS_SLEEP_TIMER_RESTART -> {
AutoSleepTimerRestart(
saved = settings.autoSleepTimerRestart.flow.collectAsState().value,
onSave = {
analyticsTracker.track(
AnalyticsEvent.SETTINGS_GENERAL_AUTO_SLEEP_TIMER_RESTART_TOGGLED,
mapOf("enabled" to it),
)
settings.autoSleepTimerRestart.set(it, updateModifiedAt = true)
},
)
}

SettingsItems.SETTINGS_SLEEP_TIMER_SHAKE -> {
ShakeToResetSleepTimer(
saved = settings.shakeToResetSleepTimer.flow.collectAsState().value,
onSave = {
analyticsTracker.track(
AnalyticsEvent.SETTINGS_GENERAL_SHAKE_TO_RESET_SLEEP_TIMER_TOGGLED,
mapOf("enabled" to it),
)
settings.shakeToResetSleepTimer.set(it, updateModifiedAt = true)
},
)
}

SettingsItems.SETTINGS_GENERAL_AUTOPLAY -> {
Expand Down Expand Up @@ -387,6 +405,7 @@ class PlaybackSettingsFragment : BaseFragment() {
savedOption = saved,
onSave = onSave,
optionToLocalisedString = { getString(rowActionToStringRes(it)) },
indent = false,
)
}

Expand All @@ -411,6 +430,7 @@ class PlaybackSettingsFragment : BaseFragment() {
savedOption = saved,
optionToLocalisedString = { getString(upNextActionToStringRes(it)) },
onSave = onSave,
indent = false,
)
}

Expand Down Expand Up @@ -438,6 +458,7 @@ class PlaybackSettingsFragment : BaseFragment() {
savedOption = saved,
optionToLocalisedString = { getString(podcastGroupingToStringRes(it)) },
onSave = onSave,
indent = false,
)
}

Expand Down Expand Up @@ -469,6 +490,7 @@ class PlaybackSettingsFragment : BaseFragment() {
false -> getString(LR.string.settings_show_archived_action_hide)
}
},
indent = false,
)

@Composable
Expand All @@ -483,6 +505,7 @@ class PlaybackSettingsFragment : BaseFragment() {
primaryText = primaryText,
secondaryText = stringResource(LR.string.seconds_plural, saved),
modifier = Modifier.clickable { showDialog = true },
indent = false,
) {
if (showDialog) {
val focusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -571,6 +594,7 @@ class PlaybackSettingsFragment : BaseFragment() {
secondaryText = stringResource(LR.string.settings_keep_screen_awake_summary),
toggle = SettingRowToggle.Switch(checked = saved),
modifier = Modifier.toggleable(value = saved, role = Role.Switch) { onSave(!saved) },
indent = false,
)

@Composable
Expand All @@ -580,6 +604,7 @@ class PlaybackSettingsFragment : BaseFragment() {
secondaryText = stringResource(id = LR.string.settings_open_player_automatically_summary),
toggle = SettingRowToggle.Switch(checked = saved),
modifier = Modifier.toggleable(value = saved, role = Role.Switch) { onSave(!saved) },
indent = false,
)

@Composable
Expand All @@ -589,6 +614,7 @@ class PlaybackSettingsFragment : BaseFragment() {
secondaryText = stringResource(LR.string.settings_playback_resumption_summary),
toggle = SettingRowToggle.Switch(checked = saved),
modifier = Modifier.toggleable(value = saved, role = Role.Switch) { onSave(!saved) },
indent = false,
)

@Composable
Expand All @@ -598,6 +624,7 @@ class PlaybackSettingsFragment : BaseFragment() {
secondaryText = stringResource(LR.string.settings_up_next_tap_summary),
toggle = SettingRowToggle.Switch(checked = saved),
modifier = Modifier.toggleable(value = saved, role = Role.Switch) { onSave(!saved) },
indent = false,
)

@Composable
Expand All @@ -607,6 +634,7 @@ class PlaybackSettingsFragment : BaseFragment() {
secondaryText = stringResource(LR.string.settings_sleep_timer_shake_to_reset_summary),
toggle = SettingRowToggle.Switch(checked = saved),
modifier = Modifier.toggleable(value = saved, role = Role.Switch) { onSave(!saved) },
indent = false,
)

@Composable
Expand All @@ -616,6 +644,7 @@ class PlaybackSettingsFragment : BaseFragment() {
secondaryText = stringResource(LR.string.settings_sleep_timer_auto_restart_summary),
toggle = SettingRowToggle.Switch(checked = saved),
modifier = Modifier.toggleable(value = saved, role = Role.Switch) { onSave(!saved) },
indent = false,
)

@Composable
Expand All @@ -627,17 +656,19 @@ class PlaybackSettingsFragment : BaseFragment() {
secondaryText = stringResource(LR.string.settings_continuous_playback_summary),
toggle = SettingRowToggle.Switch(checked = saved),
modifier = Modifier.toggleable(value = saved, role = Role.Switch) { onSave(!saved) },
indent = false,
)

@Composable
private fun UseRealTimeForPlaybackRemaingingTime(
private fun UseRealTimeForPlaybackRemainingTime(
saved: Boolean,
onSave: (Boolean) -> Unit,
) = SettingRow(
primaryText = stringResource(LR.string.settings_real_time_playback),
secondaryText = stringResource(LR.string.settings_real_time_playback_summary),
toggle = SettingRowToggle.Switch(checked = saved),
modifier = Modifier.toggleable(value = saved, role = Role.Switch) { onSave(!saved) },
indent = false,
)

private fun showSetAllGroupingDialog(grouping: PodcastGrouping) {
Expand Down Expand Up @@ -677,19 +708,23 @@ class PlaybackSettingsFragment : BaseFragment() {
}

private enum class SettingsItems {
SETTINGS_GENERAL_DEFAULTS,
SETTINGS_GENERAL_UP_NEXT,
SETTINGS_GENERAL_EPISODE,
SETTINGS_GENERAL_ARCHIVED_EPISODES,
SETTINGS_HEADER_DEFAULTS,
SETTINGS_ROW_ACTION,
SETTINGS_UP_NEXT_SWIPE,
SETTINGS_EPISODE_GROUPING,
SETTINGS_ARCHIVED_EPISODES,
SETTINGS_MEDIA_NOTIFICATION_CONTROLS,
SETTINGS_GENERAL_PLAYER,
SETTINGS_HEADER_PLAYER,
SETTINGS_SKIP_FORWARD_TIME,
SETTINGS_SKIP_BACK_TIME,
SETTINGS_GENERAL_KEEP_SCREEN_AWAKE,
SETTINGS_GENERAL_OPEN_PLAYER_AUTOMATICALLY,
SETTINGS_GENERAL_INTELLIGENT_PLAYBACK,
SETTINGS_GENERAL_PLAY_UP_NEXT,
SETTINGS_USE_REAL_TIME_FOR_PLAYBACK_REMAINING_TIME,
SETTINGS_GENERAL_SLEEP_TIMER,
SETTINGS_KEEP_SCREEN_AWAKE,
SETTINGS_OPEN_PLAYER_AUTOMATICALLY,
SETTINGS_INTELLIGENT_PLAYBACK,
SETTINGS_PLAY_UP_NEXT_EPISODE,
SETTINGS_ADJUST_REMAINING_TIME,
SETTINGS_HEADER_SLEEP_TIMER,
SETTINGS_SLEEP_TIMER_RESTART,
SETTINGS_SLEEP_TIMER_SHAKE,

// The [scrollToAutoPlay] fragment argument handling depends on this item being last
// in the list. If it's position is changed, make sure you update the handling when
Expand Down
Loading

0 comments on commit fe12a85

Please sign in to comment.