Skip to content

Commit

Permalink
Add ability to long press setting group to change it's default visibi…
Browse files Browse the repository at this point in the history
…lity by #1538
  • Loading branch information
T8RIN committed Dec 23, 2024
1 parent d8ed587 commit 04cc0c2
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 9 deletions.
2 changes: 2 additions & 0 deletions core/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1508,4 +1508,6 @@
<string name="fast_settings_side">Fast Settings Side</string>
<string name="fast_settings_side_sub">Add floating strip at chosen side while editing images, which will open fast settings if clicked</string>
<string name="clear_selection">Clear Selection</string>
<string name="settings_group_visibility_hidden">Setting group \"%s\" will be collapsed by default</string>
<string name="settings_group_visibility_visible">Setting group \"%s\" will be expanded by default</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,13 @@ fun SettingsInteractor.toSimpleSettingsInteractor(): SimpleSettingsInteractor {

override fun isInstalledFromPlayStore(): Boolean = instance.isInstalledFromPlayStore()

override suspend fun toggleSettingsGroupVisibility(
key: Int,
value: Boolean
) = instance.toggleSettingsGroupVisibility(
key = key,
value = value
)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ interface SimpleSettingsInteractor {

fun isInstalledFromPlayStore(): Boolean

suspend fun toggleSettingsGroupVisibility(
key: Int,
value: Boolean
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ data class SettingsState(
val mainScreenTitle: String,
val sliderType: SliderType,
val isCenterAlignDialogButtons: Boolean,
val fastSettingsSide: FastSettingsSide
val fastSettingsSide: FastSettingsSide,
val settingGroupsInitialVisibility: Map<Int, Boolean>
) {

companion object {
Expand Down Expand Up @@ -200,7 +201,8 @@ data class SettingsState(
mainScreenTitle = "",
sliderType = SliderType.Fancy,
isCenterAlignDialogButtons = false,
fastSettingsSide = FastSettingsSide.CenterStart
fastSettingsSide = FastSettingsSide.CenterStart,
settingGroupsInitialVisibility = emptyMap()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ import ru.tech.imageresizershrinker.core.resources.icons.Shadow
import ru.tech.imageresizershrinker.core.resources.icons.Stacks

sealed class SettingsGroup(
val id: Int,
val titleId: Int,
val icon: ImageVector,
val settingsList: List<Setting>,
val initialState: Boolean,
) {
data object ContactMe : SettingsGroup(
id = 0,
icon = Icons.Rounded.PersonSearch,
titleId = R.string.contact_me,
settingsList = listOf(
Expand All @@ -64,6 +66,7 @@ sealed class SettingsGroup(
)

data object PrimaryCustomization : SettingsGroup(
id = 1,
icon = Icons.Rounded.Palette,
titleId = R.string.customization,
settingsList = listOf(
Expand All @@ -77,6 +80,7 @@ sealed class SettingsGroup(
)

data object SecondaryCustomization : SettingsGroup(
id = 2,
icon = Icons.TwoTone.Palette,
titleId = R.string.secondary_customization,
settingsList = listOf(
Expand All @@ -88,6 +92,7 @@ sealed class SettingsGroup(
)

data object Layout : SettingsGroup(
id = 3,
icon = Icons.Rounded.ViewCarousel,
titleId = R.string.layout,
settingsList = listOf(
Expand All @@ -102,6 +107,7 @@ sealed class SettingsGroup(
)

data object NightMode : SettingsGroup(
id = 4,
icon = Icons.Rounded.ShieldMoon,
titleId = R.string.night_mode,
settingsList = listOf(
Expand All @@ -111,6 +117,7 @@ sealed class SettingsGroup(
)

data object Shadows : SettingsGroup(
id = 5,
icon = Icons.Filled.Shadow,
titleId = R.string.shadows,
settingsList = listOf(
Expand All @@ -125,6 +132,7 @@ sealed class SettingsGroup(
)

data object Font : SettingsGroup(
id = 6,
icon = Icons.Rounded.SortByAlpha,
titleId = R.string.text,
settingsList = listOf(
Expand All @@ -136,6 +144,7 @@ sealed class SettingsGroup(
)

data object ToolsArrangement : SettingsGroup(
id = 7,
icon = Icons.Rounded.Stacks,
titleId = R.string.tools_arrangement,
settingsList = listOf(
Expand All @@ -147,6 +156,7 @@ sealed class SettingsGroup(
)

data object Presets : SettingsGroup(
id = 8,
icon = Icons.Rounded.LabelPercent,
titleId = R.string.presets,
settingsList = listOf(
Expand All @@ -157,6 +167,7 @@ sealed class SettingsGroup(
)

data object DefaultValues : SettingsGroup(
id = 9,
icon = Icons.Outlined.Architecture,
titleId = R.string.default_values,
settingsList = listOf(
Expand All @@ -167,6 +178,7 @@ sealed class SettingsGroup(
)

data object Draw : SettingsGroup(
id = 10,
icon = Icons.Rounded.Draw,
titleId = R.string.draw,
settingsList = listOf(
Expand All @@ -180,6 +192,7 @@ sealed class SettingsGroup(
)

data object Exif : SettingsGroup(
id = 11,
icon = Icons.Rounded.Exif,
titleId = R.string.exif,
settingsList = listOf(
Expand All @@ -189,6 +202,7 @@ sealed class SettingsGroup(
)

data object Folder : SettingsGroup(
id = 12,
icon = Icons.Rounded.FolderOpened,
titleId = R.string.folder,
settingsList = listOf(
Expand All @@ -199,6 +213,7 @@ sealed class SettingsGroup(
)

data object Filename : SettingsGroup(
id = 13,
icon = Icons.Rounded.Description,
titleId = R.string.filename,
settingsList = listOf(
Expand All @@ -216,6 +231,7 @@ sealed class SettingsGroup(
)

data object Cache : SettingsGroup(
id = 14,
icon = Icons.Rounded.Mop,
titleId = R.string.cache,
settingsList = listOf(
Expand All @@ -226,6 +242,7 @@ sealed class SettingsGroup(
)

data object ImageSource : SettingsGroup(
id = 15,
icon = Icons.Rounded.ImageSearch,
titleId = R.string.image_source,
settingsList = listOf(
Expand All @@ -235,6 +252,7 @@ sealed class SettingsGroup(
)

data object BackupRestore : SettingsGroup(
id = 16,
icon = Icons.Rounded.SettingsBackupRestore,
titleId = R.string.backup_and_restore,
settingsList = listOf(
Expand All @@ -246,6 +264,7 @@ sealed class SettingsGroup(
)

data object Firebase : SettingsGroup(
id = 17,
icon = Icons.Rounded.Firebase,
titleId = R.string.firebase,
settingsList = listOf(
Expand All @@ -256,6 +275,7 @@ sealed class SettingsGroup(
)

data object Updates : SettingsGroup(
id = 17,
icon = Icons.Rounded.SystemSecurityUpdate,
titleId = R.string.updates,
settingsList = listOf(
Expand All @@ -267,6 +287,7 @@ sealed class SettingsGroup(
)

data object AboutApp : SettingsGroup(
id = 18,
icon = Icons.Rounded.Info,
titleId = R.string.about_app,
settingsList = listOf(
Expand All @@ -282,6 +303,7 @@ sealed class SettingsGroup(
)

data object Clipboard : SettingsGroup(
id = 19,
icon = Icons.Rounded.ClipboardFile,
titleId = R.string.clipboard,
settingsList = listOf(
Expand All @@ -293,6 +315,7 @@ sealed class SettingsGroup(
)

data object Haptics : SettingsGroup(
id = 20,
icon = Icons.Rounded.Vibration,
titleId = R.string.vibration,
settingsList = listOf(
Expand All @@ -302,6 +325,7 @@ sealed class SettingsGroup(
)

data object Screen : SettingsGroup(
id = 21,
icon = Icons.Rounded.PhoneAndroid,
titleId = R.string.screen,
settingsList = listOf(
Expand All @@ -314,6 +338,7 @@ sealed class SettingsGroup(
)

data object Emoji : SettingsGroup(
id = 22,
icon = Icons.Rounded.Face6,
titleId = R.string.emoji,
settingsList = listOf(
Expand All @@ -325,6 +350,7 @@ sealed class SettingsGroup(
)

data object Confetti : SettingsGroup(
id = 23,
icon = Icons.Rounded.Celebration,
titleId = R.string.confetti,
settingsList = listOf(
Expand All @@ -337,6 +363,7 @@ sealed class SettingsGroup(
)

data object Behavior : SettingsGroup(
id = 24,
icon = Icons.Rounded.Explore,
titleId = R.string.behavior,
settingsList = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ data class UiSettingsState(
val sliderType: SliderType,
val isCenterAlignDialogButtons: Boolean,
val fastSettingsSide: FastSettingsSide,
val settingGroupsInitialVisibility: Map<Int, Boolean>
)

fun UiSettingsState.isFirstLaunch(
Expand Down Expand Up @@ -357,7 +358,8 @@ fun SettingsState.toUiState(
mainScreenTitle = mainScreenTitle,
sliderType = sliderType,
isCenterAlignDialogButtons = isCenterAlignDialogButtons,
fastSettingsSide = fastSettingsSide
fastSettingsSide = fastSettingsSide,
settingGroupsInitialVisibility = settingGroupsInitialVisibility
)
}
}.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -71,6 +71,7 @@ fun ExpandableItem(
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
canExpand: Boolean = true,
onClick: () -> Unit = {},
onLongClick: (() -> Unit)? = null,
expansionIconContainerColor: Color = Color.Transparent
) {
val haptics = LocalHapticFeedback.current
Expand All @@ -86,14 +87,22 @@ fun ExpandableItem(
shape = shape
)
) {
var expanded by rememberSaveable { mutableStateOf(initialState) }
var expanded by rememberSaveable(initialState) { mutableStateOf(initialState) }
val rotation by animateFloatAsState(if (expanded) 180f else 0f)
Row(
modifier = Modifier
.clip(shape)
.clickable(
.combinedClickable(
interactionSource = interactionSource,
indication = LocalIndication.current
indication = LocalIndication.current,
onLongClick = if (onLongClick != null) {
{
haptics.performHapticFeedback(
HapticFeedbackType.LongPress
)
onLongClick()
}
} else null
) {
haptics.performHapticFeedback(
HapticFeedbackType.LongPress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ import ru.tech.imageresizershrinker.feature.settings.data.SettingKeys.SCREEN_SEA
import ru.tech.imageresizershrinker.feature.settings.data.SettingKeys.SECURE_MODE
import ru.tech.imageresizershrinker.feature.settings.data.SettingKeys.SELECTED_EMOJI_INDEX
import ru.tech.imageresizershrinker.feature.settings.data.SettingKeys.SELECTED_FONT_INDEX
import ru.tech.imageresizershrinker.feature.settings.data.SettingKeys.SETTINGS_GROUP_VISIBILITY
import ru.tech.imageresizershrinker.feature.settings.data.SettingKeys.SHOW_SETTINGS_IN_LANDSCAPE
import ru.tech.imageresizershrinker.feature.settings.data.SettingKeys.SHOW_UPDATE_DIALOG
import ru.tech.imageresizershrinker.feature.settings.data.SettingKeys.SKIP_IMAGE_PICKING
Expand Down Expand Up @@ -312,7 +313,8 @@ internal class AndroidSettingsManager @Inject constructor(
?: default.isCenterAlignDialogButtons,
fastSettingsSide = prefs[FAST_SETTINGS_SIDE]?.let {
FastSettingsSide.fromOrdinal(it)
} ?: default.fastSettingsSide
} ?: default.fastSettingsSide,
settingGroupsInitialVisibility = prefs[SETTINGS_GROUP_VISIBILITY].toSettingGroupsInitialVisibility()
)
}.onEach { currentSettings = it }

Expand Down Expand Up @@ -1102,6 +1104,21 @@ internal class AndroidSettingsManager @Inject constructor(

override fun isInstalledFromPlayStore(): Boolean = context.isInstalledFromPlayStore()

override suspend fun toggleSettingsGroupVisibility(
key: Int,
value: Boolean
) {
dataStore.edit {
it[SETTINGS_GROUP_VISIBILITY] =
currentSettings.settingGroupsInitialVisibility.toMutableMap().run {
this[key] = value
map {
"${it.key}:${it.value}"
}.toSet()
}
}
}

override suspend fun setFastSettingsSide(side: FastSettingsSide) {
dataStore.edit {
it[FAST_SETTINGS_SIDE] = side.ordinal
Expand All @@ -1128,4 +1145,9 @@ internal class AndroidSettingsManager @Inject constructor(
this[key] = !value
}

private fun Set<String>?.toSettingGroupsInitialVisibility(): Map<Int, Boolean> =
this?.map { key ->
key.split(":").let { it[0].toInt() to it[1].toBoolean() }
}?.toMap() ?: default.settingGroupsInitialVisibility

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.datastore.preferences.core.doublePreferencesKey
import androidx.datastore.preferences.core.floatPreferencesKey
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.core.stringSetPreferencesKey

internal object SettingKeys {
val SAVE_FOLDER_URI = stringPreferencesKey("saveFolder")
Expand Down Expand Up @@ -111,4 +112,5 @@ internal object SettingKeys {
val SLIDER_TYPE = intPreferencesKey("SLIDER_TYPE")
val CENTER_ALIGN_DIALOG_BUTTONS = booleanPreferencesKey("CENTER_ALIGN_DIALOG_BUTTONS")
val FAST_SETTINGS_SIDE = intPreferencesKey("FAST_SETTINGS_SIDE")
val SETTINGS_GROUP_VISIBILITY = stringSetPreferencesKey("SETTINGS_GROUP_VISIBILITY")
}
Loading

0 comments on commit 04cc0c2

Please sign in to comment.