Skip to content

Commit

Permalink
Renamed deadlineColor to urgencyColor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Adams committed Jan 5, 2025
1 parent cfe2601 commit f00472a
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package org.secuso.privacyfriendlytodolist.model

import android.os.Parcelable
import org.secuso.privacyfriendlytodolist.model.TodoTask.DeadlineColors
import org.secuso.privacyfriendlytodolist.model.TodoTask.Urgency

/**
* Created by Sebastian Lutz on 12.03.2018.
Expand All @@ -39,7 +39,7 @@ interface TodoList : BaseTodo, Parcelable {
fun getColor(): Int
fun getDoneTodos(): Int
fun getNextDeadline(): Long?
fun getDeadlineColor(reminderTimeSpan: Long): DeadlineColors
fun getUrgency(reminderTimeSpan: Long): Urgency
fun checkQueryMatch(query: String?, recursive: Boolean): Boolean
fun checkQueryMatch(query: String?): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlytodolist.model

import android.content.Context
import android.os.Parcelable
import androidx.core.content.ContextCompat
import org.secuso.privacyfriendlytodolist.R


interface TodoTask : BaseTodo, Parcelable {
Expand Down Expand Up @@ -74,10 +77,20 @@ interface TodoTask : BaseTodo, Parcelable {
}
}

enum class DeadlineColors {
BLUE,
ORANGE,
RED
/**
* The urgency of a to-do task.
*/
enum class Urgency(private val colorId: Int) {
/** Task has no deadline or the deadline is far away. */
NONE(R.color.urgencyNone),
/** The deadline is near. */
IMMINENT(R.color.urgencyImminent),
/** The deadline has been elapsed. */
ELAPSED(R.color.urgencyElapsed);

fun getColor(context: Context): Int {
return ContextCompat.getColor(context, colorId)
}
}

