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,18 +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) {
binding.pingleCardTopMapPingleCard.initLayout(pingleEntity)
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 @@ -246,11 +249,11 @@ class MapFragment : BindingFragment<FragmentMapBinding>(R.layout.fragment_map),

private fun setLocationTrackingMode() {
if (LOCATION_PERMISSIONS.any { permission ->
ContextCompat.checkSelfPermission(
ContextCompat.checkSelfPermission(
requireContext(),
permission
) == PackageManager.PERMISSION_GRANTED
}
}
) {
locationSource = FusedLocationSource(this, LOCATION_PERMISSION_REQUEST_CODE)

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.PingleCardTop.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.PingleCardTop.Companion.MEETING_ID
import org.sopt.pingle.util.view.UiState

@AndroidEntryPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.sopt.pingle.util.component

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
Expand All @@ -11,7 +10,6 @@ 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.presentation.ui.participant.ParticipantActivity
import org.sopt.pingle.util.view.colorOf

@SuppressLint("CustomViewStyleable")
Expand All @@ -21,6 +19,7 @@ class PingleCardTop @JvmOverloads constructor(
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)
Expand Down Expand Up @@ -55,15 +54,12 @@ class PingleCardTop @JvmOverloads constructor(
}

layoutCardTopParticipationStatus.setOnClickListener {
Intent(context, ParticipantActivity::class.java).apply {
putExtra(MEETING_ID, pingleEntity.id)
context.startActivity(this)
}
onParticipationStatusLayoutClick(pingleEntity.id)
}
}
}

companion object {
const val MEETING_ID = "meetingId"
fun setOnParticipationStatusLayoutClick(participationStatusLayoutClickListener: (Long) -> Unit) {
onParticipationStatusLayoutClick = participationStatusLayoutClickListener
}
}