Check Custom Watchface version

This commit is contained in:
Philoul 2023-08-13 14:42:07 +02:00
parent d06a3c3e53
commit 3349017ae0
2 changed files with 16 additions and 4 deletions

View file

@ -17,7 +17,7 @@ import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
import java.util.zip.ZipOutputStream import java.util.zip.ZipOutputStream
val CUSTOM_VERSION = "v0.2" val CUSTOM_VERSION = "0.2"
enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon: Int?, val fileName: String) { enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon: Int?, val fileName: String) {
UNKNOWN("unknown", null, "Unknown"), UNKNOWN("unknown", null, "Unknown"),
CUSTOM_WATCHFACE("customWatchface", R.drawable.watchface_custom, "CustomWatchface"), CUSTOM_WATCHFACE("customWatchface", R.drawable.watchface_custom, "CustomWatchface"),

View file

@ -14,12 +14,15 @@ import info.nightscout.interfaces.maintenance.PrefFileListProvider
import info.nightscout.configuration.databinding.CustomWatchfaceImportListActivityBinding import info.nightscout.configuration.databinding.CustomWatchfaceImportListActivityBinding
import info.nightscout.configuration.R import info.nightscout.configuration.R
import info.nightscout.configuration.databinding.CustomWatchfaceImportListItemBinding import info.nightscout.configuration.databinding.CustomWatchfaceImportListItemBinding
import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventMobileDataToWear import info.nightscout.rx.events.EventMobileDataToWear
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.weardata.CUSTOM_VERSION
import info.nightscout.rx.weardata.CustomWatchfaceData import info.nightscout.rx.weardata.CustomWatchfaceData
import info.nightscout.rx.weardata.CustomWatchfaceDrawableDataKey import info.nightscout.rx.weardata.CustomWatchfaceDrawableDataKey
import info.nightscout.rx.weardata.CustomWatchfaceMetadataKey.* import info.nightscout.rx.weardata.CustomWatchfaceMetadataKey.*
import info.nightscout.rx.weardata.CustomWatchfaceMetadataMap
import info.nightscout.rx.weardata.EventData import info.nightscout.rx.weardata.EventData
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
@ -32,10 +35,10 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
@Inject lateinit var prefFileListProvider: PrefFileListProvider @Inject lateinit var prefFileListProvider: PrefFileListProvider
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var versionCheckerUtils: VersionCheckerUtils
private lateinit var binding: CustomWatchfaceImportListActivityBinding private lateinit var binding: CustomWatchfaceImportListActivityBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = CustomWatchfaceImportListActivityBinding.inflate(layoutInflater) binding = CustomWatchfaceImportListActivityBinding.inflate(layoutInflater)
@ -63,7 +66,6 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
val customWF = EventData.ActionSetCustomWatchface(customWatchfaceFile) val customWF = EventData.ActionSetCustomWatchface(customWatchfaceFile)
val i = Intent() val i = Intent()
setResult(FragmentActivity.RESULT_OK, i) setResult(FragmentActivity.RESULT_OK, i)
//rxBus.send(EventWearUpdateGui(customWatchfaceFile))
rxBus.send(EventMobileDataToWear(customWF)) rxBus.send(EventMobileDataToWear(customWF))
finish() finish()
} }
@ -93,7 +95,8 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
author.text = rh.gs(CWF_AUTHOR.label, metadata[CWF_AUTHOR] ?:"") author.text = rh.gs(CWF_AUTHOR.label, metadata[CWF_AUTHOR] ?:"")
createdAt.text = rh.gs(CWF_CREATED_AT.label, metadata[CWF_CREATED_AT] ?:"") createdAt.text = rh.gs(CWF_CREATED_AT.label, metadata[CWF_CREATED_AT] ?:"")
cwfVersion.text = rh.gs(CWF_VERSION.label, metadata[CWF_VERSION] ?:"") cwfVersion.text = rh.gs(CWF_VERSION.label, metadata[CWF_VERSION] ?:"")
val colorAttr = if (checkCustomVersion(metadata)) info.nightscout.core.ui.R.attr.metadataTextOkColor else info.nightscout.core.ui.R.attr.metadataTextWarningColor
cwfVersion.setTextColor(rh.gac(cwfVersion.context, colorAttr))
} }
} }
} }
@ -106,4 +109,13 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
private fun checkCustomVersion(metadata: CustomWatchfaceMetadataMap): Boolean {
metadata[CWF_VERSION]?.let { version ->
val currentAppVer = versionCheckerUtils.versionDigits(CUSTOM_VERSION)
val metadataVer = versionCheckerUtils.versionDigits(version)
//Only check that Loaded Watchface version is lower or equal to Wear CustomWatchface version
return ((currentAppVer.size >= 2) && (metadataVer.size >= 2) && (currentAppVer[0] >= metadataVer[0]))
}
return false
}
} }