From 4ba7ab7e09cee9b9cde66b36ba6d34cc765f8bc9 Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 15 Sep 2023 08:41:04 +0200 Subject: [PATCH] Wear CWF Add Week number field and include it within BaseWatchFace --- .../rx/weardata/CustomWatchfaceFormat.kt | 4 +++- .../shared/src/main/res/values/strings.xml | 4 +++- .../androidaps/watchfaces/CustomWatchface.kt | 4 +++- .../watchfaces/DigitalStyleWatchface.kt | 5 ----- .../androidaps/watchfaces/utils/BaseWatchFace.kt | 2 ++ .../watchfaces/utils/WatchfaceViewAdapter.kt | 1 + wear/src/main/res/layout/activity_custom.xml | 15 ++++++++++++++- .../res/xml/watch_face_configuration_custom.xml | 7 +++++++ 8 files changed, 33 insertions(+), 9 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 e41b38778e..dc659d29f5 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 @@ -161,7 +161,8 @@ enum class CwfMetadataKey(val key: String, @StringRes val label: Int, val isPref 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_LOOP_STATUS("key_show_loop_status", R.string.pref_show_loop_status, true), + CWF_PREF_WATCH_SHOW_WEEK_NUMBER("key_show_week_number", R.string.pref_show_week_number, true); companion object { @@ -196,6 +197,7 @@ enum class ViewKeys(val key: String, @StringRes val comment: Int) { TIMEPERIOD("timePeriod", R.string.cwf_comment_timePeriod), DAY_NAME("day_name", R.string.cwf_comment_day_name), DAY("day", R.string.cwf_comment_day), + WEEKNUMBER("week_number",R.string.cwf_comment_week_number), MONTH("month", R.string.cwf_comment_month), LOOP("loop", R.string.cwf_comment_loop), DIRECTION("direction", R.string.cwf_comment_direction), 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 50f3869b5d..6198eb283a 100644 --- a/app-wear-shared/shared/src/main/res/values/strings.xml +++ b/app-wear-shared/shared/src/main/res/values/strings.xml @@ -62,6 +62,7 @@ Show BGI Show Direction Arrow Show Ago + Show Week number Default watchface, you can click on EXPORT WATCHFACE button to generate a template Default Watchface Background image @@ -88,12 +89,13 @@ AM or PM Name of day of the week Day (DD) + Week number (ww) Month name (short) Loop status and ago Direction arrow Mintutes ago for last received BG BG value - Cover image in front of text (dials...) + Cover image in front of text (dials…) Image of hour hand (Analog Watch) Image of minute hand (Analog Watch) Image of second hand (Analog Watch) 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 8de450df86..cfb1765d17 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt @@ -438,6 +438,7 @@ class CustomWatchface : BaseWatchFace() { TIMEPERIOD(ViewKeys.TIMEPERIOD.key, R.id.timePeriod, null, null, null, null, null), DAY_NAME(ViewKeys.DAY_NAME.key, R.id.day_name, null, null, null, null, null), DAY(ViewKeys.DAY.key, R.id.day, null, null, null, null, null), + WEEKNUMBER(ViewKeys.WEEKNUMBER.key, R.id.week_number, R.string.key_show_week_number, null, null, null, null), MONTH(ViewKeys.MONTH.key, R.id.month, null, null, null, null, null), LOOP(ViewKeys.LOOP.key, R.id.loop, R.string.key_show_external_status, null, null, null, null), DIRECTION(ViewKeys.DIRECTION.key, R.id.direction2, R.string.key_show_direction, null, null, null, null), @@ -595,7 +596,8 @@ private enum class PrefMap(val key: String, @StringRes val prefKey: Int) { 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_WEEK_NUMBER(CwfMetadataKey.CWF_PREF_WATCH_SHOW_WEEK_NUMBER.key, R.string.key_show_week_number) } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt index af2fb397cb..b9db42cdd9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt @@ -113,11 +113,6 @@ class DigitalStyleWatchface : BaseWatchFace() { binding.minute.textSize = 26f binding.hour.letterSpacing = 0.toFloat() binding.minute.letterSpacing = 0.toFloat() - - /* display week number */ - val mWeekNumber = layoutView?.findViewById(R.id.week_number) - mWeekNumber?.visibility = sp.getBoolean(R.string.key_show_week_number, false).toVisibility() - mWeekNumber?.text = "(" + dateUtil.weekString() + ")" } } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt index be755229ce..8c8d4fdbe9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt @@ -378,6 +378,8 @@ abstract class BaseWatchFace : WatchFace() { binding.month?.text = dateUtil.monthString(monthFormat).substringBeforeLast(".") binding.timePeriod?.visibility = android.text.format.DateFormat.is24HourFormat(this).not().toVisibility() binding.timePeriod?.text = dateUtil.amPm() + binding.weekNumber?.visibility = sp.getBoolean(R.string.key_show_week_number, false).toVisibility() + binding.weekNumber?.text = "(" + dateUtil.weekString() + ")" if (showSecond) setSecond() } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt index 0498c48637..9ccd931586 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt @@ -73,6 +73,7 @@ class WatchfaceViewAdapter( val mainMenuTap = ds?.mainMenuTap ?: sP?.mainMenuTap val chartZoomTap = ds?.chartZoomTap ?: sP?.chartZoomTap val dateTime = ds?.dateTime ?: a2?.dateTime + val weekNumber = ds?.weekNumber ?: cU?.weekNumber // val minuteHand = sP?.minuteHand // val secondaryLayout = aL?.secondaryLayout ?: a2?.secondaryLayout ?: aa?.secondaryLayout ?: ds?.secondaryLayout ?: sP?.secondaryLayout // val tertiaryLayout = a2?.tertiaryLayout ?: sP?.tertiaryLayout diff --git a/wear/src/main/res/layout/activity_custom.xml b/wear/src/main/res/layout/activity_custom.xml index 293c06d248..95c231dbcb 100644 --- a/wear/src/main/res/layout/activity_custom.xml +++ b/wear/src/main/res/layout/activity_custom.xml @@ -282,7 +282,7 @@ android:textStyle="bold" android:textColor="@color/white" android:visibility="visible" - tools:text="day." /> + tools:text="day" /> + + + +