Skip to content

Commit

Permalink
[chore] #194 나의 단체 뷰 : 코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
HAJIEUN02 committed Mar 1, 2024
1 parent 45319c2 commit 62b6a15
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.sopt.pingle.R
import org.sopt.pingle.databinding.ActivityMyGroupBinding
import org.sopt.pingle.domain.model.MyGroupEntity
import org.sopt.pingle.presentation.type.SnackbarType
import org.sopt.pingle.presentation.ui.onboarding.OnBoardingActivity
import org.sopt.pingle.util.base.BindingActivity
Expand All @@ -33,10 +34,8 @@ class MyGroupActivity : BindingActivity<ActivityMyGroupBinding>(R.layout.activit
super.onCreate(savedInstanceState)

binding.myGroupviewModel = viewModel
binding.lifecycleOwner = this

initLayout()
initAdapter()
addListeners()
collectData()
}
Expand All @@ -48,7 +47,8 @@ class MyGroupActivity : BindingActivity<ActivityMyGroupBinding>(R.layout.activit

private fun initLayout() {
viewModel.getGroupList()
binding.toolbarMyGroup.text = getString(R.string.my_group_title)
binding.toolbarMyGroup.text = stringOf(R.string.my_group_title)
initAdapter()
}

private fun initAdapter() {
Expand Down Expand Up @@ -77,7 +77,7 @@ class MyGroupActivity : BindingActivity<ActivityMyGroupBinding>(R.layout.activit

viewModel.selectedMyGroup.flowWithLifecycle(lifecycle).onEach { selectedMyGroup ->
with(binding) {
if (selectedMyGroup!!.isOwner) {
if (selectedMyGroup?.isOwner == true) {
ivMyGroupSelectedOwner.visibility = View.VISIBLE
} else {
ivMyGroupSelectedOwner.visibility = View.INVISIBLE
Expand All @@ -96,22 +96,22 @@ class MyGroupActivity : BindingActivity<ActivityMyGroupBinding>(R.layout.activit
}
}

private fun showChangeGroupModal(clickedPosition: Int) {
private fun showChangeGroupModal(clickedEntity: MyGroupEntity) {
binding.layoutMyGroupSelectedMenu.visibility = View.INVISIBLE
MyGroupModalDialogFragment(
title = getString(
R.string.my_group_modal_move_question,
viewModel.filteredGroupList.value[clickedPosition].name
clickedEntity.name
),
buttonText = getString(R.string.my_group_modal_change),
textButtonText = getString(R.string.my_group_modal_back),
clickBtn = { chageToNewGroup(clickedPosition) },
buttonText = stringOf(R.string.my_group_modal_change),
textButtonText = stringOf(R.string.my_group_modal_back),
clickBtn = { chageToNewGroup(clickedEntity) },
clickTextBtn = { }
).show(supportFragmentManager, CHANGE_MODAL)
}

private fun chageToNewGroup(clickedPosition: Int) {
viewModel.changeGroupList(clickedPosition)
private fun chageToNewGroup(clickedEntity: MyGroupEntity) {
viewModel.changeGroupList(clickedEntity)

PingleSnackbar.makeSnackbar(
view = binding.root,
Expand All @@ -135,9 +135,7 @@ class MyGroupActivity : BindingActivity<ActivityMyGroupBinding>(R.layout.activit
private fun shareGroupCode() {
// TODO 콘텐츠 내용 알려주면 ContextExt와 함께 수정
binding.layoutMyGroupSelectedMenu.visibility = View.INVISIBLE
this.sharePingle(
"핑글 앱을 다운받고, ${viewModel.getGroupName()} 사람들을 만나보세요!\n\n$PINGLE_SHARE_CODE ${viewModel.getGroupCode()} \n\n $PINGLE_PLAY_STORE_LINK"
)
this.sharePingle(getString(R.string.my_group_share_pingle, viewModel.getGroupName(), PINGLE_SHARE_CODE, viewModel.getGroupCode(), PINGLE_PLAY_STORE_LINK))
}

private fun navigateToNewGroupInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.sopt.pingle.domain.model.MyGroupEntity
import org.sopt.pingle.util.view.ItemDiffCallback

class MyGroupAdapter(
private val groupOnClick: (Int) -> Unit
private val groupOnClick: (MyGroupEntity) -> Unit
) : ListAdapter<MyGroupEntity, RecyclerView.ViewHolder>(
ItemDiffCallback<MyGroupEntity>(
onContentsTheSame = { old, new -> old == new },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import org.sopt.pingle.domain.model.MyGroupEntity

class MyGroupOwnerViewHolder(
private val binding: ItemMyGroupOwnerBinding,
private val groupOnClick: (Int) -> Unit
private val groupOnClick: (MyGroupEntity) -> Unit
) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(myGroupEntity: MyGroupEntity) {
with(binding) {
this.groupListEntity = myGroupEntity
tvMyGroupOwnerName.text = myGroupEntity.name
layoutMyGroupOwner.setOnClickListener { groupOnClick(absoluteAdapterPosition) }
layoutMyGroupOwner.setOnClickListener { groupOnClick(myGroupEntity) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import org.sopt.pingle.domain.model.MyGroupEntity

class MyGroupViewHolder(
private val binding: ItemMyGroupDefaultBinding,
private val groupOnClick: (Int) -> Unit
private val groupOnClick: (MyGroupEntity) -> Unit
) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(myGroupEntity: MyGroupEntity) {
with(binding) {
this.groupListEntity = myGroupEntity
tvMyGroupDefaultName.text = myGroupEntity.name
layoutMyGroupDefault.setOnClickListener { groupOnClick(absoluteAdapterPosition) }
layoutMyGroupDefault.setOnClickListener { groupOnClick(myGroupEntity) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,51 @@ class MyGroupViewModel @Inject constructor(
fun getGroupList() {
// TODO 서버통신
selectedMyGroup.value = dummyGroupList.find { it.id == localStorgae.groupId }
selectedMyGroup.value.let {
selectedMyGroup.value?.let { selectedMyGroup ->
with(localStorgae) {
groupId = it!!.id
groupName = it!!.name
groupKeyword = it!!.keyword
meetingCount = it!!.meetingCount
participantCount = it!!.participantCount
isOwner = it!!.isOwner
code = it!!.code
groupId = selectedMyGroup.id
groupName = selectedMyGroup.name
groupKeyword = selectedMyGroup.keyword
meetingCount = selectedMyGroup.meetingCount
participantCount = selectedMyGroup.participantCount
isOwner = selectedMyGroup.isOwner
code = selectedMyGroup.code
}
}

_filteredGroupList.value = dummyGroupList.filterNot { it == selectedMyGroup.value }
}

fun changeGroupList(clickedPosition: Int) {
fun changeGroupList(clickedEntity: MyGroupEntity) {
// _filteredGroupList의 clickedPosition에 해당하는 값을 localStorage에 저장하고,
// _filteredGroupList의 clickedPosition에 selectedMyGroup를 저장
// selectedMyGroup에는 localStorage에 저장된 값과 같은 GroupListEntity를 저장
val clickedGroup = _filteredGroupList.value.getOrNull(clickedPosition)
clickedGroup?.let {
clickedEntity?.let { clickedEntity ->
with(localStorgae) {
groupId = it.id
groupName = it.name
groupKeyword = it.keyword
meetingCount = it.meetingCount
participantCount = it.participantCount
isOwner = it.isOwner
code = it.code
groupId = clickedEntity.id
groupName = clickedEntity.name
groupKeyword = clickedEntity.keyword
meetingCount = clickedEntity.meetingCount
participantCount = clickedEntity.participantCount
isOwner = clickedEntity.isOwner
code = clickedEntity.code
}
}
_selectedMyGroup.value = clickedGroup
_selectedMyGroup.value = clickedEntity
_filteredGroupList.value = dummyGroupList.filterNot { it == selectedMyGroup.value }
}

fun getMyGroupIsOwner(): Boolean = _selectedMyGroup.value!!.isOwner
fun getMyGroupIsOwner(): Boolean = _selectedMyGroup.value?.isOwner ?: false

fun getGroupName(): String = _selectedMyGroup.value!!.name
fun getGroupName(): String = _selectedMyGroup.value?.name.orEmpty()

fun getGroupMeetingCount(): String = _selectedMyGroup.value!!.meetingCount
fun getGroupMeetingCount(): String = _selectedMyGroup.value?.meetingCount.orEmpty()

fun getGroupParticipantCount(): String = _selectedMyGroup.value!!.participantCount
fun getGroupParticipantCount(): String = _selectedMyGroup.value?.participantCount.orEmpty()

fun getGroupCode(): String = _selectedMyGroup.value!!.code
fun getGroupCode(): String = _selectedMyGroup.value?.code.orEmpty()

fun getGroupKeyword(): String = _selectedMyGroup.value!!.keyword
fun getGroupKeyword(): String = _selectedMyGroup.value?.keyword.orEmpty()

val dummyGroupList = listOf<MyGroupEntity>(
MyGroupEntity(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,5 @@
<string name="my_group_snack_bar_chage_group_complete">단체가 변경되었습니다!</string>
<string name="my_group_menu_copy">초대코드 복사하기</string>
<string name="my_group_menu_share">공유하기</string>
<string name="my_group_share_pingle">핑글 앱을 다운받고, %s 사람들을 만나보세요!\n\n%s %s\n\n %s</string>
</resources>

0 comments on commit 62b6a15

Please sign in to comment.