Update event type color dialog

This commit is contained in:
Naveen
2023-04-11 17:28:23 +05:30
parent 4a3fbf194b
commit 85e05f07a9
6 changed files with 26 additions and 96 deletions

View File

@@ -4,6 +4,7 @@ import android.app.Activity
import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
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.helpers.OTHER_EVENT
import com.simplemobiletools.calendar.pro.models.EventType
@@ -32,7 +33,9 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
}
}
} 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
setupColor(type_color)
}

View File

@@ -8,13 +8,13 @@ import com.simplemobiletools.calendar.pro.adapters.CheckableColorAdapter
import com.simplemobiletools.calendar.pro.views.AutoGridLayoutManager
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
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) {
private var dialog: AlertDialog? = null
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 ->
callback(color)
dialog?.dismiss()

View File

@@ -1,44 +1,38 @@
package com.simplemobiletools.calendar.pro.dialogs
import android.app.Activity
import android.provider.CalendarContract.Colors
import android.view.ViewGroup
import android.widget.RadioButton
import android.widget.RadioGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.extensions.calDAVHelper
import com.simplemobiletools.calendar.pro.models.EventType
import com.simplemobiletools.calendar.pro.adapters.CheckableColorAdapter
import com.simplemobiletools.calendar.pro.views.AutoGridLayoutManager
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
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 kotlinx.android.synthetic.main.dialog_select_event_type_color.view.*
import kotlinx.android.synthetic.main.radio_button_with_color.view.*
import kotlinx.android.synthetic.main.dialog_select_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 val radioGroup: RadioGroup
private var wasInit = false
private val colors = activity.calDAVHelper.getAvailableCalDAVCalendarColors(eventType, Colors.TYPE_CALENDAR).keys
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_select_event_type_color, null) as ViewGroup
radioGroup = view.dialog_select_event_type_color_radio
view.dialog_select_event_type_other_value.setOnClickListener {
showCustomColorPicker()
val view = activity.layoutInflater.inflate(R.layout.dialog_select_color, null) as ViewGroup
val colorAdapter = CheckableColorAdapter(activity, colors, currentColor) { color ->
callback(color)
dialog?.dismiss()
}
colors.forEachIndexed { index, color ->
addRadioButton(index, color)
view.color_grid.apply {
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()
.setNegativeButton(R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
dialog = alertDialog
activity.setupDialogStuff(view, this, R.string.color) {
dialog = it
}
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() {
ColorPickerDialog(activity, eventType.color) { wasPositivePressed, color ->
ColorPickerDialog(activity, currentColor) { wasPositivePressed, color ->
if (wasPositivePressed) {
callback(color)
}
dialog?.dismiss()
}
}

View File

@@ -85,8 +85,9 @@ class CalDAVHelper(val context: Context) {
val accountType = cursor.getStringValue(Calendars.ACCOUNT_TYPE)
val ownerName = cursor.getStringValue(Calendars.OWNER_ACCOUNT) ?: ""
val color = cursor.getIntValue(Calendars.CALENDAR_COLOR)
val displayColor = getDisplayColorFromColor(color)
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)
}

View File

@@ -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>