diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/FilterEventTypeAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/FilterEventTypeAdapter.kt new file mode 100644 index 000000000..bbfa4ab94 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/FilterEventTypeAdapter.kt @@ -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) : + RecyclerView.Adapter() { + val views = ArrayList() + + 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 + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventsDialog.kt index a953afc91..f80da5cbf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventsDialog.kt @@ -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() 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) diff --git a/app/src/main/res/layout/filter_event_type_view.xml b/app/src/main/res/layout/filter_event_type_view.xml new file mode 100644 index 000000000..17ab8c4fe --- /dev/null +++ b/app/src/main/res/layout/filter_event_type_view.xml @@ -0,0 +1,38 @@ + + + + + + + + + +