Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Allow users to create groups of habits #2020

Draft
wants to merge 51 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9bfae97
Upgrade gradle version
May 12, 2024
ec08b60
Skip days implemented. Scores not correct yet
May 18, 2024
f5da00a
All scores, frequency, history, etc. corrected for the skip days feat…
May 20, 2024
c764461
Change db version
May 20, 2024
053bfe1
Fix linting
May 20, 2024
340bde9
Create HabitGroup and HabitGroup list classes
May 23, 2024
73387e5
Creating the Habitgroup model
May 26, 2024
262b49d
Adding Habitgroup to type selection screen
May 26, 2024
832d51a
Make HabitGroups simpler
May 28, 2024
2146ce7
Revert "Skip days implemented. Scores not correct yet"
Jun 25, 2024
08113a5
Remove SkipDays feature
Jun 25, 2024
af3283e
Can create habit groups now
Jun 26, 2024
506086f
Can show habit group without interaction / scrolling
Jul 1, 2024
676f141
Implement scrolling with group
Jul 1, 2024
17e6c4f
Fix habit group creation
Jul 2, 2024
cac62c0
Add Habits to groups without displaying
Jul 2, 2024
a2cf78f
Add show habit group activity
Jul 3, 2024
0a1cdd4
Implement edit habit group activity
Jul 3, 2024
35c9a1a
Implement listing sub habits
Jul 5, 2024
6ff9c2d
Implement show sub habits
Jul 5, 2024
b043c90
Implement edits sub habits
Jul 5, 2024
c1f0dae
Implement habit group score ring, sorting sub habits (except with score)
Jul 6, 2024
c060249
Fixed sorting habit groups and sub habits by score
Jul 6, 2024
c77da18
Implement saving of sub habits but breaks updating group score ring
Jul 6, 2024
be81a06
Sub habits and groups are filtered correctly
Jul 6, 2024
8df1fb7
Implement sub habit reordering within group
Jul 6, 2024
26260fb
Implement partial reordering or habit groups
Jul 7, 2024
584aace
Fix filtering by status
Jul 7, 2024
3ba214f
Fix streaks of HabitGroups
Jul 7, 2024
6b1eed0
Fix updating of group score ring on appropriate action
Jul 7, 2024
186d672
Implement all widgets for sub habits
Jul 7, 2024
30b124a
Implement all relevant card views for habit groups
Jul 9, 2024
32c6977
Make ids unique across both habits and groups
Jul 9, 2024
8fac8af
Implement notifications for both habit groups and sub habits
Jul 10, 2024
6abea29
Implement score and frequency widgets for habit groups
Jul 11, 2024
0de7c7f
Change implementation to use ids instead of uuids
Jul 11, 2024
fc16c70
Fix database issues
Jul 13, 2024
d9213ed
Implement option to remove sub habits from groups
Jul 13, 2024
811b818
Implement collapsible habit groups
Jul 13, 2024
e85f582
Implement Add existing habits to existing groups
Jul 14, 2024
0ae5a53
Fix entries of transferred habits and dragging and dropping of groups
Jul 14, 2024
57b3b9d
Fix position of ringview of subhabits after removed from the group
Jul 14, 2024
f5ca6b0
Fix displaying empty habit group
Jul 14, 2024
68b4beb
Fix collapsing and sorting of collapsed groups
Jul 23, 2024
34a7f78
New subhabit inherits color of habit group
Jul 23, 2024
7a2d486
Implement import from db
Jul 24, 2024
8043cb2
Unit tests for habit group
Jul 24, 2024
5ba2001
Fix for editing standalone habits
Jul 24, 2024
4e70c38
Models unit tests and fix sorting of habitgrouplist
Aug 15, 2024
e65ed03
Database test fix
Aug 15, 2024
bad674d
Rest of unit tests in uhabits-core
Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
val kotlinVersion = "1.9.22"
id("com.android.application") version "8.1.4" apply (false)
id("com.android.application") version "8.4.0" apply (false)
id("org.jetbrains.kotlin.android") version kotlinVersion apply (false)
id("org.jetbrains.kotlin.kapt") version kotlinVersion apply (false)
id("org.jetbrains.kotlin.multiplatform") version kotlinVersion apply (false)
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
org.gradle.java.installations.auto-download=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion uhabits-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

