From 33bae657a32defbf422fe5e94d118cc8f3065da2 Mon Sep 17 00:00:00 2001 From: Alinson Xavier Date: Tue, 2 Apr 2019 20:16:00 -0500 Subject: [PATCH] Show numerical habits --- .../org/isoron/uhabits/backend/Backend.kt | 4 ++-- .../uhabits/backend/MainScreenDataSource.kt | 3 ++- .../isoron/uhabits/models/CheckmarkList.kt | 11 ++++++--- .../isoron/uhabits/models/HabitRepository.kt | 2 +- .../org/isoron/uhabits/models/HabitType.kt | 2 +- .../uhabits/models/CheckmarkListTest.kt | 4 ++-- .../uhabits/models/HabitRepositoryTest.kt | 6 ++--- .../Frontend/AboutScreenController.swift | 23 +++++++++++++++++++ .../Frontend/MainScreenController.swift | 23 +++++++++++++------ ios/uhabits.xcodeproj/project.pbxproj | 6 ++++- 10 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 ios/Application/Frontend/AboutScreenController.swift diff --git a/core/src/commonMain/kotlin/org/isoron/uhabits/backend/Backend.kt b/core/src/commonMain/kotlin/org/isoron/uhabits/backend/Backend.kt index ecb18cdd6..c1ca28607 100644 --- a/core/src/commonMain/kotlin/org/isoron/uhabits/backend/Backend.kt +++ b/core/src/commonMain/kotlin/org/isoron/uhabits/backend/Backend.kt @@ -66,7 +66,7 @@ class Backend(databaseName: String, habits.putAll(habitsRepository.findAll()) for ((key, habit) in habits) { val checks = checkmarkRepository.findAll(key) - checkmarks[habit] = CheckmarkList(habit.frequency) + checkmarks[habit] = CheckmarkList(habit.frequency, habit.type) checkmarks[habit]?.setManualCheckmarks(checks) } } @@ -81,7 +81,7 @@ class Backend(databaseName: String, habit.id = id habit.position = habits.size habits[id] = habit - checkmarks[habit] = CheckmarkList(habit.frequency) + checkmarks[habit] = CheckmarkList(habit.frequency, habit.type) habitsRepository.insert(habit) mainScreenDataSource.requestData() } diff --git a/core/src/commonMain/kotlin/org/isoron/uhabits/backend/MainScreenDataSource.kt b/core/src/commonMain/kotlin/org/isoron/uhabits/backend/MainScreenDataSource.kt index ba69e0c55..76a36e8b1 100644 --- a/core/src/commonMain/kotlin/org/isoron/uhabits/backend/MainScreenDataSource.kt +++ b/core/src/commonMain/kotlin/org/isoron/uhabits/backend/MainScreenDataSource.kt @@ -57,7 +57,8 @@ class MainScreenDataSource(val preferences: Preferences, if (!preferences.showCompleted) { 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) } } diff --git a/core/src/commonMain/kotlin/org/isoron/uhabits/models/CheckmarkList.kt b/core/src/commonMain/kotlin/org/isoron/uhabits/models/CheckmarkList.kt index 9a9be2b8d..87ea7fc51 100644 --- a/core/src/commonMain/kotlin/org/isoron/uhabits/models/CheckmarkList.kt +++ b/core/src/commonMain/kotlin/org/isoron/uhabits/models/CheckmarkList.kt @@ -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.UNCHECKED -class CheckmarkList(private val frequency: Frequency) { +class CheckmarkList(private val frequency: Frequency, + private val habitType: HabitType) { private val manualCheckmarks = mutableListOf() private val automaticCheckmarks = mutableListOf() @@ -37,8 +38,12 @@ class CheckmarkList(private val frequency: Frequency) { manualCheckmarks.clear() automaticCheckmarks.clear() manualCheckmarks.addAll(checks) - automaticCheckmarks.addAll(computeAutomaticCheckmarks(checks, - frequency)) + if (habitType == HabitType.NUMERICAL_HABIT) { + automaticCheckmarks.addAll(checks) + } else { + val computed = computeAutomaticCheckmarks(checks, frequency) + automaticCheckmarks.addAll(computed) + } } /** diff --git a/core/src/commonMain/kotlin/org/isoron/uhabits/models/HabitRepository.kt b/core/src/commonMain/kotlin/org/isoron/uhabits/models/HabitRepository.kt index f66520cfb..961956f51 100644 --- a/core/src/commonMain/kotlin/org/isoron/uhabits/models/HabitRepository.kt +++ b/core/src/commonMain/kotlin/org/isoron/uhabits/models/HabitRepository.kt @@ -75,7 +75,7 @@ class HabitRepository(var db: Database) { position = stmt.getInt(7), unit = stmt.getText(8), 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) { diff --git a/core/src/commonMain/kotlin/org/isoron/uhabits/models/HabitType.kt b/core/src/commonMain/kotlin/org/isoron/uhabits/models/HabitType.kt index 3fb8ba57f..a02beff5c 100644 --- a/core/src/commonMain/kotlin/org/isoron/uhabits/models/HabitType.kt +++ b/core/src/commonMain/kotlin/org/isoron/uhabits/models/HabitType.kt @@ -20,6 +20,6 @@ package org.isoron.uhabits.models enum class HabitType(val code: Int) { - YES_NO_HABIT(0), + BOOLEAN_HABIT(0), NUMERICAL_HABIT(1), } \ No newline at end of file diff --git a/core/src/jvmTest/kotlin/org/isoron/uhabits/models/CheckmarkListTest.kt b/core/src/jvmTest/kotlin/org/isoron/uhabits/models/CheckmarkListTest.kt index 6ecab8319..fdb5e19e6 100644 --- a/core/src/jvmTest/kotlin/org/isoron/uhabits/models/CheckmarkListTest.kt +++ b/core/src/jvmTest/kotlin/org/isoron/uhabits/models/CheckmarkListTest.kt @@ -159,7 +159,7 @@ class CheckmarkListTest : BaseTest() { @Test 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), Checkmark(day(7), CHECKED_MANUAL))) val expected = listOf(UNCHECKED, @@ -182,7 +182,7 @@ class CheckmarkListTest : BaseTest() { @Test fun testGetValuesUntil2() { - val list = CheckmarkList(Frequency(1, 2)) + val list = CheckmarkList(Frequency(1, 2), HabitType.BOOLEAN_HABIT) val expected = listOf() assertEquals(expected, list.getValuesUntil(day(0))) } diff --git a/core/src/jvmTest/kotlin/org/isoron/uhabits/models/HabitRepositoryTest.kt b/core/src/jvmTest/kotlin/org/isoron/uhabits/models/HabitRepositoryTest.kt index 013eb40a4..7e12b064b 100644 --- a/core/src/jvmTest/kotlin/org/isoron/uhabits/models/HabitRepositoryTest.kt +++ b/core/src/jvmTest/kotlin/org/isoron/uhabits/models/HabitRepositoryTest.kt @@ -44,7 +44,7 @@ class HabitRepositoryTest : BaseTest() { position = 0, unit = "", target = 0.0, - type = HabitType.YES_NO_HABIT) + type = HabitType.BOOLEAN_HABIT) original1 = Habit(id = 1, name = "Exercise", @@ -55,7 +55,7 @@ class HabitRepositoryTest : BaseTest() { position = 1, unit = "", target = 0.0, - type = HabitType.YES_NO_HABIT) + type = HabitType.BOOLEAN_HABIT) original2 = Habit(id = 2, name = "Learn Japanese", @@ -66,7 +66,7 @@ class HabitRepositoryTest : BaseTest() { position = 2, unit = "", target = 0.0, - type = HabitType.YES_NO_HABIT) + type = HabitType.BOOLEAN_HABIT) repository = HabitRepository(db) } diff --git a/ios/Application/Frontend/AboutScreenController.swift b/ios/Application/Frontend/AboutScreenController.swift new file mode 100644 index 000000000..f4cbe355b --- /dev/null +++ b/ios/Application/Frontend/AboutScreenController.swift @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2016-2019 Álinson Santos Xavier + * + * 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 . + */ + +import UIKit + +class AboutScreenController : UITableViewController { +} diff --git a/ios/Application/Frontend/MainScreenController.swift b/ios/Application/Frontend/MainScreenController.swift index 0f19ec95b..6a15df298 100644 --- a/ios/Application/Frontend/MainScreenController.swift +++ b/ios/Application/Frontend/MainScreenController.swift @@ -33,7 +33,6 @@ class MainScreenCell : UITableViewCell { let stack = UIStackView(frame: contentView.frame) stack.autoresizingMask = [.flexibleWidth, .flexibleHeight] - stack.backgroundColor = .red stack.axis = .horizontal stack.distribution = .fill stack.alignment = .center @@ -48,7 +47,7 @@ class MainScreenCell : UITableViewCell { label.heightAnchor.constraint(equalToConstant: size).isActive = true stack.addArrangedSubview(label) - for _ in 1...3 { + for _ in 1...4 { let btn = ComponentView(frame: frame, component: nil) btn.backgroundColor = .white btn.widthAnchor.constraint(equalToConstant: size).isActive = true @@ -75,9 +74,17 @@ class MainScreenCell : UITableViewCell { ring.setNeedsDisplay() for i in 0.. Void in - // TODO + if let link = URL(string: "http://loophabits.org/faq") { + UIApplication.shared.open(link) + } }) alert.addAction(UIAlertAction(title: strings.about, style: .default) { (action: UIAlertAction) -> Void in - // TODO + self.navigationController?.pushViewController(AboutScreenController(), animated: true) }) alert.addAction(UIAlertAction(title: strings.cancel, style: .cancel) { (action: UIAlertAction) -> Void in diff --git a/ios/uhabits.xcodeproj/project.pbxproj b/ios/uhabits.xcodeproj/project.pbxproj index 9c92cf952..9eff169a3 100644 --- a/ios/uhabits.xcodeproj/project.pbxproj +++ b/ios/uhabits.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 006EFE4C2252E9F3008464E0 /* IosLocaleTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006EFE4A2252E9D3008464E0 /* IosLocaleTest.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 */; }; 00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42922009F590024E00C /* MainScreenController.swift */; }; 00A5B42F22009F5A0024E00C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 00A5B42E22009F5A0024E00C /* Assets.xcassets */; }; @@ -59,6 +60,7 @@ /* Begin PBXFileReference section */ 006EFE4A2252E9D3008464E0 /* IosLocaleTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosLocaleTest.swift; sourceTree = ""; }; 006EFE4D2252EA2B008464E0 /* IosLocale.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosLocale.swift; sourceTree = ""; }; + 006EFE4F225432B8008464E0 /* AboutScreenController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutScreenController.swift; sourceTree = ""; }; 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 = ""; }; 00A5B42922009F590024E00C /* MainScreenController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScreenController.swift; sourceTree = ""; }; @@ -108,9 +110,10 @@ 006EFE49224FF41B008464E0 /* Frontend */ = { isa = PBXGroup; children = ( + 006EFE4F225432B8008464E0 /* AboutScreenController.swift */, + 00C0C6DE224A35FC003D8AF0 /* DetailScreenController.swift */, 00D48BD22200AC1600CC4527 /* EditHabitController.swift */, 00A5B42922009F590024E00C /* MainScreenController.swift */, - 00C0C6DE224A35FC003D8AF0 /* DetailScreenController.swift */, ); path = Frontend; sourceTree = ""; @@ -338,6 +341,7 @@ 00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */, 00A5B42822009F590024E00C /* AppDelegate.swift in Sources */, 00D48BD32200AC1600CC4527 /* EditHabitController.swift in Sources */, + 006EFE50225432B8008464E0 /* AboutScreenController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };