Skip to content

Commit 4d56cfd

Browse files
add autocomplete for location
1 parent f3fe3f0 commit 4d56cfd

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

app/src/main/kotlin/org/fossify/calendar/activities/EventActivity.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import android.text.method.LinkMovementMethod
1818
import android.view.View
1919
import android.view.WindowManager
2020
import android.view.inputmethod.EditorInfo
21+
import android.widget.ArrayAdapter
2122
import android.widget.ImageView
2223
import android.widget.RelativeLayout
2324
import androidx.core.graphics.drawable.toDrawable
@@ -229,15 +230,22 @@ class EventActivity : SimpleActivity() {
229230

230231
val eventId = intent.getLongExtra(EVENT_ID, 0L)
231232
ensureBackgroundThread {
232-
mStoredCalendars =
233-
calendarsDB.getCalendars().toMutableList() as ArrayList<CalendarEntity>
233+
val locations = eventsDB.getAllLocations()
234+
235+
runOnUiThread {
236+
val adapter = ArrayAdapter(this, R.layout.item_dropdown, locations)
237+
binding.eventLocation.setAdapter(adapter)
238+
}
239+
234240
val event = eventsDB.getEventWithId(eventId)
235241
if (eventId != 0L && event == null) {
236242
hideKeyboard()
237243
finish()
238244
return@ensureBackgroundThread
239245
}
240246

247+
mStoredCalendars =
248+
calendarsDB.getCalendars().toMutableList() as ArrayList<CalendarEntity>
241249
val localCalendar =
242250
mStoredCalendars.firstOrNull { it.id == config.lastUsedLocalCalendarId }
243251
runOnUiThread {

app/src/main/kotlin/org/fossify/calendar/interfaces/EventsDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ interface EventsDao {
1919
@Query("SELECT * FROM events WHERE type = $TYPE_TASK")
2020
fun getAllTasks(): List<Event>
2121

22+
@Query("SELECT DISTINCT location FROM events")
23+
fun getAllLocations(): List<String>
24+
2225
@Query("SELECT * FROM events WHERE event_type IN (:calendarIds) AND type = $TYPE_EVENT")
2326
fun getAllEventsWithCalendarIds(calendarIds: List<Long>): List<Event>
2427

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
android:textCursorDrawable="@null"
5151
android:textSize="@dimen/day_text_size" />
5252

53-
<org.fossify.commons.views.MyEditText
53+
<AutoCompleteTextView
5454
android:id="@+id/event_location"
5555
android:layout_width="match_parent"
5656
android:layout_height="wrap_content"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2006 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<!-- Copied from simple_list_item_1.xml, textColor is needed in light mode-->
17+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:id="@android:id/text1"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:textAppearance="?android:attr/textAppearanceListItemSmall"
22+
android:gravity="center_vertical"
23+
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
24+
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
25+
android:minHeight="?android:attr/listPreferredItemHeightSmall"
26+
android:textColor="?android:attr/textColorAlertDialogListItem" />

0 commit comments

Comments
 (0)