From be60f46272c43254631b0b6f189a86fa420b0201 Mon Sep 17 00:00:00 2001 From: darken Date: Tue, 18 Jan 2022 11:32:31 +0100 Subject: [PATCH] Add hint when no main device is connected --- .../capod/main/ui/overview/OverviewAdapter.kt | 2 + .../main/ui/overview/OverviewFragmentVM.kt | 3 ++ .../ui/overview/cards/MissingMainDeviceVH.kt | 33 ++++++++++++++ .../res/layout/overview_nomaindevice_item.xml | 43 +++++++++++++++++++ .../layout/overview_nopaireddevice_item.xml | 4 +- app/src/main/res/values/strings.xml | 9 ++-- 6 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/eu/darken/capod/main/ui/overview/cards/MissingMainDeviceVH.kt create mode 100644 app/src/main/res/layout/overview_nomaindevice_item.xml diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewAdapter.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewAdapter.kt index d52e2802..4884ce48 100644 --- a/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewAdapter.kt +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewAdapter.kt @@ -11,6 +11,7 @@ import eu.darken.capod.common.lists.differ.setupDiffer import eu.darken.capod.common.lists.modular.ModularAdapter import eu.darken.capod.common.lists.modular.mods.DataBinderMod import eu.darken.capod.common.lists.modular.mods.TypedVHCreatorMod +import eu.darken.capod.main.ui.overview.cards.MissingMainDeviceVH import eu.darken.capod.main.ui.overview.cards.NoPairedDeviceCardVH import eu.darken.capod.main.ui.overview.cards.PermissionCardVH import eu.darken.capod.main.ui.overview.cards.pods.BasicSingleApplePodsCardVH @@ -33,6 +34,7 @@ class OverviewAdapter @Inject constructor() : modules.add(TypedVHCreatorMod({ data[it] is BasicSingleApplePodsCardVH.Item }) { BasicSingleApplePodsCardVH(it) }) modules.add(TypedVHCreatorMod({ data[it] is UnknownPodDeviceCardVH.Item }) { UnknownPodDeviceCardVH(it) }) modules.add(TypedVHCreatorMod({ data[it] is NoPairedDeviceCardVH.Item }) { NoPairedDeviceCardVH(it) }) + modules.add(TypedVHCreatorMod({ data[it] is MissingMainDeviceVH.Item }) { MissingMainDeviceVH(it) }) } override fun getItemCount(): Int = data.size diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewFragmentVM.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewFragmentVM.kt index d633acd8..211c3275 100644 --- a/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewFragmentVM.kt +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/OverviewFragmentVM.kt @@ -16,6 +16,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.PermissionTool +import eu.darken.capod.main.ui.overview.cards.MissingMainDeviceVH import eu.darken.capod.main.ui.overview.cards.NoPairedDeviceCardVH import eu.darken.capod.main.ui.overview.cards.PermissionCardVH import eu.darken.capod.main.ui.overview.cards.pods.* @@ -155,6 +156,8 @@ class OverviewFragmentVM @Inject constructor( NoPairedDeviceCardVH.Item { generalSettings.showAll.value = true }.run { items.add(this) } + } else if (showAll && mainPod == null) { + items.add(0, MissingMainDeviceVH.Item) } items diff --git a/app/src/main/java/eu/darken/capod/main/ui/overview/cards/MissingMainDeviceVH.kt b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/MissingMainDeviceVH.kt new file mode 100644 index 00000000..437b4a55 --- /dev/null +++ b/app/src/main/java/eu/darken/capod/main/ui/overview/cards/MissingMainDeviceVH.kt @@ -0,0 +1,33 @@ +package eu.darken.capod.main.ui.overview.cards + +import android.view.ViewGroup +import eu.darken.capod.R +import eu.darken.capod.common.lists.binding +import eu.darken.capod.common.lists.differ.DifferItem +import eu.darken.capod.databinding.OverviewNomaindeviceItemBinding +import eu.darken.capod.main.ui.overview.OverviewAdapter + +class MissingMainDeviceVH(parent: ViewGroup) : + OverviewAdapter.BaseVH( + R.layout.overview_nomaindevice_item, + parent + ) { + + override val viewBinding = lazy { + OverviewNomaindeviceItemBinding.bind(itemView) + } + + override val onBindData: OverviewNomaindeviceItemBinding.( + item: Item, + payloads: List + ) -> Unit = binding(payload = true) { item -> + + } + + object Item : OverviewAdapter.Item { + override val stableId: Long = Item::class.hashCode().toLong() + + override val payloadProvider: ((DifferItem, DifferItem) -> DifferItem?) + get() = { old, new -> if (new::class.isInstance(old)) new else null } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/overview_nomaindevice_item.xml b/app/src/main/res/layout/overview_nomaindevice_item.xml new file mode 100644 index 00000000..02535fca --- /dev/null +++ b/app/src/main/res/layout/overview_nomaindevice_item.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/overview_nopaireddevice_item.xml b/app/src/main/res/layout/overview_nopaireddevice_item.xml index 94c69ca2..5f0e7928 100644 --- a/app/src/main/res/layout/overview_nopaireddevice_item.xml +++ b/app/src/main/res/layout/overview_nopaireddevice_item.xml @@ -23,7 +23,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - android:text="@string/pods_none_label" /> + android:text="@string/overview_nopaireddevices_label" /> + android:text="@string/overview_nopaireddevices_description" /> Red Black Not connected to a device - Connected, but idle + Connected to a device, but idle In music mode In call mode Ringing @@ -66,13 +66,16 @@ Unknown device This is an unknown device, but it is using similar message format. Let\'s add support for it, contact me :). No device - No paired device connected. - Connect a paired device or enable the \'Show all\' option. Charging In ear Microphone Yours + No paired device connected. + Connect a paired device or enable the \'Show all\' option. + Missing main device + All detected devices are unlikely to be yours. Power on and connect your device or adjust the settings. + Settings Privacy policy Handling data responsibly.