plugins {
id("com.github.triplet.play") version "3.8.6"
id("com.android.application") version "8.1.4"
id("com.android.application") version "8.4.0"
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.kapt")
id("org.jlleitschuh.gradle.ktlint")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class HabitCardViewTest : BaseViewTest() {
.getByInterval(today.minus(300), today)
.map { it.value }.toIntArray()

view = component.getHabitCardViewFactory().create().apply {
view = component.getHabitCardViewFactory().createHabitCard().apply {
habit = habit1
values = entries
score = habit1.scores[today].value
Expand Down
33 changes: 33 additions & 0 deletions uhabits-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
android:value=".activities.habits.list.ListHabitsActivity" />
</activity>

<activity
android:name=".activities.habits.list.HabitGroupPickerDialog"
android:exported="true">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.habits.list.ListHabitsActivity" />
</activity>

<activity
android:name=".activities.habits.edit.EditHabitGroupActivity"
android:exported="true">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.habits.list.ListHabitsActivity" />
</activity>

<meta-data
android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAI6aeWncbnMNo8E5GWeZ44dlc5cQ7tCROwFhOtiw" />
Expand Down Expand Up @@ -72,6 +88,14 @@
android:value=".activities.habits.list.ListHabitsActivity" />
</activity>

<activity
android:name=".activities.habits.show.ShowHabitGroupActivity"
android:label="@string/title_activity_show_habit">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.habits.list.ListHabitsActivity" />
</activity>

<activity
android:name=".activities.settings.SettingsActivity"
android:label="@string/settings">
Expand Down Expand Up @@ -112,6 +136,15 @@
</intent-filter>
</activity>

<activity
android:name=".widgets.activities.HabitAndGroupPickerDialog"
android:exported="true"
android:theme="@style/Theme.AppCompat.Light.Dialog">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>

<activity
android:name=".activities.about.AboutActivity"
android:label="@string/about">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class HabitsApplication : Application() {
val habitList = component.habitList
for (h in habitList) h.recompute()

val habitGroupList = component.habitGroupList
for (hgr in habitGroupList) hgr.recompute()
habitGroupList.attachHabitsToGroups()

widgetUpdater = component.widgetUpdater.apply {
startListening()
scheduleStartDayWidgetUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.isoron.uhabits.activities

import org.isoron.uhabits.AndroidDirFinder
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitGroupMenuPresenter
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitMenuPresenter
import java.io.File
import javax.inject.Inject
Expand All @@ -33,3 +34,13 @@ constructor(
return androidDirFinder.getFilesDir("CSV")!!
}
}

class HabitGroupsDirFinder @Inject
constructor(
private val androidDirFinder: AndroidDirFinder
) : ShowHabitGroupMenuPresenter.System, ListHabitsBehavior.DirFinder {

override fun getCSVOutputDir(): File {
return androidDirFinder.getFilesDir("CSV")!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ import org.isoron.uhabits.activities.common.dialogs.WeekdayPickerDialog
import org.isoron.uhabits.core.commands.CommandRunner
import org.isoron.uhabits.core.commands.CreateHabitCommand
import org.isoron.uhabits.core.commands.EditHabitCommand
import org.isoron.uhabits.core.commands.RefreshParentGroupCommand
import org.isoron.uhabits.core.models.Frequency
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.HabitGroup
import org.isoron.uhabits.core.models.HabitType
import org.isoron.uhabits.core.models.NumericalHabitType
import org.isoron.uhabits.core.models.PaletteColor
Expand Down Expand Up @@ -76,6 +77,7 @@ class EditHabitActivity : AppCompatActivity() {

var habitId = -1L
lateinit var habitType: HabitType
var parentGroup: HabitGroup? = null
var unit = ""
var color = PaletteColor(11)
var androidColor = 0
Expand All @@ -96,10 +98,21 @@ class EditHabitActivity : AppCompatActivity() {
binding = ActivityEditHabitBinding.inflate(layoutInflater)
setContentView(binding.root)

if (intent.hasExtra("groupId")) {
val groupId = intent.getLongExtra("groupId", -1L)
parentGroup = component.habitGroupList.getById(groupId)
color = parentGroup!!.color
}

if (intent.hasExtra("habitId")) {
binding.toolbar.title = getString(R.string.edit_habit)
habitId = intent.getLongExtra("habitId", -1)
val habit = component.habitList.getById(habitId)!!
habitId = intent.getLongExtra("habitId", -1L)
val habitList = if (parentGroup != null) {
parentGroup!!.habitList
} else {
component.habitList
}
val habit = habitList.getById(habitId)!!
habitType = habit.type
color = habit.color
freqNum = habit.frequency.numerator
Expand Down Expand Up @@ -260,9 +273,14 @@ class EditHabitActivity : AppCompatActivity() {
val component = (application as HabitsApplication).component
val habit = component.modelFactory.buildHabit()

var original: Habit? = null
if (habitId >= 0) {
original = component.habitList.getById(habitId)!!
val habitList = if (parentGroup != null) {
parentGroup!!.habitList
} else {
component.habitList
}

if (habitId > 0) {
val original = habitList.getById(habitId)!!
habit.copyFrom(original)
}

Expand All @@ -283,21 +301,31 @@ class EditHabitActivity : AppCompatActivity() {
habit.unit = binding.unitInput.text.trim().toString()
}
habit.type = habitType
habit.group = parentGroup
habit.groupId = parentGroup?.id
habit.groupUUID = parentGroup?.uuid

val command = if (habitId >= 0) {
val command = if (habitId > 0) {
EditHabitCommand(
component.habitList,
habitList,
habitId,
habit
)
} else {
CreateHabitCommand(
component.modelFactory,
component.habitList,
habitList,
habit
)
}
component.commandRunner.run(command)

if (habit.groupId != null) {
val habitGroupList = component.habitGroupList
val refreshCommand = RefreshParentGroupCommand(habit, habitGroupList)
component.commandRunner.run(refreshCommand)
}

finish()
}

Expand Down
Loading