Skip to content

Commit

Permalink
Add feature-dashboard module
Browse files Browse the repository at this point in the history
  • Loading branch information
ofalvai committed Sep 16, 2022
1 parent e54914e commit 8c6e35b
Show file tree
Hide file tree
Showing 61 changed files with 578 additions and 393 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ dependencies {
implementation project(':core-common')
implementation project(':core-database')
implementation project(':core-ui')
implementation project(':core-model')
implementation project(':feature-dashboard')
implementation project(':feature-insights')
implementation project(':feature-misc')

Expand All @@ -137,31 +137,21 @@ dependencies {
implementation libs.compose.ui.toolingpreview
debugImplementation libs.compose.ui.tooling

implementation libs.kotlin.coroutines.core
implementation libs.kotlin.immutable

implementation libs.androidx.navigation.compose

implementation libs.androidx.room.runtime

implementation libs.logcat
implementation libs.calendarview
implementation libs.reorderable
implementation libs.accompanist.systemuicontroller
implementation libs.accompanist.navigation

// Required by layout inspector
debugRuntimeOnly libs.kotlin.reflect

implementation libs.showkase.annotation
debugImplementation libs.showkase.full
kspDebug libs.showkase.processor

testImplementation project(':core-testing')
testImplementation libs.junit
testImplementation libs.kotlin.coroutines.test
testImplementation libs.mockito.kotlin
testImplementation libs.turbine

androidTestImplementation project(':core-testing')
androidTestImplementation libs.kotlin.coroutines.test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ofalvai.habittracker.core.model.Habit
import com.ofalvai.habittracker.core.testing.BaseInstrumentedTest
import com.ofalvai.habittracker.core.ui.theme.PreviewTheme
import com.ofalvai.habittracker.ui.dashboard.AddHabitForm
import com.ofalvai.habittracker.feature.dashboard.ui.dashboard.AddHabitForm
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.VIBRATE" />

<application
android:name=".HabitTrackerApplication"
android:allowBackup="true"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/ofalvai/habittracker/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ import com.ofalvai.habittracker.core.common.OnboardingManager
import com.ofalvai.habittracker.core.common.TelemetryImpl
import com.ofalvai.habittracker.core.database.AppDatabase
import com.ofalvai.habittracker.core.database.MIGRATIONS
import com.ofalvai.habittracker.feature.dashboard.repo.ActionRepository
import com.ofalvai.habittracker.feature.dashboard.ui.dashboard.AddHabitViewModel
import com.ofalvai.habittracker.feature.dashboard.ui.dashboard.DashboardViewModel
import com.ofalvai.habittracker.feature.dashboard.ui.habitdetail.HabitDetailViewModel
import com.ofalvai.habittracker.feature.insights.ui.InsightsViewModel
import com.ofalvai.habittracker.feature.misc.archive.ArchiveViewModel
import com.ofalvai.habittracker.feature.misc.export.ExportViewModel
import com.ofalvai.habittracker.feature.misc.settings.AppInfo
import com.ofalvai.habittracker.feature.misc.settings.LicensesViewModel
import com.ofalvai.habittracker.feature.misc.settings.SettingsViewModel
import com.ofalvai.habittracker.repo.ActionRepository
import com.ofalvai.habittracker.ui.dashboard.AddHabitViewModel
import com.ofalvai.habittracker.ui.dashboard.DashboardViewModel
import com.ofalvai.habittracker.ui.habitdetail.HabitDetailViewModel
import logcat.logcat

object Dependencies {
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/ofalvai/habittracker/ui/Icons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@ object AppIcons {
val Insights: Painter
@Composable
get() = painterResource(R.drawable.ic_insights)

val DashboardLayout: Painter
@Composable
get() = painterResource(R.drawable.ic_dashboard_layout)
}
58 changes: 29 additions & 29 deletions app/src/main/java/com/ofalvai/habittracker/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Olivér Falvai
* Copyright 2022 Olivér Falvai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,16 +43,17 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.ofalvai.habittracker.Dependencies
import com.ofalvai.habittracker.R
import com.ofalvai.habittracker.core.common.Telemetry
import com.ofalvai.habittracker.core.model.HabitId
import com.ofalvai.habittracker.core.ui.theme.AppTheme
import com.ofalvai.habittracker.core.ui.theme.CoreIcons
import com.ofalvai.habittracker.feature.dashboard.ui.dashboard.AddHabitScreen
import com.ofalvai.habittracker.feature.dashboard.ui.dashboard.DashboardScreen
import com.ofalvai.habittracker.feature.dashboard.ui.habitdetail.HabitDetailScreen
import com.ofalvai.habittracker.feature.insights.ui.InsightsScreen
import com.ofalvai.habittracker.feature.misc.archive.ArchiveScreen
import com.ofalvai.habittracker.feature.misc.export.ExportScreen
import com.ofalvai.habittracker.feature.misc.settings.LicensesScreen
import com.ofalvai.habittracker.feature.misc.settings.SettingsScreen
import com.ofalvai.habittracker.ui.dashboard.AddHabitScreen
import com.ofalvai.habittracker.ui.dashboard.DashboardScreen
import com.ofalvai.habittracker.ui.habitdetail.HabitDetailScreen
import com.ofalvai.habittracker.ui.settings.DebugSettings

class MainActivity : ComponentActivity() {
Expand Down Expand Up @@ -103,31 +104,45 @@ private fun Screens(
) {
val vmFactory = Dependencies.viewModelFactory
val navigateBack: () -> Unit = { navController.popBackStack() }
val navigateToSettings: () -> Unit = { navController.navigate(Destination.Settings.route) }
val navigateToArchive: () -> Unit = { navController.navigate(Destination.Archive.route) }
val navigateToExport: () -> Unit = { navController.navigate(Destination.Export.route) }
val navigateToHabitDetails: (HabitId) -> Unit = { habitId ->
val route = Destination.HabitDetails.buildRoute(habitId = habitId)
navController.navigate(route)
}

AnimatedNavHost(
navController,
startDestination = Destination.Dashboard.route,
modifier = Modifier.padding(padding).fillMaxSize()
) {
appDestination(Destination.Dashboard) { DashboardScreen(vmFactory, navController, scaffoldState) }
appDestination(Destination.Dashboard) {
DashboardScreen(
vmFactory,
scaffoldState,
navigateToHabitDetails,
navigateToAddHabit = { navController.navigate(Destination.AddHabit.route) },
navigateToSettings,
navigateToArchive,
navigateToExport
)
}
appDestination(Destination.Insights) {
InsightsScreen(
vmFactory,
navigateToArchive = { navController.navigate(Destination.Archive.route) },
navigateToSettings = { navController.navigate(Destination.Settings.route) },
navigateToExport = { navController.navigate(Destination.Export.route) },
navigateToHabitDetails = { habitId ->
val route = Destination.HabitDetails.buildRoute(habitId = habitId)
navController.navigate(route)
}
navigateToArchive = navigateToArchive,
navigateToSettings = navigateToSettings,
navigateToExport = navigateToExport,
navigateToHabitDetails = navigateToHabitDetails
)
}
appDestination(Destination.AddHabit) { AddHabitScreen(vmFactory, navController) }
appDestination(Destination.AddHabit) { AddHabitScreen(vmFactory, navigateBack) }
appDestination(Destination.HabitDetails) { backStackEntry ->
HabitDetailScreen(
vmFactory,
habitId = Destination.HabitDetails.idFrom(backStackEntry.arguments),
navController = navController
navigateBack
)
}
appDestination(Destination.Settings) {
Expand All @@ -152,21 +167,6 @@ private fun Screens(
}
}

@Composable
fun TextFieldError(
modifier: Modifier = Modifier,
textError: String
) {
Row(modifier = modifier.fillMaxWidth()) {
Spacer(modifier = Modifier.width(16.dp))
Text(
text = textError,
modifier = Modifier.fillMaxWidth(),
style = LocalTextStyle.current.copy(color = MaterialTheme.colors.error)
)
}
}

@Composable
private fun AppBottomNavigation(navController: NavController) {
// Recreating the BottomNavigation() composable because window insets and elevation don't play
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Olivér Falvai
* Copyright 2022 Olivér Falvai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
60 changes: 0 additions & 60 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,7 @@
<resources>
<string name="app_name">HabitTracker</string>

<string name="addhabit_appbar_title">Create new habit</string>
<string name="addhabit_name_label">Habit name</string>
<string name="addhabit_name_error">Enter a name for new habit</string>
<string name="addhabit_notes_label">Notes</string>
<string name="addhabit_notes_description">Recording the exact time and location of the new habit increases the odds of sticking to it. Avoid vague habits like \"Exercise more\".</string>
<string name="addhabit_save">Create habit</string>

<string name="dashboard_title">My habits</string>
<string name="dashboard_change_layout">Change layout</string>
<string name="dashboard_empty_label">You don\'t have any habits yet.</string>
<string name="dashboard_toggle_help">Long press to toggle</string>
<string name="dashboard_create_habit">Create new habit</string>
<string name="dashboard_create_habit_first">Create your first habit</string>
<string name="dashboard_item_details">Habit details</string>
<string name="dashboard_error">Failed to load habit list</string>
<string name="dashboard_error_toggle_action">Failed to save action</string>
<string name="dashboard_error_item_move">Failed to move habit, try again</string>
<string name="dashboard_event_action_performed">Well done!</string>
<string name="dashboard_config_dialog_title">Choose a layout</string>
<string name="dashboard_config_dialog_fiveday">Five day</string>
<string name="dashboard_config_dialog_compact">Compact</string>

<string name="habit_suggestion_meditation">Meditate</string>
<string name="habit_suggestion_workout">Exercise for 10 min</string>
<string name="habit_suggestion_reading">Read for 20 min</string>
<string name="habit_suggestion_walk">Go for a walk</string>
<string name="habit_suggestion_plan_my_day">Plan my day</string>
<string name="habit_suggestion_stretch">Stretch after wakeup</string>
<string name="habit_suggestion_go_to_bed">Go to bed early</string>
<string name="habit_suggestion_journal">Write in my journal</string>
<string name="habit_suggestion_spend_time">Spend time with…</string>

<string name="tab_dashboard">Habits</string>
<string name="tab_insights">Insights</string>

<string name="common_action_count_clean">Start today</string>
<plurals name="common_action_count_total">
<item quantity="one">%d total</item>
<item quantity="other">%d total</item>
</plurals>
<plurals name="common_action_count_streak">
<item quantity="one">%d day streak</item>
<item quantity="other">%d day streak</item>
</plurals>
<plurals name="common_action_count_missed_days">
<item quantity="one">%d missed day</item>
<item quantity="other">%d missed days</item>
</plurals>

<string name="habitdetails_singlestat_total">times total</string>
<string name="habitdetails_singlestat_weekly">times this week</string>
<string name="habitdetails_singlestat_completionrate">completion rate</string>
<string name="habitdetails_archive_confirm">Archive</string>
<string name="habitdetails_archive_title">Archive habit?</string>
<string name="habitdetails_archive_description">This habit will be moved to the archive. If you change your mind, you can unarchive the habit without data loss, or delete it forever.</string>
<string name="habitdetails_edit_name_label">Name</string>
<string name="habitdetails_edit_notes_label">Notes</string>
<string name="habitdetails_error">Failed to load habit details</string>
<string name="habitdetails_error_stats">Failed to load habit statistics</string>
<string name="habitdetails_actioncount_selector_label">Times a</string>
<string name="habitdetails_actioncount_selector_weekly">Week</string>
<string name="habitdetails_actioncount_selector_monthly">Month</string>

</resources>
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ plugins {
alias(libs.plugins.gradle.buildtimetracker)
alias(libs.plugins.gradle.cachefix) apply false // Applied in convention plugins
alias(libs.plugins.dependencyanalysis)
id 'com.android.library' version '7.3.0-rc01' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

doctor {
Expand Down
5 changes: 5 additions & 0 deletions core-ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
id 'habittracker.android.library.compose'
}

apply plugin: 'com.google.devtools.ksp'

android {
namespace 'com.ofalvai.habittracker.core.ui'
}
Expand All @@ -14,4 +16,7 @@ dependencies {
implementation libs.compose.ui.googlefonts
implementation libs.androidx.lifecycle.runtime
implementation libs.kotlin.coroutines.core

implementation libs.showkase.annotation
kspDebug libs.showkase.processor
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2022 Olivér Falvai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.ofalvai.habittracker.core.ui.component

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun TextFieldError(
modifier: Modifier = Modifier,
textError: String
) {
Row(modifier = modifier.fillMaxWidth()) {
Spacer(modifier = Modifier.width(16.dp))
Text(
text = textError,
modifier = Modifier.fillMaxWidth(),
style = LocalTextStyle.current.copy(color = MaterialTheme.colors.error)
)
}
}
1 change: 1 addition & 0 deletions feature-dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions feature-dashboard/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id 'habittracker.android.library'
id 'habittracker.android.library.compose'
}

apply plugin: 'com.google.devtools.ksp'

android {
namespace 'com.ofalvai.habittracker.feature.dashboard'
}

dependencies {
api project(':core-common')
api project(':core-database')
api project(':core-model')
implementation project(':core-ui')

implementation libs.kotlin.immutable
implementation libs.androidx.lifecycle.viewmodel.compose
implementation libs.calendarview
implementation libs.reorderable

implementation libs.showkase.annotation
kspDebug libs.showkase.processor

testImplementation project(':core-testing')
testImplementation libs.junit
testImplementation libs.kotlin.coroutines.test
testImplementation libs.mockito.kotlin
testImplementation libs.turbine
}
Loading

0 comments on commit 8c6e35b

Please sign in to comment.