Fix Amient mode for second

This commit is contained in:
Philoul 2023-08-08 12:12:27 +02:00
parent 9bf6545f5d
commit 363877175b
2 changed files with 22 additions and 11 deletions

View file

@ -112,6 +112,7 @@ class CustomWatchface : BaseWatchFace() {
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")
} }
private fun setWatchfaceStyle() { private fun setWatchfaceStyle() {

View file

@ -36,8 +36,10 @@ import info.nightscout.shared.extensions.toVisibilityKeepSpace
import info.nightscout.shared.sharedPreferences.SP 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.disposables.Disposable
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
@ -87,7 +89,14 @@ abstract class BaseWatchFace : WatchFace() {
var dividerMatchesBg = false var dividerMatchesBg = false
var pointSize = 2 var pointSize = 2
var enableSecond = false var enableSecond = false
var updateSecond: Disposable? = null
// SecondUpdater (Ambient mode)
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
@ -249,8 +258,9 @@ abstract class BaseWatchFace : WatchFace() {
override fun onDestroy() { override fun onDestroy() {
disposable.clear() disposable.clear()
updateSecond?.dispose()
simpleUi.onDestroy() simpleUi.onDestroy()
cancelSecondUpdater()
mScheduledSecondUpdaterPool.shutdown()
super.onDestroy() super.onDestroy()
} }
@ -394,16 +404,16 @@ abstract class BaseWatchFace : WatchFace() {
lowResMode = isLowRes(watchMode) lowResMode = isLowRes(watchMode)
if (simpleUi.isEnabled(currentWatchMode)) simpleUi.setAntiAlias(currentWatchMode) if (simpleUi.isEnabled(currentWatchMode)) simpleUi.setAntiAlias(currentWatchMode)
else setDataFields() else setDataFields()
invalidate() if (watchMode == WatchMode.AMBIENT && enableSecond) {
/* val initialDelay = 1000L - System.currentTimeMillis() % 1000L
if (enableSecond) mScheduledSecondUpdater = mScheduledSecondUpdaterPool.scheduleAtFixedRate(mSecondUpdater, initialDelay, 1000L, TimeUnit.MILLISECONDS)
if (updateSecond == null) } else {
updateSecond = aapsSchedulers.io.schedulePeriodicallyDirect( cancelSecondUpdater()
::setSecond, 1000L, 1000L, TimeUnit.MILLISECONDS)
else
updateSecond?.dispose()
*/
} }
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