mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Update event type color dialog
This commit is contained in:
@@ -4,6 +4,7 @@ import android.app.Activity
|
|||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
|
import com.simplemobiletools.calendar.pro.extensions.calDAVHelper
|
||||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||||
import com.simplemobiletools.calendar.pro.helpers.OTHER_EVENT
|
import com.simplemobiletools.calendar.pro.helpers.OTHER_EVENT
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
import com.simplemobiletools.calendar.pro.models.EventType
|
||||||
@@ -32,7 +33,9 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SelectEventTypeColorDialog(activity, eventType!!) {
|
val currentColor = eventType!!.color
|
||||||
|
val colors = activity.calDAVHelper.getAvailableCalDAVCalendarColors(eventType!!).keys.toIntArray()
|
||||||
|
SelectEventTypeColorDialog(activity, colors = colors, currentColor = currentColor) {
|
||||||
eventType!!.color = it
|
eventType!!.color = it
|
||||||
setupColor(type_color)
|
setupColor(type_color)
|
||||||
}
|
}
|
||||||
|
@@ -8,13 +8,13 @@ import com.simplemobiletools.calendar.pro.adapters.CheckableColorAdapter
|
|||||||
import com.simplemobiletools.calendar.pro.views.AutoGridLayoutManager
|
import com.simplemobiletools.calendar.pro.views.AutoGridLayoutManager
|
||||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import kotlinx.android.synthetic.main.dialog_select_event_color.view.*
|
import kotlinx.android.synthetic.main.dialog_select_color.view.*
|
||||||
|
|
||||||
class SelectEventColorDialog(val activity: Activity, val colors: IntArray, var currentColor: Int, val callback: (color: Int) -> Unit) {
|
class SelectEventColorDialog(val activity: Activity, val colors: IntArray, var currentColor: Int, val callback: (color: Int) -> Unit) {
|
||||||
private var dialog: AlertDialog? = null
|
private var dialog: AlertDialog? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_event_color, null) as ViewGroup
|
val view = activity.layoutInflater.inflate(R.layout.dialog_select_color, null) as ViewGroup
|
||||||
val colorAdapter = CheckableColorAdapter(activity, colors, currentColor) { color ->
|
val colorAdapter = CheckableColorAdapter(activity, colors, currentColor) { color ->
|
||||||
callback(color)
|
callback(color)
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
|
@@ -1,44 +1,38 @@
|
|||||||
package com.simplemobiletools.calendar.pro.dialogs
|
package com.simplemobiletools.calendar.pro.dialogs
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.provider.CalendarContract.Colors
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.RadioButton
|
|
||||||
import android.widget.RadioGroup
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
import com.simplemobiletools.calendar.pro.extensions.calDAVHelper
|
import com.simplemobiletools.calendar.pro.adapters.CheckableColorAdapter
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
import com.simplemobiletools.calendar.pro.views.AutoGridLayoutManager
|
||||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
||||||
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
|
|
||||||
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import kotlinx.android.synthetic.main.dialog_select_event_type_color.view.*
|
import kotlinx.android.synthetic.main.dialog_select_color.view.*
|
||||||
import kotlinx.android.synthetic.main.radio_button_with_color.view.*
|
|
||||||
|
|
||||||
class SelectEventTypeColorDialog(val activity: Activity, val eventType: EventType, val callback: (color: Int) -> Unit) {
|
class SelectEventTypeColorDialog(val activity: Activity, val colors: IntArray, var currentColor: Int, val callback: (color: Int) -> Unit) {
|
||||||
private var dialog: AlertDialog? = null
|
private var dialog: AlertDialog? = null
|
||||||
private val radioGroup: RadioGroup
|
|
||||||
private var wasInit = false
|
|
||||||
private val colors = activity.calDAVHelper.getAvailableCalDAVCalendarColors(eventType, Colors.TYPE_CALENDAR).keys
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_event_type_color, null) as ViewGroup
|
val view = activity.layoutInflater.inflate(R.layout.dialog_select_color, null) as ViewGroup
|
||||||
radioGroup = view.dialog_select_event_type_color_radio
|
val colorAdapter = CheckableColorAdapter(activity, colors, currentColor) { color ->
|
||||||
view.dialog_select_event_type_other_value.setOnClickListener {
|
callback(color)
|
||||||
showCustomColorPicker()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
colors.forEachIndexed { index, color ->
|
view.color_grid.apply {
|
||||||
addRadioButton(index, color)
|
val width = activity.resources.getDimensionPixelSize(R.dimen.smaller_icon_size)
|
||||||
|
val spacing = activity.resources.getDimensionPixelSize(R.dimen.small_margin) * 2
|
||||||
|
layoutManager = AutoGridLayoutManager(context = activity, itemWidth = width + spacing)
|
||||||
|
adapter = colorAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
wasInit = true
|
|
||||||
activity.getAlertDialogBuilder()
|
activity.getAlertDialogBuilder()
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.apply {
|
.apply {
|
||||||
activity.setupDialogStuff(view, this) { alertDialog ->
|
activity.setupDialogStuff(view, this, R.string.color) {
|
||||||
dialog = alertDialog
|
dialog = it
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colors.isEmpty()) {
|
if (colors.isEmpty()) {
|
||||||
@@ -47,35 +41,12 @@ class SelectEventTypeColorDialog(val activity: Activity, val eventType: EventTyp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addRadioButton(index: Int, color: Int) {
|
|
||||||
val view = activity.layoutInflater.inflate(R.layout.radio_button_with_color, null)
|
|
||||||
(view.dialog_radio_button as RadioButton).apply {
|
|
||||||
text = if (color == 0) activity.getString(R.string.transparent) else String.format("#%06X", 0xFFFFFF and color)
|
|
||||||
isChecked = color == eventType.color
|
|
||||||
id = index
|
|
||||||
}
|
|
||||||
|
|
||||||
view.dialog_radio_color.setFillWithStroke(color, activity.getProperBackgroundColor())
|
|
||||||
view.setOnClickListener {
|
|
||||||
viewClicked(color)
|
|
||||||
}
|
|
||||||
radioGroup.addView(view, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun viewClicked(color: Int) {
|
|
||||||
if (!wasInit) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(color)
|
|
||||||
dialog?.dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showCustomColorPicker() {
|
private fun showCustomColorPicker() {
|
||||||
ColorPickerDialog(activity, eventType.color) { wasPositivePressed, color ->
|
ColorPickerDialog(activity, currentColor) { wasPositivePressed, color ->
|
||||||
if (wasPositivePressed) {
|
if (wasPositivePressed) {
|
||||||
callback(color)
|
callback(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -85,8 +85,9 @@ class CalDAVHelper(val context: Context) {
|
|||||||
val accountType = cursor.getStringValue(Calendars.ACCOUNT_TYPE)
|
val accountType = cursor.getStringValue(Calendars.ACCOUNT_TYPE)
|
||||||
val ownerName = cursor.getStringValue(Calendars.OWNER_ACCOUNT) ?: ""
|
val ownerName = cursor.getStringValue(Calendars.OWNER_ACCOUNT) ?: ""
|
||||||
val color = cursor.getIntValue(Calendars.CALENDAR_COLOR)
|
val color = cursor.getIntValue(Calendars.CALENDAR_COLOR)
|
||||||
|
val displayColor = getDisplayColorFromColor(color)
|
||||||
val accessLevel = cursor.getIntValue(Calendars.CALENDAR_ACCESS_LEVEL)
|
val accessLevel = cursor.getIntValue(Calendars.CALENDAR_ACCESS_LEVEL)
|
||||||
val calendar = CalDAVCalendar(id, displayName, accountName, accountType, ownerName, color, accessLevel)
|
val calendar = CalDAVCalendar(id, displayName, accountName, accountType, ownerName, displayColor, accessLevel)
|
||||||
calendars.add(calendar)
|
calendars.add(calendar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/dialog_select_event_type_color_scrollview"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/dialog_select_event_type_other_holder"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
|
||||||
android:id="@+id/dialog_select_event_type_other_value"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:paddingStart="@dimen/big_margin"
|
|
||||||
android:paddingTop="@dimen/activity_margin"
|
|
||||||
android:paddingEnd="@dimen/activity_margin"
|
|
||||||
android:paddingBottom="@dimen/activity_margin"
|
|
||||||
android:text="@string/select_a_different_caldav_color"
|
|
||||||
android:textSize="@dimen/normal_text_size"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/dialog_select_event_type_other_divider"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="@dimen/divider_height"
|
|
||||||
android:layout_below="@+id/dialog_select_event_type_other_value"
|
|
||||||
android:background="@color/divider_grey"
|
|
||||||
android:importantForAccessibility="no"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
<RadioGroup
|
|
||||||
android:id="@+id/dialog_select_event_type_color_radio"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/dialog_select_event_type_other_divider"
|
|
||||||
android:paddingStart="@dimen/activity_margin"
|
|
||||||
android:paddingTop="@dimen/normal_margin"
|
|
||||||
android:paddingEnd="@dimen/activity_margin"
|
|
||||||
android:paddingBottom="@dimen/normal_margin" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
</ScrollView>
|
|
Reference in New Issue
Block a user