Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to inverse checkmark widget On/Off colours #2092

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class SharedPreferencesStorage
"pref_unknown_enabled" -> {
preferences.areQuestionMarksEnabled = getBoolean(key, false)
}
"pref_inverse_checkmark_colors" ->
preferences.isCheckmarkWidgetColorInverted = getBoolean(key, false)
}
sharedPreferences.registerOnSharedPreferenceChangeListener(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,45 @@ class CheckmarkWidgetView : HabitWidgetView {
val bgColor: Int
val fgColor: Int
setShadowAlpha(0x4f)
when (entryState) {
YES_MANUAL, SKIP, YES_AUTO -> {
bgColor = activeColor
fgColor = res.getColor(R.attr.contrast0)
backgroundPaint!!.color = bgColor
frame!!.setBackgroundDrawable(background)
}
NO, UNKNOWN -> {
bgColor = res.getColor(R.attr.cardBgColor)
fgColor = res.getColor(R.attr.contrast60)
if (preferences!!.isCheckmarkWidgetColorInverted) {
when (entryState) {
YES_MANUAL, SKIP, YES_AUTO -> {
bgColor = res.getColor(R.attr.cardBgColor)
fgColor = res.getColor(R.attr.contrast60)
}

NO, UNKNOWN -> {
bgColor = activeColor
fgColor = res.getColor(R.attr.contrast0)
backgroundPaint!!.color = bgColor
frame!!.setBackgroundDrawable(background)
}

else -> {
bgColor = activeColor
fgColor = res.getColor(R.attr.contrast0)
backgroundPaint!!.color = bgColor
frame!!.setBackgroundDrawable(background)
}
}
else -> {
bgColor = res.getColor(R.attr.cardBgColor)
fgColor = res.getColor(R.attr.contrast60)
} else {
when (entryState) {
YES_MANUAL, SKIP, YES_AUTO -> {
bgColor = activeColor
fgColor = res.getColor(R.attr.contrast0)
backgroundPaint!!.color = bgColor
frame!!.setBackgroundDrawable(background)
}

NO, UNKNOWN -> {
bgColor = res.getColor(R.attr.cardBgColor)
fgColor = res.getColor(R.attr.contrast60)
}

else -> {
bgColor = res.getColor(R.attr.cardBgColor)
fgColor = res.getColor(R.attr.contrast60)
}
}
}
ring.setPercentage(percentage)
Expand Down
2 changes: 2 additions & 0 deletions uhabits-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,6 @@
<string name="activity_not_found">No app was found to support this action</string>
<string name="pref_midnight_delay_title">Extend day a few hours past midnight</string>
<string name="pref_midnight_delay_description">Wait until 3:00 AM to show a new day. Useful if you typically go to sleep after midnight. Requires app restart.</string>
<string name="pref_inverse_checkmark_colors_title">Inverse checkmark widget colors</string>
<string name="pref_inverse_checkmark_colors_description">Make the checkmark widget looked turn off once the task is done.</string>
</resources>
7 changes: 7 additions & 0 deletions uhabits-android/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
android:title="@string/first_day_of_the_week"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_inverse_checkmark_colors"
android:summary="@string/pref_inverse_checkmark_colors_description"
android:title="@string/pref_inverse_checkmark_colors_title"
app:iconSpaceReserved="false" />

</PreferenceCategory>

<PreferenceCategory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ open class Preferences(private val storage: Storage) {
for (l in listeners) l.onQuestionMarksChanged()
}

var isCheckmarkWidgetColorInverted: Boolean
get() = storage.getBoolean("pref_inverse_checkmark_colors", false)
set(value) {
storage.putBoolean("pref_inverse_checkmark_colors", value)
for (l in listeners) l.onCheckmarkColorsChanged()
}

/**
* @return An integer representing the first day of the week. Sunday
* corresponds to 1, Monday to 2, and so on, until Saturday, which is
Expand Down Expand Up @@ -237,6 +244,7 @@ open class Preferences(private val storage: Storage) {
fun onCheckmarkSequenceChanged() {}
fun onNotificationsChanged() {}
fun onQuestionMarksChanged() {}
fun onCheckmarkColorsChanged() {}
}

interface Storage {
Expand Down