creating a TimeZone picker adapter

This commit is contained in:
tibbi 2019-12-10 11:49:31 +01:00
parent 4800dce9ce
commit 9a281fbe58
3 changed files with 67 additions and 0 deletions

View File

@ -8,6 +8,9 @@ import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.adapters.SelectTimeZoneAdapter
import com.simplemobiletools.calendar.pro.helpers.getAllTimeZones
import kotlinx.android.synthetic.main.activity_select_time_zone.*
class SelectTimeZoneActivity : SimpleActivity() {
private var mIsSearchOpen = false
@ -17,6 +20,12 @@ class SelectTimeZoneActivity : SimpleActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_select_time_zone)
title = ""
SelectTimeZoneAdapter(this, getAllTimeZones(), select_time_zone_list) {
}.apply {
select_time_zone_list.adapter = this
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {

View File

@ -0,0 +1,40 @@
package com.simplemobiletools.calendar.pro.adapters
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.models.MyTimeZone
import com.simplemobiletools.commons.views.MyRecyclerView
import kotlinx.android.synthetic.main.item_select_time_zone.view.*
import java.util.*
class SelectTimeZoneAdapter(val activity: SimpleActivity, val timeZones: ArrayList<MyTimeZone>, recyclerView: MyRecyclerView, val itemClick: (Any) -> Unit) :
RecyclerView.Adapter<SelectTimeZoneAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = activity.layoutInflater.inflate(R.layout.item_select_time_zone, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val timeZone = timeZones[position]
holder.bindView(timeZone)
}
override fun getItemCount() = timeZones.size
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(timeZone: MyTimeZone): View {
itemView.apply {
item_time_zone_title.text = timeZone.zoneName
item_select_time_zone_holder.setOnClickListener {
itemClick(timeZone)
}
}
return itemView
}
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_select_time_zone_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/item_time_zone_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="@dimen/bigger_text_size"
tools:text="Europe/Bratislava" />
</RelativeLayout>