mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
show the event type color at the selection dialog
This commit is contained in:
parent
73a9dc56da
commit
82213b1ea5
@ -1,39 +1,42 @@
|
||||
package com.simplemobiletools.calendar.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Color
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.helpers.DBHelper
|
||||
import com.simplemobiletools.calendar.models.EventType
|
||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||
import com.simplemobiletools.commons.extensions.setBackgroundWithStroke
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.dialog_radio_group.view.*
|
||||
import kotlinx.android.synthetic.main.radio_button_with_color.view.*
|
||||
import java.util.*
|
||||
|
||||
class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val callback: (checkedId: Int) -> Unit) : RadioGroup.OnCheckedChangeListener {
|
||||
class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val callback: (checkedId: Int) -> Unit) {
|
||||
val NEW_TYPE_ID = -2
|
||||
|
||||
val dialog: AlertDialog?
|
||||
val radioGroup: RadioGroup
|
||||
var wasInit = false
|
||||
var eventTypes = ArrayList<EventType>()
|
||||
var radioGroup: RadioGroup
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null) as ViewGroup
|
||||
radioGroup = view.dialog_radio_group
|
||||
radioGroup.setOnCheckedChangeListener(this)
|
||||
|
||||
DBHelper.newInstance(activity).getEventTypes {
|
||||
eventTypes = it
|
||||
activity.runOnUiThread {
|
||||
eventTypes.forEach {
|
||||
addRadioButton(it.title, it.id)
|
||||
addRadioButton(it.title, it.id, it.color)
|
||||
}
|
||||
addRadioButton(activity.getString(R.string.add_new_type), NEW_TYPE_ID)
|
||||
addRadioButton(activity.getString(R.string.add_new_type), NEW_TYPE_ID, Color.TRANSPARENT)
|
||||
wasInit = true
|
||||
activity.updateTextColors(view.dialog_radio_holder)
|
||||
}
|
||||
@ -45,27 +48,33 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val
|
||||
}
|
||||
}
|
||||
|
||||
private fun addRadioButton(title: String, typeId: Int) {
|
||||
val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply {
|
||||
private fun addRadioButton(title: String, typeId: Int, color: Int) {
|
||||
val view = activity.layoutInflater.inflate(R.layout.radio_button_with_color, null)
|
||||
(view.dialog_radio_button as RadioButton).apply {
|
||||
text = title
|
||||
isChecked = typeId == currEventType
|
||||
id = typeId
|
||||
}
|
||||
radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
|
||||
if (color != Color.TRANSPARENT)
|
||||
view.dialog_radio_color.setBackgroundWithStroke(color, activity.config.backgroundColor)
|
||||
|
||||
view.setOnClickListener { viewClicked(typeId) }
|
||||
radioGroup.addView(view, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
}
|
||||
|
||||
override fun onCheckedChanged(group: RadioGroup, checkedId: Int) {
|
||||
fun viewClicked(typeId: Int) {
|
||||
if (!wasInit)
|
||||
return
|
||||
|
||||
if (checkedId == NEW_TYPE_ID) {
|
||||
if (typeId == NEW_TYPE_ID) {
|
||||
NewEventTypeDialog(activity) {
|
||||
callback.invoke(it)
|
||||
activity.hideKeyboard()
|
||||
dialog?.dismiss()
|
||||
}
|
||||
} else {
|
||||
callback.invoke(checkedId)
|
||||
callback.invoke(typeId)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
|
27
app/src/main/res/layout/radio_button_with_color.xml
Normal file
27
app/src/main/res/layout/radio_button_with_color.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_radio_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_centerVertical="true"
|
||||
android:layout_marginEnd="@dimen/medium_margin"
|
||||
android:layout_marginRight="@dimen/medium_margin"
|
||||
android:clickable="false"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user