feat(ui): new option to grey completed/entered habits

Works the same way as hiding habits, but only changes the color.

The reason this is useful, is because when a habit is treated as
completed/entered, the cause might be just the frequency set for
that habit. So, if it's once per month and you've entered it only
once, till a month has passed the habit will be hidden, but
the habit might've been done again within that month and it would
be useful to be able to see it to enter that data.

At some point it'll be good to change the darkest grey in the
habit palet in "Edit habit", so that it doesn't conflict with
the archived habit and "grey complete" colors.
pull/2138/head
powerjungle 6 months ago
parent 897a236501
commit c7cc1583ac
No known key found for this signature in database
GPG Key ID: 5392BD8A57239AD8

@ -49,13 +49,17 @@ class ListHabitsMenu @Inject constructor(
val nightModeItem = menu.findItem(R.id.actionToggleNightMode) val nightModeItem = menu.findItem(R.id.actionToggleNightMode)
val hideArchivedItem = menu.findItem(R.id.actionHideArchived) val hideArchivedItem = menu.findItem(R.id.actionHideArchived)
val hideCompletedItem = menu.findItem(R.id.actionHideCompleted) val hideCompletedItem = menu.findItem(R.id.actionHideCompleted)
val greyCompletedItem = menu.findItem(R.id.actionGreyCompleted)
nightModeItem.isChecked = themeSwitcher.isNightMode nightModeItem.isChecked = themeSwitcher.isNightMode
hideArchivedItem.isChecked = !preferences.showArchived hideArchivedItem.isChecked = !preferences.showArchived
hideCompletedItem.isChecked = !preferences.showCompleted hideCompletedItem.isChecked = !preferences.showCompleted
greyCompletedItem.isChecked = preferences.greyCompleted
if (preferences.areQuestionMarksEnabled || preferences.isSkipEnabled) { if (preferences.areQuestionMarksEnabled || preferences.isSkipEnabled) {
hideCompletedItem.title = activity.resources.getString(R.string.hide_entered) hideCompletedItem.title = activity.resources.getString(R.string.hide_entered)
greyCompletedItem.title = activity.resources.getString(R.string.grey_entered)
} else { } else {
hideCompletedItem.title = activity.resources.getString(R.string.hide_completed) hideCompletedItem.title = activity.resources.getString(R.string.hide_completed)
greyCompletedItem.title = activity.resources.getString(R.string.grey_completed)
} }
updateArrows(menu) updateArrows(menu)
} }
@ -121,6 +125,12 @@ class ListHabitsMenu @Inject constructor(
return true return true
} }
R.id.actionGreyCompleted -> {
behavior.onToggleGreyCompleted()
activity.invalidateOptionsMenu()
return true
}
R.id.actionSortColor -> { R.id.actionSortColor -> {
behavior.onSortByColor() behavior.onSortByColor()
return true return true

@ -35,14 +35,17 @@ import android.widget.FrameLayout
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import org.isoron.platform.gui.toInt import org.isoron.platform.gui.toInt
import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.activities.common.views.RingView import org.isoron.uhabits.activities.common.views.RingView
import org.isoron.uhabits.core.models.Habit import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.ModelObservable import org.isoron.uhabits.core.models.ModelObservable
import org.isoron.uhabits.core.models.Timestamp import org.isoron.uhabits.core.models.Timestamp
import org.isoron.uhabits.core.preferences.Preferences
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
import org.isoron.uhabits.core.utils.DateUtils import org.isoron.uhabits.core.utils.DateUtils
import org.isoron.uhabits.inject.ActivityContext import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.inject.HabitsApplicationComponent
import org.isoron.uhabits.utils.currentTheme import org.isoron.uhabits.utils.currentTheme
import org.isoron.uhabits.utils.dp import org.isoron.uhabits.utils.dp
import org.isoron.uhabits.utils.sres import org.isoron.uhabits.utils.sres
@ -123,7 +126,12 @@ class HabitCardView(
numberPanel.notes = values numberPanel.notes = values
} }
private val appComponent: HabitsApplicationComponent =
(context.applicationContext as HabitsApplication).component
private val prefs: Preferences = appComponent.preferences
var checkmarkPanel: CheckmarkPanelView var checkmarkPanel: CheckmarkPanelView
private var numberPanel: NumberPanelView private var numberPanel: NumberPanelView
private var innerFrame: LinearLayout private var innerFrame: LinearLayout
private var label: TextView private var label: TextView
@ -264,10 +272,19 @@ class HabitCardView(
private fun copyAttributesFrom(h: Habit) { private fun copyAttributesFrom(h: Habit) {
fun getActiveColor(habit: Habit): Int { fun getActiveColor(habit: Habit): Int {
return when (habit.isArchived) { var retCol: Int = currentTheme().color(habit.color).toInt()
true -> sres.getColor(R.attr.contrast60)
false -> currentTheme().color(habit.color).toInt() if (habit.isArchived) {
retCol = sres.getColor(R.attr.contrast60)
} else if (prefs.greyCompleted) {
if (prefs.areQuestionMarksEnabled && habit.isEnteredToday()) {
retCol = sres.getColor(R.attr.contrast40)
} else if (!prefs.areQuestionMarksEnabled && habit.isCompletedToday()) {
retCol = sres.getColor(R.attr.contrast40)
}
} }
return retCol
} }
val c = getActiveColor(h) val c = getActiveColor(h)

@ -48,6 +48,12 @@
android:enabled="true" android:enabled="true"
android:title="@string/hide_completed"/> android:title="@string/hide_completed"/>
<item
android:id="@+id/actionGreyCompleted"
android:checkable="true"
android:enabled="true"
android:title="@string/grey_completed"/>
<item android:title="@string/sort"> <item android:title="@string/sort">
<menu> <menu>
<item <item

@ -161,7 +161,9 @@
<string name="none">None</string> <string name="none">None</string>
<string name="filter">Filter</string> <string name="filter">Filter</string>
<string name="hide_completed">Hide completed</string> <string name="hide_completed">Hide completed</string>
<string name="grey_completed">Grey completed</string>
<string name="hide_entered">Hide entered</string> <string name="hide_entered">Hide entered</string>
<string name="grey_entered">Grey entered</string>
<string name="hide_archived">Hide archived</string> <string name="hide_archived">Hide archived</string>
<string name="sticky_notifications">Make notifications sticky</string> <string name="sticky_notifications">Make notifications sticky</string>
<string name="sticky_notifications_description">Prevents notifications from being swiped away.</string> <string name="sticky_notifications_description">Prevents notifications from being swiped away.</string>

@ -101,6 +101,11 @@ open class Preferences(private val storage: Storage) {
set(showCompleted) { set(showCompleted) {
storage.putBoolean("pref_show_completed", showCompleted) storage.putBoolean("pref_show_completed", showCompleted)
} }
var greyCompleted: Boolean
get() = storage.getBoolean("pref_grey_completed", false)
set(greyCompleted) {
storage.putBoolean("pref_grey_completed", greyCompleted)
}
var theme: Int var theme: Int
get() = storage.getInt("pref_theme", ThemeSwitcher.THEME_AUTOMATIC) get() = storage.getInt("pref_theme", ThemeSwitcher.THEME_AUTOMATIC)

@ -31,6 +31,7 @@ class ListHabitsMenuBehavior @Inject constructor(
private val themeSwitcher: ThemeSwitcher private val themeSwitcher: ThemeSwitcher
) { ) {
private var showCompleted: Boolean private var showCompleted: Boolean
private var greyCompleted: Boolean
private var showArchived: Boolean private var showArchived: Boolean
fun onCreateHabit() { fun onCreateHabit() {
@ -61,6 +62,12 @@ class ListHabitsMenuBehavior @Inject constructor(
updateAdapterFilter() updateAdapterFilter()
} }
fun onToggleGreyCompleted() {
greyCompleted = !greyCompleted
preferences.greyCompleted = greyCompleted
updateAdapterFilter()
}
fun onSortByManually() { fun onSortByManually() {
adapter.primaryOrder = HabitList.Order.BY_POSITION adapter.primaryOrder = HabitList.Order.BY_POSITION
} }
@ -137,6 +144,7 @@ class ListHabitsMenuBehavior @Inject constructor(
init { init {
showCompleted = preferences.showCompleted showCompleted = preferences.showCompleted
greyCompleted = preferences.greyCompleted
showArchived = preferences.showArchived showArchived = preferences.showArchived
updateAdapterFilter() updateAdapterFilter()
} }

@ -156,10 +156,13 @@ class PreferencesTest : BaseUnitTest() {
fun testFiltering() { fun testFiltering() {
assertFalse(prefs.showArchived) assertFalse(prefs.showArchived)
assertTrue(prefs.showCompleted) assertTrue(prefs.showCompleted)
assertFalse(prefs.greyCompleted)
prefs.showArchived = true prefs.showArchived = true
prefs.showCompleted = false prefs.showCompleted = false
prefs.greyCompleted = true
assertTrue(prefs.showArchived) assertTrue(prefs.showArchived)
assertFalse(prefs.showCompleted) assertFalse(prefs.showCompleted)
assertTrue(prefs.greyCompleted)
} }
@Test @Test

Loading…
Cancel
Save