Skip to content
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

[refactor] 핑글 카드 커스텀 뷰 분리 및 지도 ViewPager Item 재구현 #185

Merged
merged 10 commits into from
Feb 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.sopt.pingle.domain.model.PingleEntity
import org.sopt.pingle.util.view.ItemDiffCallback

class MapCardAdapter(
private val navigateToParticipant: (Long) -> Unit,
private val navigateToWebViewWithChatLink: (String) -> Unit,
private val showMapJoinModalDialogFragment: (PingleEntity) -> Unit,
private val showMapCancelModalDialogFragment: (PingleEntity) -> Unit,
Expand All @@ -23,11 +24,16 @@ class MapCardAdapter(

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapCardViewHolder =
MapCardViewHolder(
ItemMapPingleCardBinding.inflate(LayoutInflater.from(parent.context), parent, false),
navigateToWebViewWithChatLink,
showMapJoinModalDialogFragment,
showMapCancelModalDialogFragment,
showMapDeleteModalDialogFragment
binding = ItemMapPingleCardBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
),
navigateToParticipant = navigateToParticipant,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

named parameter 좋네여 ~~

navigateToWebViewWithChatLink = navigateToWebViewWithChatLink,
showMapJoinModalDialogFragment = showMapJoinModalDialogFragment,
showMapCancelModalDialogFragment = showMapCancelModalDialogFragment,
showMapDeleteModalDialogFragment = showMapDeleteModalDialogFragment
)

override fun onBindViewHolder(holder: MapCardViewHolder, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ import org.sopt.pingle.domain.model.PingleEntity

class MapCardViewHolder(
private val binding: ItemMapPingleCardBinding,
private val navigateToWebView: (String) -> Unit,
private val navigateToParticipant: (Long) -> Unit,
private val navigateToWebViewWithChatLink: (String) -> Unit,
private val showMapJoinModalDialogFragment: (PingleEntity) -> Unit,
private val showMapCancelModalDialogFragment: (PingleEntity) -> Unit,
private val showMapDeleteModalDialogFragment: (PingleEntity) -> Unit
) : RecyclerView.ViewHolder(binding.root) {
fun onBind(pinId: Long, pingleEntity: PingleEntity) {
with(binding.cardMapPingleCard) {
with(binding.pingleCardTopMapPingleCard) {
initLayout(pingleEntity)
setOnParticipationStatusLayoutClick {
navigateToParticipant(pingleEntity.id)
}
}

with(binding.pingleCardBottomMapPingleCard) {
initLayout(pingleEntity)
setPinId(pinId)
setOnChatButtonClick {
navigateToWebView(pingleEntity.chatLink)
navigateToWebViewWithChatLink(pingleEntity.chatLink)
}
setOnParticipateButtonClick {
when {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.pingle.presentation.ui.main.home.map

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Rect
import android.os.Bundle
Expand Down Expand Up @@ -34,6 +35,7 @@ import org.sopt.pingle.domain.model.PingleEntity
import org.sopt.pingle.presentation.mapper.toMarkerModel
import org.sopt.pingle.presentation.type.CategoryType
import org.sopt.pingle.presentation.ui.main.home.mainlist.MainListFragment
import org.sopt.pingle.presentation.ui.participant.ParticipantActivity
import org.sopt.pingle.util.base.BindingFragment
import org.sopt.pingle.util.component.AllModalDialogFragment
import org.sopt.pingle.util.component.PingleChip
Expand Down Expand Up @@ -109,6 +111,7 @@ class MapFragment : BindingFragment<FragmentMapBinding>(R.layout.fragment_map),

private fun initLayout() {
mapCardAdapter = MapCardAdapter(
navigateToParticipant = ::navigateToParticipant,
navigateToWebViewWithChatLink = ::navigateToWebViewWithChatLink,
showMapJoinModalDialogFragment = ::showMapJoinModalDialogFragment,
showMapCancelModalDialogFragment = ::showMapCancelModalDialogFragment,
Expand Down Expand Up @@ -302,6 +305,13 @@ class MapFragment : BindingFragment<FragmentMapBinding>(R.layout.fragment_map),
}
}

private fun navigateToParticipant(pingleEntityId: Long) {
Intent(context, ParticipantActivity::class.java).apply {
putExtra(MEETING_ID, pingleEntityId)
startActivity(this)
}
}

private fun navigateToWebViewWithChatLink(chatLink: String) {
startActivity(navigateToWebView(chatLink))
}
Expand Down Expand Up @@ -371,5 +381,7 @@ class MapFragment : BindingFragment<FragmentMapBinding>(R.layout.fragment_map),

private const val VIEWPAGER_ITEM_OFFSET = 24
private const val VIEWPAGER_PAGE_TRANSFORMER = -40

const val MEETING_ID = "meetingId"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import org.sopt.pingle.R
import org.sopt.pingle.databinding.FragmentMyPingleBinding
import org.sopt.pingle.domain.model.MyPingleEntity
import org.sopt.pingle.presentation.type.MyPingleType
import org.sopt.pingle.presentation.ui.main.home.map.MapFragment.Companion.MEETING_ID
import org.sopt.pingle.presentation.ui.participant.ParticipantActivity
import org.sopt.pingle.util.base.BindingFragment
import org.sopt.pingle.util.component.AllModalDialogFragment
import org.sopt.pingle.util.component.PingleCard.Companion.MEETING_ID
import org.sopt.pingle.util.fragment.stringOf
import org.sopt.pingle.util.view.UiState

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.sopt.pingle.R
import org.sopt.pingle.databinding.ActivityParticipantBinding
import org.sopt.pingle.presentation.ui.main.home.map.MapFragment.Companion.MEETING_ID
import org.sopt.pingle.util.base.BindingActivity
import org.sopt.pingle.util.component.PingleCard.Companion.MEETING_ID
import org.sopt.pingle.util.view.UiState

@AndroidEntryPoint
Expand Down
116 changes: 0 additions & 116 deletions app/src/main/java/org/sopt/pingle/util/component/PingleCard.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.sopt.pingle.util.component

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import org.sopt.pingle.R
import org.sopt.pingle.databinding.BottomCardPingleBinding
import org.sopt.pingle.domain.model.PingleEntity
import org.sopt.pingle.presentation.mapper.isCompleted
import org.sopt.pingle.util.convertToCalenderDetailWithNewLine
import org.sopt.pingle.util.view.stringOf

@SuppressLint("CustomViewStyleable")
class PingleCardBottom @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
private val binding: BottomCardPingleBinding
private var onChatButtonClick: () -> Unit = {}
private var onParticipateButtonClick: (Long?) -> Unit = {}
private var _pinId: Long? = null
val pinId get() = _pinId

init {
binding = BottomCardPingleBinding.inflate(LayoutInflater.from(context), this, true)

addListeners()
}

private fun addListeners() {
binding.btnCardBottomMapChat.setOnClickListener {
onChatButtonClick()
}

binding.btnCardBottomMapParticipate.setOnClickListener {
onParticipateButtonClick(pinId)
}
}

fun initLayout(pingleEntity: PingleEntity) {
with(binding) {
tvCardBottomCalenderDetail.text = convertToCalenderDetailWithNewLine(
date = pingleEntity.date,
startAt = pingleEntity.startAt,
endAt = pingleEntity.endAt
)
tvCardBottomMapDetail.text = pingleEntity.location
btnCardBottomMapChat.isEnabled = pingleEntity.isParticipating
btnCardBottomMapParticipate.isEnabled = when {
pingleEntity.isOwner -> true
else -> pingleEntity.isParticipating || !pingleEntity.isCompleted()
}

btnCardBottomMapParticipate.text =
when {
pingleEntity.isOwner -> stringOf(R.string.pingle_card_delete)
pingleEntity.isParticipating -> stringOf(R.string.pingle_card_cancel)
else -> stringOf(R.string.pingle_card_participate)
}
Comment on lines +58 to +62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오옹 이런식으로 when문 사용하는 거 너무 좋네요

}
}

fun setPinId(pinId: Long) {
_pinId = pinId
}

fun setOnChatButtonClick(chatButtonClickListener: () -> Unit) {
onChatButtonClick = chatButtonClickListener
}

fun setOnParticipateButtonClick(participateButtonClickListener: (Long?) -> Unit) {
onParticipateButtonClick = participateButtonClickListener
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.sopt.pingle.util.component

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import org.sopt.pingle.databinding.TopCardPingleBinding
import org.sopt.pingle.domain.model.PingleEntity
import org.sopt.pingle.presentation.mapper.isCompleted
import org.sopt.pingle.presentation.type.CategoryType
import org.sopt.pingle.util.view.colorOf

@SuppressLint("CustomViewStyleable")
class PingleCardTop @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
private val binding: TopCardPingleBinding
private var onParticipationStatusLayoutClick: (Long) -> Unit = {}

init {
binding = TopCardPingleBinding.inflate(LayoutInflater.from(context), this, true)
}

fun initLayout(pingleEntity: PingleEntity) {
with(binding) {
(CategoryType.fromString(pingleEntity.category)).let { category ->
badgeCardTopInfo.setBadgeCategoryType(category)
tvCardTopInfoParticipationStatusCurrentParticipants.setTextColor(colorOf(category.textColor))
tvCardTopInfoName.setTextColor(colorOf(category.textColor))
}
tvCardTopInfoName.text = pingleEntity.name
tvCardTopInfoOwnerName.text = pingleEntity.ownerName

(pingleEntity.isCompleted()).let { isCompleted ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋네요!! 언니가 코리 달아준 스코프 함수를 이용해서 깔쌈하게 비지블 처리해주기

tvCardTopInfoParticipationStatusSlash.visibility =
if (isCompleted) View.INVISIBLE else View.VISIBLE
tvCardTopInfoParticipationStatusCurrentParticipants.visibility =
if (isCompleted) View.INVISIBLE else View.VISIBLE
tvCardTopInfoParticipationStatusMaxParticipants.visibility =
if (isCompleted) View.INVISIBLE else View.VISIBLE
tvCardTopInfoParticipationCompleted.visibility =
if (isCompleted) View.VISIBLE else View.INVISIBLE

if (!isCompleted) {
tvCardTopInfoParticipationStatusCurrentParticipants.text =
pingleEntity.curParticipants.toString()
tvCardTopInfoParticipationStatusMaxParticipants.text =
pingleEntity.maxParticipants.toString()
}
}

layoutCardTopParticipationStatus.setOnClickListener {
onParticipationStatusLayoutClick(pingleEntity.id)
}
}
}

fun setOnParticipationStatusLayoutClick(participationStatusLayoutClickListener: (Long) -> Unit) {
onParticipationStatusLayoutClick = participationStatusLayoutClickListener
}
}
Loading
Loading