Allow task color customization as well

This commit is contained in:
Naveen 2023-04-30 16:52:45 +05:30
parent 40beaa60e3
commit 9089c1f6ba
3 changed files with 99 additions and 21 deletions

View File

@ -647,13 +647,11 @@ class EventActivity : SimpleActivity() {
event_repetition_limit_label.text = getString(R.string.repeat)
resources.getString(R.string.forever)
}
mRepeatLimit > 0 -> {
event_repetition_limit_label.text = getString(R.string.repeat_till)
val repeatLimitDateTime = Formatter.getDateTimeFromTS(mRepeatLimit)
Formatter.getFullDate(this, repeatLimitDateTime)
}
else -> {
event_repetition_limit_label.text = getString(R.string.repeat)
"${-mRepeatLimit} ${getString(R.string.times)}"
@ -667,14 +665,12 @@ class EventActivity : SimpleActivity() {
mRepeatInterval.isXWeeklyRepetition() -> RepeatRuleWeeklyDialog(this, mRepeatRule) {
setRepeatRule(it)
}
mRepeatInterval.isXMonthlyRepetition() -> {
val items = getAvailableMonthlyRepetitionRules()
RadioGroupDialog(this, items, mRepeatRule) {
setRepeatRule(it as Int)
}
}
mRepeatInterval.isXYearlyRepetition() -> {
val items = getAvailableYearlyRepetitionRules()
RadioGroupDialog(this, items, mRepeatRule) {
@ -791,7 +787,6 @@ class EventActivity : SimpleActivity() {
mRepeatInterval.isXWeeklyRepetition() -> {
event_repetition_rule.text = if (mRepeatRule == EVERY_DAY_BIT) getString(R.string.every_day) else getSelectedDaysString(mRepeatRule)
}
mRepeatInterval.isXMonthlyRepetition() -> {
val repeatString = if (mRepeatRule == REPEAT_ORDER_WEEKDAY_USE_LAST || mRepeatRule == REPEAT_ORDER_WEEKDAY)
R.string.repeat else R.string.repeat_on
@ -799,7 +794,6 @@ class EventActivity : SimpleActivity() {
event_repetition_rule_label.text = getString(repeatString)
event_repetition_rule.text = getMonthlyRepetitionRuleText()
}
mRepeatInterval.isXYearlyRepetition() -> {
val repeatString = if (mRepeatRule == REPEAT_ORDER_WEEKDAY_USE_LAST || mRepeatRule == REPEAT_ORDER_WEEKDAY)
R.string.repeat else R.string.repeat_on

View File

@ -13,7 +13,6 @@ import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.dialogs.*
import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.calendar.pro.models.EventType
import com.simplemobiletools.calendar.pro.models.Reminder
@ -24,7 +23,7 @@ import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.activity_task.*
import org.joda.time.DateTime
import java.util.*
import java.util.Calendar
import kotlin.math.pow
class TaskActivity : SimpleActivity() {
@ -46,6 +45,7 @@ class TaskActivity : SimpleActivity() {
private var mTaskCompleted = false
private var mLastSavePromptTS = 0L
private var mIsNewTask = true
private var mEventColor = 0
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
@ -130,6 +130,7 @@ class TaskActivity : SimpleActivity() {
mRepeatInterval != mTask.repeatInterval ||
mRepeatRule != mTask.repeatRule ||
mEventTypeId != mTask.eventType ||
mEventColor != mTask.color ||
hasTimeChanged
) {
return true
@ -175,6 +176,7 @@ class TaskActivity : SimpleActivity() {
putLong(EVENT_TYPE_ID, mEventTypeId)
putBoolean(IS_NEW_EVENT, mIsNewTask)
putLong(ORIGINAL_START_TS, mOriginalStartTS)
putInt(EVENT_COLOR, mEventColor)
}
}
@ -201,6 +203,7 @@ class TaskActivity : SimpleActivity() {
mEventTypeId = getLong(EVENT_TYPE_ID)
mIsNewTask = getBoolean(IS_NEW_EVENT)
mOriginalStartTS = getLong(ORIGINAL_START_TS)
mEventColor = getInt(EVENT_COLOR)
}
updateEventType()
@ -270,6 +273,7 @@ class TaskActivity : SimpleActivity() {
task_reminder_2.setOnClickListener { showReminder2Dialog() }
task_reminder_3.setOnClickListener { showReminder3Dialog() }
task_color_holder.setOnClickListener { showTaskColorDialog() }
refreshMenuItems()
setupMarkCompleteButton()
@ -297,6 +301,7 @@ class TaskActivity : SimpleActivity() {
mRepeatInterval = mTask.repeatInterval
mRepeatLimit = mTask.repeatLimit
mRepeatRule = mTask.repeatRule
mEventColor = mTask.color
task_title.setText(mTask.title)
task_description.setText(mTask.description)
@ -416,6 +421,7 @@ class TaskActivity : SimpleActivity() {
repeatInterval = mRepeatInterval
repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit
repeatRule = mRepeatRule
color = mEventColor
}
if (mTask.getReminders().isNotEmpty()) {
@ -762,11 +768,46 @@ class TaskActivity : SimpleActivity() {
if (eventType != null) {
runOnUiThread {
task_type.text = eventType.title
task_type_color.setFillWithStroke(eventType.color, getProperBackgroundColor())
updateTaskColorInfo(eventType.color)
}
}
task_color_image.beVisibleIf(eventType != null)
task_color_holder.beVisibleIf(eventType != null)
task_color_divider.beVisibleIf(eventType != null)
}
}
private fun showTaskColorDialog() {
hideKeyboard()
ensureBackgroundThread {
val eventType = eventTypesDB.getEventTypeWithId(mEventTypeId)!!
val currentColor = if (mEventColor == 0) {
eventType.color
} else {
mEventColor
}
runOnUiThread {
ColorPickerDialog(activity = this, color = currentColor) { wasPositivePressed, newColor ->
if (wasPositivePressed) {
if (newColor != currentColor) {
mEventColor = newColor
updateTaskColorInfo(defaultColor = eventType.color)
}
}
}
}
}
}
private fun updateTaskColorInfo(defaultColor: Int) {
val taskColor = if (mEventColor == 0) {
defaultColor
} else {
mEventColor
}
task_color.setFillWithStroke(taskColor, getProperBackgroundColor())
}
private fun updateColors() {
updateTextColors(task_nested_scrollview)

View File

@ -316,10 +316,63 @@
android:importantForAccessibility="no" />
<ImageView
android:id="@+id/task_type_image"
android:id="@+id/task_color_image"
android:layout_width="@dimen/smaller_icon_size"
android:layout_height="@dimen/smaller_icon_size"
android:layout_below="@+id/task_repetition_divider"
android:layout_alignTop="@+id/task_color_holder"
android:layout_alignBottom="@+id/task_color_holder"
android:layout_marginStart="@dimen/normal_margin"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_color_vector" />
<RelativeLayout
android:id="@+id/task_color_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/task_repetition_divider"
android:layout_marginTop="@dimen/medium_margin"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_toEndOf="@+id/task_color_image"
android:background="?attr/selectableItemBackground">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/task_color_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginEnd="@dimen/medium_margin"
android:layout_toStartOf="@+id/task_color"
android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin"
android:text="@string/task_color"
android:textSize="@dimen/day_text_size" />
<ImageView
android:id="@+id/task_color"
android:layout_width="@dimen/color_sample_size"
android:layout_height="@dimen/color_sample_size"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/activity_margin"
android:clickable="false" />
</RelativeLayout>
<ImageView
android:id="@+id/task_color_divider"
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_below="@+id/task_color_image"
android:layout_marginTop="@dimen/medium_margin"
android:background="@color/divider_grey"
android:importantForAccessibility="no" />
<ImageView
android:id="@+id/task_type_image"
android:layout_width="@dimen/smaller_icon_size"
android:layout_height="@dimen/smaller_icon_size"
android:layout_below="@+id/task_color_divider"
android:layout_alignTop="@+id/task_type_holder"
android:layout_alignBottom="@+id/task_type_holder"
android:layout_marginStart="@dimen/normal_margin"
@ -330,7 +383,7 @@
android:id="@+id/task_type_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/task_repetition_divider"
android:layout_below="@+id/task_color_divider"
android:layout_marginTop="@dimen/medium_margin"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_toEndOf="@+id/task_type_image"
@ -342,20 +395,10 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginEnd="@dimen/medium_margin"
android:layout_toStartOf="@+id/task_type_color"
android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin"
android:textSize="@dimen/day_text_size" />
<ImageView
android:id="@+id/task_type_color"
android:layout_width="@dimen/color_sample_size"
android:layout_height="@dimen/color_sample_size"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/activity_margin"
android:clickable="false" />
</RelativeLayout>
<ImageView