From 5bf787bdc0306016c240a4bf830cbb9fb8750d43 Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 15 Aug 2023 23:38:29 +0200 Subject: [PATCH] Custom v0.5 modification Add Metadata keys fir Author_Version and Comment --- .../nightscout/rx/weardata/CustomWatchfaceFormat.kt | 10 +++++----- app-wear-shared/shared/src/main/res/values/strings.xml | 5 ++++- .../activities/CustomWatchfaceImportListActivity.kt | 4 ++++ .../androidaps/watchfaces/CustomWatchface.kt | 8 ++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt index 4b8fe7b6bc..14ed7df026 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt @@ -17,7 +17,7 @@ import java.util.zip.ZipEntry import java.util.zip.ZipInputStream import java.util.zip.ZipOutputStream -val CUSTOM_VERSION = "0.4" +val CUSTOM_VERSION = "0.5" enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon: Int?, val fileName: String) { UNKNOWN("unknown", null, "Unknown"), CUSTOM_WATCHFACE("customWatchface", R.drawable.watchface_custom, "CustomWatchface"), @@ -31,13 +31,12 @@ enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon companion object { fun fromKey(key: String): CustomWatchfaceDrawableDataKey = values().firstOrNull { it.key == key } ?: UNKNOWN - fun fromFileName(file: String): CustomWatchfaceDrawableDataKey = values().firstOrNull { it.fileName == file } ?: UNKNOWN + fun fromFileName(file: String): CustomWatchfaceDrawableDataKey = values().firstOrNull { it.fileName == file.substringBeforeLast(".") } ?: UNKNOWN } } enum class DrawableFormat(val extension: String) { UNKNOWN(""), - //XML("xml"), //SVG("svg"), JPG("jpg"), @@ -93,13 +92,14 @@ enum class CustomWatchfaceMetadataKey(val key: String, @StringRes val label: Int CWF_FILENAME("filename", R.string.metadata_wear_import_filename), CWF_AUTHOR("author", R.string.metadata_label_watchface_author), CWF_CREATED_AT("created_at", R.string.metadata_label_watchface_created_at), - CWF_VERSION("cwf_version", R.string.metadata_label_watchface_version); + CWF_VERSION("cwf_version", R.string.metadata_label_plugin_version), + CWF_AUTHOR_VERSION("author_version", R.string.metadata_label_watchface_name_version), + CWF_COMMENT("comment", R.string.metadata_label_watchface_comment); // label not planed to be used for CWF_COMMENT companion object { fun fromKey(key: String): CustomWatchfaceMetadataKey? = values().firstOrNull { it.key == key } } - } class ZipWatchfaceFormat { diff --git a/app-wear-shared/shared/src/main/res/values/strings.xml b/app-wear-shared/shared/src/main/res/values/strings.xml index b153a87526..fc45439638 100644 --- a/app-wear-shared/shared/src/main/res/values/strings.xml +++ b/app-wear-shared/shared/src/main/res/values/strings.xml @@ -44,7 +44,10 @@ Author: %1$s Name: %1$s File name: %1$s - Watchface version: %1$s + Plugin version: %1$s + Name: %1$s (%2$s) + %1$s + Default watchface, you can click on EXPORT WATCHFACE button to generate a template Default Watchface \ No newline at end of file diff --git a/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/activities/CustomWatchfaceImportListActivity.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/activities/CustomWatchfaceImportListActivity.kt index 0a900c8561..4ff962da95 100644 --- a/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/activities/CustomWatchfaceImportListActivity.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/activities/CustomWatchfaceImportListActivity.kt @@ -92,6 +92,10 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() { filelistName.tag = customWatchfaceFile customWatchface.setImageDrawable(drawable) customName.text = rh.gs(CWF_NAME.label, metadata[CWF_NAME]) + metadata[CWF_AUTHOR_VERSION]?.let { author_version -> + customName.text = rh.gs(CWF_AUTHOR_VERSION.label, metadata[CWF_NAME], author_version) + } + author.text = rh.gs(CWF_AUTHOR.label, metadata[CWF_AUTHOR] ?:"") createdAt.text = rh.gs(CWF_CREATED_AT.label, metadata[CWF_CREATED_AT] ?:"") cwfVersion.text = rh.gs(CWF_VERSION.label, metadata[CWF_VERSION] ?:"") diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt index 5a61a3be77..64ccdbb525 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt @@ -29,6 +29,7 @@ import androidx.viewbinding.ViewBinding import info.nightscout.androidaps.R import info.nightscout.androidaps.databinding.ActivityCustomBinding import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace +import info.nightscout.rx.logging.LTag import info.nightscout.rx.weardata.CUSTOM_VERSION import info.nightscout.rx.weardata.CustomWatchfaceData import info.nightscout.rx.weardata.CustomWatchfaceDrawableDataKey @@ -199,8 +200,10 @@ class CustomWatchface : BaseWatchFace() { } } } + binding.background.visibility = View.VISIBLE updateSecondVisibility() } catch (e:Exception) { + aapsLogger.debug(LTag.WEAR, "Crash during Custom watch load") persistence.store(defaultWatchface(), false) // relaod correct values to avoid crash of watchface } } @@ -212,7 +215,9 @@ class CustomWatchface : BaseWatchFace() { .put(CustomWatchfaceMetadataKey.CWF_FILENAME.key, getString(info.nightscout.shared.R.string.wear_default_watchface)) .put(CustomWatchfaceMetadataKey.CWF_AUTHOR.key, "Philoul") .put(CustomWatchfaceMetadataKey.CWF_CREATED_AT.key, dateUtil.dateString(dateUtil.now())) + .put(CustomWatchfaceMetadataKey.CWF_AUTHOR_VERSION.key, CUSTOM_VERSION) .put(CustomWatchfaceMetadataKey.CWF_VERSION.key, CUSTOM_VERSION) + .put(CustomWatchfaceMetadataKey.CWF_COMMENT.key,getString(info.nightscout.shared.R.string.default_custom_watchface_comment)) val json = JSONObject() .put("metadata", metadata) .put("highColor", String.format("#%06X", 0xFFFFFF and highColor)) @@ -247,7 +252,6 @@ class CustomWatchface : BaseWatchFace() { ) } if (view is ImageView) { - //view.backgroundTintList = json.put( it.key, JSONObject() @@ -256,7 +260,7 @@ class CustomWatchface : BaseWatchFace() { .put("topmargin", (params.topMargin / zoomFactor).toInt()) .put("leftmargin", (params.leftMargin / zoomFactor).toInt()) .put("visibility", getVisibility(view.visibility)) - ) + ) } if (view is lecho.lib.hellocharts.view.LineChartView) { json.put(