From 7d8ca66dbe48c1c933d154e46d364f71cf85cf0f Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 29 Aug 2023 22:02:04 +0200 Subject: [PATCH] Wear csw Customize AllCaps and dayName/Month format --- .../nightscout/rx/weardata/CustomWatchfaceFormat.kt | 5 ++++- .../java/info/nightscout/shared/utils/DateUtil.kt | 12 ++++++------ .../androidaps/watchfaces/CustomWatchface.kt | 12 ++++++++---- .../androidaps/watchfaces/utils/BaseWatchFace.kt | 8 +++++--- 4 files changed, 23 insertions(+), 14 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 66527227f2..009937c5d5 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 @@ -183,7 +183,10 @@ enum class JsonKeys(val key: String, val viewType: ViewType, @StringRes val comm FONT("font", ViewType.TEXTVIEW, null), FONTSTYLE("fontStyle", ViewType.TEXTVIEW, null), FONTCOLOR("fontColor", ViewType.TEXTVIEW, null), - COLOR("color", ViewType.IMAGEVIEW, null) + COLOR("color", ViewType.IMAGEVIEW, null), + ALLCAPS("allCaps", ViewType.TEXTVIEW, null), + DAYNAMEFORMAT("dayNameFormat", ViewType.NONE, null), + MONTHFORMAT("monthFormat", ViewType.NONE, null) } enum class JsonKeyValues(val key: String, val jsonKey: JsonKeys) { diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/shared/utils/DateUtil.kt b/app-wear-shared/shared/src/main/java/info/nightscout/shared/utils/DateUtil.kt index c24523b3c6..27e75a8c2e 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/shared/utils/DateUtil.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/shared/utils/DateUtil.kt @@ -171,17 +171,17 @@ class DateUtil @Inject constructor(private val context: Context) { fun amPm(mills: Long): String = DateTime(mills).toString(DateTimeFormat.forPattern("a")) - fun dayNameString(): String = dayNameString(now()) - fun dayNameString(mills: Long): String = - DateTime(mills).toString(DateTimeFormat.forPattern("E")) + fun dayNameString(format: String = "E"): String = dayNameString(now(), format) + fun dayNameString(mills: Long, format: String = "E"): String = + DateTime(mills).toString(DateTimeFormat.forPattern(format)) fun dayString(): String = dayString(now()) fun dayString(mills: Long): String = DateTime(mills).toString(DateTimeFormat.forPattern("dd")) - fun monthString(): String = monthString(now()) - fun monthString(mills: Long): String = - DateTime(mills).toString(DateTimeFormat.forPattern("MMM")) + fun monthString(format: String = "MMM"): String = monthString(now(), format) + fun monthString(mills: Long, format: String = "MMM"): String = + DateTime(mills).toString(DateTimeFormat.forPattern(format)) fun weekString(): String = weekString(now()) fun weekString(mills: Long): String = 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 23d4ea0739..fc86433178 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt @@ -157,6 +157,10 @@ class CustomWatchface : BaseWatchFace() { basalCenterColor = getColor(json.optString(BASALCENTERCOLOR.key), ContextCompat.getColor(this, R.color.basal_light)) gridColor = getColor(json.optString(GRIDCOLOR.key), Color.WHITE) pointSize = json.optInt(POINTSIZE.key, 2) + dayNameFormat = json.optString(DAYNAMEFORMAT.key, "E") + .takeIf { it.matches(Regex("E{1,4}")) } ?: "E" + monthFormat = json.optString(MONTHFORMAT.key, "MMM") + .takeIf { it.matches(Regex("M{1,4}")) } ?: "MMM" bgColor = when (singleBg.sgvLevel) { 1L -> highColor 0L -> midColor @@ -191,9 +195,9 @@ class CustomWatchface : BaseWatchFace() { StyleMap.style(viewJson.optString(FONTSTYLE.key, StyleMap.NORMAL.key)) ) view.setTextColor(getColor(viewJson.optString(FONTCOLOR.key))) - + view.isAllCaps = viewJson.optBoolean(ALLCAPS.key) if (viewJson.has(TEXTVALUE.key)) - view.text = viewJson.getString(TEXTVALUE.key) + view.text = viewJson.optString(TEXTVALUE.key) } is ImageView -> { @@ -204,14 +208,14 @@ class CustomWatchface : BaseWatchFace() { drawableDataMap[CwfDrawableFileMap.fromKey(id.key)]?.toDrawable(resources) drawable?.let { if (viewJson.has(COLOR.key)) - it.colorFilter = changeDrawableColor(getColor(viewJson.getString(COLOR.key))) + it.colorFilter = changeDrawableColor(getColor(viewJson.optString(COLOR.key))) else it.clearColorFilter() view.setImageDrawable(it) } ?: apply { view.setImageDrawable(CwfDrawableFileMap.fromKey(id.key).icon?.let { context.getDrawable(it) }) if (viewJson.has(COLOR.key)) - view.setColorFilter(getColor(viewJson.getString(COLOR.key))) + view.setColorFilter(getColor(viewJson.optString(COLOR.key))) else view.clearColorFilter() } 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 fe6f377428..97820a23f5 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 @@ -88,6 +88,8 @@ abstract class BaseWatchFace : WatchFace() { var enableSecond = false var detailedIob = false var externalStatus = "" + var dayNameFormat = "E" + var monthFormat = "MMM" val showSecond: Boolean get() = enableSecond && currentWatchMode == WatchMode.INTERACTIVE @@ -317,7 +319,7 @@ abstract class BaseWatchFace : WatchFace() { binding.iob1?.text = if (detailedIob) status.iobSum else getString(R.string.activity_IOB) binding.iob2?.text = if (detailedIob) status.iobDetail else status.iobSum binding.timestamp.visibility = sp.getBoolean(R.string.key_show_ago, true).toVisibility() - binding.timestamp.text = readingAge(if (binding.AAPSv2 != null) true else sp.getBoolean(R.string.key_show_external_status, true)) + binding.timestamp.text = readingAge(binding.AAPSv2 != null || sp.getBoolean(R.string.key_show_external_status, true)) binding.uploaderBattery?.visibility = sp.getBoolean(R.string.key_show_uploader_battery, true).toVisibility() binding.uploaderBattery?.text = when { @@ -371,9 +373,9 @@ abstract class BaseWatchFace : WatchFace() { binding.hour?.text = dateUtil.hourString() binding.minute?.text = dateUtil.minuteString() binding.dateTime?.visibility = sp.getBoolean(R.string.key_show_date, false).toVisibility() - binding.dayName?.text = dateUtil.dayNameString() + binding.dayName?.text = dateUtil.dayNameString(dayNameFormat) binding.day?.text = dateUtil.dayString() - binding.month?.text = dateUtil.monthString() + binding.month?.text = dateUtil.monthString(monthFormat) binding.timePeriod?.visibility = android.text.format.DateFormat.is24HourFormat(this).not().toVisibility() binding.timePeriod?.text = dateUtil.amPm() if (showSecond)