add a list of checkboxes at filter dialog
This commit is contained in:
parent
9c90774e4c
commit
a8652b06e0
|
@ -0,0 +1,49 @@
|
|||
package com.simplemobiletools.calendar.adapters
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.models.EventType
|
||||
import com.simplemobiletools.commons.extensions.setBackgroundWithStroke
|
||||
import kotlinx.android.synthetic.main.filter_event_type_view.view.*
|
||||
import java.util.*
|
||||
|
||||
class FilterEventTypeAdapter(val activity: SimpleActivity, val mItems: List<EventType>) :
|
||||
RecyclerView.Adapter<FilterEventTypeAdapter.ViewHolder>() {
|
||||
val views = ArrayList<View>()
|
||||
|
||||
companion object {
|
||||
var textColor = 0
|
||||
}
|
||||
|
||||
init {
|
||||
textColor = activity.config.textColor
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent?.context).inflate(R.layout.filter_event_type_view, parent, false)
|
||||
return ViewHolder(activity, view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
views.add(holder.bindView(mItems[position]))
|
||||
}
|
||||
|
||||
override fun getItemCount() = mItems.size
|
||||
|
||||
class ViewHolder(val activity: SimpleActivity, view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(eventType: EventType): View {
|
||||
itemView.apply {
|
||||
filter_event_type_title.text = eventType.title
|
||||
filter_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
|
||||
filter_event_type_holder.setOnClickListener { filter_event_type_checkbox.toggle() }
|
||||
}
|
||||
|
||||
return itemView
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +1,31 @@
|
|||
package com.simplemobiletools.calendar.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.adapters.FilterEventTypeAdapter
|
||||
import com.simplemobiletools.calendar.helpers.DBHelper
|
||||
import com.simplemobiletools.calendar.models.EventType
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.dialog_filter_events.view.*
|
||||
import java.util.*
|
||||
|
||||
class FilterEventsDialog(val activity: Activity, val callback: () -> Unit) : AlertDialog.Builder(activity) {
|
||||
class FilterEventsDialog(val activity: SimpleActivity, val callback: () -> Unit) : AlertDialog.Builder(activity) {
|
||||
val dialog: AlertDialog?
|
||||
var eventTypes = ArrayList<EventType>()
|
||||
|
||||
init {
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_filter_events, null)
|
||||
DBHelper.newInstance(activity).getEventTypes {
|
||||
eventTypes = it
|
||||
view.filter_events_list.adapter = FilterEventTypeAdapter(activity, it)
|
||||
|
||||
activity.runOnUiThread {
|
||||
activity.updateTextColors(view.filter_events_list)
|
||||
}
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/filter_event_type_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
android:id="@+id/filter_event_type_checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/filter_event_type_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@+id/filter_event_type_checkbox"
|
||||
android:layout_toRightOf="@+id/filter_event_type_checkbox"
|
||||
android:clickable="false"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingRight="@dimen/medium_margin"
|
||||
android:text="@string/text_color"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/filter_event_type_color"
|
||||
android:layout_width="@dimen/color_sample_size"
|
||||
android:layout_height="@dimen/color_sample_size"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginEnd="@dimen/medium_margin"
|
||||
android:layout_marginRight="@dimen/medium_margin"
|
||||
android:clickable="false"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in New Issue