Skip to content

Commit

Permalink
Merge pull request #67 from TiagoDvl/release/6_-_Release
Browse files Browse the repository at this point in the history
[6] Release
  • Loading branch information
TiagoDvl authored Aug 8, 2023
2 parents a376982 + 03ebfee commit 1010e38
Show file tree
Hide file tree
Showing 68 changed files with 1,655 additions and 550 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {
mockitoKotlinVersion = '4.0.0'
ktxCoroutinesTestVersion = '1.6.0'
lifecycleRuntimeKtx = '2.4.1'
lifecycleRuntimeCompose = '2.6.1'
turbineVersion = '0.7.0'
truthVersion = '1.1.3'
hiltVersion = '2.44'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package br.com.tick.sdk.database
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import br.com.tick.sdk.database.entities.Category
import br.com.tick.sdk.database.entities.CategoryColor
import kotlinx.coroutines.flow.Flow

Expand All @@ -14,5 +13,5 @@ interface CategoryColorDao {
suspend fun addCategoryColor(categoryColor: CategoryColor)

@Query("SELECT * FROM CategoryColor")
fun getCategoriesColors(): Flow<List<CategoryColor>>
fun getCategoryColors(): Flow<List<CategoryColor>>
}
4 changes: 4 additions & 0 deletions sdk/src/main/java/br/com/tick/sdk/database/CategoryDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package br.com.tick.sdk.database
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import br.com.tick.sdk.database.entities.Category
import kotlinx.coroutines.flow.Flow

Expand All @@ -12,6 +13,9 @@ interface CategoryDao {
@Insert
suspend fun addCategory(category: Category): Long

@Update
suspend fun updateCategory(category: Category)

@Query("SELECT * FROM category")
fun getCategories(): Flow<List<Category>>

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/main/java/br/com/tick/sdk/database/ExpenseDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface ExpenseDao {
@Query("DELETE FROM expense WHERE expense_id = :expenseId")
suspend fun removeExpenseById(expenseId: Int)

@Query("SELECT * FROM expense ORDER BY expense_id DESC LIMIT :numberOfExpenses")
fun getExpenses(numberOfExpenses: Int): Flow<List<Expense>>
@Query("SELECT * FROM expense ORDER BY expense_id")
fun getExpenses(): Flow<List<Expense>>

@Query("SELECT * FROM expense")
fun getAllExpenses(): Flow<List<Expense>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import br.com.tick.sdk.database.entities.User
Category::class,
CategoryColor::class
],
version = 6
version = 8
)
abstract class TeiraDatabase : RoomDatabase() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ data class Category(
val name: String,

@ColumnInfo(name = "category_color_id")
val categoryColorId: Int
val categoryColorId: Int?
)
2 changes: 1 addition & 1 deletion sdk/src/main/java/br/com/tick/sdk/di/DatabaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object DatabaseModule {
return Room.databaseBuilder(
app,
TeiraDatabase::class.java, "TeiraDb.db"
).addMigrations(MIGRATION_5_6).build()
).fallbackToDestructiveMigration().addMigrations(MIGRATION_5_6).build()
}

@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package br.com.tick.sdk.domain

