From d97178dcb1fc913458784dea6de7f5013bd50c73 Mon Sep 17 00:00:00 2001 From: Quentin Hibon Date: Mon, 7 Aug 2023 20:04:28 +0200 Subject: [PATCH 1/3] Prompt for notification permission Preparation for the SDK upgrade from 32 to 33. --- uhabits-android/src/main/AndroidManifest.xml | 2 ++ .../activities/habits/edit/EditHabitActivity.kt | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/uhabits-android/src/main/AndroidManifest.xml b/uhabits-android/src/main/AndroidManifest.xml index 9377e42c0..394096470 100644 --- a/uhabits-android/src/main/AndroidManifest.xml +++ b/uhabits-android/src/main/AndroidManifest.xml @@ -22,6 +22,8 @@ + + { binding.nameInput.hint = getString(R.string.measurable_short_example) binding.questionInput.hint = getString(R.string.measurable_question_example) @@ -271,6 +273,14 @@ class EditHabitActivity : AppCompatActivity() { habit.description = binding.notesInput.text.trim().toString() habit.color = color if (reminderHour >= 0) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + requestPermissions( + arrayOf( + android.Manifest.permission.POST_NOTIFICATIONS + ), + 1 + ) + } habit.reminder = Reminder(reminderHour, reminderMin, reminderDays) } else { habit.reminder = null From 426d96c5899686b7a06ce6e23927dcc2807e1284 Mon Sep 17 00:00:00 2001 From: Leonard Dizon Date: Wed, 19 Oct 2022 00:18:34 +0800 Subject: [PATCH 2/3] Update compile and target SDK to 33 (Android 13) Main breaking change: the `MotionEvent` parameters on `GestureDetector.OnGestureListener` interface are now non-nullable. --- uhabits-android/build.gradle.kts | 4 ++-- .../common/views/FrequencyChartTest.kt | 8 +++++++- .../activities/common/views/ScoreChartTest.kt | 8 +++++++- .../isoron/platform/gui/AndroidDataView.kt | 20 +++++++++---------- .../common/views/ScrollableChart.kt | 2 +- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/uhabits-android/build.gradle.kts b/uhabits-android/build.gradle.kts index 2cb5be48a..eaf2b81b4 100644 --- a/uhabits-android/build.gradle.kts +++ b/uhabits-android/build.gradle.kts @@ -42,13 +42,13 @@ kotlin { android { - compileSdk = 32 + compileSdk = 33 defaultConfig { versionCode = 20200 versionName = "2.2.0" minSdk = 28 - targetSdk = 32 + targetSdk = 33 applicationId = "org.isoron.uhabits" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/FrequencyChartTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/FrequencyChartTest.kt index 0c4225f99..390644283 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/FrequencyChartTest.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/FrequencyChartTest.kt @@ -18,6 +18,7 @@ */ package org.isoron.uhabits.activities.common.views +import android.view.MotionEvent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest import org.isoron.uhabits.BaseViewTest @@ -52,7 +53,12 @@ class FrequencyChartTest : BaseViewTest() { @Test @Throws(Throwable::class) fun testRender_withDataOffset() { - view.onScroll(null, null, -dpToPixels(150), 0f) + view.onScroll( + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_SCROLL, 0f, 0f, 0), + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_SCROLL, 0f, 0f, 0), + -dpToPixels(150), + 0f + ) view.invalidate() assertRenders(view, BASE_PATH + "renderDataOffset.png") } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/ScoreChartTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/ScoreChartTest.kt index 4f504d8be..e82693461 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/ScoreChartTest.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/ScoreChartTest.kt @@ -18,6 +18,7 @@ */ package org.isoron.uhabits.activities.common.views +import android.view.MotionEvent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest import org.isoron.uhabits.BaseViewTest @@ -63,7 +64,12 @@ class ScoreChartTest : BaseViewTest() { @Test @Throws(Throwable::class) fun testRender_withDataOffset() { - view.onScroll(null, null, -dpToPixels(150), 0f) + view.onScroll( + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_SCROLL, 0f, 0f, 0), + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_SCROLL, 0f, 0f, 0), + -dpToPixels(150), + 0f + ) view.invalidate() assertRenders(view, BASE_PATH + "renderDataOffset.png") } diff --git a/uhabits-android/src/main/java/org/isoron/platform/gui/AndroidDataView.kt b/uhabits-android/src/main/java/org/isoron/platform/gui/AndroidDataView.kt index 990314a06..f0dcd378a 100644 --- a/uhabits-android/src/main/java/org/isoron/platform/gui/AndroidDataView.kt +++ b/uhabits-android/src/main/java/org/isoron/platform/gui/AndroidDataView.kt @@ -44,21 +44,21 @@ class AndroidDataView( addUpdateListener(this@AndroidDataView) } - override fun onTouchEvent(event: MotionEvent?) = detector.onTouchEvent(event) - override fun onDown(e: MotionEvent?) = true - override fun onShowPress(e: MotionEvent?) = Unit + override fun onTouchEvent(event: MotionEvent) = detector.onTouchEvent(event) + override fun onDown(e: MotionEvent) = true + override fun onShowPress(e: MotionEvent) = Unit - override fun onSingleTapUp(e: MotionEvent?): Boolean { + override fun onSingleTapUp(e: MotionEvent): Boolean { return handleClick(e, true) } - override fun onLongPress(e: MotionEvent?) { + override fun onLongPress(e: MotionEvent) { handleClick(e) } override fun onScroll( - e1: MotionEvent?, - e2: MotionEvent?, + e1: MotionEvent, + e2: MotionEvent, dx: Float, dy: Float ): Boolean { @@ -79,8 +79,8 @@ class AndroidDataView( } override fun onFling( - e1: MotionEvent?, - e2: MotionEvent?, + e1: MotionEvent, + e2: MotionEvent, velocityX: Float, velocityY: Float ): Boolean { @@ -100,7 +100,7 @@ class AndroidDataView( return false } - override fun onAnimationUpdate(animation: ValueAnimator?) { + override fun onAnimationUpdate(animation: ValueAnimator) { if (!scroller.isFinished) { scroller.computeScrollOffset() updateDataOffset() diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.kt index 509acc067..b69e491fe 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.kt @@ -116,7 +116,7 @@ abstract class ScrollableChart : View, GestureDetector.OnGestureListener, Animat return BundleSavedState(superState, bundle) } - override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, dx: Float, dy: Float): Boolean { + override fun onScroll(e1: MotionEvent, e2: MotionEvent, dx: Float, dy: Float): Boolean { var dx = dx if (scrollerBucketSize == 0) return false if (abs(dx) > abs(dy)) { From 41179064140f46f6bc2deb11cb13cccc7c961e3a Mon Sep 17 00:00:00 2001 From: Leonard Dizon Date: Wed, 19 Oct 2022 00:45:56 +0800 Subject: [PATCH 3/3] Create locales_config.xml for per-app language --- uhabits-android/src/main/AndroidManifest.xml | 1 + .../src/main/res/xml/locales_config.xml | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 uhabits-android/src/main/res/xml/locales_config.xml diff --git a/uhabits-android/src/main/AndroidManifest.xml b/uhabits-android/src/main/AndroidManifest.xml index 394096470..e1d3d1103 100644 --- a/uhabits-android/src/main/AndroidManifest.xml +++ b/uhabits-android/src/main/AndroidManifest.xml @@ -31,6 +31,7 @@ android:backupAgent=".HabitsBackupAgent" android:icon="@mipmap/ic_launcher" android:label="@string/main_activity_title" + android:localeConfig="@xml/locales_config" android:supportsRtl="true" android:theme="@style/AppBaseTheme"> diff --git a/uhabits-android/src/main/res/xml/locales_config.xml b/uhabits-android/src/main/res/xml/locales_config.xml new file mode 100644 index 000000000..a0fefcb50 --- /dev/null +++ b/uhabits-android/src/main/res/xml/locales_config.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file