mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Remove HabitMatcherBuilder
This commit is contained in:
@@ -23,17 +23,17 @@ import android.os.Bundle
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import org.isoron.uhabits.HabitsApplication
|
import org.isoron.uhabits.HabitsApplication
|
||||||
import org.isoron.uhabits.activities.AndroidThemeSwitcher
|
import org.isoron.uhabits.activities.AndroidThemeSwitcher
|
||||||
import org.isoron.uhabits.core.models.HabitMatcherBuilder
|
import org.isoron.uhabits.core.models.HabitMatcher
|
||||||
|
|
||||||
class EditSettingActivity : AppCompatActivity() {
|
class EditSettingActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val app = applicationContext as HabitsApplication
|
val app = applicationContext as HabitsApplication
|
||||||
val habits = app.component.habitList.getFiltered(
|
val habits = app.component.habitList.getFiltered(
|
||||||
HabitMatcherBuilder()
|
HabitMatcher(
|
||||||
.setArchivedAllowed(false)
|
isArchivedAllowed = false,
|
||||||
.setCompletedAllowed(true)
|
isCompletedAllowed = true,
|
||||||
.build()
|
)
|
||||||
)
|
)
|
||||||
AndroidThemeSwitcher(this, app.component.preferences).apply()
|
AndroidThemeSwitcher(this, app.component.preferences).apply()
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ abstract class HabitList : Iterable<Habit> {
|
|||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
observable = ModelObservable()
|
observable = ModelObservable()
|
||||||
filter = HabitMatcherBuilder().setArchivedAllowed(true).build()
|
filter = HabitMatcher(isArchivedAllowed = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected constructor(filter: HabitMatcher) {
|
protected constructor(filter: HabitMatcher) {
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ data class HabitMatcher(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
val WITH_ALARM = HabitMatcherBuilder()
|
val WITH_ALARM = HabitMatcher(
|
||||||
.setArchivedAllowed(true)
|
isArchivedAllowed = true,
|
||||||
.setReminderRequired(true)
|
isReminderRequired = true,
|
||||||
.build()
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package org.isoron.uhabits.core.models
|
|
||||||
|
|
||||||
class HabitMatcherBuilder {
|
|
||||||
private var archivedAllowed = false
|
|
||||||
private var reminderRequired = false
|
|
||||||
private var completedAllowed = true
|
|
||||||
|
|
||||||
fun build(): HabitMatcher {
|
|
||||||
return HabitMatcher(
|
|
||||||
isArchivedAllowed = archivedAllowed,
|
|
||||||
isReminderRequired = reminderRequired,
|
|
||||||
isCompletedAllowed = completedAllowed,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setArchivedAllowed(archivedAllowed: Boolean): HabitMatcherBuilder {
|
|
||||||
this.archivedAllowed = archivedAllowed
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setCompletedAllowed(completedAllowed: Boolean): HabitMatcherBuilder {
|
|
||||||
this.completedAllowed = completedAllowed
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setReminderRequired(reminderRequired: Boolean): HabitMatcherBuilder {
|
|
||||||
this.reminderRequired = reminderRequired
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,6 @@ package org.isoron.uhabits.core.ui.screens.habits.list
|
|||||||
|
|
||||||
import org.isoron.uhabits.core.models.HabitList
|
import org.isoron.uhabits.core.models.HabitList
|
||||||
import org.isoron.uhabits.core.models.HabitMatcher
|
import org.isoron.uhabits.core.models.HabitMatcher
|
||||||
import org.isoron.uhabits.core.models.HabitMatcherBuilder
|
|
||||||
import org.isoron.uhabits.core.preferences.Preferences
|
import org.isoron.uhabits.core.preferences.Preferences
|
||||||
import org.isoron.uhabits.core.ui.ThemeSwitcher
|
import org.isoron.uhabits.core.ui.ThemeSwitcher
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -99,10 +98,10 @@ class ListHabitsMenuBehavior @Inject constructor(
|
|||||||
|
|
||||||
private fun updateAdapterFilter() {
|
private fun updateAdapterFilter() {
|
||||||
adapter.setFilter(
|
adapter.setFilter(
|
||||||
HabitMatcherBuilder()
|
HabitMatcher(
|
||||||
.setArchivedAllowed(showArchived)
|
isArchivedAllowed = showArchived,
|
||||||
.setCompletedAllowed(showCompleted)
|
isCompletedAllowed = showCompleted,
|
||||||
.build()
|
)
|
||||||
)
|
)
|
||||||
adapter.refresh()
|
adapter.refresh()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,12 +53,12 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
habitsArray[1].isArchived = true
|
habitsArray[1].isArchived = true
|
||||||
habitsArray[4].isArchived = true
|
habitsArray[4].isArchived = true
|
||||||
habitsArray[7].isArchived = true
|
habitsArray[7].isArchived = true
|
||||||
activeHabits = habitList.getFiltered(HabitMatcherBuilder().build())
|
activeHabits = habitList.getFiltered(HabitMatcher())
|
||||||
reminderHabits = habitList.getFiltered(
|
reminderHabits = habitList.getFiltered(
|
||||||
HabitMatcherBuilder()
|
HabitMatcher(
|
||||||
.setArchivedAllowed(true)
|
isArchivedAllowed = true,
|
||||||
.setReminderRequired(true)
|
isReminderRequired = true,
|
||||||
.build()
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,10 +181,10 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
fun testOrder_inherit() {
|
fun testOrder_inherit() {
|
||||||
habitList.primaryOrder = HabitList.Order.BY_COLOR_ASC
|
habitList.primaryOrder = HabitList.Order.BY_COLOR_ASC
|
||||||
val filteredList = habitList.getFiltered(
|
val filteredList = habitList.getFiltered(
|
||||||
HabitMatcherBuilder()
|
HabitMatcher(
|
||||||
.setArchivedAllowed(false)
|
isArchivedAllowed = false,
|
||||||
.setCompletedAllowed(false)
|
isCompletedAllowed = false,
|
||||||
.build()
|
)
|
||||||
)
|
)
|
||||||
assertEquals(filteredList.primaryOrder, HabitList.Order.BY_COLOR_ASC)
|
assertEquals(filteredList.primaryOrder, HabitList.Order.BY_COLOR_ASC)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.isoron.uhabits.core.database.Database
|
|||||||
import org.isoron.uhabits.core.database.Repository
|
import org.isoron.uhabits.core.database.Repository
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.models.HabitList
|
import org.isoron.uhabits.core.models.HabitList
|
||||||
import org.isoron.uhabits.core.models.HabitMatcherBuilder
|
import org.isoron.uhabits.core.models.HabitMatcher
|
||||||
import org.isoron.uhabits.core.models.ModelObservable
|
import org.isoron.uhabits.core.models.ModelObservable
|
||||||
import org.isoron.uhabits.core.models.Reminder
|
import org.isoron.uhabits.core.models.Reminder
|
||||||
import org.isoron.uhabits.core.models.WeekdayList
|
import org.isoron.uhabits.core.models.WeekdayList
|
||||||
@@ -69,12 +69,12 @@ class SQLiteHabitListTest : BaseUnitTest() {
|
|||||||
habitsArray[4].isArchived = true
|
habitsArray[4].isArchived = true
|
||||||
habitsArray[7].isArchived = true
|
habitsArray[7].isArchived = true
|
||||||
habitList.update(habitsArray)
|
habitList.update(habitsArray)
|
||||||
activeHabits = habitList.getFiltered(HabitMatcherBuilder().build())
|
activeHabits = habitList.getFiltered(HabitMatcher())
|
||||||
reminderHabits = habitList.getFiltered(
|
reminderHabits = habitList.getFiltered(
|
||||||
HabitMatcherBuilder()
|
HabitMatcher(
|
||||||
.setArchivedAllowed(true)
|
isArchivedAllowed = true,
|
||||||
.setReminderRequired(true)
|
isReminderRequired = true,
|
||||||
.build()
|
)
|
||||||
)
|
)
|
||||||
habitList.observable.addListener(listener)
|
habitList.observable.addListener(listener)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user