mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Allow user to show/hide archived and completed habits
This commit is contained in:
Binary file not shown.
@@ -70,7 +70,8 @@ class Backend(databaseName: String,
|
|||||||
checkmarks[habit]?.setManualCheckmarks(checks)
|
checkmarks[habit]?.setManualCheckmarks(checks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mainScreenDataSource = MainScreenDataSource(habits,
|
mainScreenDataSource = MainScreenDataSource(preferences,
|
||||||
|
habits,
|
||||||
checkmarks,
|
checkmarks,
|
||||||
taskRunner)
|
taskRunner)
|
||||||
}
|
}
|
||||||
@@ -99,6 +100,4 @@ class Backend(databaseName: String,
|
|||||||
habitsRepository.update(modified)
|
habitsRepository.update(modified)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ package org.isoron.uhabits.backend
|
|||||||
import org.isoron.platform.concurrency.*
|
import org.isoron.platform.concurrency.*
|
||||||
import org.isoron.platform.time.*
|
import org.isoron.platform.time.*
|
||||||
import org.isoron.uhabits.models.*
|
import org.isoron.uhabits.models.*
|
||||||
|
import org.isoron.uhabits.models.Checkmark.Companion.UNCHECKED
|
||||||
|
|
||||||
class MainScreenDataSource(val habits: MutableMap<Int, Habit>,
|
class MainScreenDataSource(val preferences: Preferences,
|
||||||
|
val habits: MutableMap<Int, Habit>,
|
||||||
val checkmarks: MutableMap<Habit, CheckmarkList>,
|
val checkmarks: MutableMap<Habit, CheckmarkList>,
|
||||||
val taskRunner: TaskRunner) {
|
val taskRunner: TaskRunner) {
|
||||||
|
|
||||||
@@ -41,16 +43,31 @@ class MainScreenDataSource(val habits: MutableMap<Int, Habit>,
|
|||||||
|
|
||||||
fun requestData() {
|
fun requestData() {
|
||||||
taskRunner.runInBackground {
|
taskRunner.runInBackground {
|
||||||
val filtered = habits.values.filter { h -> !h.isArchived }
|
var filtered = habits.values.toList()
|
||||||
val currentScores = filtered.associate { it to 0.0 /* TODO */}
|
|
||||||
val recentCheckmarks = filtered.associate {
|
if (!preferences.showArchived) {
|
||||||
val allValues = checkmarks[it]!!.getValuesUntil(today)
|
filtered = filtered.filter { !it.isArchived }
|
||||||
if (allValues.size <= 7) it to allValues
|
|
||||||
else it to allValues.subList(0, 7)
|
|
||||||
}
|
}
|
||||||
val data = Data(filtered, currentScores, recentCheckmarks)
|
|
||||||
|
val recentCheckmarks = filtered.associate { habit ->
|
||||||
|
val allValues = checkmarks.getValue(habit).getValuesUntil(today)
|
||||||
|
if (allValues.size <= 7) habit to allValues
|
||||||
|
else habit to allValues.subList(0, 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preferences.showCompleted) {
|
||||||
|
filtered = filtered.filter { habit ->
|
||||||
|
recentCheckmarks.getValue(habit)[0] == UNCHECKED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val currentScores = filtered.associate {
|
||||||
|
it to 0.0 /* TODO */
|
||||||
|
}
|
||||||
|
|
||||||
taskRunner.runInForeground {
|
taskRunner.runInForeground {
|
||||||
observable.notifyListeners { listener ->
|
observable.notifyListeners { listener ->
|
||||||
|
val data = Data(filtered, currentScores, recentCheckmarks)
|
||||||
listener.onDataChanged(data)
|
listener.onDataChanged(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,4 +186,5 @@ open class Strings() {
|
|||||||
open val weekends = "Weekends"
|
open val weekends = "Weekends"
|
||||||
open val year = "Year"
|
open val year = "Year"
|
||||||
open val yes = "Yes"
|
open val yes = "Yes"
|
||||||
|
open val day_mode = "Day mode"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,13 +61,11 @@ class MainScreenCell : UITableViewCell {
|
|||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(name: String,
|
func update(habit: Habit, values: [KotlinInt], theme: Theme) {
|
||||||
color: Color,
|
var color = theme.color(paletteIndex: habit.color.index)
|
||||||
values: [KotlinInt]) {
|
if habit.isArchived { color = theme.mediumContrastTextColor }
|
||||||
|
label.text = habit.name
|
||||||
label.text = name
|
|
||||||
label.textColor = color.uicolor
|
label.textColor = color.uicolor
|
||||||
|
|
||||||
ring.component = Ring(color: color,
|
ring.component = Ring(color: color,
|
||||||
percentage: Double.random(in: 0...1),
|
percentage: Double.random(in: 0...1),
|
||||||
thickness: 2.5,
|
thickness: 2.5,
|
||||||
@@ -90,6 +88,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
var backend: Backend
|
var backend: Backend
|
||||||
var dataSource: MainScreenDataSource
|
var dataSource: MainScreenDataSource
|
||||||
var data: MainScreenDataSource.Data?
|
var data: MainScreenDataSource.Data?
|
||||||
|
var preferences: Preferences
|
||||||
var theme: Theme
|
var theme: Theme
|
||||||
var nButtons = 3
|
var nButtons = 3
|
||||||
var strings: Strings
|
var strings: Strings
|
||||||
@@ -103,14 +102,11 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
self.strings = backend.strings
|
self.strings = backend.strings
|
||||||
self.dataSource = backend.mainScreenDataSource
|
self.dataSource = backend.mainScreenDataSource
|
||||||
self.theme = backend.theme
|
self.theme = backend.theme
|
||||||
|
self.preferences = backend.preferences
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
self.dataSource.observable.addListener(listener: self)
|
self.dataSource.observable.addListener(listener: self)
|
||||||
self.dataSource.requestData()
|
self.dataSource.requestData()
|
||||||
}
|
}
|
||||||
|
|
||||||
func onDataChanged(newData: MainScreenDataSource.Data) {
|
|
||||||
self.data = newData
|
|
||||||
}
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
self.title = strings.main_activity_title
|
self.title = strings.main_activity_title
|
||||||
@@ -140,12 +136,9 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
let row = indexPath.row
|
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainScreenCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainScreenCell
|
||||||
let habit = data!.habits[row]
|
let habit = data!.habits[indexPath.row]
|
||||||
cell.update(name: habit.name,
|
cell.update(habit: habit, values: data!.checkmarkValues[habit]!, theme: theme)
|
||||||
color: theme.color(paletteIndex: habit.color.index),
|
|
||||||
values: data!.checkmarkValues[habit]!)
|
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,9 +161,7 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
|
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
let habit = data!.habits[indexPath.row]
|
let habit = data!.habits[indexPath.row]
|
||||||
let color = theme.color(paletteIndex: habit.color.index)
|
self.navigationController?.pushViewController(DetailScreenController(habit: habit, backend: backend), animated: true)
|
||||||
self.navigationController?.pushViewController(DetailScreenController(habit: habit, backend: backend),
|
|
||||||
animated: true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func onCreateHabitClicked() {
|
@objc func onCreateHabitClicked() {
|
||||||
@@ -179,18 +170,47 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
|
|
||||||
@objc func onMoreActionsClicked() {
|
@objc func onMoreActionsClicked() {
|
||||||
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||||
alert.addAction(UIAlertAction(title: strings.show_archived, style: .default) {
|
|
||||||
(action: UIAlertAction) -> Void in
|
if preferences.showArchived {
|
||||||
// TODO
|
alert.addAction(UIAlertAction(title: strings.hide_archived, style: .default) {
|
||||||
})
|
(action: UIAlertAction) -> Void in
|
||||||
alert.addAction(UIAlertAction(title: strings.hide_completed, style: .default) {
|
self.preferences.showArchived = false
|
||||||
(action: UIAlertAction) -> Void in
|
self.dataSource.requestData()
|
||||||
// TODO
|
})
|
||||||
})
|
} else {
|
||||||
alert.addAction(UIAlertAction(title: strings.night_mode, style: .default) {
|
alert.addAction(UIAlertAction(title: strings.show_archived, style: .default) {
|
||||||
(action: UIAlertAction) -> Void in
|
(action: UIAlertAction) -> Void in
|
||||||
// TODO
|
self.preferences.showArchived = true
|
||||||
})
|
self.dataSource.requestData()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if preferences.showCompleted {
|
||||||
|
alert.addAction(UIAlertAction(title: strings.hide_completed, style: .default) {
|
||||||
|
(action: UIAlertAction) -> Void in
|
||||||
|
self.preferences.showCompleted = false
|
||||||
|
self.dataSource.requestData()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
alert.addAction(UIAlertAction(title: strings.show_completed, style: .default) {
|
||||||
|
(action: UIAlertAction) -> Void in
|
||||||
|
self.preferences.showCompleted = true
|
||||||
|
self.dataSource.requestData()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if preferences.nightMode {
|
||||||
|
alert.addAction(UIAlertAction(title: strings.day_mode, style: .default) {
|
||||||
|
(action: UIAlertAction) -> Void in
|
||||||
|
self.preferences.nightMode = false
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
alert.addAction(UIAlertAction(title: strings.night_mode, style: .default) {
|
||||||
|
(action: UIAlertAction) -> Void in
|
||||||
|
self.preferences.nightMode = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
alert.addAction(UIAlertAction(title: strings.help, style: .default) {
|
alert.addAction(UIAlertAction(title: strings.help, style: .default) {
|
||||||
(action: UIAlertAction) -> Void in
|
(action: UIAlertAction) -> Void in
|
||||||
// TODO
|
// TODO
|
||||||
@@ -205,4 +225,10 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
})
|
})
|
||||||
present(alert, animated: true, completion: nil)
|
present(alert, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func onDataChanged(newData: MainScreenDataSource.Data) {
|
||||||
|
data = newData
|
||||||
|
let sections = NSIndexSet(indexesIn: NSMakeRange(0, self.tableView.numberOfSections))
|
||||||
|
tableView.reloadSections(sections as IndexSet, with: .automatic)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
0057EC2B224C4CDB00C49288 /* icons in Resources */ = {isa = PBXBuildFile; fileRef = 0057EC2A224C4CDB00C49288 /* icons */; };
|
|
||||||
006EFE4C2252E9F3008464E0 /* IosLocaleTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006EFE4A2252E9D3008464E0 /* IosLocaleTest.swift */; };
|
006EFE4C2252E9F3008464E0 /* IosLocaleTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006EFE4A2252E9D3008464E0 /* IosLocaleTest.swift */; };
|
||||||
006EFE4E2252EA2B008464E0 /* IosLocale.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006EFE4D2252EA2B008464E0 /* IosLocale.swift */; };
|
006EFE4E2252EA2B008464E0 /* IosLocale.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006EFE4D2252EA2B008464E0 /* IosLocale.swift */; };
|
||||||
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42722009F590024E00C /* AppDelegate.swift */; };
|
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42722009F590024E00C /* AppDelegate.swift */; };
|
||||||
@@ -58,7 +57,6 @@
|
|||||||
/* End PBXCopyFilesBuildPhase section */
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
0057EC2A224C4CDB00C49288 /* icons */ = {isa = PBXFileReference; lastKnownFileType = folder; path = icons; sourceTree = "<group>"; };
|
|
||||||
006EFE4A2252E9D3008464E0 /* IosLocaleTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosLocaleTest.swift; sourceTree = "<group>"; };
|
006EFE4A2252E9D3008464E0 /* IosLocaleTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosLocaleTest.swift; sourceTree = "<group>"; };
|
||||||
006EFE4D2252EA2B008464E0 /* IosLocale.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosLocale.swift; sourceTree = "<group>"; };
|
006EFE4D2252EA2B008464E0 /* IosLocale.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosLocale.swift; sourceTree = "<group>"; };
|
||||||
00A5B42422009F590024E00C /* uhabits.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = uhabits.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
00A5B42422009F590024E00C /* uhabits.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = uhabits.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@@ -171,7 +169,6 @@
|
|||||||
00C0C6C022465F80003D8AF0 /* Assets */ = {
|
00C0C6C022465F80003D8AF0 /* Assets */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
0057EC2A224C4CDB00C49288 /* icons */,
|
|
||||||
00C0C6BB22465F65003D8AF0 /* databases */,
|
00C0C6BB22465F65003D8AF0 /* databases */,
|
||||||
00C0C6BA22465F65003D8AF0 /* fonts */,
|
00C0C6BA22465F65003D8AF0 /* fonts */,
|
||||||
00C0C6BC22465F65003D8AF0 /* migrations */,
|
00C0C6BC22465F65003D8AF0 /* migrations */,
|
||||||
@@ -291,7 +288,6 @@
|
|||||||
00C0C6BD22465F65003D8AF0 /* fonts in Resources */,
|
00C0C6BD22465F65003D8AF0 /* fonts in Resources */,
|
||||||
00C0C6BE22465F65003D8AF0 /* databases in Resources */,
|
00C0C6BE22465F65003D8AF0 /* databases in Resources */,
|
||||||
00C0C6BF22465F65003D8AF0 /* migrations in Resources */,
|
00C0C6BF22465F65003D8AF0 /* migrations in Resources */,
|
||||||
0057EC2B224C4CDB00C49288 /* icons in Resources */,
|
|
||||||
00A5B42F22009F5A0024E00C /* Assets.xcassets in Resources */,
|
00A5B42F22009F5A0024E00C /* Assets.xcassets in Resources */,
|
||||||
00D48BD12200A31300CC4527 /* Launch.storyboard in Resources */,
|
00D48BD12200A31300CC4527 /* Launch.storyboard in Resources */,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user