mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
@@ -53,6 +53,7 @@ class ListHabitsActivity : AppCompatActivity(), Preferences.Listener {
|
|||||||
|
|
||||||
override fun onQuestionMarksChanged() {
|
override fun onQuestionMarksChanged() {
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
|
menu.behavior.onPreferencesChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class ListHabitsMenu @Inject constructor(
|
|||||||
@ActivityContext context: Context,
|
@ActivityContext context: Context,
|
||||||
private val preferences: Preferences,
|
private val preferences: Preferences,
|
||||||
private val themeSwitcher: ThemeSwitcher,
|
private val themeSwitcher: ThemeSwitcher,
|
||||||
private val behavior: ListHabitsMenuBehavior
|
val behavior: ListHabitsMenuBehavior
|
||||||
) {
|
) {
|
||||||
val activity = (context as AppCompatActivity)
|
val activity = (context as AppCompatActivity)
|
||||||
|
|
||||||
|
|||||||
@@ -68,17 +68,10 @@ data class Habit(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isFailedToday(): Boolean {
|
fun isEnteredToday(): Boolean {
|
||||||
val today = DateUtils.getTodayWithOffset()
|
val today = DateUtils.getTodayWithOffset()
|
||||||
val value = computedEntries.get(today).value
|
val value = computedEntries.get(today).value
|
||||||
return if (isNumerical) {
|
return value != Entry.UNKNOWN
|
||||||
when (targetType) {
|
|
||||||
NumericalHabitType.AT_LEAST -> value / 1000.0 < targetValue
|
|
||||||
NumericalHabitType.AT_MOST -> value / 1000.0 > targetValue
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
value == Entry.NO
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun recompute() {
|
fun recompute() {
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ data class HabitMatcher(
|
|||||||
val isArchivedAllowed: Boolean = false,
|
val isArchivedAllowed: Boolean = false,
|
||||||
val isReminderRequired: Boolean = false,
|
val isReminderRequired: Boolean = false,
|
||||||
val isCompletedAllowed: Boolean = true,
|
val isCompletedAllowed: Boolean = true,
|
||||||
|
val isEnteredAllowed: Boolean = true,
|
||||||
) {
|
) {
|
||||||
fun matches(habit: Habit): Boolean {
|
fun matches(habit: Habit): Boolean {
|
||||||
if (!isArchivedAllowed && habit.isArchived) return false
|
if (!isArchivedAllowed && habit.isArchived) return false
|
||||||
if (isReminderRequired && !habit.hasReminder()) return false
|
if (isReminderRequired && !habit.hasReminder()) return false
|
||||||
if (!isCompletedAllowed && (habit.isCompletedToday() || habit.isFailedToday())) return false
|
if (!isCompletedAllowed && habit.isCompletedToday()) return false
|
||||||
|
if (!isEnteredAllowed && habit.isEnteredToday()) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class ListHabitsMenuBehavior @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
private var showCompleted: Boolean
|
private var showCompleted: Boolean
|
||||||
private var showArchived: Boolean
|
private var showArchived: Boolean
|
||||||
|
|
||||||
fun onCreateHabit() {
|
fun onCreateHabit() {
|
||||||
screen.showSelectHabitTypeDialog()
|
screen.showSelectHabitTypeDialog()
|
||||||
}
|
}
|
||||||
@@ -96,13 +97,26 @@ class ListHabitsMenuBehavior @Inject constructor(
|
|||||||
screen.applyTheme()
|
screen.applyTheme()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onPreferencesChanged() {
|
||||||
|
updateAdapterFilter()
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateAdapterFilter() {
|
private fun updateAdapterFilter() {
|
||||||
adapter.setFilter(
|
if (preferences.areQuestionMarksEnabled) {
|
||||||
HabitMatcher(
|
adapter.setFilter(
|
||||||
isArchivedAllowed = showArchived,
|
HabitMatcher(
|
||||||
isCompletedAllowed = showCompleted,
|
isArchivedAllowed = showArchived,
|
||||||
|
isEnteredAllowed = showCompleted,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
} else {
|
||||||
|
adapter.setFilter(
|
||||||
|
HabitMatcher(
|
||||||
|
isArchivedAllowed = showArchived,
|
||||||
|
isCompletedAllowed = showCompleted,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
adapter.refresh()
|
adapter.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,12 +82,12 @@ class HabitTest : BaseUnitTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun test_isFailed() {
|
fun test_isEntered() {
|
||||||
val h = modelFactory.buildHabit()
|
val h = modelFactory.buildHabit()
|
||||||
assertFalse(h.isFailedToday())
|
assertFalse(h.isEnteredToday())
|
||||||
h.originalEntries.add(Entry(getToday(), Entry.NO))
|
h.originalEntries.add(Entry(getToday(), Entry.NO))
|
||||||
h.recompute()
|
h.recompute()
|
||||||
assertTrue(h.isFailedToday())
|
assertTrue(h.isEnteredToday())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -119,35 +119,6 @@ class HabitTest : BaseUnitTest() {
|
|||||||
assertTrue(h.isCompletedToday())
|
assertTrue(h.isCompletedToday())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Throws(Exception::class)
|
|
||||||
fun test_isFailedNumerical() {
|
|
||||||
val h = modelFactory.buildHabit()
|
|
||||||
h.type = HabitType.NUMERICAL
|
|
||||||
h.targetType = NumericalHabitType.AT_LEAST
|
|
||||||
h.targetValue = 100.0
|
|
||||||
assertTrue(h.isFailedToday())
|
|
||||||
h.originalEntries.add(Entry(getToday(), 200000))
|
|
||||||
h.recompute()
|
|
||||||
assertFalse(h.isFailedToday())
|
|
||||||
h.originalEntries.add(Entry(getToday(), 100000))
|
|
||||||
h.recompute()
|
|
||||||
assertFalse(h.isFailedToday())
|
|
||||||
h.originalEntries.add(Entry(getToday(), 50000))
|
|
||||||
h.recompute()
|
|
||||||
assertTrue(h.isFailedToday())
|
|
||||||
h.targetType = NumericalHabitType.AT_MOST
|
|
||||||
h.originalEntries.add(Entry(getToday(), 200000))
|
|
||||||
h.recompute()
|
|
||||||
assertTrue(h.isFailedToday())
|
|
||||||
h.originalEntries.add(Entry(getToday(), 100000))
|
|
||||||
h.recompute()
|
|
||||||
assertFalse(h.isFailedToday())
|
|
||||||
h.originalEntries.add(Entry(getToday(), 50000))
|
|
||||||
h.recompute()
|
|
||||||
assertFalse(h.isFailedToday())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testURI() {
|
fun testURI() {
|
||||||
|
|||||||
Reference in New Issue
Block a user