-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: chatting view type 설정 로직 위치 변경 (#608)
* feat: 안드로이드 프로젝트 구조 기초 세팅 (#2) * feat: 백엔드 프로젝트 구조 기초 세팅 (#5) * feat: LocalDateTime -> String 으로 만드는 util 함수 구현 * feat: CommentUiModel 구현 * feat: viewmodel 과 adapter로직 변경 * feat: 변경에 따른 뷰 반영 * test: 로직 변경에 따른 test 코드 수정 * stye: ktlint 적용 * refactor: 필요없는 파일 삭제 * feat: 필요없는 파일 삭제 * refactor: LocalDate와 LocalTime을 String으로 바꾸는 함수명 변경 * style: ktlint 적용 --------- Co-authored-by: Dora Choo <[email protected]>
- Loading branch information
1 parent
69f4b30
commit b805065
Showing
15 changed files
with
153 additions
and
91 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
android/app/src/main/java/com/zzang/chongdae/presentation/util/LocalDateTimeToString.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,14 @@ | ||
package com.zzang.chongdae.presentation.util | ||
|
||
import java.time.LocalDate | ||
import java.time.LocalTime | ||
import java.time.format.DateTimeFormatter | ||
import java.util.Locale | ||
|
||
fun LocalDate.toFormattedDate(): String { | ||
return this.format(DateTimeFormatter.ofPattern("yyyy년 M월 d일")) | ||
} | ||
|
||
fun LocalTime.toFormattedTime(): String { | ||
return this.format(DateTimeFormatter.ofPattern(("a h:mm"), Locale.KOREAN)) | ||
} |
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
18 changes: 3 additions & 15 deletions
18
...ava/com/zzang/chongdae/presentation/view/commentdetail/adapter/comment/CommentViewType.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,21 +1,9 @@ | ||
package com.zzang.chongdae.presentation.view.commentdetail.adapter.comment | ||
|
||
import com.zzang.chongdae.domain.model.Comment | ||
|
||
sealed class CommentViewType { | ||
data class MyComment(val comment: Comment) : CommentViewType() | ||
|
||
data class OtherComment(val comment: Comment) : CommentViewType() | ||
data object MyComment : CommentViewType() | ||
|
||
data class DateSeparator(val comment: Comment) : CommentViewType() | ||
data object OtherComment : CommentViewType() | ||
|
||
companion object { | ||
fun fromComment(comment: Comment): CommentViewType { | ||
return if (comment.isMine) { | ||
MyComment(comment) | ||
} else { | ||
OtherComment(comment) | ||
} | ||
} | ||
} | ||
data object DateSeparator : CommentViewType() | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...n/java/com/zzang/chongdae/presentation/view/commentdetail/model/comment/CommentUiModel.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,59 @@ | ||
package com.zzang.chongdae.presentation.view.commentdetail.model.comment | ||
|
||
import com.zzang.chongdae.domain.model.Comment | ||
import com.zzang.chongdae.presentation.util.toFormattedDate | ||
import com.zzang.chongdae.presentation.util.toFormattedTime | ||
import com.zzang.chongdae.presentation.view.commentdetail.adapter.comment.CommentViewType | ||
|
||
data class CommentUiModel( | ||
val content: String, | ||
val date: String, | ||
val time: String, | ||
val isMine: Boolean, | ||
val isProposer: Boolean, | ||
val nickname: String, | ||
val commentViewType: CommentViewType, | ||
) { | ||
companion object { | ||
fun Comment.toUiModel(): CommentUiModel { | ||
val viewType = if (this.isMine) CommentViewType.MyComment else CommentViewType.OtherComment | ||
return CommentUiModel( | ||
content = this.content, | ||
date = this.commentCreatedAt.date.toFormattedDate(), | ||
time = this.commentCreatedAt.time.toFormattedTime(), | ||
isMine = this.isMine, | ||
isProposer = this.isProposer, | ||
nickname = this.nickname, | ||
commentViewType = viewType, | ||
) | ||
} | ||
|
||
fun createDateSeparator(date: String): CommentUiModel { | ||
return CommentUiModel( | ||
content = "", | ||
date = date, | ||
time = "", | ||
isMine = false, | ||
isProposer = false, | ||
nickname = "", | ||
commentViewType = CommentViewType.DateSeparator, | ||
) | ||
} | ||
|
||
fun List<Comment>.toUiModelListWithSeparators(): List<CommentUiModel> { | ||
val uiModels = mutableListOf<CommentUiModel>() | ||
var currentDate: String? = null | ||
|
||
for (comment in this) { | ||
val commentDate = comment.commentCreatedAt.date.toFormattedDate() | ||
if (commentDate != currentDate) { | ||
uiModels.add(CommentUiModel.createDateSeparator(commentDate)) | ||
currentDate = commentDate | ||
} | ||
uiModels.add(comment.toUiModel()) | ||
} | ||
|
||
return uiModels | ||
} | ||
} | ||
} |
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
Oops, something went wrong.