Skip to content

Commit 98ed552

Browse files
committed
fix: 이미 추가한 그룹 편집이 안되는 문제 수정
1 parent be506d7 commit 98ed552

File tree

7 files changed

+22
-11
lines changed

7 files changed

+22
-11
lines changed

core/model/src/main/java/com/yapp/breake/core/model/app/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.yapp.breake.core.model.app
22

33
data class App(
44
val packageName: String,
5-
val id: Long,
5+
val id: Long?,
66
val name: String,
77
val icon: ByteArray?,
88
val category: String,

data/src/main/java/com/yapp/breake/data/mapper/AppGroupMapper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal fun AppEntity.toApp(appScanner: InstalledAppScanner): App {
5353
internal fun App.toAppEntity(parentGroupId: Long): AppEntity {
5454
return AppEntity(
5555
packageName = packageName,
56-
id = id,
56+
id = id ?: 0L,
5757
name = name,
5858
category = category,
5959
parentGroupId = parentGroupId,
@@ -73,6 +73,7 @@ internal fun AppGroup.toAppGroupRequest(): AppGroupRequest {
7373
AppRequest(
7474
name = app.name,
7575
packageName = app.packageName,
76+
groupAppId = app.id,
7677
)
7778
},
7879
)

data/src/main/java/com/yapp/breake/data/remote/model/AppRequest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ import kotlinx.serialization.Serializable
66
internal data class AppRequest(
77
val name: String,
88
val packageName: String,
9+
val groupAppId: Long? = null,
910
)

data/src/main/java/com/yapp/breake/data/repository/AppGroupRepositoryImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ internal class AppGroupRepositoryImpl @Inject constructor(
2626
).map { updatedGroup ->
2727
appGroupLocalDataSource.insertAppGroup(updatedGroup)
2828
updatedGroup
29-
}.first()
29+
}
3030
} else {
3131
appGroupRemoteDataSource.createAppGroup(
3232
appGroup = appGroup,
3333
).map { newGroup ->
3434
appGroupLocalDataSource.insertAppGroup(newGroup)
3535
newGroup
36-
}.first()
37-
}
36+
}
37+
}.first()
3838
}
3939

4040
override suspend fun getAvailableMinGroupId(): Long =

presentation/home/src/main/java/com/yapp/breake/presentation/registry/RegistryViewModel.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class RegistryViewModel @Inject constructor(
6868
group.apps.forEachIndexed { index, appModel ->
6969
add(
7070
SelectedAppModel(
71+
id = appModel.id,
7172
index = index,
7273
name = appModel.name,
7374
packageName = appModel.packageName,
@@ -128,7 +129,9 @@ class RegistryViewModel @Inject constructor(
128129
.takeIf { it >= 0 }?.let { index ->
129130
set(
130131
index = index,
131-
element = cachedApps[index].copy(isSelected = true),
132+
element = cachedApps[index].copy(
133+
isSelected = true,
134+
),
132135
)
133136
}
134137
}
@@ -143,6 +146,7 @@ class RegistryViewModel @Inject constructor(
143146
name = selectedApp.name,
144147
packageName = selectedApp.packageName,
145148
icon = selectedApp.icon,
149+
id = selectedApp.id,
146150
),
147151
)
148152
}
@@ -199,10 +203,9 @@ class RegistryViewModel @Inject constructor(
199203
apps = it.selectedApps.map { selectedApp ->
200204
App(
201205
packageName = selectedApp.packageName,
202-
id = 0L,
206+
id = selectedApp.id,
203207
name = selectedApp.name,
204208
icon = selectedApp.icon.toByteArray(),
205-
// TODO: 카테고리 추후 추가 필요
206209
category = "기타",
207210
)
208211
},
@@ -292,11 +295,16 @@ class RegistryViewModel @Inject constructor(
292295
apps = it.apps,
293296
selectedApps = it.apps.mapIndexedNotNull { index, appModel ->
294297
if (appModel.isSelected) {
298+
val existingApp = it.selectedApps.find { selectedApp ->
299+
selectedApp.packageName == appModel.packageName
300+
}
301+
295302
SelectedAppModel(
296303
index = index,
297304
name = appModel.name,
298305
packageName = appModel.packageName,
299306
icon = appModel.icon,
307+
id = existingApp?.id,
300308
)
301309
} else {
302310
null

presentation/home/src/main/java/com/yapp/breake/presentation/registry/model/SelectedAppModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ data class SelectedAppModel(
99
val name: String,
1010
val packageName: String,
1111
val icon: Drawable?,
12+
val id: Long?,
1213
)

presentation/home/src/main/java/com/yapp/breake/presentation/registry/screen/GroupRegistryScreen.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ private fun GroupRegistryScreenPreview() {
386386
groupId = 1L,
387387
groupName = "그룹 이름",
388388
selectedApps = persistentListOf(
389-
SelectedAppModel(index = 0, name = "앱1", packageName = "", icon = null),
390-
SelectedAppModel(index = 1, name = "앱2", packageName = "", icon = null),
391-
SelectedAppModel(index = 2, name = "앱3", packageName = "", icon = null),
389+
SelectedAppModel(index = 0, name = "앱1", packageName = "", icon = null, id = 1L),
390+
SelectedAppModel(index = 1, name = "앱2", packageName = "", icon = null, id = 2L),
391+
SelectedAppModel(index = 2, name = "앱3", packageName = "", icon = null, id = 3L),
392392
),
393393
apps = persistentListOf(
394394
AppModel(

0 commit comments

Comments
 (0)