Skip to content
Open
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 @@ -75,8 +75,12 @@ class ListHabitsActivity : AppCompatActivity(), Preferences.Listener {
private lateinit var menu: ListHabitsMenu

override fun onQuestionMarksChanged() {
invalidateOptionsMenu()
menu.behavior.onPreferencesChanged()
if (prefs.greyCompleted) {
restartWithFade(this::class.java)
} else {
invalidateOptionsMenu()
menu.behavior.onPreferencesChanged()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ class ListHabitsMenu @Inject constructor(
val nightModeItem = menu.findItem(R.id.actionToggleNightMode)
val hideArchivedItem = menu.findItem(R.id.actionHideArchived)
val hideCompletedItem = menu.findItem(R.id.actionHideCompleted)
val greyCompletedItem = menu.findItem(R.id.actionGreyCompleted)
nightModeItem.isChecked = themeSwitcher.isNightMode
hideArchivedItem.isChecked = !preferences.showArchived
hideCompletedItem.isChecked = !preferences.showCompleted
greyCompletedItem.isChecked = preferences.greyCompleted
if (preferences.areQuestionMarksEnabled || preferences.isSkipEnabled) {
hideCompletedItem.title = activity.resources.getString(R.string.hide_entered)
greyCompletedItem.title = activity.resources.getString(R.string.grey_entered)
} else {
hideCompletedItem.title = activity.resources.getString(R.string.hide_completed)
greyCompletedItem.title = activity.resources.getString(R.string.grey_completed)
}
updateArrows(menu)
}
Expand Down Expand Up @@ -121,6 +125,12 @@ class ListHabitsMenu @Inject constructor(
return true
}

R.id.actionGreyCompleted -> {
behavior.onToggleGreyCompleted()
activity.invalidateOptionsMenu()
return true
}

R.id.actionSortColor -> {
behavior.onSortByColor()
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
import org.isoron.platform.gui.toInt
import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.R
import org.isoron.uhabits.activities.common.views.RingView
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.ModelObservable
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.utils.DateUtils
import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.inject.HabitsApplicationComponent
import org.isoron.uhabits.utils.currentTheme
import org.isoron.uhabits.utils.dp
import org.isoron.uhabits.utils.sres
Expand Down Expand Up @@ -123,7 +126,12 @@ class HabitCardView(
numberPanel.notes = values
}

private val appComponent: HabitsApplicationComponent =
(context.applicationContext as HabitsApplication).component
private val prefs: Preferences = appComponent.preferences

var checkmarkPanel: CheckmarkPanelView

private var numberPanel: NumberPanelView
private var innerFrame: LinearLayout
private var label: TextView
Expand Down Expand Up @@ -264,10 +272,19 @@ class HabitCardView(

private fun copyAttributesFrom(h: Habit) {
fun getActiveColor(habit: Habit): Int {
return when (habit.isArchived) {
true -> sres.getColor(R.attr.contrast60)
false -> currentTheme().color(habit.color).toInt()
var retCol: Int = 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)
Expand Down
6 changes: 6 additions & 0 deletions uhabits-android/src/main/res/menu/list_habits.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
android:enabled="true"
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">
<menu>
<item
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 @@ -161,7 +161,9 @@
<string name="none">None</string>
<string name="filter">Filter</string>
<string name="hide_completed">Hide completed</string>
<string name="grey_completed">Grey completed</string>
<string name="hide_entered">Hide entered</string>
<string name="grey_entered">Grey entered</string>
<string name="hide_archived">Hide archived</string>
<string name="sticky_notifications">Make notifications sticky</string>
<string name="sticky_notifications_description">Prevents notifications from being swiped away.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ open class Preferences(private val storage: Storage) {
set(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
get() = storage.getInt("pref_theme", ThemeSwitcher.THEME_AUTOMATIC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ListHabitsMenuBehavior @Inject constructor(
private val themeSwitcher: ThemeSwitcher
) {
private var showCompleted: Boolean
private var greyCompleted: Boolean
private var showArchived: Boolean

fun onCreateHabit() {
Expand Down Expand Up @@ -61,6 +62,12 @@ class ListHabitsMenuBehavior @Inject constructor(
updateAdapterFilter()
}

fun onToggleGreyCompleted() {
greyCompleted = !greyCompleted
preferences.greyCompleted = greyCompleted
screen.applyTheme()
}

fun onSortByManually() {
adapter.primaryOrder = HabitList.Order.BY_POSITION
}
Expand Down Expand Up @@ -137,6 +144,7 @@ class ListHabitsMenuBehavior @Inject constructor(

init {
showCompleted = preferences.showCompleted
greyCompleted = preferences.greyCompleted
showArchived = preferences.showArchived
updateAdapterFilter()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ class PreferencesTest : BaseUnitTest() {
fun testFiltering() {
assertFalse(prefs.showArchived)
assertTrue(prefs.showCompleted)
assertFalse(prefs.greyCompleted)
prefs.showArchived = true
prefs.showCompleted = false
prefs.greyCompleted = true
assertTrue(prefs.showArchived)
assertFalse(prefs.showCompleted)
assertTrue(prefs.greyCompleted)
}

@Test
Expand Down