차단 리스트 페이지 추가

This commit is contained in:
klaus 2024-09-04 12:31:32 +09:00
parent 6869cd62ea
commit 0ebb34a2df
15 changed files with 498 additions and 1 deletions

View File

@ -150,6 +150,7 @@
<activity android:name=".mypage.alarm.AlarmListActivity" />
<activity android:name=".mypage.alarm.AddAlarmActivity" />
<activity android:name=".mypage.alarm.select_audio_content.AlarmSelectAudioContentActivity" />
<activity android:name=".mypage.block.BlockMemberActivity" />
<activity
android:name=".mypage.alarm.AlarmActivity"
android:exported="true"

View File

@ -80,6 +80,7 @@ import kr.co.vividnext.sodalive.mypage.alarm.AlarmListRepository
import kr.co.vividnext.sodalive.mypage.alarm.AlarmListViewModel
import kr.co.vividnext.sodalive.mypage.auth.AuthApi
import kr.co.vividnext.sodalive.mypage.auth.AuthRepository
import kr.co.vividnext.sodalive.mypage.block.BlockMemberViewModel
import kr.co.vividnext.sodalive.mypage.can.CanApi
import kr.co.vividnext.sodalive.mypage.can.CanRepository
import kr.co.vividnext.sodalive.mypage.can.charge.iap.CanChargeIapViewModel
@ -256,6 +257,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
viewModel { CanCouponViewModel(get()) }
viewModel { CanChargeIapViewModel(get()) }
viewModel { AlarmListViewModel(get()) }
viewModel { BlockMemberViewModel(get()) }
}
private val repositoryModule = module {

View File

@ -32,6 +32,7 @@ import kr.co.vividnext.sodalive.mypage.alarm.AlarmListActivity
import kr.co.vividnext.sodalive.mypage.auth.Auth
import kr.co.vividnext.sodalive.mypage.auth.AuthVerifyRequest
import kr.co.vividnext.sodalive.mypage.auth.BootpayResponse
import kr.co.vividnext.sodalive.mypage.block.BlockMemberActivity
import kr.co.vividnext.sodalive.mypage.can.charge.CanChargeActivity
import kr.co.vividnext.sodalive.mypage.can.coupon.CanCouponActivity
import kr.co.vividnext.sodalive.mypage.can.status.CanStatusActivity
@ -208,6 +209,10 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
startActivity(Intent(requireContext(), FollowingCreatorActivity::class.java))
}
binding.tvBlockMemberList.setOnClickListener {
startActivity(Intent(requireContext(), BlockMemberActivity::class.java))
}
val ivHowToUseLp = binding.ivHowToUse.layoutParams as LinearLayout.LayoutParams
ivHowToUseLp.width = screenWidth
ivHowToUseLp.height = (200 * screenWidth) / 1080

View File

