Skip to content

Commit

Permalink
#470 feat: preference to show the first 5 characters of the device de…
Browse files Browse the repository at this point in the history
…scriptor for device specific triggers.
  • Loading branch information
sds100 committed Oct 8, 2020
1 parent 289a1a7 commit bdbde02
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ object AppPreferences : DefaultPreferences() {
true
)

val showDeviceDescriptors by BoolPref(
appCtx.str(R.string.key_pref_show_device_descriptors),
appCtx.bool(R.bool.default_value_show_device_descriptors)
)

@NightMode
fun getSdkNightMode(darkThemePrefValue: String): Int {
return when (darkThemePrefValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import com.airbnb.epoxy.EpoxyTouchHelper
import com.google.android.material.card.MaterialCardView
import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.TriggerKeyBindingModel_
import io.github.sds100.keymapper.data.AppPreferences
import io.github.sds100.keymapper.data.model.Trigger
import io.github.sds100.keymapper.data.viewmodel.ConfigKeymapViewModel
import io.github.sds100.keymapper.databinding.FragmentTriggerBinding
import io.github.sds100.keymapper.service.MyAccessibilityService
import io.github.sds100.keymapper.triggerKey
import io.github.sds100.keymapper.util.*
import io.github.sds100.keymapper.util.result.onSuccess
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -213,7 +215,15 @@ class TriggerFragment(private val mKeymapId: Long) : Fragment() {
yield(str(R.string.this_device))
yield(str(R.string.any_device))

yieldAll(InputDeviceUtils.getExternalDeviceNames())
if (AppPreferences.showDeviceDescriptors) {
InputDeviceUtils.getExternalDeviceDescriptors().forEach { descriptor ->
InputDeviceUtils.getName(descriptor).onSuccess { name ->
yield("$name ${descriptor.substring(0..4)}")
}
}
} else {
yieldAll(InputDeviceUtils.getExternalDeviceNames())
}

}.toList().toTypedArray()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.sds100.keymapper.util

import android.content.Context
import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.data.AppPreferences
import io.github.sds100.keymapper.data.model.DeviceInfo
import io.github.sds100.keymapper.data.model.Trigger
import io.github.sds100.keymapper.data.model.Trigger.Companion.DOUBLE_PRESS
Expand Down Expand Up @@ -76,5 +77,15 @@ fun Trigger.Key.getDeviceName(ctx: Context, deviceInfoList: List<DeviceInfo>): S
when (deviceId) {
Trigger.Key.DEVICE_ID_THIS_DEVICE -> ctx.str(R.string.this_device)
Trigger.Key.DEVICE_ID_ANY_DEVICE -> ctx.str(R.string.any_device)
else -> deviceInfoList.find { it.descriptor == deviceId }?.name ?: ctx.str(R.string.dont_know_device_name)
else -> {
val deviceInfo = deviceInfoList.find { it.descriptor == deviceId }

when {
deviceInfo == null -> ctx.str(R.string.dont_know_device_name)

AppPreferences.showDeviceDescriptors -> "${deviceInfo.name} ${deviceInfo.descriptor.substring(0..4)}"

else -> deviceInfo.name
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/default_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<string name="default_value_automatic_backup_location" />
<bool name="default_value_keymaps_paused">false</bool>
<bool name="default_value_hide_home_screen_alerts">false</bool>
<bool name="default_value_show_device_descriptors">false</bool>

<string name="default_value_dark_theme_mode">@string/value_pref_dark_theme_follow_system</string>
<integer name="default_value_long_press_delay">500</integer>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<string name="key_pref_showcase_action_list" translatable="false">pref_showcase_action_list</string>
<string name="key_pref_last_used_compatible_ime" translatable="false">pref_last_used_compatible_ime</string>
<string name="key_pref_show_gui_keyboard_ad" translatable="false">pref_show_gui_keyboard_ad</string>
<string name="key_pref_show_device_descriptors" translatable="false">pref_show_device_descriptors</string>

<string name="key_pref_category_notifications" translatable="false">pref_category_notifications</string>
<string name="key_pref_category_secure_settings" translatable="false">pref_category_secure_settings</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@

<string name="title_pref_hide_home_screen_alerts">Hide homescreen alerts</string>
<string name="summary_pref_hide_home_screen_alerts">Hide the alerts at the top of the homescreen.</string>

<string name="title_pref_show_device_descriptors">Show the first 5 characters of the device id for device specific triggers</string>
<string name="summary_pref_show_device_descriptors">This is useful to differentiate between devices that have the same name.</string>
<!--Preference titles and summaries-->

<!--Preference categories-->
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml-v19/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
android:summary="@string/summary_pref_force_vibrate"
android:title="@string/title_pref_force_vibrate" />

<androidx.preference.SwitchPreference
android:defaultValue="@bool/default_value_show_device_descriptors"
android:key="@string/key_pref_show_device_descriptors"
android:summary="@string/summary_pref_show_device_descriptors"
android:title="@string/title_pref_show_device_descriptors" />

<androidx.preference.SwitchPreference
android:defaultValue="@bool/default_value_show_toggle_remappings_notification"
android:key="@string/key_pref_show_toggle_remappings_notification"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml-v26/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
android:summary="@string/summary_pref_force_vibrate"
android:title="@string/title_pref_force_vibrate" />

<androidx.preference.SwitchPreference
android:defaultValue="@bool/default_value_show_device_descriptors"
android:key="@string/key_pref_show_device_descriptors"
android:summary="@string/summary_pref_show_device_descriptors"
android:title="@string/title_pref_show_device_descriptors" />

<androidx.preference.SeekBarPreference
android:defaultValue="@integer/default_value_long_press_delay"
android:key="@string/key_pref_long_press_delay"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml-v27/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
android:summary="@string/summary_pref_force_vibrate"
android:title="@string/title_pref_force_vibrate" />

<androidx.preference.SwitchPreference
android:defaultValue="@bool/default_value_show_device_descriptors"
android:key="@string/key_pref_show_device_descriptors"
android:summary="@string/summary_pref_show_device_descriptors"
android:title="@string/title_pref_show_device_descriptors" />

<androidx.preference.SeekBarPreference
android:defaultValue="@integer/default_value_long_press_delay"
android:key="@string/key_pref_long_press_delay"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml-v29/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
android:summary="@string/summary_pref_force_vibrate"
android:title="@string/title_pref_force_vibrate" />

<androidx.preference.SwitchPreference
android:defaultValue="@bool/default_value_show_device_descriptors"
android:key="@string/key_pref_show_device_descriptors"
android:summary="@string/summary_pref_show_device_descriptors"
android:title="@string/title_pref_show_device_descriptors" />

<androidx.preference.SeekBarPreference
android:defaultValue="@integer/default_value_long_press_delay"
android:key="@string/key_pref_long_press_delay"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
android:summary="@string/summary_pref_force_vibrate"
android:title="@string/title_pref_force_vibrate" />

<androidx.preference.SwitchPreference
android:defaultValue="@bool/default_value_show_device_descriptors"
android:key="@string/key_pref_show_device_descriptors"
android:summary="@string/summary_pref_show_device_descriptors"
android:title="@string/title_pref_show_device_descriptors" />

<androidx.preference.SwitchPreference
android:defaultValue="@bool/default_value_show_toggle_remappings_notification"
android:key="@string/key_pref_show_toggle_remappings_notification"
Expand Down

0 comments on commit bdbde02

Please sign in to comment.