Skip to content

Commit

Permalink
⬆️ 1.3.5
Browse files Browse the repository at this point in the history
* 💚 navigated navigation
* 💚 Improved Habits
* 🔥 Improved Tasks
* 🔐 Made a class for Datastore
* 📦 Done with Categories
* 📦 Updated metadata and screenshots and added german translations
  • Loading branch information
shub39 authored Dec 11, 2024
1 parent aec6d8d commit 989645e
Show file tree
Hide file tree
Showing 63 changed files with 1,551 additions and 1,140 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
> [<img src="https://m3-markdown-badges.vercel.app/issues/1/2/shub39/Grit">]()
> [<img src="https://ziadoua.github.io/m3-Markdown-Badges/badges/Discord/discord2.svg">](https://discord.gg/https://discord.gg/nxA2hgtEKf)
> [!NOTE]
> This app is personalised for my use and some versions might break or
> corrupt past data you have saved. Please reconsider using this as
> your main habit tracker/tasks app
> ### Get On
>[<img src="https://f-droid.org/badge/get-it-on.png" alt="Get it on F-Droid" height="80">](https://f-droid.org/packages/com.shub39.grit)
>[<img src="https://gitlab.com/IzzyOnDroid/repo/-/raw/master/assets/IzzyOnDroid.png" height="80">](https://apt.izzysoft.de/packages/com.shub39.grit/latest)
Expand Down
6 changes: 4 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.ksp)
alias(libs.plugins.kotlin.serialization)
}

val appName = "Grit"
Expand All @@ -15,8 +16,8 @@ android {
applicationId = "com.shub39.grit"
minSdk = 29
targetSdk = 35
versionCode = 7
versionName = "1.3.4"
versionCode = 8
versionName = "1.3.5"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -86,6 +87,7 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
implementation(libs.androidx.core.splashscreen)
implementation(libs.kotlinx.serialization.json)

implementation(libs.androidx.room.runtime)
annotationProcessor(libs.androidx.room.compiler)
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
Binary file modified app/release/baselineProfiles/0/app-release.dm
Binary file not shown.
Binary file modified app/release/baselineProfiles/1/app-release.dm
Binary file not shown.
14 changes: 0 additions & 14 deletions app/src/main/java/com/shub39/grit/app/BottomAppBarDestination.kt

This file was deleted.

39 changes: 0 additions & 39 deletions app/src/main/java/com/shub39/grit/app/BottomBar.kt

This file was deleted.

150 changes: 117 additions & 33 deletions app/src/main/java/com/shub39/grit/app/Grit.kt
Original file line number Diff line number Diff line change
@@ -1,59 +1,143 @@
package com.shub39.grit.app

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.shub39.grit.core.presentation.SettingsPage
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import androidx.navigation.compose.rememberNavController
import com.shub39.grit.R
import com.shub39.grit.habits.presentation.HabitViewModel
import com.shub39.grit.habits.presentation.HabitsPage
import com.shub39.grit.tasks.presentation.TaskListViewModel
import com.shub39.grit.tasks.presentation.TaskPage
import com.shub39.grit.tasks.presentation.task_page.TaskPage
import com.shub39.grit.tasks.presentation.tasks_settings.TaskSettings
import org.koin.androidx.compose.koinViewModel

@Composable
fun Grit(
tvm: TaskListViewModel = koinViewModel(),
hvm: HabitViewModel = koinViewModel()
) {
var currentRoute: BottomAppBarDestination by remember { mutableStateOf(BottomAppBarDestination.TasksPage) }
val navController = rememberNavController()
var currentRoute: Routes by remember { mutableStateOf(Routes.TasksGraph) }

val taskPageState by tvm.tasksState.collectAsStateWithLifecycle()
val taskSettingsState by tvm.tasksSettings.collectAsStateWithLifecycle()
val habitsPageState by hvm.habitsPageState.collectAsStateWithLifecycle()

Scaffold(
bottomBar = {
BottomBar(
currentRoute = currentRoute,
onChange = { currentRoute = it }
)
floatingActionButton = {
AnimatedContent(
targetState = currentRoute,
label = "fab"
) {
when (it) {
Routes.HabitsPage -> {
FloatingActionButton(
onClick = {
navController.navigate(Routes.TasksGraph) {
launchSingleTop = true
}
}
) {
Icon(
painter = painterResource(R.drawable.round_checklist_24),
contentDescription = null
)
}
}

Routes.TasksPage -> {
FloatingActionButton(
onClick = {
navController.navigate(Routes.HabitGraph) {
launchSingleTop = true
}
}
) {
Icon(
painter = painterResource(R.drawable.round_alarm_24),
contentDescription = null
)
}
}

else -> {}
}
}
}
) { padding ->
NavHost(
navController = navController,
startDestination = Routes.TasksGraph,
modifier = Modifier.padding(padding),
enterTransition = { fadeIn(animationSpec = tween(300)) },
exitTransition = { fadeOut(animationSpec = tween(300)) },
popEnterTransition = { fadeIn(animationSpec = tween(300)) },
popExitTransition = { fadeOut(animationSpec = tween(300)) }
) {
navigation<Routes.TasksGraph>(
startDestination = Routes.TasksPage
) {
composable<Routes.TasksPage> {
currentRoute = Routes.TasksPage

TaskPage(
state = taskPageState,
action = tvm::taskPageAction,
onSettingsClick = {
navController.navigate(Routes.TasksSettings) {
launchSingleTop = true
}
}
)
}

composable<Routes.TasksSettings> {
currentRoute = Routes.TasksSettings

TaskSettings(
state = taskSettingsState,
action = tvm::tasksSettingsAction
)
}
}

navigation<Routes.HabitGraph>(
startDestination = Routes.HabitsPage
) {
composable<Routes.HabitsPage> {
currentRoute = Routes.HabitsPage

HabitsPage(
state = habitsPageState,
action = hvm::habitsPageAction,
onSettingsClick = {
navController.navigate(Routes.HabitsSettings) {
launchSingleTop = true
}
}
)
}

composable<Routes.HabitsSettings> {
currentRoute = Routes.HabitsSettings


}
}
}
) { innerPadding ->

AnimatedContent(
targetState = currentRoute,
modifier = Modifier.padding(innerPadding),
label = "page"
) {
when (it) {
BottomAppBarDestination.TasksPage -> {
TaskPage(
state = taskPageState,
action = tvm::taskPageAction
)
}
BottomAppBarDestination.HabitsPage -> {
HabitsPage(
state = habitsPageState,
action = hvm::habitsPageAction
)
}
BottomAppBarDestination.SettingsPage -> {
SettingsPage(tvm)
}
}
}
}

}
11 changes: 3 additions & 8 deletions app/src/main/java/com/shub39/grit/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.shub39.grit.core.data.GritDatastore
import com.shub39.grit.core.presentation.NotificationMethods.createNotificationChannel
import com.shub39.grit.core.presentation.GritTheme
import com.shub39.grit.core.presentation.createNotificationChannel
import org.koin.compose.KoinContext

class MainActivity : ComponentActivity() {
Expand All @@ -22,10 +19,8 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()

setContent {
val theme by GritDatastore.getTheme(this).collectAsState(initial = "Default")

GritTheme(theme = theme) {
// Initialising KoinContext, becuase of log warnings
GritTheme {
// Initialising KoinContext, because of log warnings
KoinContext {
Grit()
}
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/shub39/grit/app/Routes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.shub39.grit.app

import kotlinx.serialization.Serializable

@Serializable
sealed interface Routes {
@Serializable
data object HabitGraph: Routes

@Serializable
data object HabitsPage: Routes

@Serializable
data object HabitsSettings: Routes

@Serializable
data object TasksGraph: Routes

@Serializable
data object TasksPage: Routes

@Serializable
data object TasksSettings: Routes
}
32 changes: 11 additions & 21 deletions app/src/main/java/com/shub39/grit/core/data/GritDatastore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,25 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map

object GritDatastore {
private const val FILE_NAME = "settings.pb"
private val Context.dataStore by preferencesDataStore(name = FILE_NAME)
private val THEME = stringPreferencesKey("theme")
private val CLEAR_PREFERENCES = stringPreferencesKey("Daily")
private const val FILE_NAME = "settings.pb"

fun clearPreferences(context: Context): Flow<String> = context.dataStore.data
.catch {
Log.e(TAG, "clearPreferences: ", it)
}.map { preferences ->
preferences[CLEAR_PREFERENCES] ?: "Never"
}
class GritDatastore(
private val context: Context
) {

suspend fun setClearPreferences(context: Context, clear: String) {
context.dataStore.edit { settings ->
settings[CLEAR_PREFERENCES] = clear
}
}
private val Context.dataStore by preferencesDataStore(name = FILE_NAME)
private val clearPreference = stringPreferencesKey("clear_preference")

fun getTheme(context: Context): Flow<String> = context.dataStore.data
fun clearPreferences(): Flow<String> = context.dataStore.data
.catch {
Log.e(TAG, "getTheme: ", it)
Log.e(TAG, "clearPreferences: ", it)
}.map { preferences ->
preferences[THEME] ?: "Default"
preferences[clearPreference] ?: "Never"
}

suspend fun setTheme(context: Context, theme: String) {
suspend fun setClearPreferences(clear: String) {
context.dataStore.edit { settings ->
settings[THEME] = theme
settings[clearPreference] = clear
}
}

Expand Down
Loading

0 comments on commit 989645e

Please sign in to comment.