@ -0,0 +1,108 @@
package kr.co.vividnext.sodalive.mypage.block
import android.annotation.SuppressLint
import android.graphics.Rect
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kr.co.vividnext.sodalive.base.BaseActivity
import kr.co.vividnext.sodalive.common.LoadingDialog
import kr.co.vividnext.sodalive.databinding.ActivityBlockMemberBinding
import kr.co.vividnext.sodalive.extensions.dpToPx
import org.koin.android.ext.android.inject
class BlockMemberActivity : BaseActivity<ActivityBlockMemberBinding>(
ActivityBlockMemberBinding::inflate
) {
private val viewModel: BlockMemberViewModel by inject()
private lateinit var loadingDialog: LoadingDialog
private lateinit var adapter: BlockMemberAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bindData()
viewModel.getBlockedMemberList()
}
override fun setupView() {
loadingDialog = LoadingDialog(this, layoutInflater)
binding.toolbar.tvBack.text = "차단 리스트"
binding.toolbar.tvBack.setOnClickListener { finish() }
adapter = BlockMemberAdapter(
blockMember = { viewModel.blockMember(it) },
unBlockMember = { viewModel.unBlockMember(it) }
)
binding.rvBlockMember.layoutManager = LinearLayoutManager(
applicationContext,
LinearLayoutManager.VERTICAL,
false
)
binding.rvBlockMember.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val layoutManager = recyclerView.layoutManager as? LinearLayoutManager
if (
layoutManager != null &&
layoutManager.findLastCompletelyVisibleItemPosition() == adapter.itemCount - 1
) {
viewModel.getBlockedMemberList()
}
}
})
binding.rvBlockMember.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
super.getItemOffsets(outRect, view, parent, state)
outRect.left = 13.3f.dpToPx().toInt()
outRect.right = 13.3f.dpToPx().toInt()
}
})
binding.rvBlockMember.adapter = adapter
}
@SuppressLint("SetTextI18n")
private fun bindData() {
viewModel.toastLiveData.observe(this) {
it?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
}
viewModel.isLoading.observe(this) {
if (it) {
loadingDialog.show(screenWidth, "")
} else {
loadingDialog.dismiss()
}
}
viewModel.blockedMemberListLiveData.observe(this) {
adapter.addAll(it)
}
viewModel.blockedMemberTotalCountLiveData.observe(this) {
binding.tvTotalCount.text = " $it "
if (it > 0) {
binding.tvNone.visibility = View.GONE
binding.rvBlockMember.visibility = View.VISIBLE
} else {
binding.tvNone.visibility = View.VISIBLE
binding.rvBlockMember.visibility = View.GONE
}
}
}
}

View File

