From c18e5c4e204e8eab0ead590eb39865230004a3b3 Mon Sep 17 00:00:00 2001 From: Philoul Date: Thu, 24 Aug 2023 23:36:10 +0200 Subject: [PATCH] Wear cwf Add EventWearUpdateGui management for update info during cwf load --- .../plugins/general/wear/WearFragment.kt | 2 +- .../wear/activities/CwfInfosActivity.kt | 30 +++++++++++++++++++ .../main/res/layout/cwf_infos_activity.xml | 4 +-- .../layout/cwf_infos_activity_view_item.xml | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/WearFragment.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/WearFragment.kt index b92077db25..89bb490c72 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/WearFragment.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/WearFragment.kt @@ -114,7 +114,7 @@ class WearFragment : DaggerFragment() { binding.coverChart.setImageDrawable(it.drawableDatas[CwfDrawableFileMap.CUSTOM_WATCHFACE]?.toDrawable(resources)) binding.infosCustom.visibility = View.VISIBLE } ?:apply { - binding.customName.text = rh.gs(R.string.wear_custom_watchface, rh.gs(info.nightscout.shared.R.string.wear_default_watchface)) + binding.customName.text = rh.gs(R.string.wear_custom_watchface, "") binding.coverChart.setImageDrawable(null) binding.infosCustom.visibility = View.GONE } diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt index 8d24f7005e..c457d69bfa 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt @@ -11,13 +11,16 @@ import androidx.core.view.MenuProvider import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity +import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.versionChecker.VersionCheckerUtils import info.nightscout.plugins.R import info.nightscout.plugins.databinding.CwfInfosActivityBinding import info.nightscout.plugins.databinding.CwfInfosActivityPrefItemBinding import info.nightscout.plugins.databinding.CwfInfosActivityViewItemBinding import info.nightscout.plugins.general.wear.WearPlugin +import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.events.EventWearUpdateGui import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.rx.weardata.CUSTOM_VERSION @@ -27,6 +30,8 @@ import info.nightscout.rx.weardata.CwfMetadataMap import info.nightscout.rx.weardata.ViewKeys import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP +import io.reactivex.rxjava3.disposables.CompositeDisposable +import io.reactivex.rxjava3.kotlin.plusAssign import org.json.JSONObject import javax.inject.Inject @@ -35,10 +40,13 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() { @Inject lateinit var rh: ResourceHelper @Inject lateinit var sp: SP @Inject lateinit var rxBus: RxBus + @Inject lateinit var aapsSchedulers: AapsSchedulers + @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var wearPlugin: WearPlugin @Inject lateinit var versionCheckerUtils: VersionCheckerUtils + private val disposable = CompositeDisposable() private lateinit var binding: CwfInfosActivityBinding override fun onCreate(savedInstanceState: Bundle?) { @@ -69,6 +77,28 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() { }) } + override fun onPause() { + super.onPause() + disposable.clear() + } + + override fun onResume() { + super.onResume() + disposable += rxBus + .toObservable(EventWearUpdateGui::class.java) + .observeOn(aapsSchedulers.main) + .subscribe({ + it.customWatchfaceData?.let { cwf -> + if (!it.exportFile) { + wearPlugin.savedCustomWatchface = cwf + updateGui() + } + } + }, fabricPrivacy::logException) + + updateGui() + } + private fun updateGui() { wearPlugin.savedCustomWatchface?.let { val cwf_authorization = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_custom_watchface_autorization, false) diff --git a/plugins/main/src/main/res/layout/cwf_infos_activity.xml b/plugins/main/src/main/res/layout/cwf_infos_activity.xml index 9871045d67..e169f0b3e9 100644 --- a/plugins/main/src/main/res/layout/cwf_infos_activity.xml +++ b/plugins/main/src/main/res/layout/cwf_infos_activity.xml @@ -80,7 +80,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="5dp" - android:layout_marginTop="5dp" + android:layout_marginTop="0dp" android:paddingStart="0dp" android:paddingEnd="10dp" android:text="Custom plugin version:" @@ -94,7 +94,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="5dp" - android:layout_marginTop="5dp" + android:layout_marginTop="0dp" android:paddingStart="0dp" android:paddingEnd="10dp" android:text="Comment" diff --git a/plugins/main/src/main/res/layout/cwf_infos_activity_view_item.xml b/plugins/main/src/main/res/layout/cwf_infos_activity_view_item.xml index 0c4d93872e..3f24a1cc60 100644 --- a/plugins/main/src/main/res/layout/cwf_infos_activity_view_item.xml +++ b/plugins/main/src/main/res/layout/cwf_infos_activity_view_item.xml @@ -45,7 +45,7 @@ android:id="@+id/view_comment" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="10dp" + android:layout_marginStart="3dp" android:layout_marginTop="0dp" android:layout_marginBottom="0dp" android:layout_weight="1"