Skip to content

Commit 11ff262

Browse files
add autocomplete for location
1 parent 9b3ef98 commit 11ff262

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import android.text.method.LinkMovementMethod
1919
import android.view.View
2020
import android.view.WindowManager
2121
import android.view.inputmethod.EditorInfo
22+
import android.widget.ArrayAdapter
2223
import android.widget.ImageView
2324
import android.widget.RelativeLayout
2425
import androidx.core.graphics.drawable.toDrawable
@@ -236,6 +237,13 @@ class EventActivity : SimpleActivity() {
236237

237238
val eventId = intent.getLongExtra(EVENT_ID, 0L)
238239
ensureBackgroundThread {
240+
val locations = eventsDB.getAllLocations()
241+
242+
runOnUiThread {
243+
val adapter = ArrayAdapter(this, R.layout.item_dropdown, locations)
244+
binding.eventLocation.setAdapter(adapter)
245+
}
246+
239247
mStoredEventTypes = eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
240248
val event = eventsDB.getEventWithId(eventId)
241249
if (eventId != 0L && event == null) {

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

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

18+
@Query("SELECT DISTINCT location FROM events")
19+
fun getAllLocations(): List<String>
20+
1821
@Query("SELECT * FROM events WHERE event_type IN (:eventTypeIds) AND type = $TYPE_EVENT")
1922
fun getAllEventsWithTypes(eventTypeIds: List<Long>): List<Event>
2023

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
android:textCursorDrawable="@null"
4444
android:textSize="@dimen/day_text_size" />
4545

46-
<org.fossify.commons.views.MyEditText
46+
<AutoCompleteTextView
4747
android:id="@+id/event_location"
4848
android:layout_width="match_parent"
4949
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)