mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-07 23:48:41 +01:00
Add default CalDAV event color option
This commit is contained in:
parent
450354ef16
commit
b2c21c6564
@ -10,7 +10,6 @@ import android.graphics.drawable.LayerDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.CalendarContract.Attendees
|
||||
import android.provider.CalendarContract.Colors
|
||||
import android.provider.ContactsContract.CommonDataKinds
|
||||
import android.provider.ContactsContract.CommonDataKinds.StructuredName
|
||||
import android.provider.ContactsContract.Data
|
||||
@ -831,9 +830,9 @@ class EventActivity : SimpleActivity() {
|
||||
ensureBackgroundThread {
|
||||
val eventType = eventsHelper.getEventTypeWithCalDAVCalendarId(calendarId = mEventCalendarId)!!
|
||||
runOnUiThread {
|
||||
SelectEventTypeColorDialog(activity = this, eventType = eventType, selectedColor = mEvent.color, colorType = Colors.TYPE_EVENT) { color ->
|
||||
SelectEventColorDialog(activity = this, eventType = eventType, selectedColor = mEvent.color) { color ->
|
||||
mEvent.color = color
|
||||
event_caldav_color.setFillWithStroke(color, getProperBackgroundColor())
|
||||
updateEventColorInfo(eventType.color)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1023,18 +1022,21 @@ class EventActivity : SimpleActivity() {
|
||||
event_caldav_calendar_holder.apply {
|
||||
setPadding(paddingLeft, 0, paddingRight, 0)
|
||||
}
|
||||
|
||||
val eventColor = if (mEvent.color == 0) {
|
||||
calendarColor
|
||||
} else {
|
||||
mEvent.color
|
||||
}
|
||||
event_caldav_color.setFillWithStroke(eventColor, getProperBackgroundColor())
|
||||
updateEventColorInfo(calendarColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateEventColorInfo(defaultColor: Int) {
|
||||
val eventColor = if (mEvent.color == 0) {
|
||||
defaultColor
|
||||
} else {
|
||||
mEvent.color
|
||||
}
|
||||
event_caldav_color.setFillWithStroke(eventColor, getProperBackgroundColor())
|
||||
}
|
||||
|
||||
private fun resetTime() {
|
||||
if (mEventEndDateTime.isBefore(mEventStartDateTime) &&
|
||||
mEventStartDateTime.dayOfMonth() == mEventEndDateTime.dayOfMonth() &&
|
||||
|
@ -32,7 +32,7 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SelectEventTypeColorDialog(activity, eventType!!, eventType!!.color) {
|
||||
SelectEventTypeColorDialog(activity, eventType!!) {
|
||||
eventType!!.color = it
|
||||
setupColor(type_color)
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
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.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.*
|
||||
|
||||
class SelectEventColorDialog(val activity: Activity, val eventType: EventType, val selectedColor: 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_EVENT)
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_event_color, null) as ViewGroup
|
||||
radioGroup = view.dialog_select_event_type_color_radio
|
||||
|
||||
addRadioButton(colorKey = colors.values.size.inc(), color = 0)
|
||||
colors.forEach { (color, key) ->
|
||||
addRadioButton(key.toInt(), color)
|
||||
}
|
||||
|
||||
wasInit = true
|
||||
activity.getAlertDialogBuilder()
|
||||
.apply {
|
||||
activity.setupDialogStuff(view, this) { alertDialog ->
|
||||
dialog = alertDialog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addRadioButton(colorKey: 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.default_color) else String.format("#%06X", 0xFFFFFF and color)
|
||||
isChecked = color == selectedColor
|
||||
id = colorKey
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
@ -17,17 +17,11 @@ 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.*
|
||||
|
||||
class SelectEventTypeColorDialog(
|
||||
val activity: Activity,
|
||||
val eventType: EventType,
|
||||
val selectedColor: Int,
|
||||
val colorType: Int = Colors.TYPE_CALENDAR,
|
||||
val callback: (color: Int) -> Unit
|
||||
) {
|
||||
class SelectEventTypeColorDialog(val activity: Activity, val eventType: EventType, 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, colorType)
|
||||
private val colors = activity.calDAVHelper.getAvailableCalDAVCalendarColors(eventType, Colors.TYPE_CALENDAR)
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_event_type_color, null) as ViewGroup
|
||||
@ -57,7 +51,7 @@ class SelectEventTypeColorDialog(
|
||||
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 == selectedColor
|
||||
isChecked = color == eventType.color
|
||||
id = colorKey
|
||||
}
|
||||
|
||||
|
22
app/src/main/res/layout/dialog_select_event_color.xml
Normal file
22
app/src/main/res/layout/dialog_select_event_color.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?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">
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/dialog_select_event_type_color_radio"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:paddingBottom="@dimen/normal_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
Loading…
x
Reference in New Issue
Block a user