Compare commits
3 Commits
2ab7ef3f65
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfbb1056d7 | ||
|
|
43aec61c75 | ||
|
|
e6c8cf5cd3 |
@@ -10,7 +10,9 @@ plugins {
|
||||
android {
|
||||
namespace = "cc.n0th1ng.tripmoney"
|
||||
compileSdk = 36
|
||||
|
||||
buildFeatures {
|
||||
buildConfig = true
|
||||
}
|
||||
defaultConfig {
|
||||
applicationId = "cc.n0th1ng.tripmoney"
|
||||
minSdk = 24
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import cc.n0th1ng.tripmoney.BuildConfig
|
||||
import cc.n0th1ng.tripmoney.data.dao.CategoryDao
|
||||
import cc.n0th1ng.tripmoney.data.dao.ExchangeRateDao
|
||||
import cc.n0th1ng.tripmoney.data.dao.ExpenseDao
|
||||
@@ -34,8 +35,7 @@ import javax.inject.Singleton
|
||||
import kotlin.random.Random
|
||||
|
||||
@Database(
|
||||
entities = [Trip::class, Expense::class, Category::class, ExchangeRate::class],
|
||||
version = 1
|
||||
entities = [Trip::class, Expense::class, Category::class, ExchangeRate::class], version = 1
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class TripDatabase : RoomDatabase() {
|
||||
@@ -57,16 +57,19 @@ object DatabaseModule {
|
||||
fun provideTripDatabase(
|
||||
@ApplicationContext context: Context
|
||||
): TripDatabase {
|
||||
val db: TripDatabase = Room.inMemoryDatabaseBuilder(
|
||||
// val db: TripDatabase = Room.databaseBuilder(
|
||||
// name = "tripmoney_db",
|
||||
val builder = if (BuildConfig.DEBUG) Room.inMemoryDatabaseBuilder(
|
||||
context = context, klass = TripDatabase::class.java
|
||||
) else Room.databaseBuilder(
|
||||
name = "tripmoney_db",
|
||||
context = context,
|
||||
klass = TripDatabase::class.java,
|
||||
)
|
||||
.allowMainThreadQueries() // TODO Remove in production!
|
||||
.fallbackToDestructiveMigration() // TODO Handle schema changes during dev
|
||||
|
||||
val db: TripDatabase =
|
||||
builder.fallbackToDestructiveMigration() // TODO Handle schema changes during dev
|
||||
.build()
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
DatabasePrepopulator(
|
||||
tripDao = db.tripDao(),
|
||||
@@ -74,6 +77,8 @@ object DatabaseModule {
|
||||
expenseDao = db.expenseDao()
|
||||
).prepopulate()
|
||||
}
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
@@ -147,74 +152,46 @@ private class DatabasePrepopulator(
|
||||
|
||||
val sampleCategories = listOf(
|
||||
Category(
|
||||
name = "Hotel",
|
||||
icon = Icons.HOTEL,
|
||||
color = colors.random()
|
||||
name = "Hotel", icon = Icons.HOTEL, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Jedzenie",
|
||||
icon = Icons.RESTAURANT,
|
||||
color = colors.random()
|
||||
name = "Jedzenie", icon = Icons.RESTAURANT, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Transport",
|
||||
icon = Icons.FLIGHT,
|
||||
color = colors.random()
|
||||
name = "Transport", icon = Icons.FLIGHT, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Rozrywka",
|
||||
icon = Icons.ATTRACTION,
|
||||
color = colors.random()
|
||||
name = "Rozrywka", icon = Icons.ATTRACTION, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy1",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy1", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy2",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy2", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy3",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy3", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy4",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy4", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy5",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy5", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy6",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy6", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy7",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy7", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy8",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy8", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
Category(
|
||||
name = "Zakupy9",
|
||||
icon = Icons.GROCERIES,
|
||||
color = colors.random()
|
||||
name = "Zakupy9", icon = Icons.GROCERIES, color = colors.random()
|
||||
),
|
||||
)
|
||||
|
||||
@@ -240,8 +217,7 @@ private class DatabasePrepopulator(
|
||||
note = if (i % 3 == 0) "Some note" else "",
|
||||
datetime = datetime,
|
||||
rate = if (Random.nextBoolean()) Random.nextDouble(
|
||||
0.1,
|
||||
5.0
|
||||
0.1, 5.0
|
||||
) else 1.0
|
||||
)
|
||||
expense
|
||||
|
||||
@@ -7,7 +7,6 @@ import androidx.room.Query
|
||||
import androidx.room.RewriteQueriesToDropUnusedColumns
|
||||
import androidx.room.Transaction
|
||||
import androidx.room.Upsert
|
||||
import cc.n0th1ng.tripmoney.data.entity.Category
|
||||
import cc.n0th1ng.tripmoney.data.entity.Expense
|
||||
import cc.n0th1ng.tripmoney.data.entity.ExpenseDto
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -100,7 +99,7 @@ interface ExpenseDao {
|
||||
WHERE trip.id = :tripId
|
||||
"""
|
||||
)
|
||||
fun budgetLeft(tripId: Int): Double?
|
||||
fun budgetLeft(tripId: Int): Flow<Double?>
|
||||
|
||||
@Delete
|
||||
suspend fun delete(expense: Expense)
|
||||
|
||||
@@ -13,7 +13,6 @@ import cc.n0th1ng.tripmoney.data.entity.ExpenseDto
|
||||
import cc.n0th1ng.tripmoney.utils.Currencies
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import java.util.OptionalDouble
|
||||
import javax.inject.Inject
|
||||
|
||||
class ExpenseRepository @Inject constructor(
|
||||
@@ -21,7 +20,7 @@ class ExpenseRepository @Inject constructor(
|
||||
private val exchangeRateRepository: ExchangeRateRepository
|
||||
) {
|
||||
|
||||
fun getBudgetLeft(tripId: Int): Double? {
|
||||
fun getBudgetLeft(tripId: Int): Flow<Double?> {
|
||||
return expenseDao.budgetLeft(tripId)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package cc.n0th1ng.tripmoney.screens.settings
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.StringRes
|
||||
@@ -36,34 +35,23 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import cc.n0th1ng.tripmoney.R.*
|
||||
import cc.n0th1ng.tripmoney.data.entity.Category
|
||||
import cc.n0th1ng.tripmoney.R.string
|
||||
import cc.n0th1ng.tripmoney.data.entity.Trip
|
||||
import cc.n0th1ng.tripmoney.data.repository.AppTheme
|
||||
import cc.n0th1ng.tripmoney.navigation.Screens
|
||||
import cc.n0th1ng.tripmoney.screens.listexpense.CategorySelectionDialog
|
||||
import cc.n0th1ng.tripmoney.screens.listexpense.CurrencySelectionDialog
|
||||
import cc.n0th1ng.tripmoney.screens.statistics.categories
|
||||
import cc.n0th1ng.tripmoney.theme.TripMoneyTheme
|
||||
import cc.n0th1ng.tripmoney.utils.AllPreviews
|
||||
import cc.n0th1ng.tripmoney.utils.Currencies
|
||||
import cc.n0th1ng.tripmoney.utils.Icons
|
||||
import cc.n0th1ng.tripmoney.utils.saveCsv
|
||||
import cc.n0th1ng.tripmoney.utils.shareCsv
|
||||
import cc.n0th1ng.tripmoney.viewmodel.ExpenseAndCategoryViewModel
|
||||
import cc.n0th1ng.tripmoney.viewmodel.SettingsViewModel
|
||||
import cc.n0th1ng.tripmoney.viewmodel.TripViewModel
|
||||
import com.composables.icons.materialsymbols.outlined.R
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.S)
|
||||
@Composable
|
||||
@@ -168,7 +156,7 @@ fun SettingsScreen(
|
||||
iconResource = R.drawable.materialsymbols_ic_label_outlined
|
||||
)
|
||||
SettingsListItem(
|
||||
onClick = onCategoriesClick,
|
||||
onClick = {},
|
||||
stringResource(string.add_expense),
|
||||
supportingText = stringResource(string.add_expense_settings),
|
||||
iconResource = R.drawable.materialsymbols_ic_payments_outlined,
|
||||
|
||||
@@ -60,11 +60,12 @@ fun StatisticsScreen() {
|
||||
.collectAsState(emptyList())
|
||||
val summaryAmount by expenseAndCategoryViewModel.getSummaryAmount(currentTripId)
|
||||
.collectAsState(0.0)
|
||||
val moneyLeft by expenseAndCategoryViewModel.getBudgetLeft(currentTripId).collectAsState(null)
|
||||
StatisticsScreen(
|
||||
summaryPerCategoryList,
|
||||
summaryAmount,
|
||||
Currencies.valueOf(currentTrip?.currency ?: Currencies.default().name),
|
||||
expenseAndCategoryViewModel.getBudgetLeft(currentTripId)
|
||||
moneyLeft
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,7 @@ import org.apache.commons.csv.CSVFormat
|
||||
import org.apache.commons.csv.CSVPrinter
|
||||
import java.io.File
|
||||
import java.time.LocalDate
|
||||
import java.util.OptionalDouble
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.mapValues
|
||||
|
||||
|
||||
@HiltViewModel
|
||||
@@ -42,7 +40,7 @@ open class ExpenseAndCategoryViewModel @Inject constructor(
|
||||
private val tripRepo: TripRepository
|
||||
) : ViewModel() {
|
||||
|
||||
fun getBudgetLeft(tripId: Int): Double? {
|
||||
fun getBudgetLeft(tripId: Int): Flow<Double?> {
|
||||
return expenseRepo.getBudgetLeft(tripId)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user