Hide seconds in Ambient mode

This commit is contained in:
Philoul 2023-08-10 22:25:52 +02:00
parent dd24dd5051
commit f8dbcf2edd
2 changed files with 24 additions and 31 deletions

View file

@ -108,11 +108,16 @@ class CustomWatchface : BaseWatchFace() {
} }
override fun setSecond() { override fun setSecond() {
binding.time.text = "${dateUtil.hourString()}:${dateUtil.minuteString()}" + if (enableSecond) ":${dateUtil.secondString()}" else "" binding.time.text = "${dateUtil.hourString()}:${dateUtil.minuteString()}" + if (showSecond) ":${dateUtil.secondString()}" else ""
binding.second.text = dateUtil.secondString() binding.second.text = dateUtil.secondString()
// rotate the second hand. // rotate the second hand.
binding.secondHand.rotation = TimeOfDay().secondOfMinute * 6f binding.secondHand.rotation = TimeOfDay().secondOfMinute * 6f
//aapsLogger.debug("XXXXX SetSecond") //aapsLogger.debug("XXXXX SetSecond $watchModeString")
}
override fun updateSecondVisibility() {
binding.second.visibility = (enableSecond && showSecond).toVisibility()
binding.secondHand.visibility = (enableSecond && showSecond).toVisibility()
} }
private fun setWatchfaceStyle() { private fun setWatchfaceStyle() {
@ -179,8 +184,7 @@ class CustomWatchface : BaseWatchFace() {
} }
} }
} }
binding.second.visibility= ((binding.second.visibility==View.VISIBLE) && enableSecond).toVisibility() updateSecondVisibility()
binding.secondHand.visibility= ((binding.secondHand.visibility==View.VISIBLE) && enableSecond).toVisibility()
} }
} }

View file

@ -37,9 +37,6 @@ import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.floor import kotlin.math.floor
@ -89,14 +86,8 @@ abstract class BaseWatchFace : WatchFace() {
var dividerMatchesBg = false var dividerMatchesBg = false
var pointSize = 2 var pointSize = 2
var enableSecond = false var enableSecond = false
val showSecond: Boolean
// SecondUpdater (Ambient mode) get() = enableSecond && currentWatchMode == WatchMode.INTERACTIVE
private val mScheduledSecondUpdaterPool = Executors.newScheduledThreadPool(2)
private var mScheduledSecondUpdater: ScheduledFuture<*>? = null
private val mSecondUpdater = Runnable {
setSecond()
invalidate()
}
// Tapping times // Tapping times
private var sgvTapTime: Long = 0 private var sgvTapTime: Long = 0
@ -259,13 +250,11 @@ abstract class BaseWatchFace : WatchFace() {
override fun onDestroy() { override fun onDestroy() {
disposable.clear() disposable.clear()
simpleUi.onDestroy() simpleUi.onDestroy()
cancelSecondUpdater()
mScheduledSecondUpdaterPool.shutdown()
super.onDestroy() super.onDestroy()
} }
override fun getInteractiveModeUpdateRate(): Long { override fun getInteractiveModeUpdateRate(): Long {
return if (enableSecond) 1000L else 60 * 1000L // Only call onTimeChanged every 60 seconds return if (showSecond) 1000L else 60 * 1000L // Only call onTimeChanged every 60 seconds
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
@ -286,7 +275,7 @@ abstract class BaseWatchFace : WatchFace() {
missedReadingAlert() missedReadingAlert()
checkVibrateHourly(oldTime, newTime) checkVibrateHourly(oldTime, newTime)
if (!simpleUi.isEnabled(currentWatchMode)) setDataFields() if (!simpleUi.isEnabled(currentWatchMode)) setDataFields()
} else if (layoutSet && !simpleUi.isEnabled(currentWatchMode) && enableSecond && newTime.hasSecondChanged(oldTime)) { } else if (layoutSet && !simpleUi.isEnabled(currentWatchMode) && showSecond && newTime.hasSecondChanged(oldTime)) {
setSecond() setSecond()
} }
} }
@ -366,23 +355,28 @@ abstract class BaseWatchFace : WatchFace() {
} }
private fun setDateAndTime() { private fun setDateAndTime() {
binding.time?.text = if(binding.timePeriod == null) dateUtil.timeString() else dateUtil.hourString() + ":" + dateUtil.minuteString() + if (enableSecond) ":" + dateUtil.secondString() else "" binding.time?.text = if(binding.timePeriod == null) dateUtil.timeString() else dateUtil.hourString() + ":" + dateUtil.minuteString()
binding.hour?.text = dateUtil.hourString() binding.hour?.text = dateUtil.hourString()
binding.minute?.text = dateUtil.minuteString() binding.minute?.text = dateUtil.minuteString()
binding.second?.text = dateUtil.secondString()
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()
binding.day?.text = dateUtil.dayString() binding.day?.text = dateUtil.dayString()
binding.month?.text = dateUtil.monthString() binding.month?.text = dateUtil.monthString()
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)
setSecond()
} }
open fun setSecond() { open fun setSecond() {
binding.time?.text = if(binding.timePeriod == null) dateUtil.timeString() else dateUtil.hourString() + ":" + dateUtil.minuteString() + if (enableSecond) ":" + dateUtil.secondString() else "" binding.time?.text = if(binding.timePeriod == null) dateUtil.timeString() else dateUtil.hourString() + ":" + dateUtil.minuteString() + if (showSecond) ":" + dateUtil.secondString() else ""
binding.second?.text = dateUtil.secondString() binding.second?.text = dateUtil.secondString()
} }
open fun updateSecondVisibility() {
binding.second?.visibility = showSecond.toVisibility()
}
fun setColor() { fun setColor() {
dividerMatchesBg = sp.getBoolean(R.string.key_match_divider, false) dividerMatchesBg = sp.getBoolean(R.string.key_match_divider, false)
when { when {
@ -401,20 +395,15 @@ abstract class BaseWatchFace : WatchFace() {
} }
override fun onWatchModeChanged(watchMode: WatchMode) { override fun onWatchModeChanged(watchMode: WatchMode) {
updateSecondVisibility() // will show second if enabledSecond and Interactive mode, hide in other situation
setSecond() // will remove second from main date and time if not in Interactive mode
lowResMode = isLowRes(watchMode) lowResMode = isLowRes(watchMode)
if (simpleUi.isEnabled(currentWatchMode)) simpleUi.setAntiAlias(currentWatchMode) if (simpleUi.isEnabled(currentWatchMode)) simpleUi.setAntiAlias(currentWatchMode)
else setDataFields() else
if (watchMode == WatchMode.AMBIENT && enableSecond) { setDataFields()
val initialDelay = 1000L - System.currentTimeMillis() % 1000L
mScheduledSecondUpdater = mScheduledSecondUpdaterPool.scheduleAtFixedRate(mSecondUpdater, initialDelay, 1000L, TimeUnit.MILLISECONDS)
} else {
cancelSecondUpdater()
}
invalidate() invalidate()
} }
private fun cancelSecondUpdater() = mScheduledSecondUpdater?.cancel(true)
private fun isLowRes(watchMode: WatchMode): Boolean { private fun isLowRes(watchMode: WatchMode): Boolean {
return watchMode == WatchMode.LOW_BIT || watchMode == WatchMode.LOW_BIT_BURN_IN return watchMode == WatchMode.LOW_BIT || watchMode == WatchMode.LOW_BIT_BURN_IN
} }