fun setId(id: Int)
Expand Down Expand Up @@ -112,9 +125,11 @@ interface TodoTask : BaseTodo, Parcelable {
fun getSubtasks(): MutableList<TodoSubtask>

/**
* @param reminderTimeSpan The reminder time span is a relative value in seconds (e.g. 86400 s == 1 day).
* @param reminderTimeSpan The reminder time span is a relative value in seconds
* (e.g. 86400 s == 1 day). This is the time span before the deadline elapses where
* Urgency#IMMINENT gets returned.
*/
fun getDeadlineColor(reminderTimeSpan: Long): DeadlineColors
fun getUrgency(reminderTimeSpan: Long): Urgency
fun setPriority(priority: Priority)
fun getPriority(): Priority
fun setProgress(progress: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.os.Parcel
import android.os.Parcelable.Creator
import org.secuso.privacyfriendlytodolist.model.TodoList
import org.secuso.privacyfriendlytodolist.model.TodoTask
import org.secuso.privacyfriendlytodolist.model.TodoTask.DeadlineColors
import org.secuso.privacyfriendlytodolist.model.TodoTask.Urgency
import org.secuso.privacyfriendlytodolist.model.database.entities.TodoListData
import java.util.Locale

Expand Down Expand Up @@ -139,15 +139,15 @@ class TodoListImpl : BaseTodoImpl, TodoList {
return minDeadLine
}

override fun getDeadlineColor(reminderTimeSpan: Long): DeadlineColors {
var result = DeadlineColors.BLUE
override fun getUrgency(reminderTimeSpan: Long): Urgency {
var result = Urgency.NONE
for (currentTask in tasks) {
when (currentTask.getDeadlineColor(reminderTimeSpan)) {
DeadlineColors.ORANGE -> {
result = DeadlineColors.ORANGE
when (currentTask.getUrgency(reminderTimeSpan)) {
Urgency.IMMINENT -> {
result = Urgency.IMMINENT
}
DeadlineColors.RED -> {
result = DeadlineColors.RED
Urgency.ELAPSED -> {
result = Urgency.ELAPSED
break
}
else -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import android.os.Parcel
import android.os.Parcelable.Creator
import org.secuso.privacyfriendlytodolist.model.TodoSubtask
import org.secuso.privacyfriendlytodolist.model.TodoTask
import org.secuso.privacyfriendlytodolist.model.TodoTask.DeadlineColors
import org.secuso.privacyfriendlytodolist.model.TodoTask.Urgency
import org.secuso.privacyfriendlytodolist.model.TodoTask.Priority
import org.secuso.privacyfriendlytodolist.model.TodoTask.RecurrencePattern
import org.secuso.privacyfriendlytodolist.model.database.entities.TodoTaskData
Expand Down Expand Up @@ -185,8 +185,8 @@ class TodoTaskImpl : BaseTodoImpl, TodoTask {
return subtasks
}

override fun getDeadlineColor(reminderTimeSpan: Long): DeadlineColors {
var color = DeadlineColors.BLUE
override fun getUrgency(reminderTimeSpan: Long): Urgency {
var color = Urgency.NONE
var deadline = data.deadline
if (!isDone() && deadline != null) {
// Set time-part to 00:00:00 to ensure that comparison with reminder time span doesn't
Expand All @@ -213,9 +213,9 @@ class TodoTaskImpl : BaseTodoImpl, TodoTask {
}

if (deadline <= now) {
color = DeadlineColors.RED
color = Urgency.ELAPSED
} else if ((deadline - finalReminderTimeSpan) <= now) {
color = DeadlineColors.ORANGE
color = Urgency.IMMINENT
}
}
return color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import org.secuso.privacyfriendlytodolist.R
import org.secuso.privacyfriendlytodolist.model.TodoTask
import org.secuso.privacyfriendlytodolist.model.TodoTask.DeadlineColors
import org.secuso.privacyfriendlytodolist.model.TodoTask.Urgency
import org.secuso.privacyfriendlytodolist.model.TodoTask.RecurrencePattern
import java.text.SimpleDateFormat
import java.util.Calendar
Expand Down Expand Up @@ -164,15 +164,6 @@ object Helper {
return d1.compareTo(d2)
}

fun getDeadlineColor(context: Context, color: DeadlineColors?): Int {
return when (color) {
DeadlineColors.RED -> ContextCompat.getColor(context, R.color.deadlineRed)
DeadlineColors.BLUE -> ContextCompat.getColor(context, R.color.deadlineBlue)
DeadlineColors.ORANGE -> ContextCompat.getColor(context, R.color.deadlineOrange)
else -> throw IllegalArgumentException("Unknown deadline color '$color'.")
}
}

fun recurrencePatternToAdverbString(context: Context, recurrencePattern: RecurrencePattern?): String {
return when (recurrencePattern) {
RecurrencePattern.NONE -> context.resources.getString(R.string.none)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ class ExpandableTodoTaskAdapter(private val context: Context, private val model:
tvh.reminderIcon.visibility = View.GONE
tvh.reminder.visibility = View.GONE
}
val deadlineColor = currentTask.getDeadlineColor(PreferenceMgr.getDefaultReminderTimeSpan(context))
tvh.deadlineColorBar.setBackgroundColor(Helper.getDeadlineColor(context, deadlineColor))
val urgency = currentTask.getUrgency(PreferenceMgr.getDefaultReminderTimeSpan(context))
val urgencyColor = urgency.getColor(context)
tvh.urgencyColorBar.setBackgroundColor(urgencyColor)
tvh.done.isChecked = currentTask.isDone()
tvh.done.jumpDrawablesToCurrentState()
tvh.done.setOnCheckedChangeListener { buttonView, isChecked ->
Expand Down Expand Up @@ -509,8 +510,9 @@ class ExpandableTodoTaskAdapter(private val context: Context, private val model:
} else {
dvh.taskDescription.visibility = View.GONE
}
dvh.deadlineColorBar.setBackgroundColor(Helper.getDeadlineColor(context,
currentTask.getDeadlineColor(PreferenceMgr.getDefaultReminderTimeSpan(context))))
val urgency = currentTask.getUrgency(PreferenceMgr.getDefaultReminderTimeSpan(context))
val urgencyColor = urgency.getColor(context)
dvh.urgencyColorBar.setBackgroundColor(urgencyColor)
}

ChildType.SETTING_ROW -> {
Expand Down Expand Up @@ -538,8 +540,9 @@ class ExpandableTodoTaskAdapter(private val context: Context, private val model:
}
newSubtaskDialog.show()
}
sevh.deadlineColorBar.setBackgroundColor(Helper.getDeadlineColor(context,
currentTask.getDeadlineColor(PreferenceMgr.getDefaultReminderTimeSpan(context))))
val urgency = currentTask.getUrgency(PreferenceMgr.getDefaultReminderTimeSpan(context))
val urgencyColor = urgency.getColor(context)
sevh.urgencyColorBar.setBackgroundColor(urgencyColor)
}

ChildType.SUBTASK_ROW -> {
Expand All @@ -562,8 +565,9 @@ class ExpandableTodoTaskAdapter(private val context: Context, private val model:
)
actualConvertView.tag = svh
}
svh.deadlineColorBar.setBackgroundColor(Helper.getDeadlineColor(context,
currentTask.getDeadlineColor(PreferenceMgr.getDefaultReminderTimeSpan(context))))
val urgency = currentTask.getUrgency(PreferenceMgr.getDefaultReminderTimeSpan(context))
val urgencyColor = urgency.getColor(context)
svh.urgencyColorBar.setBackgroundColor(urgencyColor)
svh.done.isChecked = currentSubtask.isDone()
svh.done.jumpDrawablesToCurrentState()
svh.done.setOnCheckedChangeListener { buttonView, isChecked ->
Expand Down Expand Up @@ -735,7 +739,7 @@ class ExpandableTodoTaskAdapter(private val context: Context, private val model:
val reminder: TextView,
val listName: TextView,
val done: CheckBox,
val deadlineColorBar: View,
val urgencyColorBar: View,
val progressBar: ProgressBar
)

Expand All @@ -746,20 +750,20 @@ class ExpandableTodoTaskAdapter(private val context: Context, private val model:
private inner class SubtaskViewHolder(
val subtaskName: TextView,
val done: CheckBox,
val deadlineColorBar: View,
val urgencyColorBar: View,
val moveUpButton: ImageButton,
val moveDownButton: ImageButton,
val subtaskMenuButton: ImageButton
)

private inner class TaskDescriptionViewHolder(
val taskDescription: TextView,
val deadlineColorBar: View
val urgencyColorBar: View
)

private inner class SettingViewHolder(
val addSubtaskButton: LinearLayout,
val deadlineColorBar: View
val urgencyColorBar: View
)

private inner class TaskHolder(val todoTask: TodoTask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.secuso.privacyfriendlytodolist.R
import org.secuso.privacyfriendlytodolist.model.ModelServices
import org.secuso.privacyfriendlytodolist.model.ModelServices.DeliveryOption
import org.secuso.privacyfriendlytodolist.model.TodoTask
import org.secuso.privacyfriendlytodolist.util.Helper
import org.secuso.privacyfriendlytodolist.util.LogTag
import org.secuso.privacyfriendlytodolist.util.PreferenceMgr
import org.secuso.privacyfriendlytodolist.util.TaskComparator
Expand Down Expand Up @@ -121,9 +120,8 @@ class TodoListWidgetViewsFactory(private val context: Context, private val appWi

private fun createItem(todoTask: TodoTask, reminderTimeSpan: Long, fillInIntent: Intent): RemoteViews {
val view = RemoteViews(context.packageName, R.layout.widget_task)
val deadlineColor = todoTask.getDeadlineColor(reminderTimeSpan)
val color = Helper.getDeadlineColor(context, deadlineColor)
view.setInt(R.id.ll_widget_urgency_task, "setBackgroundColor", color)
val urgencyColor = todoTask.getUrgency(reminderTimeSpan).getColor(context)
view.setInt(R.id.ll_widget_urgency_task, "setBackgroundColor", urgencyColor)
view.setImageViewResource(R.id.iv_widget_task_state, if (todoTask.isDone()) R.drawable.done else ResourcesCompat.ID_NULL)
view.setTextViewText(R.id.tv_widget_task_name, todoTask.getName())
view.setOnClickFillInIntent(R.id.iv_widget_task_state, fillInIntent)
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<color name="yellow">#f6d126</color>
<color name="green">#68e504</color>

<color name="deadlineBlue">#024265</color>
<color name="deadlineOrange">#ea9d16</color>
<color name="deadlineRed">#ef0606</color>
<color name="urgencyNone">#024265</color>
<color name="urgencyImminent">#ea9d16</color>
<color name="urgencyElapsed">#ef0606</color>

<!-- dots inactive colors -->
<color name="dotInactive">#026499</color>
Expand Down

0 comments on commit f00472a

Please sign in to comment.