-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 키워드, 매력포인트 추가 #829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 키워드, 매력포인트 추가 #829
Changes from all commits
aed1a9c
2584d38
4c7a0a2
2dca29b
6b5c44b
2adbc23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,22 +122,34 @@ class NovelRatingActivity : BaseActivity<ActivityNovelRatingBinding>(activity_no | |
|
|
||
| novelRatingViewModel.uiState.observe(this) { uiState -> | ||
| when { | ||
| uiState.loading -> binding.wllNovelRating.setWebsosoLoadingVisibility(true) | ||
| uiState.loading -> { | ||
| binding.wllNovelRating.setWebsosoLoadingVisibility(true) | ||
| } | ||
|
|
||
| uiState.novelRatingModel.isCharmPointExceed -> handleCharmPointError(uiState) | ||
| uiState.novelRatingModel.isCharmPointExceed -> { | ||
| handleCharmPointError(uiState) | ||
| } | ||
|
|
||
| uiState.isFetchError -> binding.wllNovelRating.setErrorLayoutVisibility(true) | ||
| uiState.isFetchError -> { | ||
| binding.wllNovelRating.setErrorLayoutVisibility(true) | ||
| } | ||
|
|
||
| uiState.isSaveSuccess -> handleRatingSuccess() | ||
| uiState.isSaveSuccess -> { | ||
| handleRatingSuccess() | ||
| } | ||
|
|
||
| uiState.isSaveError -> handleRatingError() | ||
| uiState.isSaveError -> { | ||
| handleRatingError() | ||
| } | ||
|
|
||
| isInitialUpdate -> { | ||
| isInitialUpdate = false | ||
| initView() | ||
| } | ||
|
|
||
| else -> updateView(uiState) | ||
| else -> { | ||
| updateView(uiState) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -199,11 +211,16 @@ class NovelRatingActivity : BaseActivity<ActivityNovelRatingBinding>(activity_no | |
| } | ||
|
|
||
| private fun updateCharmPointChips(previousSelectedCharmPoints: List<CharmPoint>) { | ||
| binding.wcgNovelRatingCharmPoints.forEach { view -> | ||
| val chip = view as WebsosoChip | ||
| chip.isSelected = previousSelectedCharmPoints.contains( | ||
| charmPoints.find { charmPoint -> charmPoint.title == chip.text.toString() }, | ||
| ) | ||
| val selectedTitles = previousSelectedCharmPoints.map { it.title }.toSet() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previousSelectedCharmPoints가 이미 unique한 값들을 가지며 개수가 적다면 toList가 더 빠른 것으로 알고있습니다! 그리고 데이터가 많다면 mapTo(HashSet()) 구문을 써보는 것도 고려하시면 좋을 것 같아요!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 고생하셨습니다
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이번 케이스는 selectedTitles를 만든 뒤 각 칩에 대해 포함 여부를 여러 번 확인하는 구조라, 생성 비용보다 조회 비용을 줄이는 쪽이 더 적절하다고 판단해 Set은 유지했습니다. 또 mapTo(hashSetOf()) 방식도 생각해봤지만, 현재 데이터 크기가 작고 매력포인트 특성상 크게 확장될 가능성은 낮아 보여 우선은 가독성을 고려해 말씀 주신 덕분에 생성 비용 관점도 함께 생각해볼 수 있었습니다. 감사합니다! |
||
|
|
||
| listOf( | ||
| binding.wcgNovelRatingCharmPointsRow1, | ||
| binding.wcgNovelRatingCharmPointsRow2, | ||
| ).forEach { chipGroup -> | ||
| chipGroup.forEach { view -> | ||
| val chip = view as WebsosoChip | ||
| chip.isSelected = chip.text.toString() in selectedTitles | ||
| } | ||
|
Comment on lines
+220
to
+223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 칩 순회 중 강제 캐스팅은 런타임 크래시 위험이 있습니다.
🔧 제안 수정안 ).forEach { chipGroup ->
chipGroup.forEach { view ->
- val chip = view as WebsosoChip
- chip.isSelected = chip.text.toString() in selectedTitles
+ (view as? WebsosoChip)?.let { chip ->
+ chip.isSelected = chip.text.toString() in selectedTitles
+ }
}
}🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 구조에서는 chipGroup에 추후 다른 View가 섞일 가능성을 열어두는 방향이라면 방어적으로 처리할 수도 있겠지만, 현재는 잘못된 타입이 들어오는 경우 조용히 넘기기보다 빠르게 드러나는 편이 낫다고 판단했습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -235,22 +252,36 @@ class NovelRatingActivity : BaseActivity<ActivityNovelRatingBinding>(activity_no | |
| } | ||
|
|
||
| private fun setupCharmPointChips() { | ||
| getString(novel_rating_charm_points).toWrappedCharmPoint().forEach { charmPoint -> | ||
| WebsosoChip(this@NovelRatingActivity) | ||
| .apply { | ||
| setWebsosoChipText(charmPoint.title) | ||
| setWebsosoChipTextAppearance(body2) | ||
| setWebsosoChipTextColor(bg_novel_rating_chip_text_selector) | ||
| setWebsosoChipStrokeColor(bg_novel_rating_chip_stroke_selector) | ||
| setWebsosoChipBackgroundColor(bg_novel_rating_chip_background_selector) | ||
| setWebsosoChipPaddingVertical(12f.toFloatPxFromDp()) | ||
| setWebsosoChipPaddingHorizontal(6f.toFloatPxFromDp()) | ||
| setWebsosoChipRadius(20f.toFloatPxFromDp()) | ||
| setOnWebsosoChipClick { handleCharmPointClick(charmPoint) } | ||
| }.also { websosoChip -> binding.wcgNovelRatingCharmPoints.addChip(websosoChip) } | ||
| val charmPoints = getString(novel_rating_charm_points).toWrappedCharmPoint() | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| val firstRow = charmPoints.take(3) | ||
| val secondRow = charmPoints.drop(3) | ||
|
|
||
| binding.wcgNovelRatingCharmPointsRow1.removeAllViews() | ||
| binding.wcgNovelRatingCharmPointsRow2.removeAllViews() | ||
|
|
||
| firstRow.forEach { charmPoint -> | ||
| binding.wcgNovelRatingCharmPointsRow1.addChip(createCharmPointChip(charmPoint)) | ||
| } | ||
|
|
||
| secondRow.forEach { charmPoint -> | ||
| binding.wcgNovelRatingCharmPointsRow2.addChip(createCharmPointChip(charmPoint)) | ||
| } | ||
| } | ||
|
|
||
| private fun createCharmPointChip(charmPoint: CharmPoint): WebsosoChip = | ||
| WebsosoChip(this@NovelRatingActivity).apply { | ||
| setWebsosoChipText(charmPoint.title) | ||
| setWebsosoChipTextAppearance(body2) | ||
| setWebsosoChipTextColor(bg_novel_rating_chip_text_selector) | ||
| setWebsosoChipStrokeColor(bg_novel_rating_chip_stroke_selector) | ||
| setWebsosoChipBackgroundColor(bg_novel_rating_chip_background_selector) | ||
| setWebsosoChipPaddingVertical(12f.toFloatPxFromDp()) | ||
| setWebsosoChipPaddingHorizontal(6f.toFloatPxFromDp()) | ||
| setWebsosoChipRadius(20f.toFloatPxFromDp()) | ||
| setOnWebsosoChipClick { handleCharmPointClick(charmPoint) } | ||
| } | ||
|
|
||
| private fun handleCharmPointClick(charmPoint: CharmPoint) { | ||
| novelRatingViewModel.updateCharmPoints(charmPoints.find { it == charmPoint } ?: return) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="36dp" | ||
| android:height="36dp" | ||
| android:viewportWidth="36" | ||
| android:viewportHeight="36"> | ||
| <group> | ||
| <clip-path | ||
| android:pathData="M5.903,8.281h23v23h-23z"/> | ||
| <path | ||
| android:pathData="M28.903,8.281C26.577,8.441 10.235,9.997 9.093,21.201C8.954,22.399 8.876,23.602 8.824,24.806L16.859,16.779C17.14,16.498 17.596,16.498 17.877,16.779C18.157,17.059 18.157,17.514 17.877,17.795L6.219,29.441C5.798,29.862 5.798,30.545 6.219,30.965C6.641,31.386 7.324,31.386 7.746,30.965L10.312,28.402C12.203,28.396 14.092,28.288 15.97,28.071C18.373,27.827 20.329,26.882 21.926,25.531H17.391L23.986,23.336C24.491,22.667 24.945,21.956 25.353,21.219H21.708L26.494,18.829C28.377,14.25 28.822,9.461 28.903,8.281Z" | ||
| android:fillColor="#C7C7D0"/> | ||
| </group> | ||
| </vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