From d932ef70d2269f23ff41076d9a2ce057ad88e71e Mon Sep 17 00:00:00 2001 From: Philoul Date: Wed, 23 Aug 2023 23:03:37 +0200 Subject: [PATCH] wear cwf First version of Watchface Info with metadata and pref requested or locked --- .../rx/weardata/CustomWatchfaceFormat.kt | 29 +-- .../shared/src/main/res/values/strings.xml | 18 +- .../CustomWatchfaceImportListActivity.kt | 10 +- plugins/main/src/main/AndroidManifest.xml | 5 + .../info/nightscout/plugins/di/WearModule.kt | 2 + .../plugins/general/wear/WearFragment.kt | 7 + .../wear/activities/CwfInfosActivity.kt | 142 ++++++++++++++ .../src/main/res/drawable/export_custom.xml | 6 +- .../src/main/res/drawable/ic_cwf_infos.xml | 9 + .../src/main/res/drawable/load_custom.xml | 6 +- .../src/main/res/drawable/send_custom.xml | 6 +- .../src/main/res/drawable/set_default.xml | 6 +- .../src/main/res/drawable/settings_off.xml | 10 + .../src/main/res/drawable/settings_on.xml | 10 + .../main/res/layout/cwf_infos_activity.xml | 175 ++++++++++++++++++ .../layout/cwf_infos_activity_pref_item.xml | 60 ++++++ .../src/main/res/layout/wear_fragment.xml | 30 +-- plugins/main/src/main/res/values/strings.xml | 5 +- .../androidaps/watchfaces/CustomWatchface.kt | 3 +- 19 files changed, 491 insertions(+), 48 deletions(-) create mode 100644 plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt create mode 100644 plugins/main/src/main/res/drawable/ic_cwf_infos.xml create mode 100644 plugins/main/src/main/res/drawable/settings_off.xml create mode 100644 plugins/main/src/main/res/drawable/settings_on.xml create mode 100644 plugins/main/src/main/res/layout/cwf_infos_activity.xml create mode 100644 plugins/main/src/main/res/layout/cwf_infos_activity_pref_item.xml 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 ee90cc3563..36e3813a12 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 @@ -103,20 +103,21 @@ enum class CwfMetadataKey(val key: String, @StringRes val label: Int, val isPref CWF_AUTHOR_VERSION("author_version", R.string.metadata_label_watchface_name_version, false), CWF_COMMENT("comment", R.string.metadata_label_watchface_comment, false), // label not planed to be used for CWF_COMMENT CWF_AUTHORIZATION("cwf_authorization", R.string.metadata_label_watchface_authorization, false), - CWF_PREF_WATCH_SHOW_DETAILED_IOB("key_show_detailed_iob", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_DETAILED_DELTA("key_show_detailed_delta", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_BGI("key_show_bgi", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_IOB("key_show_iob", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_COB("key_show_cob", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_DELTA("key_show_delta", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_AVG_DELTA("key_show_avg_delta", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_UPLOADER_BATTERY("key_show_uploader_battery", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_RIG_BATTERY("key_show_rig_battery", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_TEMP_BASAL("key_show_temp_basal", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_DIRECTION("key_show_direction", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_AGO("key_show_ago", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_BG("key_show_bg", R.string.metadata_label_watchface_pref, true), - CWF_PREF_WATCH_SHOW_LOOP_STATUS("key_show_loop_status", R.string.metadata_label_watchface_pref, true); + CWF_PREF_WATCH_SHOW_DETAILED_IOB("key_show_detailed_iob", R.string.pref_show_detailed_iob, true), + CWF_PREF_WATCH_SHOW_DETAILED_DELTA("key_show_detailed_delta", R.string.pref_show_detailed_delta, true), + CWF_PREF_WATCH_SHOW_BGI("key_show_bgi", R.string.pref_show_bgi, true), + CWF_PREF_WATCH_SHOW_IOB("key_show_iob", R.string.pref_show_iob, true), + CWF_PREF_WATCH_SHOW_COB("key_show_cob", R.string.pref_show_cob, true), + CWF_PREF_WATCH_SHOW_DELTA("key_show_delta", R.string.pref_show_delta, true), + CWF_PREF_WATCH_SHOW_AVG_DELTA("key_show_avg_delta", R.string.pref_show_avgdelta, true), + CWF_PREF_WATCH_SHOW_UPLOADER_BATTERY("key_show_uploader_battery", R.string.pref_show_phone_battery, true), + CWF_PREF_WATCH_SHOW_RIG_BATTERY("key_show_rig_battery", R.string.pref_show_rig_battery, true), + CWF_PREF_WATCH_SHOW_TEMP_BASAL("key_show_temp_basal", R.string.pref_show_basal_rate, true), + CWF_PREF_WATCH_SHOW_DIRECTION("key_show_direction", R.string.pref_show_direction_arrow, true), + CWF_PREF_WATCH_SHOW_AGO("key_show_ago", R.string.pref_show_ago, true), + CWF_PREF_WATCH_SHOW_BG("key_show_bg", R.string.pref_show_bg, true), + CWF_PREF_WATCH_SHOW_LOOP_STATUS("key_show_loop_status", R.string.pref_show_loop_status, true), + CWF_PREF_WATCH_SHOW_DATE("key_show_date", R.string.pref_show_date, true); companion object { 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 2aa54ab4c3..486bb43b7f 100644 --- a/app-wear-shared/shared/src/main/res/values/strings.xml +++ b/app-wear-shared/shared/src/main/res/values/strings.xml @@ -46,9 +46,23 @@ File name: %1$s Plugin version: %1$s Name: %1$s (%2$s) - %1$s + Comment: %1$s %1$s - %1$s + Show Date + Show IOB + Show detailed IOB + Show COB + Show Delta + Show detailed Delta + Show AvgDelta + Show Phone Battery + Show Rig Battery + Show Basal Rate + Show Loop Status + Show BG + Show BGI + Show Direction Arrow + Show Ago Default watchface, you can click on EXPORT WATCHFACE button to generate a template Default Watchface 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 780eae0d9e..f6f1c69caf 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 @@ -55,9 +55,9 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() { binding.recyclerview.adapter = RecyclerViewAdapter(prefFileListProvider.listCustomWatchfaceFiles()) } - inner class RecyclerViewAdapter internal constructor(private var customWatchfaceFileList: List) : RecyclerView.Adapter() { + inner class RecyclerViewAdapter internal constructor(private var customWatchfaceFileList: List) : RecyclerView.Adapter() { - inner class PrefFileViewHolder(val customWatchfaceImportListItemBinding: CustomWatchfaceImportListItemBinding) : RecyclerView.ViewHolder(customWatchfaceImportListItemBinding.root) { + inner class CwfFileViewHolder(val customWatchfaceImportListItemBinding: CustomWatchfaceImportListItemBinding) : RecyclerView.ViewHolder(customWatchfaceImportListItemBinding.root) { init { with(customWatchfaceImportListItemBinding) { @@ -74,16 +74,16 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() { } } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PrefFileViewHolder { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CwfFileViewHolder { val binding = CustomWatchfaceImportListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) - return PrefFileViewHolder(binding) + return CwfFileViewHolder(binding) } override fun getItemCount(): Int { return customWatchfaceFileList.size } - override fun onBindViewHolder(holder: PrefFileViewHolder, position: Int) { + override fun onBindViewHolder(holder: CwfFileViewHolder, position: Int) { val customWatchfaceFile = customWatchfaceFileList[position] val metadata = customWatchfaceFile.metadata val drawable = customWatchfaceFile.drawableDatas[CwfDrawableFileMap diff --git a/plugins/main/src/main/AndroidManifest.xml b/plugins/main/src/main/AndroidManifest.xml index e65f86f5fb..b830dd73bb 100644 --- a/plugins/main/src/main/AndroidManifest.xml +++ b/plugins/main/src/main/AndroidManifest.xml @@ -23,6 +23,11 @@ + + { + onBackPressedDispatcher.onBackPressed() + true + } + + else -> false + } + }) + } + + private fun updateGui() { + wearPlugin.savedCustomWatchface?.let { + val cwf_authorization = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_custom_watchface_autorization, false) + val metadata = it.metadata + val drawable = it.drawableDatas[CwfDrawableFileMap.CUSTOM_WATCHFACE]?.toDrawable(resources) + binding.customWatchface.setImageDrawable(drawable) + title = rh.gs(CwfMetadataKey.CWF_NAME.label, metadata[CwfMetadataKey.CWF_NAME]) + metadata[CwfMetadataKey.CWF_AUTHOR_VERSION]?.let { author_version -> + title = "${metadata[CwfMetadataKey.CWF_NAME]} ($author_version)" + } + binding.filelistName.text = rh.gs(CwfMetadataKey.CWF_FILENAME.label, metadata[CwfMetadataKey.CWF_FILENAME] ?: "") + binding.author.text = rh.gs(CwfMetadataKey.CWF_AUTHOR.label, metadata[CwfMetadataKey.CWF_AUTHOR] ?: "") + binding.createdAt.text = rh.gs(CwfMetadataKey.CWF_CREATED_AT.label, metadata[CwfMetadataKey.CWF_CREATED_AT] ?: "") + binding.cwfVersion.text = rh.gs(CwfMetadataKey.CWF_VERSION.label, metadata[CwfMetadataKey.CWF_VERSION] ?: "") + val colorAttr = if (checkCustomVersion(metadata)) info.nightscout.core.ui.R.attr.metadataTextOkColor else info.nightscout.core.ui.R.attr.metadataTextWarningColor + binding.cwfVersion.setTextColor(rh.gac(binding.cwfVersion.context, colorAttr)) + binding.cwfComment.text = rh.gs(CwfMetadataKey.CWF_COMMENT.label, metadata[CwfMetadataKey.CWF_COMMENT] ?: "") + if (metadata.count { it.key.isPref } > 0) { + binding.prefLayout.visibility = View.VISIBLE + binding.prefTitle.text = rh.gs(if (cwf_authorization) R.string.cwf_infos_pref_locked else R.string.cwf_infos_pref_requested) + binding.prefRecyclerview.layoutManager = LinearLayoutManager(this) + binding.prefRecyclerview.adapter = PrefRecyclerViewAdapter( + metadata.filter { it.key.isPref && (it.value.lowercase() == "true" || it.value.lowercase() == "false") }.toList() + ) + } else + binding.prefLayout.visibility = View.GONE + } + + } + + inner class PrefRecyclerViewAdapter internal constructor(private var prefList: List>) : RecyclerView.Adapter() { + + inner class CwfFileViewHolder(val cwfInfosActivityPrefItemBinding: CwfInfosActivityPrefItemBinding) : RecyclerView.ViewHolder(cwfInfosActivityPrefItemBinding.root) { + init { + with(cwfInfosActivityPrefItemBinding) { + root.isClickable = false + } + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CwfFileViewHolder { + val binding = CwfInfosActivityPrefItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return CwfFileViewHolder(binding) + } + + override fun getItemCount(): Int { + return prefList.size + } + + override fun onBindViewHolder(holder: CwfFileViewHolder, position: Int) { + val pref = prefList[position] + val key = pref.first + val value = pref.second.lowercase().toBooleanStrictOrNull() // should never be null here, just safety to avoid exception + with(holder.cwfInfosActivityPrefItemBinding) { + prefLabel.text = rh.gs(key.label) + value?.let { prefValue.setImageResource(if (it) R.drawable.settings_on else R.drawable.settings_off) }// should never be null here, just safety to avoid exception + } + } + } + + + private fun checkCustomVersion(metadata: CwfMetadataMap): Boolean { + metadata[CwfMetadataKey.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 + } + +} \ No newline at end of file diff --git a/plugins/main/src/main/res/drawable/export_custom.xml b/plugins/main/src/main/res/drawable/export_custom.xml index 3779b637df..ee0fd501aa 100644 --- a/plugins/main/src/main/res/drawable/export_custom.xml +++ b/plugins/main/src/main/res/drawable/export_custom.xml @@ -5,13 +5,13 @@ android:viewportHeight="24"> + android:fillColor="?attr/colorControlNormal"/> + android:fillColor="?attr/colorControlNormal"/> + android:fillColor="?attr/colorControlNormal"/> + + + + + + + diff --git a/plugins/main/src/main/res/drawable/load_custom.xml b/plugins/main/src/main/res/drawable/load_custom.xml index 26a7dda859..5536d11976 100644 --- a/plugins/main/src/main/res/drawable/load_custom.xml +++ b/plugins/main/src/main/res/drawable/load_custom.xml @@ -1,8 +1,8 @@ - - - + + + diff --git a/plugins/main/src/main/res/drawable/send_custom.xml b/plugins/main/src/main/res/drawable/send_custom.xml index 2602e2953d..61364fd806 100644 --- a/plugins/main/src/main/res/drawable/send_custom.xml +++ b/plugins/main/src/main/res/drawable/send_custom.xml @@ -1,7 +1,7 @@ - - - + + + diff --git a/plugins/main/src/main/res/drawable/set_default.xml b/plugins/main/src/main/res/drawable/set_default.xml index ff43d0d255..83a675a779 100644 --- a/plugins/main/src/main/res/drawable/set_default.xml +++ b/plugins/main/src/main/res/drawable/set_default.xml @@ -1,7 +1,7 @@ - - - + + + diff --git a/plugins/main/src/main/res/drawable/settings_off.xml b/plugins/main/src/main/res/drawable/settings_off.xml new file mode 100644 index 0000000000..bbe06c1740 --- /dev/null +++ b/plugins/main/src/main/res/drawable/settings_off.xml @@ -0,0 +1,10 @@ + + + diff --git a/plugins/main/src/main/res/drawable/settings_on.xml b/plugins/main/src/main/res/drawable/settings_on.xml new file mode 100644 index 0000000000..b63a5fba59 --- /dev/null +++ b/plugins/main/src/main/res/drawable/settings_on.xml @@ -0,0 +1,10 @@ + + + diff --git a/plugins/main/src/main/res/layout/cwf_infos_activity.xml b/plugins/main/src/main/res/layout/cwf_infos_activity.xml new file mode 100644 index 0000000000..061c623e60 --- /dev/null +++ b/plugins/main/src/main/res/layout/cwf_infos_activity.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/main/src/main/res/layout/cwf_infos_activity_pref_item.xml b/plugins/main/src/main/res/layout/cwf_infos_activity_pref_item.xml new file mode 100644 index 0000000000..198029ad75 --- /dev/null +++ b/plugins/main/src/main/res/layout/cwf_infos_activity_pref_item.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + diff --git a/plugins/main/src/main/res/layout/wear_fragment.xml b/plugins/main/src/main/res/layout/wear_fragment.xml index 8e8b421c3d..bd72587c38 100644 --- a/plugins/main/src/main/res/layout/wear_fragment.xml +++ b/plugins/main/src/main/res/layout/wear_fragment.xml @@ -119,27 +119,29 @@ android:paddingStart="0dp" android:paddingEnd="0dp" android:text="@string/wear_load_watchface" - android:textSize="11sp" + android:textSize="12sp" + android:textColor="?attr/treatmentButton" app:layout_columnWeight="1" app:layout_gravity="fill" app:layout_row="0" app:layout_column="0" /> - + + app:layout_row="1" + app:layout_column="0" /> + app:layout_column="1" /> diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index ac287f9873..7670630b8c 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -360,11 +360,14 @@ Authorize loaded custom watchface to change and lock some watch display settings to suit watchface design Custom Watchface: %1$s Load Watchface - Send Watchface + Infos Watchface Export template Custom watchface template exported Resend All Data Open Settings on Wear + List of prefs locked by the Watchface + List of prefs requested by the Watchface + List of fields included into the Watchface Ongoing Notification 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 e36ed13137..c52d8a22ec 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt @@ -496,7 +496,8 @@ class CustomWatchface : BaseWatchFace() { SHOW_AGO(CwfMetadataKey.CWF_PREF_WATCH_SHOW_AGO.key, R.string.key_show_ago), SHOW_BG(CwfMetadataKey.CWF_PREF_WATCH_SHOW_BG.key, R.string.key_show_bg), SHOW_BGI(CwfMetadataKey.CWF_PREF_WATCH_SHOW_BGI.key, R.string.key_show_bgi), - SHOW_LOOP_STATUS(CwfMetadataKey.CWF_PREF_WATCH_SHOW_LOOP_STATUS.key, R.string.key_show_external_status) + SHOW_LOOP_STATUS(CwfMetadataKey.CWF_PREF_WATCH_SHOW_LOOP_STATUS.key, R.string.key_show_external_status), + SHOW_DATE(CwfMetadataKey.CWF_PREF_WATCH_SHOW_DATE.key, R.string.key_show_date) } }