@ -0,0 +1,95 @@
package kr.co.vividnext.sodalive.mypage.block
import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil.transform.CircleCropTransformation
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.databinding.ItemBlockedMemberListBinding
class BlockMemberAdapter(
private val blockMember: (Long) -> Unit,
private val unBlockMember: (Long) -> Unit
) : RecyclerView.Adapter<BlockMemberAdapter.ViewHolder>() {
private val items = mutableListOf<GetBlockedMemberListItem>()
inner class ViewHolder(
private val context: Context,
private val binding: ItemBlockedMemberListBinding
) : RecyclerView.ViewHolder(binding.root) {
@SuppressLint("NotifyDataSetChanged")
fun bind(item: GetBlockedMemberListItem) {
binding.tvNickname.text = item.nickname
binding.ivProfile.load(item.profileImageUrl) {
transformations(CircleCropTransformation())
placeholder(R.drawable.bg_placeholder)
crossfade(true)
}
binding.tvBlock.visibility = View.VISIBLE
if (item.isBlocked) {
binding.tvBlock.text = "차단해제"
binding.tvBlock.background = ContextCompat.getDrawable(
context,
R.drawable.bg_round_corner_13_3_333bb9f1_3bb9f1
)
binding.tvBlock.setOnClickListener {
val index = items.indexOf(item)
val copyItem = item.copy(isBlocked = false)
items.add(index, copyItem)
items.removeAt(index + 1)
notifyDataSetChanged()
unBlockMember(item.memberId)
}
} else {
binding.tvBlock.text = "차단"
binding.tvBlock.background = ContextCompat.getDrawable(
context,
R.drawable.bg_round_corner_13_3_transparent_3bb9f1
)
binding.tvBlock.setOnClickListener {
val index = items.indexOf(item)
val copyItem = item.copy(isBlocked = true)
items.add(index, copyItem)
items.removeAt(index + 1)
notifyDataSetChanged()
blockMember(item.memberId)
}
}
}
}
@SuppressLint("NotifyDataSetChanged")
fun addAll(items: List<GetBlockedMemberListItem>) {
this.items.addAll(items)
notifyDataSetChanged()
}
fun clear() {
this.items.clear()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(
parent.context,
ItemBlockedMemberListBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
override fun onBindViewHolder(
holder: ViewHolder,
position: Int
) {
holder.bind(items[position])
}
override fun getItemCount() = items.size
}

View File

@ -0,0 +1,104 @@
package kr.co.vividnext.sodalive.mypage.block
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.orhanobut.logger.Logger
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
import kr.co.vividnext.sodalive.base.BaseViewModel
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.user.UserRepository
class BlockMemberViewModel(private val userRepository: UserRepository) : BaseViewModel() {
private val _blockedMemberListLiveData = MutableLiveData<List<GetBlockedMemberListItem>>()
val blockedMemberListLiveData: LiveData<List<GetBlockedMemberListItem>>
get() = _blockedMemberListLiveData
private val _blockedMemberTotalCountLiveData = MutableLiveData(0)
val blockedMemberTotalCountLiveData: LiveData<Int>
get() = _blockedMemberTotalCountLiveData
private var _isLoading = MutableLiveData(false)
val isLoading: LiveData<Boolean>
get() = _isLoading
private val _toastLiveData = MutableLiveData<String?>()
val toastLiveData: LiveData<String?>
get() = _toastLiveData
var page = 1
var isLast = false
private val pageSize = 10
fun getBlockedMemberList() {
if (!isLast && !_isLoading.value!!) {
_isLoading.value = true
compositeDisposable.add(
userRepository.getBlockedMemberList(
page = page,
size = pageSize,
token = "Bearer ${SharedPreferenceManager.token}"
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
_isLoading.value = false
if (it.success && it.data != null) {
val data = it.data
if (data.items.isEmpty()) {
isLast = true
} else {
page += 1
_blockedMemberTotalCountLiveData.value = data.totalCount
_blockedMemberListLiveData.value = data.items
}
} else {
if (it.message != null) {
_toastLiveData.postValue(it.message)
} else {
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
)
}
}
},
{
_isLoading.value = false
it.message?.let { message -> Logger.e(message) }
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
)
}
)
)
}
}
fun blockMember(blockMemberId: Long) {
_blockedMemberTotalCountLiveData.value = _blockedMemberTotalCountLiveData.value!! + 1
compositeDisposable.add(
userRepository.memberBlock(
blockMemberId,
"Bearer ${SharedPreferenceManager.token}"
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({}, {})
)
}
fun unBlockMember(blockMemberId: Long) {
_blockedMemberTotalCountLiveData.value = _blockedMemberTotalCountLiveData.value!! - 1
compositeDisposable.add(
userRepository.memberUnBlock(
blockMemberId,
"Bearer ${SharedPreferenceManager.token}"
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({}, {})
)
}
}

View File

@ -0,0 +1,18 @@
package kr.co.vividnext.sodalive.mypage.block
import androidx.annotation.Keep
import com.google.gson.annotations.SerializedName
@Keep
data class GetBlockedMemberListResponse(
@SerializedName("totalCount") val totalCount: Int,
@SerializedName("items") val items: List<GetBlockedMemberListItem>
)
@Keep
data class GetBlockedMemberListItem(
@SerializedName("memberId") val memberId: Long,
@SerializedName("nickname") val nickname: String,
@SerializedName("profileImageUrl") val profileImageUrl: String,
@SerializedName("isBlocked") val isBlocked: Boolean
)

View File

@ -7,6 +7,7 @@ import kr.co.vividnext.sodalive.live.room.detail.GetRoomDetailUser
import kr.co.vividnext.sodalive.main.GaidUpdateRequest
import kr.co.vividnext.sodalive.main.PushTokenUpdateRequest
import kr.co.vividnext.sodalive.mypage.MyPageResponse
import kr.co.vividnext.sodalive.mypage.block.GetBlockedMemberListResponse
import kr.co.vividnext.sodalive.mypage.profile.ProfileResponse
import kr.co.vividnext.sodalive.mypage.profile.ProfileUpdateRequest
import kr.co.vividnext.sodalive.mypage.profile.nickname.GetChangeNicknamePriceResponse
@ -144,4 +145,11 @@ interface UserApi {
@Body request: GaidUpdateRequest,
@Header("Authorization") authHeader: String
): Single<ApiResponse<Any>>
@GET("/member/block")
fun getBlockedMemberList(
@Query("page") page: Int,
@Query("size") size: Int,
@Header("Authorization") authHeader: String
): Single<ApiResponse<GetBlockedMemberListResponse>>
}

