From 727e88b7b11cff79bdc666406af1fd989ac7e76a Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Sun, 4 Jun 2023 17:30:38 -0500 Subject: [PATCH 1/8] Fix skip button in locales that use comma instead of dot Fixes #1721 --- uhabits-android/build.gradle.kts | 4 ++-- .../isoron/uhabits/activities/common/dialogs/NumberDialog.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/uhabits-android/build.gradle.kts b/uhabits-android/build.gradle.kts index 49fb4c8b7..22c9c6bc3 100644 --- a/uhabits-android/build.gradle.kts +++ b/uhabits-android/build.gradle.kts @@ -35,8 +35,8 @@ android { compileSdk = 31 defaultConfig { - versionCode = 20102 - versionName = "2.1.2" + versionCode = 20103 + versionName = "2.1.3" minSdk = 23 targetSdk = 31 applicationId = "org.isoron.uhabits" diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt index 7e10baa51..38c0a5756 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt @@ -65,7 +65,7 @@ class NumberDialog : AppCompatDialogFragment() { save() } view.skipBtnNumber.setOnClickListener { - view.value.setText((Entry.SKIP.toDouble() / 1000).toString()) + view.value.setText(DecimalFormat("#.###").format((Entry.SKIP.toDouble() / 1000))) save() } view.notes.setOnEditorActionListener { v, actionId, event -> From 8b55ffb147cb3d015e60b2db7aec5a3a0854270e Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Sun, 4 Jun 2023 18:25:33 -0500 Subject: [PATCH 2/8] Fix timezone bug in MidnightTimer; increase logging --- .../org/isoron/uhabits/core/utils/DateUtils.kt | 2 +- .../org/isoron/uhabits/core/utils/MidnightTimer.kt | 14 +++++++++++--- .../isoron/uhabits/core/utils/MidnightTimerTest.kt | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/utils/DateUtils.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/utils/DateUtils.kt index b06513140..d0ca726a5 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/utils/DateUtils.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/utils/DateUtils.kt @@ -227,7 +227,7 @@ abstract class DateUtils { fun getStartOfTodayWithOffset(): Long = getStartOfDayWithOffset(getLocalTime()) @JvmStatic - fun millisecondsUntilTomorrowWithOffset(): Long = getStartOfTomorrowWithOffset() - getLocalTime() + fun millisecondsUntilTomorrowWithOffset(): Long = getStartOfTomorrowWithOffset() - applyTimezone(getLocalTime()) @JvmStatic fun getStartOfTodayCalendar(): GregorianCalendar = getCalendar(getStartOfToday()) diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/utils/MidnightTimer.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/utils/MidnightTimer.kt index 903099293..b63569533 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/utils/MidnightTimer.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/utils/MidnightTimer.kt @@ -19,6 +19,7 @@ package org.isoron.uhabits.core.utils import org.isoron.uhabits.core.AppScope +import org.isoron.uhabits.core.io.Logging import java.util.LinkedList import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService @@ -29,9 +30,10 @@ import javax.inject.Inject * A class that emits events when a new day starts. */ @AppScope -open class MidnightTimer @Inject constructor() { +open class MidnightTimer @Inject constructor(logging: Logging) { private val listeners: MutableList = LinkedList() private lateinit var executor: ScheduledExecutorService + private val logger = logging.getLogger("MidnightTimer") @Synchronized fun addListener(listener: MidnightListener) { @@ -39,7 +41,10 @@ open class MidnightTimer @Inject constructor() { } @Synchronized - fun onPause(): MutableList? = executor.shutdownNow() + fun onPause(): MutableList? { + logger.info("Pausing timer") + return executor.shutdownNow() + } @Synchronized fun onResume( @@ -47,9 +52,11 @@ open class MidnightTimer @Inject constructor() { testExecutor: ScheduledExecutorService? = null ) { executor = testExecutor ?: Executors.newSingleThreadScheduledExecutor() + val initialDelay = DateUtils.millisecondsUntilTomorrowWithOffset() + delayOffsetInMillis + logger.info("Scheduling refresh for $initialDelay ms from now") executor.scheduleAtFixedRate( { notifyListeners() }, - DateUtils.millisecondsUntilTomorrowWithOffset() + delayOffsetInMillis, + initialDelay, DateUtils.DAY_LENGTH, TimeUnit.MILLISECONDS ) @@ -60,6 +67,7 @@ open class MidnightTimer @Inject constructor() { @Synchronized private fun notifyListeners() { + logger.info("Midnight refresh") for (l in listeners) { l.atMidnight() } diff --git a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/MidnightTimerTest.kt b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/MidnightTimerTest.kt index b92507da0..c0eb3fe2d 100644 --- a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/MidnightTimerTest.kt +++ b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/MidnightTimerTest.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.isoron.uhabits.core.BaseUnitTest +import org.isoron.uhabits.core.io.StandardLogging import org.junit.Test import java.util.Calendar import java.util.TimeZone @@ -34,7 +35,7 @@ class MidnightTimerTest : BaseUnitTest() { ) val suspendedListener = suspendCoroutine { continuation -> - MidnightTimer().apply { + MidnightTimer(StandardLogging()).apply { addListener { continuation.resume(true) } // When onResume(1, executor) From ba57ebad310a8e39e4e7a68303239be66293edd5 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Mon, 5 Jun 2023 20:01:41 -0500 Subject: [PATCH 3/8] Fix an invisible color in widgets; adjust another color --- .../isoron/uhabits/core/ui/views/Themes.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/views/Themes.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/views/Themes.kt index 1b1d989e4..eef7f26d0 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/views/Themes.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/views/Themes.kt @@ -125,4 +125,30 @@ class WidgetTheme : LightTheme() { override val highContrastTextColor = Color.WHITE override val mediumContrastTextColor = Color.WHITE.withAlpha(0.50) override val lowContrastTextColor = Color.WHITE.withAlpha(0.10) + + override fun color(paletteIndex: Int): Color { + return when (paletteIndex) { + 0 -> Color(0xD32F2F) + 1 -> Color(0xE64A19) + 2 -> Color(0xF57C00) + 3 -> Color(0xFF8F00) + 4 -> Color(0xF9A825) + 5 -> Color(0xAFB42B) + 6 -> Color(0x7CB342) + 7 -> Color(0x388E3C) + 8 -> Color(0x00897B) + 9 -> Color(0x00ACC1) + 10 -> Color(0x039BE5) + 11 -> Color(0x1976D2) + 12 -> Color(0x6275f0) + 13 -> Color(0x5E35B1) + 14 -> Color(0x8E24AA) + 15 -> Color(0xD81B60) + 16 -> Color(0x5D4037) + 17 -> Color(0x757575) + 18 -> Color(0x757575) + 19 -> Color(0x9E9E9E) + else -> Color(0x000000) + } + } } From 9ca1aa911a2a73cbb10e00303aa51fd490fd2741 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Mon, 5 Jun 2023 20:04:20 -0500 Subject: [PATCH 4/8] Minor layout fixes --- uhabits-android/src/main/res/layout/checkmark_popup.xml | 2 +- uhabits-android/src/main/res/layout/widget_graph.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/uhabits-android/src/main/res/layout/checkmark_popup.xml b/uhabits-android/src/main/res/layout/checkmark_popup.xml index e21c2fb54..59f5c81a1 100644 --- a/uhabits-android/src/main/res/layout/checkmark_popup.xml +++ b/uhabits-android/src/main/res/layout/checkmark_popup.xml @@ -36,7 +36,7 @@ android:layout_height="0dp" android:layout_weight="1" android:gravity="center" - android:inputType="textCapSentences" + android:inputType="textCapSentences|textMultiLine" android:textSize="@dimen/smallTextSize" android:padding="4dp" android:background="@color/transparent" diff --git a/uhabits-android/src/main/res/layout/widget_graph.xml b/uhabits-android/src/main/res/layout/widget_graph.xml index 6ee9cfb8b..6349717bd 100644 --- a/uhabits-android/src/main/res/layout/widget_graph.xml +++ b/uhabits-android/src/main/res/layout/widget_graph.xml @@ -44,6 +44,7 @@ android:layout_height="wrap_content" android:gravity="center" android:textSize="@dimen/smallTextSize" + android:maxLines="2" android:textColor="@color/white"/> From d4f4f8b4a95dc7ee238636e5c107b9a8a90d144d Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Mon, 5 Jun 2023 20:25:00 -0500 Subject: [PATCH 5/8] Prevent crash if exact alarm permission is revoked --- .../main/java/org/isoron/uhabits/intents/IntentScheduler.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt b/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt index 089af4af2..007b7f08d 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt @@ -25,6 +25,7 @@ import android.app.AlarmManager.RTC_WAKEUP import android.app.PendingIntent import android.content.Context import android.content.Context.ALARM_SERVICE +import android.os.Build import android.util.Log import org.isoron.uhabits.core.AppScope import org.isoron.uhabits.core.models.Habit @@ -56,6 +57,10 @@ class IntentScheduler ) return SchedulerResult.IGNORED } + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !manager.canScheduleExactAlarms()) { + Log.e("IntentScheduler", "No permission to schedule exact alarms") + return SchedulerResult.IGNORED + } manager.setExactAndAllowWhileIdle(alarmType, timestamp, intent) return SchedulerResult.OK } From 88df8d2552bb6af5b15dd0a689b21b5d85cb4230 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Sat, 8 Jul 2023 17:13:45 -0500 Subject: [PATCH 6/8] Format source code --- .../src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt b/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt index 007b7f08d..047474d67 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt @@ -57,7 +57,7 @@ class IntentScheduler ) return SchedulerResult.IGNORED } - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !manager.canScheduleExactAlarms()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !manager.canScheduleExactAlarms()) { Log.e("IntentScheduler", "No permission to schedule exact alarms") return SchedulerResult.IGNORED } From b0a4284b66d1f407d457dfb1d7be828615a049bd Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Sat, 8 Jul 2023 18:05:01 -0500 Subject: [PATCH 7/8] NumberDialog: Use text input on Samsung devices Fixes #1719 --- .../uhabits/activities/common/dialogs/NumberDialog.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt index 38c0a5756..423e90958 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt @@ -2,11 +2,13 @@ package org.isoron.uhabits.activities.common.dialogs import android.app.Dialog import android.os.Bundle +import android.provider.Settings import android.text.method.DigitsKeyListener import android.view.KeyEvent import android.view.LayoutInflater import android.view.MotionEvent import android.view.View +import android.view.inputmethod.EditorInfo import androidx.appcompat.app.AppCompatDialogFragment import org.isoron.uhabits.HabitsApplication import org.isoron.uhabits.R @@ -86,6 +88,15 @@ class NumberDialog : AppCompatDialogFragment() { // https://stackoverflow.com/a/34256139 val separator = DecimalFormatSymbols.getInstance().decimalSeparator view.value.keyListener = DigitsKeyListener.getInstance("0123456789$separator") + + // https://github.com/flutter/flutter/issues/61175 + val currKeyboard = Settings.Secure.getString( + requireContext().contentResolver, + Settings.Secure.DEFAULT_INPUT_METHOD + ) + if (currKeyboard.contains("swiftkey") || currKeyboard.contains("samsung")) { + view.value.inputType = EditorInfo.TYPE_CLASS_TEXT + } } fun save() { From 8801960615dccbb3d9277f7f1685d7df66121e88 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Mon, 28 Aug 2023 05:43:12 -0500 Subject: [PATCH 8/8] Update CHANGELOG --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbc344341..d927bfe39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [2.1.3] -- 2023-08-28 +### Fixed +- Use text input on Samsung devices (@iSoron, #1719) +- Prevent crash if alarm permission is revoked (@iSoron) +- Adjust widget colors (@iSoron) +- Fix bug preventing screens from updating at midnight (@iSoron) +- Fix skip button in locales that use comma instead of dot (@iSoron, #1721) + ## [2.1.2] -- 2023-05-26 ### Fixed - Fix bug that caused widget to enter checkmark on wrong date (@iSoron, #1541)