Add device filtering + showall option

This commit is contained in:
darken
2022-01-04 21:07:12 +01:00
parent 54e59adf01
commit 2b965ea098
8 changed files with 78 additions and 13 deletions
@@ -16,8 +16,8 @@ import javax.inject.Singleton
@Singleton
class GeneralSettings @Inject constructor(
@ApplicationContext private val context: Context,
private val debugSettings: DebugSettings,
private val moshi: Moshi,
debugSettings: DebugSettings,
moshi: Moshi,
) : Settings() {
override val preferences: SharedPreferences = context.getSharedPreferences("settings_general", Context.MODE_PRIVATE)
@@ -34,9 +34,21 @@ class GeneralSettings @Inject constructor(
moshi
)
val autoPause = preferences.createFlowPreference(
"core.eardetection.autopause.enabled",
false
)
val showAll = preferences.createFlowPreference(
"core.showall.enabled",
false
)
override val preferenceDataStore: PreferenceDataStore = PreferenceStoreMapper(
monitorMode,
scannerMode,
autoPause,
showAll,
debugSettings.isDebugModeEnabled,
debugSettings.isAutoReportEnabled
)
@@ -13,6 +13,7 @@ import eu.darken.capod.common.navigation.navVia
import eu.darken.capod.common.permissions.Permission
import eu.darken.capod.common.permissions.isGrantedOrNotRequired
import eu.darken.capod.common.uix.ViewModel3
import eu.darken.capod.main.core.GeneralSettings
import eu.darken.capod.main.ui.overview.cards.PermissionCardVH
import eu.darken.capod.main.ui.overview.cards.pods.BasicSingleApplePodsCardVH
import eu.darken.capod.main.ui.overview.cards.pods.DualApplePodsCardVH
@@ -39,13 +40,10 @@ class OverviewFragmentVM @Inject constructor(
private val recorderModule: RecorderModule,
private val monitorControl: MonitorControl,
private val podMonitor: PodMonitor,
private val generalSettings: GeneralSettings,
private val debugSettings: DebugSettings,
) : ViewModel3(dispatcherProvider = dispatcherProvider) {
private val enabledState: Flow<Boolean> = flow {
emit(false)
}
private val updateTicker = channelFlow<Unit> {
while (isActive) {
trySend(Unit)
@@ -66,9 +64,19 @@ class OverviewFragmentVM @Inject constructor(
val requestPermissionevent = SingleLiveEvent<Permission>()
private val pods: Flow<List<PodDevice>> = requiredPermissions
.flatMapLatest {
if (it.isEmpty()) {
podMonitor.pods
.flatMapLatest { permissions ->
if (permissions.isEmpty()) {
combine(podMonitor.pods, generalSettings.showAll.flow) { pods, showAll ->
if (showAll) {
pods
.sortedByDescending { it.rssi }
} else {
pods
.maxByOrNull { it.rssi }
?.let { listOf(it) }
?: emptyList()
}
}
} else {
channelFlow {
send(emptyList())
@@ -79,11 +87,10 @@ class OverviewFragmentVM @Inject constructor(
val listItems: LiveData<List<OverviewAdapter.Item>> = combine(
updateTicker,
enabledState,
requiredPermissions,
pods,
debugSettings.isDebugModeEnabled.flow
) { tick, state, permissions, pods, isDebugMode ->
debugSettings.isDebugModeEnabled.flow,
) { _, permissions, pods, isDebugMode ->
val items = mutableListOf<OverviewAdapter.Item>()
permissions
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M3,6h18L21,4L3,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h4v-2L3,18L3,6zM13,12L9,12v1.78c-0.61,0.55 -1,1.33 -1,2.22s0.39,1.67 1,2.22L9,20h4v-1.78c0.61,-0.55 1,-1.34 1,-2.22s-0.39,-1.67 -1,-2.22L13,12zM11,17.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM22,8h-6c-0.5,0 -1,0.5 -1,1v10c0,0.5 0.5,1 1,1h6c0.5,0 1,-0.5 1,-1L23,9c0,-0.5 -0.5,-1 -1,-1zM21,18h-4v-8h4v8z" />
</vector>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2zM11,16H9V8h2V16zM15,16h-2V8h2V16z" />
</vector>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z" />
</vector>
+1 -1
View File
@@ -33,6 +33,6 @@
android:layout_margin="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_baseline_add_24" />
app:srcCompat="@drawable/ic_baseline_refresh_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
+4
View File
@@ -95,4 +95,8 @@
<string name="settings_scanner_mode_lowpower_label">Low power</string>
<string name="settings_scanner_mode_balanced_label">Balanced</string>
<string name="settings_scanner_mode_lowlatency_label">Low latency</string>
<string name="settings_autopause_label">Auto pause</string>
<string name="settings_autopause_description">Pause music when removing the device from your ear (if your device supports it).</string>
<string name="settings_showall_label">Show all devices</string>
<string name="settings_showall_description">Show other people\'s devices that are near you.</string>
</resources>
@@ -13,6 +13,18 @@
android:summary="@string/settings_scanner_mode_description"
android:title="@string/settings_scanner_mode_label" />
<CheckBoxPreference
android:icon="@drawable/ic_baseline_pause_circle_24"
android:key="core.eardetection.autopause.enabled"
android:summary="@string/settings_autopause_description"
android:title="@string/settings_autopause_label" />
<CheckBoxPreference
android:icon="@drawable/ic_baseline_devices_other_24"
android:key="core.showall.enabled"
android:summary="@string/settings_showall_description"
android:title="@string/settings_showall_label" />
<PreferenceCategory android:title="@string/settings_category_other_label">
<CheckBoxPreference