fix(mypage): 기능 버튼 배치와 쿠폰 분기를 정리한다
This commit is contained in:
@@ -4,11 +4,15 @@ import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.URLUtil
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.net.toUri
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.load
|
||||
@@ -20,10 +24,12 @@ import kr.co.vividnext.sodalive.audio_content.detail.AudioContentDetailActivity
|
||||
import kr.co.vividnext.sodalive.base.BaseFragment
|
||||
import kr.co.vividnext.sodalive.common.Constants
|
||||
import kr.co.vividnext.sodalive.common.FunctionButtonHelper
|
||||
import kr.co.vividnext.sodalive.common.GridSpacingItemDecoration
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.common.SodaLiveApplicationHolder
|
||||
import kr.co.vividnext.sodalive.databinding.FragmentMyBinding
|
||||
import kr.co.vividnext.sodalive.databinding.ItemFunctionButtonBinding
|
||||
import kr.co.vividnext.sodalive.explorer.profile.UserProfileActivity
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.extensions.moneyFormat
|
||||
@@ -52,10 +58,15 @@ import org.koin.android.ext.android.inject
|
||||
@UnstableApi
|
||||
class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflate) {
|
||||
|
||||
companion object {
|
||||
private const val FUNCTION_BUTTON_SPAN_COUNT = 4
|
||||
}
|
||||
|
||||
private val viewModel: MyPageViewModel by inject()
|
||||
private val recentContentViewModel: RecentContentViewModel by inject()
|
||||
|
||||
private lateinit var loadingDialog: LoadingDialog
|
||||
private val functionButtonAdapter = FunctionButtonAdapter()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
@@ -187,6 +198,7 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
binding.llProfileLoginContainer.visibility = View.GONE
|
||||
|
||||
binding.llFunctionButtonGrid.visibility = View.VISIBLE
|
||||
setupFunctionButtonGrid()
|
||||
|
||||
binding.ivSettings.setOnClickListener {
|
||||
startActivity(
|
||||
@@ -239,84 +251,6 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
}
|
||||
}
|
||||
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnStorage.root,
|
||||
iconRes = R.drawable.ic_my_storage,
|
||||
title = getString(R.string.screen_my_storage)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireContext(),
|
||||
AudioContentBoxActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnBlockList.root,
|
||||
iconRes = R.drawable.ic_my_block,
|
||||
title = getString(R.string.screen_my_block_list)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireContext(),
|
||||
BlockMemberActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnMorningCall.root,
|
||||
iconRes = R.drawable.ic_my_alarm,
|
||||
title = getString(R.string.screen_my_morning_call)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
AlarmListActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnNotice.root,
|
||||
iconRes = R.drawable.ic_my_notice,
|
||||
title = getString(R.string.screen_my_notice)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
NoticeActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnEvent.root,
|
||||
iconRes = R.drawable.ic_my_event,
|
||||
title = getString(R.string.screen_my_event)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
EventActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnCustomerService.root,
|
||||
iconRes = R.drawable.ic_my_service_center,
|
||||
title = getString(R.string.screen_my_customer_service)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
ServiceCenterActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (SharedPreferenceManager.role == MemberRole.CREATOR.name) {
|
||||
binding.tvMyChannel.visibility = View.VISIBLE
|
||||
binding.tvMyChannel.setOnClickListener {
|
||||
@@ -335,6 +269,8 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
} else {
|
||||
binding.tvMyChannel.visibility = View.GONE
|
||||
}
|
||||
|
||||
updateFunctionButtons()
|
||||
} else {
|
||||
binding.ivSettings.visibility = View.GONE
|
||||
binding.llFunctionButtonGrid.visibility = View.GONE
|
||||
@@ -380,29 +316,6 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
}
|
||||
|
||||
viewModel.myPageLiveData.observe(viewLifecycleOwner) {
|
||||
val isKoreanUser = SharedPreferenceManager.countryCode.ifBlank { "KR" } == "KR"
|
||||
|
||||
if (isKoreanUser) {
|
||||
binding.btnIdentityVerification.root.visibility = View.VISIBLE
|
||||
if (it.isAuth) {
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnIdentityVerification.root,
|
||||
iconRes = R.drawable.ic_my_auth,
|
||||
title = getString(R.string.screen_my_identity_verified)
|
||||
)
|
||||
} else {
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnIdentityVerification.root,
|
||||
iconRes = R.drawable.ic_my_auth,
|
||||
title = getString(R.string.screen_my_identity_verification)
|
||||
) {
|
||||
showAuthDialog()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
binding.btnIdentityVerification.root.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
binding.ivProfile.load(it.profileUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_place_holder)
|
||||
@@ -413,41 +326,75 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
binding.tvCanAmount.text = (it.chargeCan + it.rewardCan).moneyFormat()
|
||||
binding.tvPointAmount.text = it.point.moneyFormat()
|
||||
|
||||
val shouldShowCouponButton = if (isKoreanUser) {
|
||||
true
|
||||
} else {
|
||||
SharedPreferenceManager.isAdultContentVisible
|
||||
}
|
||||
updateFunctionButtons(it.isAuth)
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnCoupon.root.visibility = if (shouldShowCouponButton) {
|
||||
View.VISIBLE
|
||||
} else {
|
||||
View.GONE
|
||||
}
|
||||
private fun setupFunctionButtonGrid() {
|
||||
binding.rvFunctionButtons.layoutManager = GridLayoutManager(
|
||||
requireContext(),
|
||||
FUNCTION_BUTTON_SPAN_COUNT
|
||||
)
|
||||
|
||||
if (!shouldShowCouponButton) {
|
||||
return@observe
|
||||
}
|
||||
if (binding.rvFunctionButtons.itemDecorationCount == 0) {
|
||||
binding.rvFunctionButtons.addItemDecoration(
|
||||
GridSpacingItemDecoration(
|
||||
spanCount = FUNCTION_BUTTON_SPAN_COUNT,
|
||||
spacing = 16f.dpToPx().toInt(),
|
||||
includeEdge = false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.isAuth || !isKoreanUser) {
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnCoupon.root,
|
||||
iconRes = R.drawable.ic_my_coupon,
|
||||
title = getString(R.string.screen_my_coupon_register)
|
||||
) {
|
||||
binding.rvFunctionButtons.adapter = functionButtonAdapter
|
||||
}
|
||||
|
||||
private fun updateFunctionButtons(isAuth: Boolean? = null) {
|
||||
val isKoreanUser = SharedPreferenceManager.countryCode.ifBlank { "KR" } == "KR"
|
||||
val items = mutableListOf(
|
||||
FunctionButtonItem(
|
||||
iconRes = R.drawable.ic_my_storage,
|
||||
title = getString(R.string.screen_my_storage)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireContext(),
|
||||
AudioContentBoxActivity::class.java
|
||||
)
|
||||
)
|
||||
},
|
||||
FunctionButtonItem(
|
||||
iconRes = R.drawable.ic_my_block,
|
||||
title = getString(R.string.screen_my_block_list)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireContext(),
|
||||
BlockMemberActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
val shouldShowCouponButton = if (isKoreanUser) {
|
||||
isAuth != null
|
||||
} else {
|
||||
SharedPreferenceManager.isAdultContentVisible
|
||||
}
|
||||
|
||||
if (shouldShowCouponButton) {
|
||||
items += FunctionButtonItem(
|
||||
iconRes = R.drawable.ic_my_coupon,
|
||||
title = getString(R.string.screen_my_coupon_register)
|
||||
) {
|
||||
if ((isAuth == true) || !isKoreanUser) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
CanCouponActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.btnCoupon.root,
|
||||
iconRes = R.drawable.ic_my_coupon,
|
||||
title = getString(R.string.screen_my_coupon_register)
|
||||
) {
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
getString(R.string.screen_my_auth_required),
|
||||
@@ -458,6 +405,70 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items += listOf(
|
||||
FunctionButtonItem(
|
||||
iconRes = R.drawable.ic_my_alarm,
|
||||
title = getString(R.string.screen_my_morning_call)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
AlarmListActivity::class.java
|
||||
)
|
||||
)
|
||||
},
|
||||
FunctionButtonItem(
|
||||
iconRes = R.drawable.ic_my_notice,
|
||||
title = getString(R.string.screen_my_notice)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
NoticeActivity::class.java
|
||||
)
|
||||
)
|
||||
},
|
||||
FunctionButtonItem(
|
||||
iconRes = R.drawable.ic_my_event,
|
||||
title = getString(R.string.screen_my_event)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
EventActivity::class.java
|
||||
)
|
||||
)
|
||||
},
|
||||
FunctionButtonItem(
|
||||
iconRes = R.drawable.ic_my_service_center,
|
||||
title = getString(R.string.screen_my_customer_service)
|
||||
) {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
ServiceCenterActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
if (isKoreanUser && isAuth != null) {
|
||||
items += FunctionButtonItem(
|
||||
iconRes = R.drawable.ic_my_auth,
|
||||
title = if (isAuth) {
|
||||
getString(R.string.screen_my_identity_verified)
|
||||
} else {
|
||||
getString(R.string.screen_my_identity_verification)
|
||||
}
|
||||
) {
|
||||
if (!isAuth) {
|
||||
showAuthDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
functionButtonAdapter.submitList(items)
|
||||
}
|
||||
|
||||
private fun showAuthDialog() {
|
||||
@@ -486,3 +497,47 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class FunctionButtonItem(
|
||||
@field:DrawableRes val iconRes: Int,
|
||||
val title: String,
|
||||
val onClick: () -> Unit
|
||||
)
|
||||
|
||||
private class FunctionButtonAdapter : RecyclerView.Adapter<FunctionButtonAdapter.ViewHolder>() {
|
||||
private val items = mutableListOf<FunctionButtonItem>()
|
||||
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemFunctionButtonBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(item: FunctionButtonItem) {
|
||||
FunctionButtonHelper.setupFunctionButton(
|
||||
buttonView = binding.root,
|
||||
iconRes = item.iconRes,
|
||||
title = item.title,
|
||||
clickListener = View.OnClickListener { item.onClick() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(
|
||||
ItemFunctionButtonBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount() = items.size
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun submitList(newItems: List<FunctionButtonItem>) {
|
||||
items.clear()
|
||||
items.addAll(newItems)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,86 +276,13 @@
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<!-- First Row -->
|
||||
<LinearLayout
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_function_buttons"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<include
|
||||
android:id="@+id/btn_storage"
|
||||
layout="@layout/item_function_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<include
|
||||
android:id="@+id/btn_block_list"
|
||||
layout="@layout/item_function_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<include
|
||||
android:id="@+id/btn_coupon"
|
||||
layout="@layout/item_function_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<include
|
||||
android:id="@+id/btn_morning_call"
|
||||
layout="@layout/item_function_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Second Row -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<include
|
||||
android:id="@+id/btn_notice"
|
||||
layout="@layout/item_function_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<include
|
||||
android:id="@+id/btn_event"
|
||||
layout="@layout/item_function_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<include
|
||||
android:id="@+id/btn_customer_service"
|
||||
layout="@layout/item_function_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<include
|
||||
android:id="@+id/btn_identity_verification"
|
||||
layout="@layout/item_function_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
android:nestedScrollingEnabled="false"
|
||||
tools:itemCount="8"
|
||||
tools:listitem="@layout/item_function_button" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user