mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Show numerical habits
This commit is contained in:
@@ -66,7 +66,7 @@ class Backend(databaseName: String,
|
|||||||
habits.putAll(habitsRepository.findAll())
|
habits.putAll(habitsRepository.findAll())
|
||||||
for ((key, habit) in habits) {
|
for ((key, habit) in habits) {
|
||||||
val checks = checkmarkRepository.findAll(key)
|
val checks = checkmarkRepository.findAll(key)
|
||||||
checkmarks[habit] = CheckmarkList(habit.frequency)
|
checkmarks[habit] = CheckmarkList(habit.frequency, habit.type)
|
||||||
checkmarks[habit]?.setManualCheckmarks(checks)
|
checkmarks[habit]?.setManualCheckmarks(checks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ class Backend(databaseName: String,
|
|||||||
habit.id = id
|
habit.id = id
|
||||||
habit.position = habits.size
|
habit.position = habits.size
|
||||||
habits[id] = habit
|
habits[id] = habit
|
||||||
checkmarks[habit] = CheckmarkList(habit.frequency)
|
checkmarks[habit] = CheckmarkList(habit.frequency, habit.type)
|
||||||
habitsRepository.insert(habit)
|
habitsRepository.insert(habit)
|
||||||
mainScreenDataSource.requestData()
|
mainScreenDataSource.requestData()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ class MainScreenDataSource(val preferences: Preferences,
|
|||||||
|
|
||||||
if (!preferences.showCompleted) {
|
if (!preferences.showCompleted) {
|
||||||
filtered = filtered.filter { habit ->
|
filtered = filtered.filter { habit ->
|
||||||
recentCheckmarks.getValue(habit)[0] == UNCHECKED
|
(habit.type == HabitType.BOOLEAN_HABIT && recentCheckmarks.getValue(habit)[0] == UNCHECKED) ||
|
||||||
|
(habit.type == HabitType.NUMERICAL_HABIT && recentCheckmarks.getValue(habit)[0] * 1000 < habit.target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ import org.isoron.uhabits.models.Checkmark.Companion.CHECKED_AUTOMATIC
|
|||||||
import org.isoron.uhabits.models.Checkmark.Companion.CHECKED_MANUAL
|
import org.isoron.uhabits.models.Checkmark.Companion.CHECKED_MANUAL
|
||||||
import org.isoron.uhabits.models.Checkmark.Companion.UNCHECKED
|
import org.isoron.uhabits.models.Checkmark.Companion.UNCHECKED
|
||||||
|
|
||||||
class CheckmarkList(private val frequency: Frequency) {
|
class CheckmarkList(private val frequency: Frequency,
|
||||||
|
private val habitType: HabitType) {
|
||||||
|
|
||||||
private val manualCheckmarks = mutableListOf<Checkmark>()
|
private val manualCheckmarks = mutableListOf<Checkmark>()
|
||||||
private val automaticCheckmarks = mutableListOf<Checkmark>()
|
private val automaticCheckmarks = mutableListOf<Checkmark>()
|
||||||
@@ -37,8 +38,12 @@ class CheckmarkList(private val frequency: Frequency) {
|
|||||||
manualCheckmarks.clear()
|
manualCheckmarks.clear()
|
||||||
automaticCheckmarks.clear()
|
automaticCheckmarks.clear()
|
||||||
manualCheckmarks.addAll(checks)
|
manualCheckmarks.addAll(checks)
|
||||||
automaticCheckmarks.addAll(computeAutomaticCheckmarks(checks,
|
if (habitType == HabitType.NUMERICAL_HABIT) {
|
||||||
frequency))
|
automaticCheckmarks.addAll(checks)
|
||||||
|
} else {
|
||||||
|
val computed = computeAutomaticCheckmarks(checks, frequency)
|
||||||
|
automaticCheckmarks.addAll(computed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class HabitRepository(var db: Database) {
|
|||||||
position = stmt.getInt(7),
|
position = stmt.getInt(7),
|
||||||
unit = stmt.getText(8),
|
unit = stmt.getText(8),
|
||||||
target = stmt.getReal(9),
|
target = stmt.getReal(9),
|
||||||
type = if (stmt.getInt(10) == 0) HabitType.YES_NO_HABIT else HabitType.NUMERICAL_HABIT)
|
type = if (stmt.getInt(10) == 0) HabitType.BOOLEAN_HABIT else HabitType.NUMERICAL_HABIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bindHabitToStatement(habit: Habit, statement: PreparedStatement) {
|
private fun bindHabitToStatement(habit: Habit, statement: PreparedStatement) {
|
||||||
|
|||||||
@@ -20,6 +20,6 @@
|
|||||||
package org.isoron.uhabits.models
|
package org.isoron.uhabits.models
|
||||||
|
|
||||||
enum class HabitType(val code: Int) {
|
enum class HabitType(val code: Int) {
|
||||||
YES_NO_HABIT(0),
|
BOOLEAN_HABIT(0),
|
||||||
NUMERICAL_HABIT(1),
|
NUMERICAL_HABIT(1),
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ class CheckmarkListTest : BaseTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGetValuesUntil() {
|
fun testGetValuesUntil() {
|
||||||
val list = CheckmarkList(Frequency(1, 2))
|
val list = CheckmarkList(Frequency(1, 2), HabitType.BOOLEAN_HABIT)
|
||||||
list.setManualCheckmarks(listOf(Checkmark(day(4), CHECKED_MANUAL),
|
list.setManualCheckmarks(listOf(Checkmark(day(4), CHECKED_MANUAL),
|
||||||
Checkmark(day(7), CHECKED_MANUAL)))
|
Checkmark(day(7), CHECKED_MANUAL)))
|
||||||
val expected = listOf(UNCHECKED,
|
val expected = listOf(UNCHECKED,
|
||||||
@@ -182,7 +182,7 @@ class CheckmarkListTest : BaseTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGetValuesUntil2() {
|
fun testGetValuesUntil2() {
|
||||||
val list = CheckmarkList(Frequency(1, 2))
|
val list = CheckmarkList(Frequency(1, 2), HabitType.BOOLEAN_HABIT)
|
||||||
val expected = listOf<Int>()
|
val expected = listOf<Int>()
|
||||||
assertEquals(expected, list.getValuesUntil(day(0)))
|
assertEquals(expected, list.getValuesUntil(day(0)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class HabitRepositoryTest : BaseTest() {
|
|||||||
position = 0,
|
position = 0,
|
||||||
unit = "",
|
unit = "",
|
||||||
target = 0.0,
|
target = 0.0,
|
||||||
type = HabitType.YES_NO_HABIT)
|
type = HabitType.BOOLEAN_HABIT)
|
||||||
|
|
||||||
original1 = Habit(id = 1,
|
original1 = Habit(id = 1,
|
||||||
name = "Exercise",
|
name = "Exercise",
|
||||||
@@ -55,7 +55,7 @@ class HabitRepositoryTest : BaseTest() {
|
|||||||
position = 1,
|
position = 1,
|
||||||
unit = "",
|
unit = "",
|
||||||
target = 0.0,
|
target = 0.0,
|
||||||
type = HabitType.YES_NO_HABIT)
|
type = HabitType.BOOLEAN_HABIT)
|
||||||
|
|
||||||
original2 = Habit(id = 2,
|
original2 = Habit(id = 2,
|
||||||
name = "Learn Japanese",
|
name = "Learn Japanese",
|
||||||
@@ -66,7 +66,7 @@ class HabitRepositoryTest : BaseTest() {
|
|||||||
position = 2,
|
position = 2,
|
||||||
unit = "",
|
unit = "",
|
||||||
target = 0.0,
|
target = 0.0,
|
||||||
type = HabitType.YES_NO_HABIT)
|
type = HabitType.BOOLEAN_HABIT)
|
||||||
|
|
||||||
repository = HabitRepository(db)
|
repository = HabitRepository(db)
|
||||||
}
|
}
|
||||||
|
|||||||
23
ios/Application/Frontend/AboutScreenController.swift
Normal file
23
ios/Application/Frontend/AboutScreenController.swift
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
class AboutScreenController : UITableViewController {
|
||||||
|
}
|
||||||
@@ -33,7 +33,6 @@ class MainScreenCell : UITableViewCell {
|
|||||||
|
|
||||||
let stack = UIStackView(frame: contentView.frame)
|
let stack = UIStackView(frame: contentView.frame)
|
||||||
stack.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
stack.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||||
stack.backgroundColor = .red
|
|
||||||
stack.axis = .horizontal
|
stack.axis = .horizontal
|
||||||
stack.distribution = .fill
|
stack.distribution = .fill
|
||||||
stack.alignment = .center
|
stack.alignment = .center
|
||||||
@@ -48,7 +47,7 @@ class MainScreenCell : UITableViewCell {
|
|||||||
label.heightAnchor.constraint(equalToConstant: size).isActive = true
|
label.heightAnchor.constraint(equalToConstant: size).isActive = true
|
||||||
stack.addArrangedSubview(label)
|
stack.addArrangedSubview(label)
|
||||||
|
|
||||||
for _ in 1...3 {
|
for _ in 1...4 {
|
||||||
let btn = ComponentView(frame: frame, component: nil)
|
let btn = ComponentView(frame: frame, component: nil)
|
||||||
btn.backgroundColor = .white
|
btn.backgroundColor = .white
|
||||||
btn.widthAnchor.constraint(equalToConstant: size).isActive = true
|
btn.widthAnchor.constraint(equalToConstant: size).isActive = true
|
||||||
@@ -75,9 +74,17 @@ class MainScreenCell : UITableViewCell {
|
|||||||
ring.setNeedsDisplay()
|
ring.setNeedsDisplay()
|
||||||
|
|
||||||
for i in 0..<buttons.count {
|
for i in 0..<buttons.count {
|
||||||
|
if habit.type == .numerical {
|
||||||
|
buttons[i].component = NumberButton(color: color,
|
||||||
|
value: Double(truncating: values[i]) / 1000.0,
|
||||||
|
threshold: habit.target,
|
||||||
|
units: habit.unit,
|
||||||
|
theme: theme)
|
||||||
|
} else {
|
||||||
buttons[i].component = CheckmarkButton(value: Int32(truncating: values[i]),
|
buttons[i].component = CheckmarkButton(value: Int32(truncating: values[i]),
|
||||||
color: color,
|
color: color,
|
||||||
theme: theme)
|
theme: theme)
|
||||||
|
}
|
||||||
buttons[i].setNeedsDisplay()
|
buttons[i].setNeedsDisplay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,11 +220,13 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener
|
|||||||
|
|
||||||
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
|
if let link = URL(string: "http://loophabits.org/faq") {
|
||||||
|
UIApplication.shared.open(link)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
alert.addAction(UIAlertAction(title: strings.about, style: .default) {
|
alert.addAction(UIAlertAction(title: strings.about, style: .default) {
|
||||||
(action: UIAlertAction) -> Void in
|
(action: UIAlertAction) -> Void in
|
||||||
// TODO
|
self.navigationController?.pushViewController(AboutScreenController(), animated: true)
|
||||||
})
|
})
|
||||||
alert.addAction(UIAlertAction(title: strings.cancel, style: .cancel) {
|
alert.addAction(UIAlertAction(title: strings.cancel, style: .cancel) {
|
||||||
(action: UIAlertAction) -> Void in
|
(action: UIAlertAction) -> Void in
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
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 */; };
|
||||||
|
006EFE50225432B8008464E0 /* AboutScreenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006EFE4F225432B8008464E0 /* AboutScreenController.swift */; };
|
||||||
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42722009F590024E00C /* AppDelegate.swift */; };
|
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42722009F590024E00C /* AppDelegate.swift */; };
|
||||||
00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42922009F590024E00C /* MainScreenController.swift */; };
|
00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42922009F590024E00C /* MainScreenController.swift */; };
|
||||||
00A5B42F22009F5A0024E00C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 00A5B42E22009F5A0024E00C /* Assets.xcassets */; };
|
00A5B42F22009F5A0024E00C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 00A5B42E22009F5A0024E00C /* Assets.xcassets */; };
|
||||||
@@ -59,6 +60,7 @@
|
|||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
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>"; };
|
||||||
|
006EFE4F225432B8008464E0 /* AboutScreenController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutScreenController.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; };
|
||||||
00A5B42722009F590024E00C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
00A5B42722009F590024E00C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
00A5B42922009F590024E00C /* MainScreenController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScreenController.swift; sourceTree = "<group>"; };
|
00A5B42922009F590024E00C /* MainScreenController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScreenController.swift; sourceTree = "<group>"; };
|
||||||
@@ -108,9 +110,10 @@
|
|||||||
006EFE49224FF41B008464E0 /* Frontend */ = {
|
006EFE49224FF41B008464E0 /* Frontend */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
006EFE4F225432B8008464E0 /* AboutScreenController.swift */,
|
||||||
|
00C0C6DE224A35FC003D8AF0 /* DetailScreenController.swift */,
|
||||||
00D48BD22200AC1600CC4527 /* EditHabitController.swift */,
|
00D48BD22200AC1600CC4527 /* EditHabitController.swift */,
|
||||||
00A5B42922009F590024E00C /* MainScreenController.swift */,
|
00A5B42922009F590024E00C /* MainScreenController.swift */,
|
||||||
00C0C6DE224A35FC003D8AF0 /* DetailScreenController.swift */,
|
|
||||||
);
|
);
|
||||||
path = Frontend;
|
path = Frontend;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -338,6 +341,7 @@
|
|||||||
00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */,
|
00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */,
|
||||||
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */,
|
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */,
|
||||||
00D48BD32200AC1600CC4527 /* EditHabitController.swift in Sources */,
|
00D48BD32200AC1600CC4527 /* EditHabitController.swift in Sources */,
|
||||||
|
006EFE50225432B8008464E0 /* AboutScreenController.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user