Skip to content
Snippets Groups Projects
Unverified Commit 1e1064c0 authored by Sebastiano Barezzi's avatar Sebastiano Barezzi Committed by LuK1337
Browse files

Aperture: Dynamically fill the gestures settings

Change-Id: I04f054543c13afef7dee0569f38be05d21b81810
parent 1b1631b2
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.MaterialToolbar
import org.lineageos.aperture.ext.gestureActionToString
import org.lineageos.aperture.ext.setOffset
import org.lineageos.aperture.models.HardwareKey
import org.lineageos.aperture.utils.CameraSoundsUtils
......@@ -224,6 +225,60 @@ class SettingsActivity : AppCompatActivity(R.layout.activity_settings) {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
super.onCreatePreferences(savedInstanceState, rootKey)
val context = requireContext()
for (hardwareKey in HardwareKey.entries) {
val actionPreference = ListPreference(context, null).apply {
key = "${hardwareKey.sharedPreferencesKeyPrefix}_action"
setTitle(hardwareKey.actionPreferenceTitleStringResId)
setDialogTitle(hardwareKey.actionPreferenceTitleStringResId)
when {
hardwareKey.supportsDefault && hardwareKey.isTwoWayKey -> {
setEntries(R.array.gesture_actions_entries)
setEntryValues(R.array.gesture_actions_values)
}
hardwareKey.supportsDefault && !hardwareKey.isTwoWayKey -> {
setEntries(R.array.gesture_actions_no_two_way_entries)
setEntryValues(R.array.gesture_actions_no_two_way_values)
}
!hardwareKey.supportsDefault && hardwareKey.isTwoWayKey -> {
setEntries(R.array.gesture_actions_no_two_way_entries)
setEntryValues(R.array.gesture_actions_no_two_way_values)
}
else -> {
setEntries(R.array.gesture_actions_no_default_no_two_way_entries)
setEntryValues(R.array.gesture_actions_no_default_no_two_way_values)
}
}
setDefaultValue(gestureActionToString(hardwareKey.defaultAction))
isIconSpaceReserved = false
summaryProvider = ListPreference.SimpleSummaryProvider.getInstance()
}
if (!hardwareKey.isTwoWayKey) {
singleButtonsPreferenceCategory?.addPreference(actionPreference)
} else {
val invertPreference = SwitchPreference(context, null).apply {
key = "${hardwareKey.sharedPreferencesKeyPrefix}_invert"
setTitle(hardwareKey.invertPreferenceTitleStringResId!!)
setSummary(hardwareKey.invertPreferenceSummaryStringResId!!)
setDefaultValue(false)
isIconSpaceReserved = false
}
val keyCategory = PreferenceCategory(context, null).apply {
key = hardwareKey.sharedPreferencesKeyPrefix
setTitle(hardwareKey.preferenceCategoryTitleStringResId!!)
isIconSpaceReserved = false
}
preferenceScreen.addPreference(keyCategory)
keyCategory.addPreference(actionPreference)
keyCategory.addPreference(invertPreference)
}
}
recheckKeys()
}
......
......@@ -481,3 +481,11 @@ internal fun SharedPreferences.getHardwareKeyInvert(
) = hardwareKey.isTwoWayKey && getBoolean(
"${hardwareKey.sharedPreferencesKeyPrefix}_invert", false
)
internal fun gestureActionToString(gestureAction: GestureAction) = when (gestureAction) {
GestureAction.SHUTTER -> "shutter"
GestureAction.FOCUS -> "focus"
GestureAction.ZOOM -> "zoom"
GestureAction.DEFAULT -> "default"
GestureAction.NOTHING -> "nothing"
}
......@@ -7,6 +7,8 @@ package org.lineageos.aperture.models
import android.content.SharedPreferences
import android.view.KeyEvent
import androidx.annotation.StringRes
import org.lineageos.aperture.R
/**
* Collection of keys that can be used to do things.
......@@ -24,6 +26,10 @@ enum class HardwareKey(
val sharedPreferencesKeyPrefix: String,
val supportsDefault: Boolean,
val defaultAction: GestureAction,
@StringRes val actionPreferenceTitleStringResId: Int,
@StringRes val preferenceCategoryTitleStringResId: Int? = null,
@StringRes val invertPreferenceTitleStringResId: Int? = null,
@StringRes val invertPreferenceSummaryStringResId: Int? = null,
) {
CAMERA(
KeyEvent.KEYCODE_CAMERA,
......@@ -31,6 +37,7 @@ enum class HardwareKey(
"camera_button",
false,
GestureAction.SHUTTER,
R.string.camera_button_action_title,
),
FOCUS(
KeyEvent.KEYCODE_FOCUS,
......@@ -38,6 +45,7 @@ enum class HardwareKey(
"focus_button",
false,
GestureAction.FOCUS,
R.string.focus_button_action_title,
),
VOLUME(
KeyEvent.KEYCODE_VOLUME_UP,
......@@ -45,6 +53,10 @@ enum class HardwareKey(
"volume_buttons",
true,
GestureAction.SHUTTER,
R.string.volume_buttons_action_title,
R.string.volume_buttons_title,
R.string.volume_buttons_invert_title,
R.string.volume_buttons_invert_summary,
),
ZOOM(
KeyEvent.KEYCODE_ZOOM_IN,
......@@ -52,10 +64,22 @@ enum class HardwareKey(
"zoom_buttons",
false,
GestureAction.ZOOM,
R.string.zoom_buttons_action_title,
R.string.zoom_buttons_title,
R.string.zoom_buttons_invert_title,
R.string.zoom_buttons_invert_summary,
);
val isTwoWayKey = secondKeycode != null
init {
require(
!isTwoWayKey || (preferenceCategoryTitleStringResId != null
&& invertPreferenceTitleStringResId != null
&& invertPreferenceSummaryStringResId != null)
)
}
companion object {
/**
* keycode to ([HardwareKey], first or increase)
......
......@@ -8,72 +8,6 @@
<PreferenceCategory
app:iconSpaceReserved="false"
app:key="single_buttons"
app:title="@string/single_buttons_title">
<ListPreference
app:defaultValue="shutter"
app:entries="@array/gesture_actions_no_default_no_two_way_entries"
app:entryValues="@array/gesture_actions_no_default_no_two_way_values"
app:iconSpaceReserved="false"
app:key="camera_button_action"
app:title="@string/camera_button_action_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="focus"
app:entries="@array/gesture_actions_no_default_no_two_way_entries"
app:entryValues="@array/gesture_actions_no_default_no_two_way_values"
app:iconSpaceReserved="false"
app:key="focus_button_action"
app:title="@string/focus_button_action_title"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
app:key="volume_buttons"
app:title="@string/volume_buttons_title">
<ListPreference
app:defaultValue="shutter"
app:entries="@array/gesture_actions_entries"
app:entryValues="@array/gesture_actions_values"
app:iconSpaceReserved="false"
app:key="volume_buttons_action"
app:title="@string/volume_buttons_action_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="volume_buttons_invert"
app:summary="@string/volume_buttons_invert_summary"
app:title="@string/volume_buttons_invert_title" />
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
app:key="zoom_buttons"
app:title="@string/zoom_buttons_title">
<ListPreference
app:defaultValue="zoom"
app:entries="@array/gesture_actions_no_default_entries"
app:entryValues="@array/gesture_actions_no_default_values"
app:iconSpaceReserved="false"
app:key="zoom_buttons_action"
app:title="@string/zoom_buttons_action_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="zoom_buttons_invert"
app:summary="@string/zoom_buttons_invert_summary"
app:title="@string/zoom_buttons_invert_title" />
</PreferenceCategory>
app:title="@string/single_buttons_title" />
</PreferenceScreen>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment