Skip to content

Commit fd875fd

Browse files
authored
Group management (#139)
* Define Group model, GroupRepo, GroupDao * Group management feature common ui * Rework GroupRepo, group use cases * Setup core presentation for group * Quick feature impl group management * PairAlert feature impl group management * Portfolio feature impl group management * fix quick widget feature * Feature pages rely on groups sorting * Remove isDefault field from Group model * minor fix * Setup feature pairs cascade delete on group delete * ui fix * ValidateGroupNameUseCase * Reuse GroupCreateDialog instead of PortfolioCreateDialog * Reuse GroupSelectPopup instead of PortfolioSelectPopup * Add new groups to the right * Fix inconsistent orderIndex bug * Add bottom padding to add screens * Room migration 14->15 * Test Room migration 14->15 * typo fix * Validate group name on rename * Remove Send Telegram message job because tg channel was deleted
1 parent 91a229e commit fd875fd

File tree

76 files changed

+2789
-676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2789
-676
lines changed

.github/workflows/main-message-telegram.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/src/main/java/dev/arkbuilders/rate/presentation/MainScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ fun MainScreen() {
5757
val intent = activity?.intent
5858
val createNewPair = intent?.getStringExtra(ADD_NEW_PAIR) ?: ""
5959
if (createNewPair.isNotEmpty()) {
60-
val group = intent?.getStringExtra(ADD_NEW_PAIR_GROUP_KEY)
61-
navController.navigate(AddQuickScreenDestination(group = group))
60+
val groupId = intent?.getLongExtra(ADD_NEW_PAIR_GROUP_KEY, 0L)
61+
navController.navigate(AddQuickScreenDestination(groupId = groupId))
6262
intent?.removeExtra(ADD_NEW_PAIR_GROUP_KEY)
6363
intent?.removeExtra(ADD_NEW_PAIR)
6464
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package dev.arkbuilders.rate.core.data.repo
2+
3+
import dev.arkbuilders.rate.core.db.dao.GroupDao
4+
import dev.arkbuilders.rate.core.db.entity.RoomGroup
5+
import dev.arkbuilders.rate.core.domain.model.Group
6+
import dev.arkbuilders.rate.core.domain.model.GroupFeatureType
7+
import dev.arkbuilders.rate.core.domain.repo.GroupRepo
8+
import kotlinx.coroutines.flow.Flow
9+
import kotlinx.coroutines.flow.distinctUntilChanged
10+
import kotlinx.coroutines.flow.map
11+
import java.time.OffsetDateTime
12+
13+
class GroupRepoImpl(
14+
private val groupDao: GroupDao,
15+
) : GroupRepo {
16+
override suspend fun new(
17+
name: String,
18+
featureType: GroupFeatureType,
19+
): Group {
20+
val all = groupDao.getAllByFeatureType(featureType)
21+
val sortIndex = all.maxOf { it.orderIndex } + 1
22+
val group =
23+
Group(
24+
id = 0,
25+
name = name,
26+
orderIndex = sortIndex,
27+
creationTime = OffsetDateTime.now(),
28+
)
29+
val id = groupDao.insert(group.toRoom(featureType))
30+
return group.copy(id = id)
31+
}
32+
33+
override suspend fun update(
34+
updated: Group,
35+
featureType: GroupFeatureType,
36+
): Long {
37+
return groupDao.insert(updated.toRoom(featureType))
38+
}
39+
40+
override suspend fun update(
41+
updated: List<Group>,
42+
featureType: GroupFeatureType,
43+
) {
44+
groupDao.insert(updated.map { it.toRoom(featureType) })
45+
}
46+
47+
override suspend fun getById(id: Long): Group {
48+
return groupDao.getById(id).toGroup()
49+
}
50+
51+
override suspend fun delete(id: Long) {
52+
groupDao.delete(id)
53+
}
54+
55+
override fun allFlow(featureType: GroupFeatureType): Flow<List<Group>> {
56+
return groupDao
57+
.allFlow(featureType)
58+
.distinctUntilChanged()
59+
.map { list -> list.map { it.toGroup() } }
60+
}
61+
62+
override suspend fun getAllSorted(featureType: GroupFeatureType): List<Group> {
63+
return groupDao
64+
.getAllByFeatureType(featureType)
65+
.map { it.toGroup() }
66+
.sortedBy { it.orderIndex }
67+
}
68+
}
69+
70+
private fun Group.toRoom(featureType: GroupFeatureType) =
71+
RoomGroup(id, name, orderIndex, creationTime, featureType)
72+
73+
private fun RoomGroup.toGroup() = Group(id, name, orderIndex, creationTime)

core/db/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ android {
3535
kotlinOptions {
3636
jvmTarget = "17"
3737
}
38+
sourceSets {
39+
// Adds exported schema location as test app assets.
40+
getByName("androidTest").assets.srcDir("$projectDir/schemas")
41+
}
3842
}
3943

4044
dependencies {
@@ -48,6 +52,7 @@ dependencies {
4852
ksp(libs.androidx.room.compiler)
4953

5054
testImplementation(libs.junit)
55+
androidTestImplementation(libs.androidx.room.testing)
5156
androidTestImplementation(libs.androidx.junit)
5257
androidTestImplementation(libs.androidx.espresso.core)
5358
}

0 commit comments

Comments
 (0)