Merge pull request #2719 from Philoul/wear/new_custom_watchface
Wear CSW Add AllCaps and dayName Month format customization
This commit is contained in:
commit
c8db44f8b3
4 changed files with 23 additions and 14 deletions
|
@ -183,7 +183,10 @@ enum class JsonKeys(val key: String, val viewType: ViewType, @StringRes val comm
|
||||||
FONT("font", ViewType.TEXTVIEW, null),
|
FONT("font", ViewType.TEXTVIEW, null),
|
||||||
FONTSTYLE("fontStyle", ViewType.TEXTVIEW, null),
|
FONTSTYLE("fontStyle", ViewType.TEXTVIEW, null),
|
||||||
FONTCOLOR("fontColor", 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) {
|
enum class JsonKeyValues(val key: String, val jsonKey: JsonKeys) {
|
||||||
|
|
|
@ -171,17 +171,17 @@ class DateUtil @Inject constructor(private val context: Context) {
|
||||||
fun amPm(mills: Long): String =
|
fun amPm(mills: Long): String =
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("a"))
|
DateTime(mills).toString(DateTimeFormat.forPattern("a"))
|
||||||
|
|
||||||
fun dayNameString(): String = dayNameString(now())
|
fun dayNameString(format: String = "E"): String = dayNameString(now(), format)
|
||||||
fun dayNameString(mills: Long): String =
|
fun dayNameString(mills: Long, format: String = "E"): String =
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("E"))
|
DateTime(mills).toString(DateTimeFormat.forPattern(format))
|
||||||
|
|
||||||
fun dayString(): String = dayString(now())
|
fun dayString(): String = dayString(now())
|
||||||
fun dayString(mills: Long): String =
|
fun dayString(mills: Long): String =
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("dd"))
|
DateTime(mills).toString(DateTimeFormat.forPattern("dd"))
|
||||||
|
|
||||||
fun monthString(): String = monthString(now())
|
fun monthString(format: String = "MMM"): String = monthString(now(), format)
|
||||||
fun monthString(mills: Long): String =
|
fun monthString(mills: Long, format: String = "MMM"): String =
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("MMM"))
|
DateTime(mills).toString(DateTimeFormat.forPattern(format))
|
||||||
|
|
||||||
fun weekString(): String = weekString(now())
|
fun weekString(): String = weekString(now())
|
||||||
fun weekString(mills: Long): String =
|
fun weekString(mills: Long): String =
|
||||||
|
|
|
@ -157,6 +157,10 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
basalCenterColor = getColor(json.optString(BASALCENTERCOLOR.key), ContextCompat.getColor(this, R.color.basal_light))
|
basalCenterColor = getColor(json.optString(BASALCENTERCOLOR.key), ContextCompat.getColor(this, R.color.basal_light))
|
||||||
gridColor = getColor(json.optString(GRIDCOLOR.key), Color.WHITE)
|
gridColor = getColor(json.optString(GRIDCOLOR.key), Color.WHITE)
|
||||||
pointSize = json.optInt(POINTSIZE.key, 2)
|
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) {
|
bgColor = when (singleBg.sgvLevel) {
|
||||||
1L -> highColor
|
1L -> highColor
|
||||||
0L -> midColor
|
0L -> midColor
|
||||||
|
@ -191,9 +195,9 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
StyleMap.style(viewJson.optString(FONTSTYLE.key, StyleMap.NORMAL.key))
|
StyleMap.style(viewJson.optString(FONTSTYLE.key, StyleMap.NORMAL.key))
|
||||||
)
|
)
|
||||||
view.setTextColor(getColor(viewJson.optString(FONTCOLOR.key)))
|
view.setTextColor(getColor(viewJson.optString(FONTCOLOR.key)))
|
||||||
|
view.isAllCaps = viewJson.optBoolean(ALLCAPS.key)
|
||||||
if (viewJson.has(TEXTVALUE.key))
|
if (viewJson.has(TEXTVALUE.key))
|
||||||
view.text = viewJson.getString(TEXTVALUE.key)
|
view.text = viewJson.optString(TEXTVALUE.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ImageView -> {
|
is ImageView -> {
|
||||||
|
@ -204,14 +208,14 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
drawableDataMap[CwfDrawableFileMap.fromKey(id.key)]?.toDrawable(resources)
|
drawableDataMap[CwfDrawableFileMap.fromKey(id.key)]?.toDrawable(resources)
|
||||||
drawable?.let {
|
drawable?.let {
|
||||||
if (viewJson.has(COLOR.key))
|
if (viewJson.has(COLOR.key))
|
||||||
it.colorFilter = changeDrawableColor(getColor(viewJson.getString(COLOR.key)))
|
it.colorFilter = changeDrawableColor(getColor(viewJson.optString(COLOR.key)))
|
||||||
else
|
else
|
||||||
it.clearColorFilter()
|
it.clearColorFilter()
|
||||||
view.setImageDrawable(it)
|
view.setImageDrawable(it)
|
||||||
} ?: apply {
|
} ?: apply {
|
||||||
view.setImageDrawable(CwfDrawableFileMap.fromKey(id.key).icon?.let { context.getDrawable(it) })
|
view.setImageDrawable(CwfDrawableFileMap.fromKey(id.key).icon?.let { context.getDrawable(it) })
|
||||||
if (viewJson.has(COLOR.key))
|
if (viewJson.has(COLOR.key))
|
||||||
view.setColorFilter(getColor(viewJson.getString(COLOR.key)))
|
view.setColorFilter(getColor(viewJson.optString(COLOR.key)))
|
||||||
else
|
else
|
||||||
view.clearColorFilter()
|
view.clearColorFilter()
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,8 @@ abstract class BaseWatchFace : WatchFace() {
|
||||||
var enableSecond = false
|
var enableSecond = false
|
||||||
var detailedIob = false
|
var detailedIob = false
|
||||||
var externalStatus = ""
|
var externalStatus = ""
|
||||||
|
var dayNameFormat = "E"
|
||||||
|
var monthFormat = "MMM"
|
||||||
val showSecond: Boolean
|
val showSecond: Boolean
|
||||||
get() = enableSecond && currentWatchMode == WatchMode.INTERACTIVE
|
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.iob1?.text = if (detailedIob) status.iobSum else getString(R.string.activity_IOB)
|
||||||
binding.iob2?.text = if (detailedIob) status.iobDetail else status.iobSum
|
binding.iob2?.text = if (detailedIob) status.iobDetail else status.iobSum
|
||||||
binding.timestamp.visibility = sp.getBoolean(R.string.key_show_ago, true).toVisibility()
|
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?.visibility = sp.getBoolean(R.string.key_show_uploader_battery, true).toVisibility()
|
||||||
binding.uploaderBattery?.text =
|
binding.uploaderBattery?.text =
|
||||||
when {
|
when {
|
||||||
|
@ -371,9 +373,9 @@ abstract class BaseWatchFace : WatchFace() {
|
||||||
binding.hour?.text = dateUtil.hourString()
|
binding.hour?.text = dateUtil.hourString()
|
||||||
binding.minute?.text = dateUtil.minuteString()
|
binding.minute?.text = dateUtil.minuteString()
|
||||||
binding.dateTime?.visibility = sp.getBoolean(R.string.key_show_date, false).toVisibility()
|
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.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?.visibility = android.text.format.DateFormat.is24HourFormat(this).not().toVisibility()
|
||||||
binding.timePeriod?.text = dateUtil.amPm()
|
binding.timePeriod?.text = dateUtil.amPm()
|
||||||
if (showSecond)
|
if (showSecond)
|
||||||
|
|
Loading…
Reference in a new issue