-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from YAPP-Github/feature/MZ-180-ledger-list-ed…
…it-delete Feature/mz 180 ledger list edit delete, error handling, category config
- Loading branch information
Showing
54 changed files
with
1,267 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com.susu.core.model | ||
|
||
import androidx.compose.runtime.Stable | ||
import kotlinx.serialization.Serializable | ||
|
||
@Stable | ||
@Serializable | ||
data class Category( | ||
val id: Int, | ||
val seq: Int, | ||
val category: String, | ||
val id: Int = 0, | ||
val seq: Int = 0, | ||
val name: String = "", | ||
val customCategory: String? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
package com.susu.core.model | ||
|
||
import androidx.compose.runtime.Stable | ||
import java.time.LocalDateTime | ||
import kotlinx.datetime.LocalDateTime | ||
import kotlinx.datetime.toKotlinLocalDateTime | ||
import kotlinx.serialization.Serializable | ||
|
||
@Stable | ||
@Serializable | ||
data class Ledger( | ||
val id: Int, | ||
val title: String, | ||
val description: String, | ||
val startAt: LocalDateTime, | ||
val endAt: LocalDateTime, | ||
val category: Category, | ||
val totalAmounts: Int, | ||
val id: Int = -1, | ||
val title: String = "", | ||
val description: String = "", | ||
val startAt: LocalDateTime = java.time.LocalDateTime.now().toKotlinLocalDateTime(), | ||
val endAt: LocalDateTime = java.time.LocalDateTime.now().toKotlinLocalDateTime(), | ||
val category: Category = Category(), | ||
val totalAmounts: Int = 0, | ||
val totalCounts: Int = 0, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.susu.core.ui.extension | ||
|
||
import android.net.Uri | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
inline fun <reified T> Json.encodeToUri(value: T): String { | ||
return Uri.encode(encodeToString(value)) | ||
} | ||
|
||
inline fun <reified T> Json.decodeFromUri(value: String): T { | ||
return decodeFromString(Uri.decode(value)) | ||
} |
38 changes: 38 additions & 0 deletions
38
core/ui/src/main/java/com/susu/core/ui/extension/LazyGridState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.susu.core.ui.extension | ||
|
||
import androidx.compose.foundation.lazy.grid.LazyGridState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.snapshotFlow | ||
import kotlinx.coroutines.flow.collectLatest | ||
|
||
// https://manavtamboli.medium.com/infinite-list-paged-list-in-jetpack-compose-b10fc7e74768 | ||
@Composable | ||
fun LazyGridState.OnBottomReached( | ||
// tells how many items before we reach the bottom of the list | ||
// to call onLoadMore function | ||
buffer: Int = 0, | ||
onLoadMore: () -> Unit, | ||
) { | ||
// Buffer must be positive. | ||
// Or our list will never reach the bottom. | ||
require(buffer >= 0) { "buffer cannot be negative, but was $buffer" } | ||
|
||
val shouldLoadMore = remember { | ||
derivedStateOf { | ||
val lastVisibleItem = layoutInfo.visibleItemsInfo.lastOrNull() ?: return@derivedStateOf false | ||
|
||
lastVisibleItem.index >= layoutInfo.totalItemsCount - 1 - buffer | ||
} | ||
} | ||
LaunchedEffect(shouldLoadMore) { | ||
snapshotFlow { shouldLoadMore.value } | ||
.collectLatest { | ||
if (it) { | ||
onLoadMore() | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
core/ui/src/main/java/com/susu/core/ui/extension/LazyListState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.susu.core.ui.extension | ||
|
||
import androidx.compose.foundation.lazy.LazyListState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.snapshotFlow | ||
|
||
// https://manavtamboli.medium.com/infinite-list-paged-list-in-jetpack-compose-b10fc7e74768 | ||
@Composable | ||
fun LazyListState.OnBottomReached( | ||
// tells how many items before we reach the bottom of the list | ||
// to call onLoadMore function | ||
buffer: Int = 3, | ||
onLoadMore: () -> Unit, | ||
) { | ||
// Buffer must be positive. | ||
// Or our list will never reach the bottom. | ||
require(buffer >= 0) { "buffer cannot be negative, but was $buffer" } | ||
|
||
val shouldLoadMore = remember { | ||
derivedStateOf { | ||
val lastVisibleItem = layoutInfo.visibleItemsInfo.lastOrNull() ?: return@derivedStateOf false | ||
|
||
lastVisibleItem.index >= layoutInfo.totalItemsCount - 1 - buffer | ||
} | ||
} | ||
LaunchedEffect(shouldLoadMore) { | ||
snapshotFlow { shouldLoadMore.value } | ||
.collect { | ||
if (it) { | ||
onLoadMore() | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun LazyListState.isScrolledToEnd() = layoutInfo.visibleItemsInfo.lastOrNull()?.index == layoutInfo.totalItemsCount - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
data/src/main/java/com/susu/data/data/repository/CategoryConfigRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.susu.data.data.repository | ||
|
||
import com.susu.core.android.Dispatcher | ||
import com.susu.core.android.SusuDispatchers | ||
import com.susu.core.model.Category | ||
import com.susu.data.local.dao.CategoryConfigDao | ||
import com.susu.data.local.model.toEntity | ||
import com.susu.data.local.model.toModel | ||
import com.susu.data.remote.api.CategoryService | ||
import com.susu.data.remote.model.response.toModel | ||
import com.susu.domain.repository.CategoryConfigRepository | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class CategoryConfigRepositoryImpl @Inject constructor( | ||
private val dao: CategoryConfigDao, | ||
private val api: CategoryService, | ||
@Dispatcher(SusuDispatchers.IO) private val ioDispatcher: CoroutineDispatcher, | ||
) : CategoryConfigRepository { | ||
override suspend fun getCategoryConfig(): List<Category> = withContext(ioDispatcher) { | ||
val localCategoryConfig = dao.getCategoryConfig().map { it.toModel() } | ||
if (localCategoryConfig.isNotEmpty()) return@withContext localCategoryConfig | ||
|
||
val remoteCategoryConfig = api.getCategoryConfig().getOrThrow().map { it.toModel() } | ||
dao.insert(remoteCategoryConfig.map { it.toEntity() }) | ||
return@withContext remoteCategoryConfig | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
data/src/main/java/com/susu/data/local/RoomInMemoryDataBase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.susu.data.local | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.susu.data.local.dao.CategoryConfigDao | ||
import com.susu.data.local.model.CategoryConfigEntity | ||
|
||
@Database( | ||
entities = [ | ||
CategoryConfigEntity::class, | ||
], | ||
version = 1, | ||
) | ||
abstract class RoomInMemoryDataBase : RoomDatabase() { | ||
abstract fun categoryConfigDao(): CategoryConfigDao | ||
} |
16 changes: 16 additions & 0 deletions
16
data/src/main/java/com/susu/data/local/dao/CategoryConfigDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.susu.data.local.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import com.susu.data.local.model.CategoryConfigEntity | ||
import com.susu.data.local.model.EntityTable | ||
|
||
@Dao | ||
interface CategoryConfigDao { | ||
@Query("SELECT * FROM ${EntityTable.CATEGORY_CONFIG}") | ||
fun getCategoryConfig(): List<CategoryConfigEntity> | ||
|
||
@Insert | ||
fun insert(categoryConfig: List<CategoryConfigEntity>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.