implementing the autocompletetextview at attendee suggestions

This commit is contained in:
tibbi 2019-03-13 22:37:06 +01:00
parent f48b16a188
commit 362599fcdf
5 changed files with 89 additions and 4 deletions

View File

@ -57,7 +57,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:5.10.9' implementation 'com.simplemobiletools:commons:5.10.10'
implementation 'joda-time:joda-time:2.10.1' implementation 'joda-time:joda-time:2.10.1'
implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.multidex:multidex:2.0.1'

View File

@ -13,12 +13,14 @@ import android.text.method.LinkMovementMethod
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.WindowManager import android.view.WindowManager
import android.widget.EditText
import android.widget.ImageView import android.widget.ImageView
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.adapters.AutoCompleteTextViewAdapter
import com.simplemobiletools.calendar.pro.dialogs.* import com.simplemobiletools.calendar.pro.dialogs.*
import com.simplemobiletools.calendar.pro.extensions.* import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.helpers.*
@ -29,7 +31,6 @@ import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.MyEditText
import kotlinx.android.synthetic.main.activity_event.* import kotlinx.android.synthetic.main.activity_event.*
import kotlinx.android.synthetic.main.activity_event.view.* import kotlinx.android.synthetic.main.activity_event.view.*
import kotlinx.android.synthetic.main.item_attendee.view.* import kotlinx.android.synthetic.main.item_attendee.view.*
@ -72,7 +73,7 @@ class EventActivity : SimpleActivity() {
private var mWasActivityInitialized = false private var mWasActivityInitialized = false
private var mWasContactsPermissionChecked = false private var mWasContactsPermissionChecked = false
private var mAttendees = ArrayList<Attendee>() private var mAttendees = ArrayList<Attendee>()
private var mAttendeeViews = ArrayList<MyEditText>() private var mAttendeeViews = ArrayList<EditText>()
private var mAvailableContacts = ArrayList<Attendee>() private var mAvailableContacts = ArrayList<Attendee>()
private lateinit var mEventStartDateTime: DateTime private lateinit var mEventStartDateTime: DateTime
@ -1166,6 +1167,9 @@ class EventActivity : SimpleActivity() {
if (value != null) { if (value != null) {
attendeeHolder.event_attendee.setText(value) attendeeHolder.event_attendee.setText(value)
} }
val adapter = AutoCompleteTextViewAdapter(this, mAvailableContacts)
attendeeHolder.event_attendee.setAdapter(adapter)
} }
private fun checkNewAttendeeField(value: String?) { private fun checkNewAttendeeField(value: String?) {

View File

@ -0,0 +1,58 @@
package com.simplemobiletools.calendar.pro.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Filter
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.models.Attendee
import kotlinx.android.synthetic.main.item_autocomplete.view.*
class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: ArrayList<Attendee>) : ArrayAdapter<Attendee>(activity, 0, contacts) {
private var resultList = ArrayList<Attendee>()
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
var listItem = convertView
if (listItem == null) {
listItem = LayoutInflater.from(activity).inflate(R.layout.item_autocomplete, parent, false)
}
val contact = resultList[position]
listItem!!.item_autocomplete.text = contact.email
return listItem
}
override fun getFilter() = object : Filter() {
override fun performFiltering(constraint: CharSequence?): FilterResults {
val filterResults = Filter.FilterResults()
if (constraint != null) {
resultList.clear()
contacts.forEach {
if (it.email.contains(constraint, true)) {
resultList.add(it)
}
}
filterResults.values = resultList
filterResults.count = resultList.size
}
return filterResults
}
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
if (results?.count ?: -1 > 0) {
notifyDataSetChanged()
} else {
notifyDataSetInvalidated()
}
}
override fun convertResultToString(resultValue: Any?) = (resultValue as? Attendee)?.email
}
override fun getItem(index: Int) = resultList[index]
override fun getCount() = resultList.size
}

View File

@ -7,12 +7,13 @@
android:paddingTop="@dimen/medium_margin" android:paddingTop="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"> android:paddingBottom="@dimen/medium_margin">
<com.simplemobiletools.commons.views.MyEditText <com.simplemobiletools.commons.views.MyAutoCompleteTextView
android:id="@+id/event_attendee" android:id="@+id/event_attendee"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/activity_margin" android:layout_marginEnd="@dimen/activity_margin"
android:completionThreshold="2"
android:hint="@string/add_another_attendee" android:hint="@string/add_another_attendee"
android:lines="1" android:lines="1"
android:maxLines="1" android:maxLines="1"

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_autocomplete_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin">
<TextView
android:id="@+id/item_autocomplete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/activity_margin"
android:lines="1"
android:maxLines="1"
android:padding="@dimen/medium_margin"
android:singleLine="true"
android:textSize="@dimen/bigger_text_size"/>
</RelativeLayout>