generated from ajou4095/template-android
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Refactor]: 관계 등록 기능 구조 변경 -> 등록 + 수정 * [Feat]: relation 모델 구현 * [Feat]: destination 연걸, edit,add 구분 * [Feat]: Relation usecase 기능 추가 * [Fix]: Textfield focus 밖으로 빼기 * [Fix]: Textfield focus 수정 * [Fix]: Snackbar ui 수정 * [Feat]: 관게 등록 & 수정 구체화 * [Chore]: 코드 포맷 변경
- Loading branch information
Showing
21 changed files
with
1,227 additions
and
554 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
42 changes: 42 additions & 0 deletions
42
...ac/dnd/bookkeeping/android/presentation/model/relation/RelationDetailWithUserInfoModel.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,42 @@ | ||
package ac.dnd.bookkeeping.android.presentation.model.relation | ||
|
||
import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationDetailGroup | ||
import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationDetailWithUserInfo | ||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class RelationDetailWithUserInfoModel( | ||
val id: Long, | ||
val name: String, | ||
val imageUrl: String, | ||
val memo: String, | ||
val group: RelationDetailGroupModel, | ||
val giveMoney: Long, | ||
val takeMoney: Long | ||
) : Parcelable | ||
|
||
fun RelationDetailWithUserInfo.toUiModel(): RelationDetailWithUserInfoModel { | ||
return RelationDetailWithUserInfoModel( | ||
id = id, | ||
name = name, | ||
imageUrl = imageUrl, | ||
memo = memo, | ||
group = group.toUiModel(), | ||
giveMoney = giveMoney, | ||
takeMoney = takeMoney | ||
) | ||
} | ||
|
||
@Parcelize | ||
data class RelationDetailGroupModel( | ||
val id: Long, | ||
val name: String | ||
) : Parcelable | ||
|
||
fun RelationDetailGroup.toUiModel(): RelationDetailGroupModel { | ||
return RelationDetailGroupModel( | ||
id = id, | ||
name = name | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
...on/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/model/relation/RelationType.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,6 @@ | ||
package ac.dnd.bookkeeping.android.presentation.model.relation | ||
|
||
enum class RelationType { | ||
EDIT, | ||
ADD | ||
} |
6 changes: 3 additions & 3 deletions
6
...ommon/relation/add/AddRelationConstant.kt → .../home/common/relation/RelationConstant.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation.add | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation | ||
|
||
object AddRelationConstant { | ||
object RelationConstant { | ||
const val ROUTE: String = "/addName" | ||
|
||
const val ROUTE_ARGUMENT_MODEL = "relation" | ||
const val CONTAIN_RELATION = "${ROUTE}/{${ROUTE_ARGUMENT_MODEL}}" | ||
const val CONTAIN_RELATION = "$ROUTE/{$ROUTE_ARGUMENT_MODEL}" | ||
} |
93 changes: 93 additions & 0 deletions
93
.../dnd/bookkeeping/android/presentation/ui/main/home/common/relation/RelationDestination.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,93 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation | ||
|
||
import ac.dnd.bookkeeping.android.presentation.common.util.ErrorObserver | ||
import ac.dnd.bookkeeping.android.presentation.model.relation.RelationDetailGroupModel | ||
import ac.dnd.bookkeeping.android.presentation.model.relation.RelationDetailWithUserInfoModel | ||
import ac.dnd.bookkeeping.android.presentation.model.relation.RelationType | ||
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState | ||
import androidx.compose.runtime.getValue | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
|
||
fun NavGraphBuilder.RelationDestination( | ||
appState: ApplicationState | ||
) { | ||
val defaultModel = RelationDetailWithUserInfoModel( | ||
id = 0L, | ||
name = "", | ||
imageUrl = "", | ||
memo = "", | ||
group = RelationDetailGroupModel( | ||
id = -1L, | ||
name = "" | ||
), | ||
giveMoney = 0L, | ||
takeMoney = 0L | ||
) | ||
|
||
composable( | ||
route = RelationConstant.ROUTE | ||
) { | ||
val viewModel: RelationViewModel = hiltViewModel() | ||
|
||
val model: RelationModel = let { | ||
val state by viewModel.state.collectAsStateWithLifecycle() | ||
val groups by viewModel.groups.collectAsStateWithLifecycle() | ||
|
||
RelationModel( | ||
state = state, | ||
groups = groups, | ||
relationDetail = defaultModel | ||
) | ||
} | ||
|
||
ErrorObserver(viewModel) | ||
|
||
RelationScreen( | ||
relationType = RelationType.ADD, | ||
appState = appState, | ||
model = model, | ||
event = viewModel.event, | ||
intent = viewModel::onIntent, | ||
handler = viewModel.handler | ||
) | ||
} | ||
|
||
composable( | ||
route = RelationConstant.CONTAIN_RELATION | ||
) { | ||
val relationModel = appState.navController.previousBackStackEntry | ||
?.savedStateHandle | ||
?.get<RelationDetailWithUserInfoModel>(RelationConstant.ROUTE_ARGUMENT_MODEL) | ||
?: defaultModel | ||
|
||
if (relationModel.id == -1L) { | ||
appState.navController.popBackStack() | ||
} | ||
|
||
val viewModel: RelationViewModel = hiltViewModel() | ||
val model: RelationModel = let { | ||
val state by viewModel.state.collectAsStateWithLifecycle() | ||
val groups by viewModel.groups.collectAsStateWithLifecycle() | ||
|
||
RelationModel( | ||
state = state, | ||
groups = groups, | ||
relationDetail = relationModel | ||
) | ||
} | ||
|
||
ErrorObserver(viewModel) | ||
|
||
RelationScreen( | ||
relationType = RelationType.EDIT, | ||
appState = appState, | ||
model = model, | ||
event = viewModel.event, | ||
intent = viewModel::onIntent, | ||
handler = viewModel.handler | ||
) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...lin/ac/dnd/bookkeeping/android/presentation/ui/main/home/common/relation/RelationEvent.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,22 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation | ||
|
||
sealed interface RelationEvent { | ||
sealed interface AddRelation : RelationEvent { | ||
data object Success : AddRelation | ||
} | ||
|
||
sealed interface EditRelation : RelationEvent { | ||
data object Success : EditRelation | ||
} | ||
|
||
sealed interface DeleteRelation : RelationEvent { | ||
data object Success : DeleteRelation | ||
} | ||
|
||
sealed interface LoadKakaoFriend : RelationEvent { | ||
data class Success( | ||
val name: String, | ||
val imageUrl: String | ||
) : LoadKakaoFriend | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...in/ac/dnd/bookkeeping/android/presentation/ui/main/home/common/relation/RelationIntent.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,24 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation | ||
|
||
sealed interface RelationIntent { | ||
data class OnClickAdd( | ||
val groupId: Long, | ||
val name: String, | ||
val imageUrl: String, | ||
val memo: String | ||
) : RelationIntent | ||
|
||
data class OnClickEdit( | ||
val id: Long, | ||
val groupId: Long, | ||
val name: String, | ||
val imageUrl: String, | ||
val memo: String | ||
) : RelationIntent | ||
|
||
data class OnClickDelete( | ||
val id: Long | ||
) : RelationIntent | ||
|
||
data object OnClickLoadFriend : RelationIntent | ||
} |
12 changes: 12 additions & 0 deletions
12
...lin/ac/dnd/bookkeeping/android/presentation/ui/main/home/common/relation/RelationModel.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,12 @@ | ||
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation | ||
|
||
import ac.dnd.bookkeeping.android.domain.model.feature.group.Group | ||
import ac.dnd.bookkeeping.android.presentation.model.relation.RelationDetailWithUserInfoModel | ||
import androidx.compose.runtime.Immutable | ||
|
||
@Immutable | ||
data class RelationModel( | ||
val state: RelationState, | ||
val relationDetail: RelationDetailWithUserInfoModel, | ||
val groups: List<Group> | ||
) |
Oops, something went wrong.