From d58336e87cf842f2b8e4bad76afa01e9d14308bf Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Sun, 11 Sep 2022 13:23:58 +0200 Subject: [PATCH 1/9] Convert comment to KDoc --- .../streetcomplete/util/LastPickedValuesStore.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/util/LastPickedValuesStore.kt b/app/src/main/java/de/westnordost/streetcomplete/util/LastPickedValuesStore.kt index 6cb493ef24..c89619eee7 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/util/LastPickedValuesStore.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/util/LastPickedValuesStore.kt @@ -28,11 +28,11 @@ class LastPickedValuesStore( private fun getKey() = Prefs.LAST_PICKED_PREFIX + key } -/* Returns the `target` most-common non-null items in the first `historyCount` +/** Returns the [target] most-common non-null items in the first [historyCount] * items of the sequence, in their original order. - * If there are fewer than `target` unique items, continues counting items + * If there are fewer than [target] unique items, continues counting items * until that many are found, or the end of the sequence is reached. - * If the `first` most recent items are not null, they are always included, + * If the [first] most recent items are not null, they are always included, * displacing the least-common of the other items if necessary. */ fun Sequence.mostCommonWithin(target: Int, historyCount: Int, first: Int): Sequence { From 1e1ab20ef2cabe3ff2546bea96b57acc3524483d Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Sun, 11 Sep 2022 13:24:20 +0200 Subject: [PATCH 2/9] Drop invalid/unused attributes from layout --- .../res/layout/quest_building_levels_last_picked_button.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/res/layout/quest_building_levels_last_picked_button.xml b/app/src/main/res/layout/quest_building_levels_last_picked_button.xml index e8e296d490..e1ca0bd7f6 100644 --- a/app/src/main/res/layout/quest_building_levels_last_picked_button.xml +++ b/app/src/main/res/layout/quest_building_levels_last_picked_button.xml @@ -5,8 +5,6 @@ style="@style/Widget.AppCompat.Button.Small" android:layout_width="wrap_content" android:layout_height="51dp" - android:layout_alignBottom="@id/buildingImage" - android:layout_alignParentRight="true" tools:ignore="RtlHardcoded"> Date: Sun, 11 Sep 2022 14:02:38 +0200 Subject: [PATCH 3/9] Add last picked buttons to fire hydrant diameter quest --- .../AddFireHydrantDiameterForm.kt | 70 ++++++++++++++++++- .../quest_fire_hydrant_diameter.xml | 14 ++++ .../quest_fire_hydrant_diameter.xml | 14 ++++ .../quest_fire_hydrant_diameter.xml | 14 ++++ .../quest_fire_hydrant_diameter.xml | 14 ++++ .../quest_fire_hydrant_diameter.xml | 14 ++++ .../quest_fire_hydrant_diameter.xml | 14 ++++ .../quest_fire_hydrant_diameter.xml | 14 ++++ .../layout/quest_fire_hydrant_diameter.xml | 54 +++++++++----- ...re_hydrant_diameter_last_picked_button.xml | 16 +++++ 10 files changed, 219 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/layout/quest_fire_hydrant_diameter_last_picked_button.xml diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt index cb01da71a4..a443ffaa27 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt @@ -1,16 +1,24 @@ package de.westnordost.streetcomplete.quests.fire_hydrant_diameter +import android.content.Context import android.os.Bundle +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import androidx.appcompat.app.AlertDialog import androidx.core.widget.doAfterTextChanged +import androidx.preference.PreferenceManager +import androidx.recyclerview.widget.RecyclerView import de.westnordost.streetcomplete.R import de.westnordost.streetcomplete.databinding.QuestFireHydrantDiameterBinding +import de.westnordost.streetcomplete.databinding.QuestFireHydrantDiameterLastPickedButtonBinding import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm import de.westnordost.streetcomplete.quests.AnswerItem import de.westnordost.streetcomplete.quests.fire_hydrant_diameter.FireHydrantDiameterMeasurementUnit.INCH import de.westnordost.streetcomplete.quests.fire_hydrant_diameter.FireHydrantDiameterMeasurementUnit.MILLIMETER +import de.westnordost.streetcomplete.util.LastPickedValuesStore import de.westnordost.streetcomplete.util.ktx.intOrNull +import de.westnordost.streetcomplete.util.mostCommonWithin class AddFireHydrantDiameterForm : AbstractOsmQuestForm() { @@ -23,9 +31,33 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm + + override fun onAttach(ctx: Context) { + super.onAttach(ctx) + favs = LastPickedValuesStore( + PreferenceManager.getDefaultSharedPreferences(ctx.applicationContext), + key = javaClass.simpleName, + serialize = { it.toString() }, + deserialize = { it.toInt() } + ) + } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.diameterInput.doAfterTextChanged { checkIsFormComplete() } + + binding.lastPickedButtons.adapter = LastPickedAdapter(lastPickedAnswers, ::onLastPickedButtonClicked) + } + + private fun onLastPickedButtonClicked(position: Int) { + binding.diameterInput.setText(lastPickedAnswers[position].toString()) } override fun isFormComplete() = diameterValue > 0 @@ -38,8 +70,12 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm, + private val onItemClicked: (position: Int) -> Unit +) : RecyclerView.Adapter() { + + class ViewHolder( + private val binding: QuestFireHydrantDiameterLastPickedButtonBinding, + private val onItemClicked: (position: Int) -> Unit + ) : RecyclerView.ViewHolder(binding.root) { + + init { + itemView.setOnClickListener { onItemClicked(bindingAdapterPosition) } + } + + fun onBind(item: Int) { + binding.lastDiameterLabel.text = item.toString() + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val inflater = LayoutInflater.from(parent.context) + val binding = QuestFireHydrantDiameterLastPickedButtonBinding.inflate(inflater, parent, false) + return ViewHolder(binding, onItemClicked) + } + + override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { + viewHolder.onBind(lastPickedAnswers[position]) + } + + override fun getItemCount() = lastPickedAnswers.size +} diff --git a/app/src/main/res/layout-mcc204/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc204/quest_fire_hydrant_diameter.xml index f2bc30f739..76c9709908 100644 --- a/app/src/main/res/layout-mcc204/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout-mcc204/quest_fire_hydrant_diameter.xml @@ -33,4 +33,18 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="RtlHardcoded,SpUsage" /> + + diff --git a/app/src/main/res/layout-mcc206/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc206/quest_fire_hydrant_diameter.xml index a1853c23a4..d17d9acb88 100644 --- a/app/src/main/res/layout-mcc206/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout-mcc206/quest_fire_hydrant_diameter.xml @@ -34,4 +34,18 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="RtlHardcoded,SpUsage" /> + + diff --git a/app/src/main/res/layout-mcc234/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc234/quest_fire_hydrant_diameter.xml index df022bb5bb..c35c5733b8 100644 --- a/app/src/main/res/layout-mcc234/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout-mcc234/quest_fire_hydrant_diameter.xml @@ -35,4 +35,18 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="SpUsage" /> + + diff --git a/app/src/main/res/layout-mcc244/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc244/quest_fire_hydrant_diameter.xml index 338caeb1f4..e5337a3cd8 100644 --- a/app/src/main/res/layout-mcc244/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout-mcc244/quest_fire_hydrant_diameter.xml @@ -34,4 +34,18 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="SpUsage" /> + + diff --git a/app/src/main/res/layout-mcc260/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc260/quest_fire_hydrant_diameter.xml index e7dc4d399c..72f5a1d062 100644 --- a/app/src/main/res/layout-mcc260/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout-mcc260/quest_fire_hydrant_diameter.xml @@ -34,4 +34,18 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="RtlHardcoded,SpUsage" /> + + diff --git a/app/src/main/res/layout-mcc262/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc262/quest_fire_hydrant_diameter.xml index 0ec8c2e377..055403ae24 100644 --- a/app/src/main/res/layout-mcc262/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout-mcc262/quest_fire_hydrant_diameter.xml @@ -34,4 +34,18 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="RtlHardcoded,SpUsage" /> + + diff --git a/app/src/main/res/layout-mcc272/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc272/quest_fire_hydrant_diameter.xml index b6b5d5b527..f46da5fef6 100644 --- a/app/src/main/res/layout-mcc272/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout-mcc272/quest_fire_hydrant_diameter.xml @@ -36,4 +36,18 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="SpUsage" /> + + diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter.xml index 54c0b095d4..8d74c3b84c 100644 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter.xml @@ -1,30 +1,48 @@ + android:orientation="vertical"> - + android:gravity="center" + android:orientation="horizontal"> - + + + + + + + android:orientation="horizontal" + android:padding="4dp" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" + tools:itemCount="6" + tools:listitem="@layout/quest_fire_hydrant_diameter_last_picked_button" /> diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter_last_picked_button.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_last_picked_button.xml new file mode 100644 index 0000000000..643337f9d6 --- /dev/null +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_last_picked_button.xml @@ -0,0 +1,16 @@ + + + + + + From 7b1cadc9d99252c8a10fd9eee7663ff6ff4133e4 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Tue, 13 Sep 2022 21:59:18 +0200 Subject: [PATCH 4/9] Fix comment formatting Co-authored-by: smichel17 --- .../westnordost/streetcomplete/util/LastPickedValuesStore.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/util/LastPickedValuesStore.kt b/app/src/main/java/de/westnordost/streetcomplete/util/LastPickedValuesStore.kt index c89619eee7..cbd7732c5f 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/util/LastPickedValuesStore.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/util/LastPickedValuesStore.kt @@ -28,7 +28,8 @@ class LastPickedValuesStore( private fun getKey() = Prefs.LAST_PICKED_PREFIX + key } -/** Returns the [target] most-common non-null items in the first [historyCount] +/** + * Returns the [target] most-common non-null items in the first [historyCount] * items of the sequence, in their original order. * If there are fewer than [target] unique items, continues counting items * until that many are found, or the end of the sequence is reached. From 711ddeb849d9c275e6dba88c6e2a2976ccd771dd Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Wed, 14 Sep 2022 00:23:39 +0200 Subject: [PATCH 5/9] Don't use mobile country codes to inflate correct layout --- .../AddFireHydrantDiameterForm.kt | 23 ++++++-- .../quest_fire_hydrant_diameter.xml | 51 ------------------ .../quest_fire_hydrant_diameter.xml | 53 ------------------- .../layout/quest_fire_hydrant_diameter.xml | 29 ++-------- .../quest_fire_hydrant_diameter_sign_de.xml} | 16 +----- .../quest_fire_hydrant_diameter_sign_fi.xml} | 14 ----- ...est_fire_hydrant_diameter_sign_generic.xml | 31 +++++++++++ .../quest_fire_hydrant_diameter_sign_nl.xml} | 14 ----- .../quest_fire_hydrant_diameter_sign_pl.xml} | 14 ----- .../quest_fire_hydrant_diameter_sign_uk.xml} | 14 ----- 10 files changed, 55 insertions(+), 204 deletions(-) delete mode 100644 app/src/main/res/layout-mcc262/quest_fire_hydrant_diameter.xml delete mode 100644 app/src/main/res/layout-mcc272/quest_fire_hydrant_diameter.xml rename app/src/main/res/{layout-mcc206/quest_fire_hydrant_diameter.xml => layout/quest_fire_hydrant_diameter_sign_de.xml} (69%) rename app/src/main/res/{layout-mcc244/quest_fire_hydrant_diameter.xml => layout/quest_fire_hydrant_diameter_sign_fi.xml} (69%) create mode 100644 app/src/main/res/layout/quest_fire_hydrant_diameter_sign_generic.xml rename app/src/main/res/{layout-mcc204/quest_fire_hydrant_diameter.xml => layout/quest_fire_hydrant_diameter_sign_nl.xml} (68%) rename app/src/main/res/{layout-mcc260/quest_fire_hydrant_diameter.xml => layout/quest_fire_hydrant_diameter_sign_pl.xml} (69%) rename app/src/main/res/{layout-mcc234/quest_fire_hydrant_diameter.xml => layout/quest_fire_hydrant_diameter_sign_uk.xml} (69%) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt index a443ffaa27..f374ca6518 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.EditText import androidx.appcompat.app.AlertDialog import androidx.core.widget.doAfterTextChanged import androidx.preference.PreferenceManager @@ -28,8 +29,9 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm(R.id.diameterInput) } - private val diameterValue get() = binding.diameterInput.intOrNull ?: 0 + private val diameterValue get() = diameterInput.intOrNull ?: 0 private val lastPickedAnswers by lazy { favs.get() @@ -49,15 +51,21 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm 0 @@ -117,6 +125,15 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm R.layout.quest_fire_hydrant_diameter_sign_de + "FI" -> R.layout.quest_fire_hydrant_diameter_sign_fi + "NL" -> R.layout.quest_fire_hydrant_diameter_sign_nl + "PL" -> R.layout.quest_fire_hydrant_diameter_sign_pl + "UK" -> R.layout.quest_fire_hydrant_diameter_sign_uk + else -> R.layout.quest_fire_hydrant_diameter_sign_generic +} + private class LastPickedAdapter( private val lastPickedAnswers: List, private val onItemClicked: (position: Int) -> Unit diff --git a/app/src/main/res/layout-mcc262/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc262/quest_fire_hydrant_diameter.xml deleted file mode 100644 index 055403ae24..0000000000 --- a/app/src/main/res/layout-mcc262/quest_fire_hydrant_diameter.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/layout-mcc272/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout-mcc272/quest_fire_hydrant_diameter.xml deleted file mode 100644 index f46da5fef6..0000000000 --- a/app/src/main/res/layout-mcc272/quest_fire_hydrant_diameter.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter.xml index 8d74c3b84c..3618b3d6d2 100644 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter.xml @@ -7,33 +7,10 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - - - - - - + android:layout_height="wrap_content" /> - - diff --git a/app/src/main/res/layout-mcc244/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_fi.xml similarity index 69% rename from app/src/main/res/layout-mcc244/quest_fire_hydrant_diameter.xml rename to app/src/main/res/layout/quest_fire_hydrant_diameter_sign_fi.xml index e5337a3cd8..338caeb1f4 100644 --- a/app/src/main/res/layout-mcc244/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_fi.xml @@ -34,18 +34,4 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="SpUsage" /> - - diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_generic.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_generic.xml new file mode 100644 index 0000000000..d0689170e9 --- /dev/null +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_generic.xml @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/app/src/main/res/layout-mcc204/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_nl.xml similarity index 68% rename from app/src/main/res/layout-mcc204/quest_fire_hydrant_diameter.xml rename to app/src/main/res/layout/quest_fire_hydrant_diameter_sign_nl.xml index 76c9709908..f2bc30f739 100644 --- a/app/src/main/res/layout-mcc204/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_nl.xml @@ -33,18 +33,4 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="RtlHardcoded,SpUsage" /> - - diff --git a/app/src/main/res/layout-mcc260/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_pl.xml similarity index 69% rename from app/src/main/res/layout-mcc260/quest_fire_hydrant_diameter.xml rename to app/src/main/res/layout/quest_fire_hydrant_diameter_sign_pl.xml index 72f5a1d062..e7dc4d399c 100644 --- a/app/src/main/res/layout-mcc260/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_pl.xml @@ -34,18 +34,4 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="RtlHardcoded,SpUsage" /> - - diff --git a/app/src/main/res/layout-mcc234/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_uk.xml similarity index 69% rename from app/src/main/res/layout-mcc234/quest_fire_hydrant_diameter.xml rename to app/src/main/res/layout/quest_fire_hydrant_diameter_sign_uk.xml index c35c5733b8..df022bb5bb 100644 --- a/app/src/main/res/layout-mcc234/quest_fire_hydrant_diameter.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_uk.xml @@ -35,18 +35,4 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="SpUsage" /> - - From 9b88a9e2b4a2c7c7fb8d879cac04298c4b4b7bbe Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Tue, 1 Nov 2022 18:45:23 +0100 Subject: [PATCH 6/9] Simplify last picked building levels button --- ...est_building_levels_last_picked_button.xml | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/app/src/main/res/layout/quest_building_levels_last_picked_button.xml b/app/src/main/res/layout/quest_building_levels_last_picked_button.xml index e1ca0bd7f6..8d8ca6bcff 100644 --- a/app/src/main/res/layout/quest_building_levels_last_picked_button.xml +++ b/app/src/main/res/layout/quest_building_levels_last_picked_button.xml @@ -1,39 +1,32 @@ - - - + android:orientation="horizontal"> + + - + From b9b194915d1d00f32c35cc2ef39d06199a5f3844 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Tue, 1 Nov 2022 22:00:15 +0100 Subject: [PATCH 7/9] Show suggestions as dropdown instead of buttons --- .../AddFireHydrantDiameterForm.kt | 79 +++++++------------ .../layout/quest_fire_hydrant_diameter.xml | 25 ------ ...re_hydrant_diameter_last_picked_button.xml | 16 ---- .../quest_fire_hydrant_diameter_sign_de.xml | 11 +++ .../quest_fire_hydrant_diameter_sign_fi.xml | 11 +++ ...est_fire_hydrant_diameter_sign_generic.xml | 8 ++ .../quest_fire_hydrant_diameter_sign_nl.xml | 11 +++ .../quest_fire_hydrant_diameter_sign_pl.xml | 11 +++ .../quest_fire_hydrant_diameter_sign_uk.xml | 11 +++ 9 files changed, 93 insertions(+), 90 deletions(-) delete mode 100644 app/src/main/res/layout/quest_fire_hydrant_diameter.xml delete mode 100644 app/src/main/res/layout/quest_fire_hydrant_diameter_last_picked_button.xml diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt index f374ca6518..12b153278a 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt @@ -2,17 +2,15 @@ package de.westnordost.streetcomplete.quests.fire_hydrant_diameter import android.content.Context import android.os.Bundle -import android.view.LayoutInflater +import android.view.Menu import android.view.View -import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.app.AlertDialog +import androidx.appcompat.widget.PopupMenu +import androidx.core.view.isGone import androidx.core.widget.doAfterTextChanged import androidx.preference.PreferenceManager -import androidx.recyclerview.widget.RecyclerView import de.westnordost.streetcomplete.R -import de.westnordost.streetcomplete.databinding.QuestFireHydrantDiameterBinding -import de.westnordost.streetcomplete.databinding.QuestFireHydrantDiameterLastPickedButtonBinding import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm import de.westnordost.streetcomplete.quests.AnswerItem import de.westnordost.streetcomplete.quests.fire_hydrant_diameter.FireHydrantDiameterMeasurementUnit.INCH @@ -27,9 +25,9 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm(R.id.diameterInput) } + override val contentLayoutResId get() = getHydrantDiameterSignLayoutResId(countryInfo.countryCode) + private val diameterInput by lazy { requireView().findViewById(R.id.diameterInput) } + private val suggestionsButton by lazy { requireView().findViewById(R.id.suggestionsButton) } private val diameterValue get() = diameterInput.intOrNull ?: 0 @@ -54,18 +52,15 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm 0 @@ -123,6 +118,24 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm + diameterInput.setText(item.title.toString()) + true + } + popup.show() + } } private fun getHydrantDiameterSignLayoutResId(countryCode: String): Int = when (countryCode) { @@ -133,35 +146,3 @@ private fun getHydrantDiameterSignLayoutResId(countryCode: String): Int = when ( "UK" -> R.layout.quest_fire_hydrant_diameter_sign_uk else -> R.layout.quest_fire_hydrant_diameter_sign_generic } - -private class LastPickedAdapter( - private val lastPickedAnswers: List, - private val onItemClicked: (position: Int) -> Unit -) : RecyclerView.Adapter() { - - class ViewHolder( - private val binding: QuestFireHydrantDiameterLastPickedButtonBinding, - private val onItemClicked: (position: Int) -> Unit - ) : RecyclerView.ViewHolder(binding.root) { - - init { - itemView.setOnClickListener { onItemClicked(bindingAdapterPosition) } - } - - fun onBind(item: Int) { - binding.lastDiameterLabel.text = item.toString() - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val inflater = LayoutInflater.from(parent.context) - val binding = QuestFireHydrantDiameterLastPickedButtonBinding.inflate(inflater, parent, false) - return ViewHolder(binding, onItemClicked) - } - - override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { - viewHolder.onBind(lastPickedAnswers[position]) - } - - override fun getItemCount() = lastPickedAnswers.size -} diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter.xml deleted file mode 100644 index 3618b3d6d2..0000000000 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter_last_picked_button.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_last_picked_button.xml deleted file mode 100644 index 643337f9d6..0000000000 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter_last_picked_button.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_de.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_de.xml index 0ec8c2e377..63f8beeaff 100644 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_de.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_de.xml @@ -34,4 +34,15 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="RtlHardcoded,SpUsage" /> + + diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_fi.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_fi.xml index 338caeb1f4..65edaf4c7b 100644 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_fi.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_fi.xml @@ -34,4 +34,15 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="SpUsage" /> + + diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_generic.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_generic.xml index d0689170e9..aacce0ecfb 100644 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_generic.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_generic.xml @@ -20,6 +20,14 @@ android:textSize="@dimen/x_large_input" tools:text="1600" /> + + + + diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_pl.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_pl.xml index e7dc4d399c..7a4dfdebdc 100644 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_pl.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_pl.xml @@ -34,4 +34,15 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="RtlHardcoded,SpUsage" /> + + diff --git a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_uk.xml b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_uk.xml index df022bb5bb..9774493684 100644 --- a/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_uk.xml +++ b/app/src/main/res/layout/quest_fire_hydrant_diameter_sign_uk.xml @@ -35,4 +35,15 @@ app:layout_constraintTop_toTopOf="@+id/fireHydrantSign" tools:ignore="SpUsage" /> + + From 9856274232c9e326b6d85983623b8e0080e88108 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Tue, 1 Nov 2022 22:10:12 +0100 Subject: [PATCH 8/9] Simplify menu creation --- .../fire_hydrant_diameter/AddFireHydrantDiameterForm.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt index 12b153278a..f181bcc57c 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt @@ -2,7 +2,6 @@ package de.westnordost.streetcomplete.quests.fire_hydrant_diameter import android.content.Context import android.os.Bundle -import android.view.Menu import android.view.View import android.widget.EditText import androidx.appcompat.app.AlertDialog @@ -126,8 +125,8 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm From fa6137a5afd4c62a35c42d27bffa6f573bd17294 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Tue, 1 Nov 2022 23:13:02 +0100 Subject: [PATCH 9/9] Restore layouts in BE, GB and IE --- .../fire_hydrant_diameter/AddFireHydrantDiameterForm.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt index f181bcc57c..d2625fa9fe 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/fire_hydrant_diameter/AddFireHydrantDiameterForm.kt @@ -138,10 +138,10 @@ class AddFireHydrantDiameterForm : AbstractOsmQuestForm R.layout.quest_fire_hydrant_diameter_sign_de + "DE", "BE" -> R.layout.quest_fire_hydrant_diameter_sign_de "FI" -> R.layout.quest_fire_hydrant_diameter_sign_fi "NL" -> R.layout.quest_fire_hydrant_diameter_sign_nl "PL" -> R.layout.quest_fire_hydrant_diameter_sign_pl - "UK" -> R.layout.quest_fire_hydrant_diameter_sign_uk + "GB", "IE" -> R.layout.quest_fire_hydrant_diameter_sign_uk else -> R.layout.quest_fire_hydrant_diameter_sign_generic }