From 71417df2c9b1898dad362cf17002621f3027e8a7 Mon Sep 17 00:00:00 2001 From: Jakub Kalinowski Date: Wed, 20 Apr 2022 23:31:25 +0200 Subject: [PATCH 1/4] Checking if a dialog was already created --- .../common/dialogs/NumberPickerFactory.kt | 13 ++++++++++++- .../activities/habits/list/ListHabitsScreen.kt | 4 +++- .../activities/habits/show/ShowHabitActivity.kt | 12 +++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPickerFactory.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPickerFactory.kt index 8c62e337a..1e8986a81 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPickerFactory.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPickerFactory.kt @@ -50,7 +50,6 @@ class NumberPickerFactory @Inject constructor( @ActivityContext private val context: Context ) { - @SuppressLint("SetTextI18n") fun create( value: Double, @@ -60,6 +59,7 @@ class NumberPickerFactory frequency: Frequency, callback: ListHabitsBehavior.NumberPickerCallback ): AlertDialog { + numberPickerExists = true val inflater = LayoutInflater.from(context) val view = inflater.inflate(R.layout.number_picker_dialog, null) @@ -113,6 +113,7 @@ class NumberPickerFactory } .setOnDismissListener { callback.onNumberPickerDismissed() + numberPickerExists = false } if (frequency == DAILY) { @@ -169,6 +170,16 @@ class NumberPickerFactory val inputMethodManager = context.getSystemService(InputMethodManager::class.java) inputMethodManager?.showSoftInput(v, 0) } + + companion object { + private var numberPickerExists = false + + fun numberPickerAlreadyExists(): Boolean = numberPickerExists + + fun setNumberPickerExists(value: Boolean) { + numberPickerExists = value + } + } } class SeparatorWatcherInputFilter(private val nextPicker: NumberPicker) : InputFilter { diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt index 4ec28f9f3..d939edb47 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt @@ -234,7 +234,9 @@ class ListHabitsScreen frequency: Frequency, callback: ListHabitsBehavior.NumberPickerCallback ) { - numberPickerFactory.create(value, unit, notes, dateString, frequency, callback).show() + if (!NumberPickerFactory.numberPickerAlreadyExists()) { + numberPickerFactory.create(value, unit, notes, dateString, frequency, callback).show() + } } override fun showCheckmarkDialog( diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt index 4af6948ad..2fd92e241 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt @@ -20,6 +20,7 @@ package org.isoron.uhabits.activities.habits.show import android.content.ContentUris import android.os.Bundle +import android.util.Log import android.view.HapticFeedbackConstants import android.view.Menu import android.view.MenuItem @@ -173,7 +174,16 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener { frequency: Frequency, callback: ListHabitsBehavior.NumberPickerCallback ) { - NumberPickerFactory(this@ShowHabitActivity).create(value, unit, notes, dateString, frequency, callback).show() + if(!NumberPickerFactory.numberPickerAlreadyExists()) { + NumberPickerFactory(this@ShowHabitActivity).create( + value, + unit, + notes, + dateString, + frequency, + callback + ).show() + } } override fun showCheckmarkDialog( From 4bff9ebefaa296f46448d445b6866aa35b4e9421 Mon Sep 17 00:00:00 2001 From: Jakub Kalinowski Date: Wed, 20 Apr 2022 23:38:00 +0200 Subject: [PATCH 2/4] Corrected ktlint stuff --- .../isoron/uhabits/activities/habits/show/ShowHabitActivity.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt index 2fd92e241..67518cb20 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt @@ -20,7 +20,6 @@ package org.isoron.uhabits.activities.habits.show import android.content.ContentUris import android.os.Bundle -import android.util.Log import android.view.HapticFeedbackConstants import android.view.Menu import android.view.MenuItem @@ -174,7 +173,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener { frequency: Frequency, callback: ListHabitsBehavior.NumberPickerCallback ) { - if(!NumberPickerFactory.numberPickerAlreadyExists()) { + if (!NumberPickerFactory.numberPickerAlreadyExists()) { NumberPickerFactory(this@ShowHabitActivity).create( value, unit, From d7293d7a8ed370c5823e0124b50e7664d7d09eaa Mon Sep 17 00:00:00 2001 From: Jakub Kalinowski Date: Thu, 21 Apr 2022 20:41:58 +0200 Subject: [PATCH 3/4] Changed the approach --- .../common/dialogs/NumberPickerFactory.kt | 17 +++++++++-------- .../habits/list/ListHabitsScreen.kt | 4 +--- .../habits/show/ShowHabitActivity.kt | 19 ++++++++----------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPickerFactory.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPickerFactory.kt index 1e8986a81..45a9aac64 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPickerFactory.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPickerFactory.kt @@ -59,7 +59,9 @@ class NumberPickerFactory frequency: Frequency, callback: ListHabitsBehavior.NumberPickerCallback ): AlertDialog { - numberPickerExists = true + + clearCurrentDialog() + val inflater = LayoutInflater.from(context) val view = inflater.inflate(R.layout.number_picker_dialog, null) @@ -113,7 +115,7 @@ class NumberPickerFactory } .setOnDismissListener { callback.onNumberPickerDismissed() - numberPickerExists = false + currentDialog = null } if (frequency == DAILY) { @@ -154,6 +156,7 @@ class NumberPickerFactory false } + currentDialog = dialog return dialog } @@ -172,12 +175,10 @@ class NumberPickerFactory } companion object { - private var numberPickerExists = false - - fun numberPickerAlreadyExists(): Boolean = numberPickerExists - - fun setNumberPickerExists(value: Boolean) { - numberPickerExists = value + private var currentDialog: AlertDialog? = null + fun clearCurrentDialog() { + currentDialog?.dismiss() + currentDialog = null } } } diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt index d939edb47..4ec28f9f3 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt @@ -234,9 +234,7 @@ class ListHabitsScreen frequency: Frequency, callback: ListHabitsBehavior.NumberPickerCallback ) { - if (!NumberPickerFactory.numberPickerAlreadyExists()) { - numberPickerFactory.create(value, unit, notes, dateString, frequency, callback).show() - } + numberPickerFactory.create(value, unit, notes, dateString, frequency, callback).show() } override fun showCheckmarkDialog( diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt index 2fd92e241..867ee864d 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt @@ -20,7 +20,6 @@ package org.isoron.uhabits.activities.habits.show import android.content.ContentUris import android.os.Bundle -import android.util.Log import android.view.HapticFeedbackConstants import android.view.Menu import android.view.MenuItem @@ -174,16 +173,14 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener { frequency: Frequency, callback: ListHabitsBehavior.NumberPickerCallback ) { - if(!NumberPickerFactory.numberPickerAlreadyExists()) { - NumberPickerFactory(this@ShowHabitActivity).create( - value, - unit, - notes, - dateString, - frequency, - callback - ).show() - } + NumberPickerFactory(this@ShowHabitActivity).create( + value, + unit, + notes, + dateString, + frequency, + callback + ).show() } override fun showCheckmarkDialog( From 4a1931fc74d6bc95d9f4b192247a2946f691a4e2 Mon Sep 17 00:00:00 2001 From: Jakub Kalinowski Date: Fri, 22 Apr 2022 20:44:33 +0200 Subject: [PATCH 4/4] Reverted unnecessary change --- .../uhabits/activities/habits/show/ShowHabitActivity.kt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt index 867ee864d..4af6948ad 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt @@ -173,14 +173,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener { frequency: Frequency, callback: ListHabitsBehavior.NumberPickerCallback ) { - NumberPickerFactory(this@ShowHabitActivity).create( - value, - unit, - notes, - dateString, - frequency, - callback - ).show() + NumberPickerFactory(this@ShowHabitActivity).create(value, unit, notes, dateString, frequency, callback).show() } override fun showCheckmarkDialog(