Skip to content

Commit 61ad106

Browse files
committed
Filter out outdated places by default
1 parent a6fd8e9 commit 61ad106

9 files changed

Lines changed: 335 additions & 12 deletions

File tree

app/src/main/kotlin/org/btcmap/db/table/place/PlaceQueries.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,30 @@ class PlaceQueries(private val conn: SQLiteConnection) {
104104
maxLat: Double,
105105
minLon: Double,
106106
maxLon: Double,
107+
minVerifiedAt: ZonedDateTime? = null,
107108
): List<Marker> {
109+
val whereClause = buildString {
110+
append("$ICON <> 'local_atm' AND $ICON <> 'currency_exchange'")
111+
append(" AND $LAT >= ?1 AND $LAT <= ?2 AND $LON >= ?3 AND $LON <= ?4")
112+
if (minVerifiedAt != null) {
113+
append(" AND $VERIFIED_AT >= ?5")
114+
}
115+
}
108116
conn.prepare(
109117
"""
110118
SELECT ${MarkerProjection.COLUMNS}
111119
FROM $TABLE
112-
WHERE
113-
$ICON <> 'local_atm' AND $ICON <> 'currency_exchange'
114-
AND $LAT >= ?1 AND $LAT <= ?2 AND $LON >= ?3 AND $LON <= ?4
120+
WHERE $whereClause
115121
ORDER BY $LAT DESC;
116122
"""
117123
).use {
118124
it.bindDouble(1, minLat)
119125
it.bindDouble(2, maxLat)
120126
it.bindDouble(3, minLon)
121127
it.bindDouble(4, maxLon)
128+
if (minVerifiedAt != null) {
129+
it.bindText(5, minVerifiedAt.toString())
130+
}
122131
val rows = mutableListOf<Marker>()
123132
while (it.step()) {
124133
rows.add(MarkerProjection.fromStatement(it))

app/src/main/kotlin/org/btcmap/map/MapFragment.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ import org.btcmap.search.SearchAdapterItem
9191
import org.btcmap.settings.badgeBackgroundColor
9292
import org.btcmap.settings.badgeTextColor
9393
import org.btcmap.settings.boostedMarkerBackgroundColor
94+
import org.btcmap.settings.verifiedFilter
9495
import java.text.NumberFormat
96+
import java.time.ZonedDateTime
9597

9698
class MapFragment : Fragment() {
9799

@@ -195,7 +197,7 @@ class MapFragment : Fragment() {
195197
var statusBarController: MapStatusBarController? = null
196198

197199
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
198-
bottomSheetBehavior = BottomSheetBehavior.from(binding.elementDetails)
200+
bottomSheetBehavior = BottomSheetBehavior.from(binding.placeBottomSheet)
199201
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
200202
bottomSheetBehavior.addSlideCallback()
201203

@@ -769,6 +771,7 @@ class MapFragment : Fragment() {
769771
expandedBounds.latitudeNorth,
770772
expandedBounds.longitudeWest,
771773
expandedBounds.longitudeEast,
774+
minVerifiedAt = computeMinVerifiedAt(),
772775
)
773776
}
774777
lastDbCallTimeMs = System.currentTimeMillis() - startTime
@@ -1128,6 +1131,11 @@ class MapFragment : Fragment() {
11281131
}
11291132
}
11301133

1134+
private fun computeMinVerifiedAt(): ZonedDateTime? {
1135+
val years = prefs.verifiedFilter.years ?: return null
1136+
return ZonedDateTime.now().minusYears(years.toLong())
1137+
}
1138+
11311139
fun dpToPx(dp: Int): Int {
11321140
return (dp * resources.displayMetrics.density).toInt()
11331141
}

app/src/main/kotlin/org/btcmap/settings/SettingsFragment.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class SettingsFragment : Fragment() {
5252
}
5353

5454
initMapStyleButton()
55+
initVerifiedFilterButton()
5556

5657
binding.useAdaptiveColors.isChecked = prefs.useAdaptiveColors
5758
binding.useAdaptiveColors.setOnCheckedChangeListener { _, isChecked ->
@@ -233,6 +234,39 @@ class SettingsFragment : Fragment() {
233234
}
234235
}
235236

237+
private fun initVerifiedFilterButton() {
238+
binding.currentVerifiedFilter.text = prefs.verifiedFilter.name(requireContext())
239+
240+
binding.verifiedFilterButton.setOnClickListener {
241+
val dialog = MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.verified_filter)
242+
.setView(R.layout.verified_filter_dialog).show()
243+
244+
val setupFilter = fun RadioButton?.(filter: VerifiedFilter) {
245+
if (this == null) return
246+
247+
text = filter.name(requireContext())
248+
isChecked = prefs.verifiedFilter == filter
249+
250+
setOnCheckedChangeListener { _, isChecked ->
251+
if (isChecked) {
252+
prefs.verifiedFilter = filter
253+
binding.currentVerifiedFilter.text = text
254+
dialog.dismiss()
255+
}
256+
}
257+
}
258+
259+
setupFilter.apply {
260+
invoke(dialog.findViewById(R.id.no_filter), VerifiedFilter.NO_FILTER)
261+
invoke(dialog.findViewById(R.id.one_year), VerifiedFilter.ONE_YEAR)
262+
invoke(dialog.findViewById(R.id.two_years), VerifiedFilter.TWO_YEARS)
263+
invoke(dialog.findViewById(R.id.three_years), VerifiedFilter.THREE_YEARS)
264+
invoke(dialog.findViewById(R.id.four_years), VerifiedFilter.FOUR_YEARS)
265+
invoke(dialog.findViewById(R.id.five_years), VerifiedFilter.FIVE_YEARS)
266+
}
267+
}
268+
}
269+
236270
private fun initMarkerBackgroundButton() {
237271
binding.markerBackgroundColor.text =
238272
"#${prefs.markerBackgroundColor(requireContext()).toHexString()}"

app/src/main/kotlin/org/btcmap/settings/SharedPreferencesExt.kt

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,59 @@ var SharedPreferences.showDebugInfo: Boolean
374374
get() = getBoolean(KEY_SHOW_DEBUG_INFO, BuildConfig.DEBUG)
375375
set(value) {
376376
edit { putBoolean(KEY_SHOW_DEBUG_INFO, value) }
377-
}
377+
}
378+
379+
enum class VerifiedFilter(val years: Int?) {
380+
NO_FILTER(null),
381+
ONE_YEAR(1),
382+
TWO_YEARS(2),
383+
THREE_YEARS(3),
384+
FOUR_YEARS(4),
385+
FIVE_YEARS(5),
386+
}
387+
388+
private const val KEY_VERIFIED_FILTER = "verified_filter"
389+
390+
var SharedPreferences.verifiedFilter: VerifiedFilter
391+
get() {
392+
return verifiedFilterFromPrefValue(getString(KEY_VERIFIED_FILTER, "3") ?: "3")
393+
}
394+
set(value) {
395+
edit {
396+
putString(KEY_VERIFIED_FILTER, value.toPrefValue())
397+
}
398+
}
399+
400+
private fun verifiedFilterFromPrefValue(pref: String): VerifiedFilter {
401+
return when (pref) {
402+
"no_filter" -> VerifiedFilter.NO_FILTER
403+
"1" -> VerifiedFilter.ONE_YEAR
404+
"2" -> VerifiedFilter.TWO_YEARS
405+
"3" -> VerifiedFilter.THREE_YEARS
406+
"4" -> VerifiedFilter.FOUR_YEARS
407+
"5" -> VerifiedFilter.FIVE_YEARS
408+
else -> VerifiedFilter.THREE_YEARS
409+
}
410+
}
411+
412+
fun VerifiedFilter.toPrefValue(): String {
413+
return when (this) {
414+
VerifiedFilter.NO_FILTER -> "no_filter"
415+
VerifiedFilter.ONE_YEAR -> "1"
416+
VerifiedFilter.TWO_YEARS -> "2"
417+
VerifiedFilter.THREE_YEARS -> "3"
418+
VerifiedFilter.FOUR_YEARS -> "4"
419+
VerifiedFilter.FIVE_YEARS -> "5"
420+
}
421+
}
422+
423+
fun VerifiedFilter.name(context: Context): String {
424+
return when (this) {
425+
VerifiedFilter.NO_FILTER -> context.getString(R.string.verified_filter_no_filter)
426+
VerifiedFilter.ONE_YEAR -> context.getString(R.string.verified_filter_1_year)
427+
VerifiedFilter.TWO_YEARS -> context.getString(R.string.verified_filter_2_years)
428+
VerifiedFilter.THREE_YEARS -> context.getString(R.string.verified_filter_3_years)
429+
VerifiedFilter.FOUR_YEARS -> context.getString(R.string.verified_filter_4_years)
430+
VerifiedFilter.FIVE_YEARS -> context.getString(R.string.verified_filter_5_years)
431+
}
432+
}

app/src/main/res/layout/map_fragment.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</com.google.android.material.search.SearchView>
5959

6060
<FrameLayout
61-
android:id="@+id/elementDetails"
61+
android:id="@+id/placeBottomSheet"
6262
android:layout_width="match_parent"
6363
android:layout_height="match_parent"
6464
android:background="?attr/colorSurface"
@@ -126,10 +126,10 @@
126126
<LinearLayout
127127
android:id="@+id/fabContainer"
128128
android:layout_width="wrap_content"
129-
android:orientation="vertical"
130-
android:layout_margin="24dp"
129+
android:layout_height="wrap_content"
131130
android:layout_gravity="end|bottom"
132-
android:layout_height="wrap_content" >
131+
android:layout_margin="24dp"
132+
android:orientation="vertical">
133133

134134
<org.btcmap.view.IconButton
135135
android:id="@+id/activityFeed"
@@ -145,9 +145,9 @@
145145

146146
<org.btcmap.view.IconButton
147147
android:id="@+id/fab"
148-
android:layout_marginTop="8dp"
149148
android:layout_width="56dp"
150149
android:layout_height="56dp"
150+
android:layout_marginTop="8dp"
151151
app:iconSrc="@drawable/icon_my_location" />
152152

153153
</LinearLayout>

app/src/main/res/layout/settings_fragment.xml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,36 @@
9696

9797
</LinearLayout>
9898

99+
<LinearLayout
100+
android:id="@+id/verifiedFilterButton"
101+
android:layout_width="match_parent"
102+
android:layout_height="wrap_content"
103+
android:background="?selectableItemBackground"
104+
android:clickable="true"
105+
android:focusable="true"
106+
android:gravity="center_vertical"
107+
android:minHeight="64dp"
108+
android:orientation="vertical"
109+
android:paddingStart="16dp"
110+
android:paddingEnd="16dp">
111+
112+
<TextView
113+
android:layout_width="wrap_content"
114+
android:layout_height="wrap_content"
115+
android:text="@string/verified_filter"
116+
android:textColor="?colorOnSurface"
117+
android:textSize="16sp" />
118+
119+
<TextView
120+
android:id="@+id/currentVerifiedFilter"
121+
android:layout_width="wrap_content"
122+
android:layout_height="wrap_content"
123+
android:alpha="0.6"
124+
android:textAppearance="?textAppearanceListItemSecondary"
125+
tools:text="3 years" />
126+
127+
</LinearLayout>
128+
99129
<LinearLayout
100130
android:layout_width="match_parent"
101131
android:layout_height="wrap_content"
@@ -383,7 +413,7 @@
383413
android:layout_height="wrap_content" />
384414

385415
</LinearLayout>
386-
416+
387417
<Space
388418
android:layout_width="match_parent"
389419
android:layout_height="40dp" />
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:paddingLeft="20dp"
7+
android:paddingTop="8dp"
8+
android:paddingRight="20dp"
9+
android:paddingBottom="8dp">
10+
11+
<RadioButton
12+
android:id="@+id/no_filter"
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:paddingStart="8dp"
16+
android:paddingEnd="8dp"
17+
android:text="@string/verified_filter_no_filter" />
18+
19+
<RadioButton
20+
android:id="@+id/one_year"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:paddingStart="8dp"
24+
android:paddingEnd="8dp"
25+
android:text="@string/verified_filter_1_year" />
26+
27+
<RadioButton
28+
android:id="@+id/two_years"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:paddingStart="8dp"
32+
android:paddingEnd="8dp"
33+
android:text="@string/verified_filter_2_years" />
34+
35+
<RadioButton
36+
android:id="@+id/three_years"
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
android:paddingStart="8dp"
40+
android:paddingEnd="8dp"
41+
android:text="@string/verified_filter_3_years" />
42+
43+
<RadioButton
44+
android:id="@+id/four_years"
45+
android:layout_width="match_parent"
46+
android:layout_height="wrap_content"
47+
android:paddingStart="8dp"
48+
android:paddingEnd="8dp"
49+
android:text="@string/verified_filter_4_years" />
50+
51+
<RadioButton
52+
android:id="@+id/five_years"
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content"
55+
android:paddingStart="8dp"
56+
android:paddingEnd="8dp"
57+
android:text="@string/verified_filter_5_years" />
58+
59+
</RadioGroup>

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,11 @@
9898
<string name="delete" tools:ignore="MissingTranslation">Delete</string>
9999
<string name="upcoming_events" tools:ignore="MissingTranslation">Upcoming events</string>
100100
<string name="show_debug_info" tools:ignore="MissingTranslation">Show debug info</string>
101+
<string name="verified_filter" tools:ignore="MissingTranslation">Hide outdated places</string>
102+
<string name="verified_filter_no_filter" tools:ignore="MissingTranslation">Show all</string>
103+
<string name="verified_filter_1_year" tools:ignore="MissingTranslation">Verified within 1 year</string>
104+
<string name="verified_filter_2_years" tools:ignore="MissingTranslation">Verified within 2 years</string>
105+
<string name="verified_filter_3_years" tools:ignore="MissingTranslation">Verified within 3 years</string>
106+
<string name="verified_filter_4_years" tools:ignore="MissingTranslation">Verified within 4 years</string>
107+
<string name="verified_filter_5_years" tools:ignore="MissingTranslation">Verified within 5 years</string>
101108
</resources>

0 commit comments

Comments
 (0)