data class ExpenseCategory(val expenseCategoryId: Int, val name: String, val color: Int)
data class ExpenseCategory(val expenseCategoryId: Int, val name: String, val color: Int?)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface CategorizedExpenseRepository {

suspend fun removeExpense(expenseId: Int)

suspend fun getCategorizedExpenses(numberOfExpenses: Int = -1): Flow<List<CategorizedExpense>>
fun getCategorizedExpenses(): Flow<List<CategorizedExpense>>

suspend fun getAccountingCycleExpenses(): Flow<List<CategorizedExpense>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ class CategorizedExpensesRepositoryImpl @Inject constructor(
expenseDao.removeExpenseById(expenseId)
}

override suspend fun getCategorizedExpenses(numberOfExpenses: Int): Flow<List<CategorizedExpense>> {
return expenseDao.getExpenses(numberOfExpenses).map { expenses ->
expenses.map { expense ->
categorize(expense)
}
override fun getCategorizedExpenses(): Flow<List<CategorizedExpense>> {
return expenseDao.getExpenses().map { expenses ->
expenses.map { categorize(it) }
}
}

Expand Down Expand Up @@ -87,8 +85,16 @@ class CategorizedExpensesRepositoryImpl @Inject constructor(

private suspend fun categorize(expense: Expense): CategorizedExpense {
val category = categoryDao.getCategoryById(expense.categoryId)
val color = categoryColorDao.getCategoriesColors().first().first { it.id == category.categoryColorId }
val expenseCategory = ExpenseCategory(category.categoryId, category.name, color.color)
val categoryColorId = category.categoryColorId

val color = if (categoryColorId != null) {
val categoryColor = categoryColorDao.getCategoryColors().first().first { it.id == categoryColorId }
categoryColor.color
} else {
null
}

val expenseCategory = ExpenseCategory(category.categoryId, category.name, color)

with(expense) {
return CategorizedExpense(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class CategoryColorRepositoryImpl @Inject constructor(
categoryColorDao.addCategoryColor(CategoryColor(color = color))
}

override fun getColors(): Flow<List<CategoryColor>> = categoryColorDao.getCategoriesColors()
override fun getColors(): Flow<List<CategoryColor>> = categoryColorDao.getCategoryColors()
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package br.com.tick.sdk.repositories.expensecategory

import br.com.tick.sdk.database.entities.CategoryColor
import br.com.tick.sdk.domain.ExpenseCategory
import kotlinx.coroutines.flow.Flow

interface ExpenseCategoryRepository {

suspend fun addCategory(categoryName: String, color: CategoryColor)
suspend fun addExpenseCategory(categoryName: String, color: Int?)

suspend fun editExpenseCategory(expenseCategoryId: Int, updatedCategoryName: String, updatedCategoryColor: Int)

fun getCategories(): Flow<List<ExpenseCategory>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,46 @@ import br.com.tick.sdk.database.entities.CategoryColor
import br.com.tick.sdk.domain.ExpenseCategory
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class ExpenseCategoryRepositoryImpl @Inject constructor(
private val categoryDao: CategoryDao,
private val categoryColorDao: CategoryColorDao,
private val categoryColorDao: CategoryColorDao
) : ExpenseCategoryRepository {

override suspend fun addCategory(categoryName: String, color: CategoryColor) {
categoryDao.addCategory(Category(name = categoryName, categoryColorId = color.id))
override suspend fun addExpenseCategory(categoryName: String, color: Int?) {
val persistedCategoriesColors = categoryColorDao.getCategoryColors().first().firstOrNull { it.color == color }
categoryDao.addCategory(Category(name = categoryName, categoryColorId = persistedCategoriesColors?.id))
}

override suspend fun editExpenseCategory(
expenseCategoryId: Int,
updatedCategoryName: String,
updatedCategoryColor: Int
) {
val category = categoryDao.getCategories().first().find { it.categoryId == expenseCategoryId }
var categoryColor = categoryColorDao.getCategoryColors().first().find { it.color == updatedCategoryColor }

if (categoryColor == null) {
categoryColorDao.addCategoryColor(CategoryColor(color = updatedCategoryColor))
categoryColor = categoryColorDao.getCategoryColors().first().find { it.color == updatedCategoryColor }
}

if (category != null && categoryColor != null) {
categoryDao.updateCategory(category.copy(name = updatedCategoryName, categoryColorId = categoryColor.id))
}
}

override fun getCategories(): Flow<List<ExpenseCategory>> {
return categoryDao.getCategories().combine(categoryColorDao.getCategoriesColors()) { categories, colors ->
return categoryDao.getCategories().combine(categoryColorDao.getCategoryColors()) { categories, colors ->
categories.map { category ->
val categoryColor = colors.first { it.id == category.categoryColorId }
ExpenseCategory(category.categoryId, category.name, categoryColor.color)
if (category.categoryColorId != null) {
val categoryColor = colors.first { it.id == category.categoryColorId }
ExpenseCategory(category.categoryId, category.name, categoryColor.color)
} else {
ExpenseCategory(category.categoryId, category.name, null)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class FakeCategorizedExpenseRepository : CategorizedExpenseRepository {
expenses.removeAt(expenseId)
}

override suspend fun getCategorizedExpenses(numberOfExpenses: Int): Flow<List<CategorizedExpense>> {
return flowOf(expenses.take(numberOfExpenses))
override fun getCategorizedExpenses(): Flow<List<CategorizedExpense>> {
return flowOf(expenses)
}

override suspend fun getAccountingCycleExpenses(): Flow<List<CategorizedExpense>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package br.com.tick.sdk.repositories
import br.com.tick.sdk.database.entities.CategoryColor
import br.com.tick.sdk.repositories.categorycolor.CategoryColorRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.MutableSharedFlow

class FakeCategoryColorRepository : CategoryColorRepository {

private val categoryColors = mutableListOf<CategoryColor>()
private val categoryColorsFlow = MutableSharedFlow<List<CategoryColor>>(replay = 1)

override suspend fun addColor(color: Int) {
categoryColors.add(CategoryColor(color = color))
categoryColorsFlow.emit(categoryColors)
}

override fun getColors(): Flow<List<CategoryColor>> {
return flowOf(categoryColors)
return categoryColorsFlow
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package br.com.tick.sdk.repositories

import br.com.tick.sdk.database.entities.CategoryColor
import br.com.tick.sdk.domain.ExpenseCategory
import br.com.tick.sdk.repositories.expensecategory.ExpenseCategoryRepository
import kotlinx.coroutines.flow.Flow
Expand All @@ -9,9 +8,19 @@ import kotlinx.coroutines.flow.flowOf
class FakeExpenseCategoryRepository : ExpenseCategoryRepository {

private val expenseCategories = mutableListOf<ExpenseCategory>()
override suspend fun addExpenseCategory(categoryName: String, color: Int?) {
expenseCategories.add(ExpenseCategory(expenseCategories.size, categoryName, color))
}

override suspend fun addCategory(categoryName: String, color: CategoryColor) {
expenseCategories.add(ExpenseCategory(expenseCategories.size, categoryName, color.color))
override suspend fun editExpenseCategory(
expenseCategoryId: Int,
updatedCategoryName: String,
updatedCategoryColor: Int
) {
expenseCategories[expenseCategoryId] = expenseCategories[expenseCategoryId].copy(
name = updatedCategoryName,
color = updatedCategoryColor
)
}

override fun getCategories(): Flow<List<ExpenseCategory>> {
Expand Down
1 change: 1 addition & 0 deletions ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dependencies {

implementation "androidx.core:core-ktx:$coreKtxVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleRuntimeKtx"
implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycleRuntimeCompose"

implementation "androidx.compose.ui:ui:$composeUi"
implementation "androidx.compose.foundation:foundation:$composeFoundation"
Expand Down
3 changes: 3 additions & 0 deletions ui/src/main/java/br/com/tick/ui/NavigationItem.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package br.com.tick.ui

import br.com.tick.ui.NavigationItem.Routes.ANALYSIS
import br.com.tick.ui.NavigationItem.Routes.HISTORY
import br.com.tick.ui.NavigationItem.Routes.SETTINGS
import br.com.tick.ui.NavigationItem.Routes.WALLET

Expand All @@ -10,10 +11,12 @@ sealed class NavigationItem(var route: String, var iconResource: Int, var titleR
const val SETTINGS = "configuration"
const val WALLET = "wallet"
const val ANALYSIS = "analysis"
const val HISTORY = "history"
}


object Settings : NavigationItem(SETTINGS, R.drawable.ic_settings, R.string.navigation_item_settings)
object Wallet : NavigationItem(WALLET, R.drawable.ic_wallet, R.string.navigation_item_wallet)
object Analysis : NavigationItem(ANALYSIS, R.drawable.ic_analysis, R.string.navigation_item_analysis)
object History : NavigationItem(HISTORY, R.drawable.ic_history, R.string.navigation_item_history)
}
Loading

0 comments on commit 1010e38

Please sign in to comment.