mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
Allow selecting the device model to help the app detect the main device.
This commit is contained in:
@@ -9,6 +9,7 @@ import eu.darken.androidstarter.common.preferences.Settings
|
||||
import eu.darken.capod.common.debug.autoreport.DebugSettings
|
||||
import eu.darken.capod.common.preferences.PreferenceStoreMapper
|
||||
import eu.darken.capod.common.preferences.createFlowPreference
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -48,6 +49,12 @@ class GeneralSettings @Inject constructor(
|
||||
null
|
||||
)
|
||||
|
||||
val mainDeviceModel = preferences.createFlowPreference<PodDevice.Model>(
|
||||
"core.maindevice.model",
|
||||
PodDevice.Model.UNKNOWN,
|
||||
moshi
|
||||
)
|
||||
|
||||
override val preferenceDataStore: PreferenceDataStore = PreferenceStoreMapper(
|
||||
monitorMode,
|
||||
scannerMode,
|
||||
|
||||
@@ -14,6 +14,7 @@ import eu.darken.capod.common.upgrade.UpgradeRepo
|
||||
import eu.darken.capod.main.core.GeneralSettings
|
||||
import eu.darken.capod.main.core.MonitorMode
|
||||
import eu.darken.capod.main.core.ScannerMode
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
import javax.inject.Inject
|
||||
|
||||
@Keep
|
||||
@@ -33,6 +34,7 @@ class GeneralSettingsFragment : PreferenceFragment2() {
|
||||
private val monitorModePref by lazy { findPreference<ListPreference>(generalSettings.monitorMode.key)!! }
|
||||
private val scanModePref by lazy { findPreference<ListPreference>(generalSettings.scannerMode.key)!! }
|
||||
private val mainDeviceAddressPref by lazy { findPreference<Preference>(generalSettings.mainDeviceAddress.key)!! }
|
||||
private val mainDeviceModelPref by lazy { findPreference<Preference>(generalSettings.mainDeviceModel.key)!! }
|
||||
|
||||
override fun onPreferencesCreated() {
|
||||
monitorModePref.apply {
|
||||
@@ -59,6 +61,16 @@ class GeneralSettingsFragment : PreferenceFragment2() {
|
||||
true
|
||||
}
|
||||
}
|
||||
mainDeviceModelPref.setOnPreferenceClickListener {
|
||||
val dialog = ModelSelectionDialogFactory(requireContext()).create(
|
||||
PodDevice.Model.values().toList(),
|
||||
generalSettings.mainDeviceModel.value
|
||||
) { selected ->
|
||||
generalSettings.mainDeviceModel.value = selected
|
||||
}
|
||||
dialog.show()
|
||||
true
|
||||
}
|
||||
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package eu.darken.capod.main.ui.settings.general
|
||||
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
|
||||
|
||||
class ModelSelectionDialogFactory constructor(private val context: Context) {
|
||||
|
||||
fun create(
|
||||
models: List<PodDevice.Model>,
|
||||
current: PodDevice.Model,
|
||||
callback: (PodDevice.Model) -> Unit
|
||||
): AlertDialog {
|
||||
return MaterialAlertDialogBuilder(context).apply {
|
||||
setTitle(R.string.settings_maindevice_model_label)
|
||||
|
||||
val pairing = models
|
||||
.map { it.label to it }
|
||||
|
||||
setSingleChoiceItems(
|
||||
pairing.map { it.first }.toTypedArray(),
|
||||
pairing.indexOfFirst { it.second == current },
|
||||
DialogInterface.OnClickListener { dialog, which ->
|
||||
val selected = pairing[which].second
|
||||
callback(selected)
|
||||
dialog.dismiss()
|
||||
}
|
||||
)
|
||||
|
||||
}.create()
|
||||
}
|
||||
}
|
||||
@@ -83,9 +83,14 @@ class PodMonitor @Inject constructor(
|
||||
|
||||
val mainDevice: Flow<PodDevice?>
|
||||
get() = devices.map { devices ->
|
||||
devices.maxByOrNull { it.rssi }?.let {
|
||||
devices.maxByOrNull { it.rssi }?.let filter@{ device ->
|
||||
val minimumSignalQuality = generalSettings.minimumSignalQuality.value
|
||||
if (it.signalQuality > minimumSignalQuality) it else null
|
||||
|
||||
generalSettings.mainDeviceModel.value.let {
|
||||
if (device.model != it && it != PodDevice.Model.UNKNOWN) return@filter null
|
||||
}
|
||||
|
||||
if (device.signalQuality > minimumSignalQuality) device else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,9 +131,12 @@
|
||||
<string name="settings_reaction_label">Reactions</string>
|
||||
<string name="settings_reaction_description">React to events and behaviors.</string>
|
||||
<string name="settings_category_yourdevice_label">Your device</string>
|
||||
<string name="settings_maindevice_address_label">Main device</string>
|
||||
<string name="settings_maindevice_address_description">The paired pod device to which this app should react.</string>
|
||||
<string name="settings_maindevice_address_label">Your device address</string>
|
||||
<string name="settings_maindevice_address_description">The address of your paired device. The app uses this to determine when it is connected to your phone.</string>
|
||||
<string name="settings_maindevice_address_none">None</string>
|
||||
<string name="settings_maindevice_model_label">Your device model</string>
|
||||
<string name="settings_maindevice_model_description">The model of your main device. This helps the app recognize your device when it is not connected to your phone.</string>
|
||||
|
||||
<string name="settings_reaction_autoconnect_whenseen_label">When seen</string>
|
||||
<string name="settings_reaction_autoconnect_caseopen_label">Case is open</string>
|
||||
<string name="settings_reaction_autoconnect_inear_label">In ear</string>
|
||||
|
||||
@@ -35,6 +35,12 @@
|
||||
android:key="core.maindevice.address"
|
||||
android:summary="@string/settings_maindevice_address_description"
|
||||
android:title="@string/settings_maindevice_address_label" />
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_device_generic_headphones"
|
||||
android:key="core.maindevice.model"
|
||||
android:summary="@string/settings_maindevice_model_description"
|
||||
android:title="@string/settings_maindevice_model_label" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/settings_category_other_label">
|
||||
|
||||
Reference in New Issue
Block a user