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

Review pr final #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

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

29 changes: 21 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ plugins {
id("org.jetbrains.kotlin.android")
id("com.google.dagger.hilt.android")
id ("kotlin-android")
id ("kotlin-kapt")
id("com.google.devtools.ksp")

}

android {
Expand All @@ -17,10 +18,19 @@ android {
versionCode = 1
versionName = "1.0"

multiDexEnabled = true
sadighasanzade marked this conversation as resolved.
Show resolved Hide resolved
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
javaCompileOptions{
annotationProcessorOptions {
arguments += mapOf(
"room.schemaLocation" to "$projectDir/schemas",
"room.incremental" to "true"
)
}
}
}

buildTypes {
Expand All @@ -47,7 +57,7 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
sadighasanzade marked this conversation as resolved.
Show resolved Hide resolved
kotlinCompilerExtensionVersion = "1.5.0"
}
packaging {
resources {
Expand All @@ -60,7 +70,7 @@ dependencies {

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.7.2")
implementation("androidx.activity:activity-compose:1.8.0")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
Expand All @@ -80,9 +90,12 @@ dependencies {
implementation("androidx.room:room-runtime:$room_version")
annotationProcessor("androidx.room:room-compiler:$room_version")
implementation("androidx.room:room-ktx:$room_version")
ksp("androidx.room:room-compiler:$room_version")

implementation("com.google.dagger:hilt-android:2.44")
kapt("com.google.dagger:hilt-android-compiler:2.44")
val hilt_version = "2.48"
implementation("com.google.dagger:hilt-android:$hilt_version")
ksp("com.google.dagger:dagger-compiler:$hilt_version") // Dagger compiler
ksp("com.google.dagger:hilt-compiler:$hilt_version")
implementation("io.coil-kt:coil-compose:2.4.0")

val nav_version = "2.7.4"
Expand All @@ -91,7 +104,7 @@ dependencies {
implementation("androidx.navigation:navigation-compose:$nav_version")
implementation("androidx.datastore:datastore-preferences:1.0.0")

implementation("androidx.multidex:multidex:2.0.1")
implementation ("co.yml:ycharts:2.1.0")
}
kapt {
correctErrorTypes = true
}

14 changes: 9 additions & 5 deletions app/src/main/java/com/sadig/spendtracker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.activity.viewModels
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -39,7 +40,9 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
val viewmodel by viewModels<HomeViewModel>()
setContent {
SpendTrackerTheme {
SpendTrackerTheme(
dynamicColor = false
) {
ScreenWithBottomAppBar(viewModel = viewmodel)
}
}
Expand All @@ -55,6 +58,7 @@ fun ScreenWithBottomAppBar(viewModel: HomeViewModel) {
bottomBar = { BottomNavigationBar(navController = navController) },
floatingActionButton = {
AddSpendingButton {
navController.navigate(BottomNavigationItem.Home.route)
viewModel.onEvent(HomeViewModel.EventType.OnAddSpendButtonClicked)
}
}
Expand All @@ -71,7 +75,7 @@ fun BottomNavigationBar(navController: NavController) {
BottomNavigationItem.History,
)
BottomNavigation(
backgroundColor = Color.Red,
backgroundColor = MaterialTheme.colorScheme.primary,
contentColor = Color.Black
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
Expand All @@ -83,7 +87,7 @@ fun BottomNavigationBar(navController: NavController) {
Text(
text = item.title,
fontSize = 12.sp,
color = Color.White
color = if(currentRoute == item.route) Color.White else MaterialTheme.colorScheme.tertiary
)
},
selectedContentColor = Color.White,
Expand All @@ -110,9 +114,9 @@ fun BottomNavigationBar(navController: NavController) {
@Composable
fun Navigation(navController: NavHostController, viewModel: HomeViewModel) {
NavHost(navController = navController, startDestination = BottomNavigationItem.Home.route) {
composable(BottomNavigationItem.Graphs.route) { GraphsScreen() }
composable(BottomNavigationItem.Graphs.route) { GraphsScreen(viewModel) }
composable(BottomNavigationItem.Home.route) { HomeScreen(viewModel) }
composable(BottomNavigationItem.History.route) { HistoryScreen() }
composable(BottomNavigationItem.History.route) { HistoryScreen(viewModel) }
}
}

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/sadig/spendtracker/SpendTracker.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.sadig.spendtracker

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class SpendTracker: Application() {
class SpendTracker: MultiDexApplication() {
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
MultiDex.install(base)
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/sadig/spendtracker/data/db/AppDatabase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sadig.spendtracker.data.db

import androidx.room.Database
import androidx.room.RoomDatabase
import com.sadig.spendtracker.data.model.Spending
import javax.inject.Inject

@Database(entities = [Spending::class], version = 1)
abstract class AppDatabase() : RoomDatabase() {
abstract fun spendingDao(): SpendingDAO
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/sadig/spendtracker/data/db/SpendingDAO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sadig.spendtracker.data.db

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import com.sadig.spendtracker.data.model.Spending

@Dao
interface SpendingDAO {
@Insert
fun insertAll(vararg spendings: Spending)

@Query("SELECT * FROM spending WHERE date >= :startDate")
fun getSpendngsOfThisMonth(startDate: Long): List<Spending>

@Query("SELECT * FROM spending")
fun getAll(): List<Spending>
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/sadig/spendtracker/data/model/Spending.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sadig.spendtracker.data.model

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.sadig.spendtracker.data.model.type_converter.SpendingTypeConverter
import java.util.Date

@Entity
@TypeConverters(SpendingTypeConverter::class)
data class Spending(
@ColumnInfo(name = "title") val title: String,
@ColumnInfo(name = "description") val description: String?,
@ColumnInfo(name = "amount") val amount: Double,
@ColumnInfo(name = "date") val date: Date,
){
@PrimaryKey(autoGenerate = true)
var uid: Int = 0

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sadig.spendtracker.data.model.query

data class GetSpendingQuery(
val takeMonthByMonth: Boolean = false,
val startDate: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sadig.spendtracker.data.model.type_converter

import androidx.room.TypeConverter
import java.util.Date

public class SpendingTypeConverter {
@TypeConverter
fun toDate(dateLong: Long?): Date? {
return dateLong?.let { Date(it) }
}

@TypeConverter
fun fromDate(date: Date?): Long? {
return date?.time
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package com.sadig.spendtracker.data.repository

import com.sadig.spendtracker.data.model.Spending
import com.sadig.spendtracker.data.model.query.GetSpendingQuery
import com.sadig.spendtracker.domain.repository.SpendingRepository
import com.sadig.spendtracker.domain.source.local.SpendingDataSource
import javax.inject.Inject

class SpendingRepositoryImpl @Inject constructor(): SpendingRepository {
class SpendingRepositoryImpl @Inject constructor(val spendingDataSource: SpendingDataSource) :
SpendingRepository {
override suspend fun putSpending(spending: Spending) {
spendingDataSource.putSpending(spending = spending)
}

override suspend fun getSpending(query: GetSpendingQuery): List<Spending> {
return spendingDataSource.getSpendings(query)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
package com.sadig.spendtracker.data.source.local

import android.util.Log
import com.sadig.spendtracker.data.db.SpendingDAO
import com.sadig.spendtracker.data.model.Spending
import com.sadig.spendtracker.data.model.query.GetSpendingQuery
import com.sadig.spendtracker.domain.source.local.SpendingDataSource
import javax.inject.Inject

class SpendingDataSourceImpl @Inject constructor(val spendingDAO: SpendingDAO) : SpendingDataSource {
override suspend fun putSpending(spending: Spending) {
spendingDAO.insertAll(spending)
}

override suspend fun getSpendings(query: GetSpendingQuery): List<Spending> {
return if (query.takeMonthByMonth){
spendingDAO.getAll()
}
else spendingDAO.getSpendngsOfThisMonth(query.startDate)
}

class SpendingDataSourceImpl: SpendingDataSource {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryComponent {
abstract class RepositoryModule {
@Singleton
@Binds
abstract fun bindDataStoreRepository(
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/sadig/spendtracker/di/module/RoomModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.sadig.spendtracker.di.module

import android.content.Context
import androidx.room.Room
import com.sadig.spendtracker.data.db.AppDatabase
import com.sadig.spendtracker.data.db.SpendingDAO
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object RoomModule {

@Provides
@Singleton
fun providesDb(@ApplicationContext context: Context): AppDatabase {
return Room.databaseBuilder(
context,
AppDatabase::class.java, "spendings_db"
).allowMainThreadQueries().build()
}
@Provides
@Singleton
fun provides(db: AppDatabase): SpendingDAO {
return db.spendingDao()
}
}
Loading