Skip to content

Commit

Permalink
[chore] #27 키워드 설정 바텀 시트 클릭 시 뷰에 반영되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jihyunniiii committed Jun 7, 2024
1 parent 4a1f5c4 commit 7f4dc9b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class BottomSheetWithSelectionAdapter : ListAdapter<String, BottomSheetWithSelec
onContentsTheSame = { old, new -> old == new },
),
) {
private var selectedItemPosition: Int = DEFAULT_OLD_POSITION
private var _selectedItemPosition: Int = DEFAULT_OLD_POSITION
val selectedItemPosition get() = _selectedItemPosition

override fun onCreateViewHolder(
parent: ViewGroup,
Expand All @@ -26,16 +27,16 @@ class BottomSheetWithSelectionAdapter : ListAdapter<String, BottomSheetWithSelec
holder: BottomSheetWithSelectionViewHolder,
position: Int,
) {
if (position == selectedItemPosition) {
if (position == _selectedItemPosition) {
holder.onSelectedItemBind(title = currentList[position])
} else {
holder.onUnselectedItemBind(title = currentList[position])
}

holder.itemView.setOnClickListener {
notifyItemChanged(selectedItemPosition)
selectedItemPosition = holder.adapterPosition
notifyItemChanged(selectedItemPosition)
notifyItemChanged(_selectedItemPosition)
_selectedItemPosition = holder.adapterPosition
notifyItemChanged(_selectedItemPosition)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BottomSheetWithSelectionDialogFragment(
private val selectionList: List<String>,
private val bottomSheetWithSelectionAdapter: BottomSheetWithSelectionAdapter,
private val clickBtn: () -> Unit = {},
private val onDialogClosed: () -> Unit = {},
private val onDialogClosed: (String) -> Unit = {},
) : BindingBottomSheetDialogFragment<DialogBottomSheetWithSelectionBinding>({ DialogBottomSheetWithSelectionBinding.inflate(it) }) {
override fun onViewCreated(
view: View,
Expand All @@ -27,7 +27,7 @@ class BottomSheetWithSelectionDialogFragment(

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
onDialogClosed()
onDialogClosed(bottomSheetWithSelectionAdapter.currentList[bottomSheetWithSelectionAdapter.selectedItemPosition])
}

private fun initLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ProfileService {
@Path("${ROOM_ID}") roomId: Int,
): BaseResponseDto<ResponseGetRoomExtraDto>

@PUT("$ROOMS/${ROOM_ID}")
@PUT("$ROOMS/{$ROOM_ID}")
suspend fun putRoomKeywordsExtra(
@Path("${ROOM_ID}") roomId: Int,
@Body requestPutRoomKeywordsExtraDto: RequestPutRoomKeywordsExtraDto,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dongguk.telepigeon.feature.setting.keywordsetting

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
Expand Down Expand Up @@ -73,6 +74,8 @@ class KeywordSettingFragment : BindingFragment<FragmentKeywordSettingBinding>({
findNavController().popBackStack()
}

is UiState.Error -> Log.e("ㅋㅋ", putRoomKeywordExtraState.message.toString())

else -> Unit
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
Expand Down Expand Up @@ -147,19 +150,19 @@ class KeywordSettingFragment : BindingFragment<FragmentKeywordSettingBinding>({

private fun setEtKeywordSettingGenderClickListener(genders: List<String>) {
binding.etKeywordSettingGender.setOnClickListener {
showSelectionBottomSheetDialogFragment(bottomSheetWithSelectionType = BottomSheetWithSelectionType.GENDER, selectionList = genders)
showSelectionBottomSheetDialogFragment(bottomSheetWithSelectionType = BottomSheetWithSelectionType.GENDER, selectionList = genders, onDialogClosed = ::setEtKeywordSettingGenderText)
}
}

private fun setEtKeywordSettingAgeRangeClickListener(ageRanges: List<String>) {
binding.etKeywordSettingAgeRange.setOnClickListener {
showSelectionBottomSheetDialogFragment(bottomSheetWithSelectionType = BottomSheetWithSelectionType.AGE_RANGE, selectionList = ageRanges)
showSelectionBottomSheetDialogFragment(bottomSheetWithSelectionType = BottomSheetWithSelectionType.AGE_RANGE, selectionList = ageRanges, onDialogClosed = ::setEtKeywordSettingAgeRangeText)
}
}

private fun setEtKeywordSettingRelationClickListener(relations: List<String>) {
binding.etKeywordSettingRelation.setOnClickListener {
showSelectionBottomSheetDialogFragment(bottomSheetWithSelectionType = BottomSheetWithSelectionType.RELATION, selectionList = relations)
showSelectionBottomSheetDialogFragment(bottomSheetWithSelectionType = BottomSheetWithSelectionType.RELATION, selectionList = relations, onDialogClosed = ::setEtKeywordSettingRelationText)
}
}

Expand All @@ -180,11 +183,13 @@ class KeywordSettingFragment : BindingFragment<FragmentKeywordSettingBinding>({
private fun showSelectionBottomSheetDialogFragment(
bottomSheetWithSelectionType: BottomSheetWithSelectionType,
selectionList: List<String>,
) {
onDialogClosed: (String) -> Unit = {}
) {
BottomSheetWithSelectionDialogFragment(
bottomSheetWithSelectionType = bottomSheetWithSelectionType,
selectionList = selectionList,
bottomSheetWithSelectionAdapter = bottomSheetWithSelectionAdapter,
onDialogClosed = onDialogClosed
).show(childFragmentManager, SELECTION_BOTTOM_SHEET)
}

Expand All @@ -202,6 +207,18 @@ class KeywordSettingFragment : BindingFragment<FragmentKeywordSettingBinding>({
return keywords
}

private fun setEtKeywordSettingGenderText(gender: String) {
binding.etKeywordSettingGender.editText.setText(gender)
}

private fun setEtKeywordSettingAgeRangeText(ageRange: String) {
binding.etKeywordSettingAgeRange.editText.setText(ageRange)
}

private fun setEtKeywordSettingRelationText(relation: String) {
binding.etKeywordSettingRelation.editText.setText(relation)
}

companion object {
const val MAX_SELECTION = 3
const val SELECTION_BOTTOM_SHEET = "selectionBottomSheet"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dongguk.telepigeon.feature.setting.worrysetting

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
Expand Down Expand Up @@ -71,10 +70,6 @@ class WorrySettingFragment : BindingFragment<FragmentWorrySettingBinding>({ Frag
worrySettingViewModel.getWorries()
}

is UiState.Error -> {
Log.e("ㅋㅋ", deleteWorryState.message.toString())
}

else -> Unit
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
Expand Down

0 comments on commit 7f4dc9b

Please sign in to comment.