View File

@ -10,9 +10,9 @@ import kr.co.vividnext.sodalive.mypage.MyPageResponse
import kr.co.vividnext.sodalive.mypage.profile.ProfileResponse
import kr.co.vividnext.sodalive.mypage.profile.ProfileUpdateRequest
import kr.co.vividnext.sodalive.settings.notification.UpdateNotificationSettingRequest
import kr.co.vividnext.sodalive.settings.signout.SignOutRequest
import kr.co.vividnext.sodalive.user.find_password.ForgotPasswordRequest
import kr.co.vividnext.sodalive.user.login.LoginRequest
import kr.co.vividnext.sodalive.settings.signout.SignOutRequest
import okhttp3.MultipartBody
import okhttp3.RequestBody
@ -116,4 +116,10 @@ class UserRepository(private val userApi: UserApi) {
): Single<ApiResponse<Any>> {
return userApi.updateGaid(request, authHeader = token)
}
fun getBlockedMemberList(page: Int, size: Int, token: String) = userApi.getBlockedMemberList(
page = page - 1,
size = size,
authHeader = token
)
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/color_333bb9f1" />
<corners android:radius="13.3dp" />
<stroke
android:width="1dp"
android:color="@color/color_3bb9f1" />
</shape>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<corners android:radius="13.3dp" />
<stroke
android:width="1dp"
android:color="@color/color_3bb9f1" />
</shape>

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/detail_toolbar" />
<LinearLayout
android:id="@+id/ll_total_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="13.3dp"
android:orientation="horizontal"
android:paddingHorizontal="13.3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gmarket_sans_medium"
android:text="총"
android:textColor="@color/color_eeeeee"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_total_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gmarket_sans_medium"
android:textColor="@color/color_dd4500"
android:textSize="12sp"
tools:text=" 10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gmarket_sans_medium"
android:text="명"
android:textColor="@color/color_eeeeee"
android:textSize="12sp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_block_member"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="13.3dp"
android:clipToPadding="false"
android:paddingBottom="13.3dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ll_total_count" />
<TextView
android:id="@+id/tv_none"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="13.3dp"
android:fontFamily="@font/gmarket_sans_medium"
android:gravity="center"
android:text="차단한 유저가 없습니다."
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ll_total_count" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -176,6 +176,19 @@
android:text="팔로잉 리스트"
android:textColor="@color/color_3bb9f1"
android:textSize="15.3sp" />
<TextView
android:id="@+id/tv_block_member_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bg_round_corner_6_7_transparent_3bb9f1"
android:fontFamily="@font/gmarket_sans_bold"
android:gravity="center"
android:paddingVertical="13.3dp"
android:text="차단 리스트"
android:textColor="@color/color_3bb9f1"
android:textSize="15.3sp" />
</LinearLayout>
<RelativeLayout

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_profile"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:contentDescription="@null" />
<TextView
android:id="@+id/tv_nickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="13.3dp"
android:layout_toStartOf="@+id/tv_block"
android:layout_toEndOf="@+id/iv_profile"
android:fontFamily="@font/gmarket_sans_medium"
android:textSize="16.7sp"
tools:text="상남자" />
<TextView
android:id="@+id/tv_block"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:fontFamily="@font/gmarket_sans_medium"
android:gravity="center"
android:minWidth="83dp"
android:paddingVertical="7dp"
android:textColor="@color/color_3bb9f1"
tools:background="@drawable/bg_round_corner_13_3_333bb9f1_3bb9f1"
tools:text="차단해제" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/iv_profile"
android:layout_marginTop="26.7dp"
android:background="@color/color_88909090" />
</RelativeLayout>

View File

@ -123,4 +123,5 @@
<color name="color_312827">#312827</color>
<color name="color_f1291c">#F1291C</color>
<color name="color_ff14d9">#FF14D9</color>
<color name="color_333bb9f1">#333BB9F1</color>
</resources>