implementing Search at the Select Time Zone screen
This commit is contained in:
parent
da4f9e3f17
commit
36e168cdca
|
@ -14,9 +14,9 @@ import com.simplemobiletools.calendar.pro.helpers.TIME_ZONE
|
|||
import com.simplemobiletools.calendar.pro.helpers.getAllTimeZones
|
||||
import com.simplemobiletools.calendar.pro.models.MyTimeZone
|
||||
import kotlinx.android.synthetic.main.activity_select_time_zone.*
|
||||
import java.util.*
|
||||
|
||||
class SelectTimeZoneActivity : SimpleActivity() {
|
||||
private var mIsSearchOpen = false
|
||||
private var mSearchMenuItem: MenuItem? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -53,9 +53,7 @@ class SelectTimeZoneActivity : SimpleActivity() {
|
|||
override fun onQueryTextSubmit(query: String) = false
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
if (mIsSearchOpen) {
|
||||
searchQueryChanged(newText)
|
||||
}
|
||||
searchQueryChanged(newText)
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
@ -64,13 +62,11 @@ class SelectTimeZoneActivity : SimpleActivity() {
|
|||
mSearchMenuItem!!.expandActionView()
|
||||
MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||
mIsSearchOpen = true
|
||||
searchQueryChanged("")
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||
mIsSearchOpen = false
|
||||
finish()
|
||||
return true
|
||||
}
|
||||
|
@ -78,6 +74,9 @@ class SelectTimeZoneActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun searchQueryChanged(text: String) {
|
||||
|
||||
val timeZones = getAllTimeZones().filter {
|
||||
it.zoneName.toLowerCase(Locale.getDefault()).contains(text.toLowerCase(Locale.getDefault()))
|
||||
}.toMutableList() as ArrayList<MyTimeZone>
|
||||
(select_time_zone_list.adapter as? SelectTimeZoneAdapter)?.updateTimeZones(timeZones)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.simplemobiletools.calendar.pro.models.MyTimeZone
|
|||
import kotlinx.android.synthetic.main.item_select_time_zone.view.*
|
||||
import java.util.*
|
||||
|
||||
class SelectTimeZoneAdapter(val activity: SimpleActivity, val timeZones: ArrayList<MyTimeZone>, val itemClick: (Any) -> Unit) :
|
||||
class SelectTimeZoneAdapter(val activity: SimpleActivity, var timeZones: ArrayList<MyTimeZone>, val itemClick: (Any) -> Unit) :
|
||||
RecyclerView.Adapter<SelectTimeZoneAdapter.ViewHolder>() {
|
||||
val textColor = activity.config.textColor
|
||||
|
||||
|
@ -26,6 +26,11 @@ class SelectTimeZoneAdapter(val activity: SimpleActivity, val timeZones: ArrayLi
|
|||
|
||||
override fun getItemCount() = timeZones.size
|
||||
|
||||
fun updateTimeZones(newTimeZones: ArrayList<MyTimeZone>) {
|
||||
timeZones = newTimeZones.clone() as ArrayList<MyTimeZone>
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(timeZone: MyTimeZone): View {
|
||||
itemView.apply {
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.io.Serializable
|
|||
|
||||
// sample MyTimeZone(id=1, title="GMT+1", zoneName="Europe/Bratislava")
|
||||
data class MyTimeZone(val id: Int, var title: String, val zoneName: String) : Serializable {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID = -32456354132688616L
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue