Wear cwf Add EventWearUpdateGui management for update info during cwf load

This commit is contained in:
Philoul 2023-08-24 23:36:10 +02:00
parent 80dcb9700a
commit c18e5c4e20
4 changed files with 34 additions and 4 deletions

View file

@ -114,7 +114,7 @@ class WearFragment : DaggerFragment() {
binding.coverChart.setImageDrawable(it.drawableDatas[CwfDrawableFileMap.CUSTOM_WATCHFACE]?.toDrawable(resources)) binding.coverChart.setImageDrawable(it.drawableDatas[CwfDrawableFileMap.CUSTOM_WATCHFACE]?.toDrawable(resources))
binding.infosCustom.visibility = View.VISIBLE binding.infosCustom.visibility = View.VISIBLE
} ?:apply { } ?: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.coverChart.setImageDrawable(null)
binding.infosCustom.visibility = View.GONE binding.infosCustom.visibility = View.GONE
} }

View file

@ -11,13 +11,16 @@ import androidx.core.view.MenuProvider
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.interfaces.versionChecker.VersionCheckerUtils import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.databinding.CwfInfosActivityBinding import info.nightscout.plugins.databinding.CwfInfosActivityBinding
import info.nightscout.plugins.databinding.CwfInfosActivityPrefItemBinding import info.nightscout.plugins.databinding.CwfInfosActivityPrefItemBinding
import info.nightscout.plugins.databinding.CwfInfosActivityViewItemBinding import info.nightscout.plugins.databinding.CwfInfosActivityViewItemBinding
import info.nightscout.plugins.general.wear.WearPlugin import info.nightscout.plugins.general.wear.WearPlugin
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventWearUpdateGui
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.rx.weardata.CUSTOM_VERSION 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.rx.weardata.ViewKeys
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject
@ -35,10 +40,13 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() {
@Inject lateinit var rh: ResourceHelper @Inject lateinit var rh: ResourceHelper
@Inject lateinit var sp: SP @Inject lateinit var sp: SP
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var wearPlugin: WearPlugin @Inject lateinit var wearPlugin: WearPlugin
@Inject lateinit var versionCheckerUtils: VersionCheckerUtils @Inject lateinit var versionCheckerUtils: VersionCheckerUtils
private val disposable = CompositeDisposable()
private lateinit var binding: CwfInfosActivityBinding private lateinit var binding: CwfInfosActivityBinding
override fun onCreate(savedInstanceState: Bundle?) { 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() { private fun updateGui() {
wearPlugin.savedCustomWatchface?.let { wearPlugin.savedCustomWatchface?.let {
val cwf_authorization = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_custom_watchface_autorization, false) val cwf_authorization = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_custom_watchface_autorization, false)

View file

@ -80,7 +80,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:layout_marginTop="5dp" android:layout_marginTop="0dp"
android:paddingStart="0dp" android:paddingStart="0dp"
android:paddingEnd="10dp" android:paddingEnd="10dp"
android:text="Custom plugin version:" android:text="Custom plugin version:"
@ -94,7 +94,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:layout_marginTop="5dp" android:layout_marginTop="0dp"
android:paddingStart="0dp" android:paddingStart="0dp"
android:paddingEnd="10dp" android:paddingEnd="10dp"
android:text="Comment" android:text="Comment"

View file

@ -45,7 +45,7 @@
android:id="@+id/view_comment" android:id="@+id/view_comment"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="3dp"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
android:layout_marginBottom="0dp" android:layout_marginBottom="0dp"
android:layout_weight="1" android:layout_weight="1"