feat: 포인트 내역 UI 추가
This commit is contained in:
@@ -126,6 +126,9 @@ import kr.co.vividnext.sodalive.mypage.can.payment.CanPaymentTempViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.can.payment.CanPaymentViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.can.payment.CanTempApi
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.CanStatusViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.point.PointStatusApi
|
||||
import kr.co.vividnext.sodalive.mypage.point.PointStatusRepository
|
||||
import kr.co.vividnext.sodalive.mypage.point.PointStatusViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.profile.ProfileUpdateViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.profile.nickname.NicknameUpdateViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.profile.tag.MemberTagApi
|
||||
@@ -236,6 +239,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
single { ApiBuilder().build(get(), AuditionApi::class.java) }
|
||||
single { ApiBuilder().build(get(), AdTrackingApi::class.java) }
|
||||
single { ApiBuilder().build(get(), SearchApi::class.java) }
|
||||
single { ApiBuilder().build(get(), PointStatusApi::class.java) }
|
||||
}
|
||||
|
||||
private val viewModelModule = module {
|
||||
@@ -331,6 +335,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
viewModel { CompletedSeriesViewModel(get()) }
|
||||
viewModel { AlarmContentAllViewModel(get()) }
|
||||
viewModel { SearchViewModel(get()) }
|
||||
viewModel { PointStatusViewModel(get()) }
|
||||
}
|
||||
|
||||
private val repositoryModule = module {
|
||||
@@ -373,6 +378,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
factory { AdTrackingRepository(get()) }
|
||||
factory { SearchRepository(get()) }
|
||||
factory { UserEventRepository(get()) }
|
||||
factory { PointStatusRepository(get()) }
|
||||
}
|
||||
|
||||
private val moduleList = listOf(
|
||||
|
||||
@@ -32,6 +32,7 @@ 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
|
||||
import kr.co.vividnext.sodalive.mypage.point.PointStatusActivity
|
||||
import kr.co.vividnext.sodalive.mypage.profile.ProfileUpdateActivity
|
||||
import kr.co.vividnext.sodalive.mypage.service_center.ServiceCenterActivity
|
||||
import kr.co.vividnext.sodalive.settings.SettingsActivity
|
||||
@@ -127,6 +128,15 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
)
|
||||
}
|
||||
|
||||
binding.llTotalPoint.setOnClickListener {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
PointStatusActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
binding.tvChargeCan.setOnClickListener {
|
||||
startActivity(
|
||||
Intent(
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@Keep
|
||||
data class GetPointStatusResponse(@SerializedName("point") val point: Int)
|
||||
@@ -0,0 +1,118 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.base.BaseActivity
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.databinding.ActivityPointStatusBinding
|
||||
import kr.co.vividnext.sodalive.extensions.moneyFormat
|
||||
import kr.co.vividnext.sodalive.main.MainActivity
|
||||
import kr.co.vividnext.sodalive.mypage.point.reward.PointRewardStatusFragment
|
||||
import kr.co.vividnext.sodalive.mypage.point.use.PointUseStatusFragment
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
class PointStatusActivity : BaseActivity<ActivityPointStatusBinding>(
|
||||
ActivityPointStatusBinding::inflate
|
||||
) {
|
||||
private val viewModel: PointStatusViewModel by inject()
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
onClickBackButton()
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var loadingDialog: LoadingDialog
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
bindData()
|
||||
viewModel.getPointStatus()
|
||||
}
|
||||
|
||||
override fun setupView() {
|
||||
binding.toolbar.tvBack.text = "포인트 내역"
|
||||
binding.toolbar.tvBack.setOnClickListener { onClickBackButton() }
|
||||
|
||||
loadingDialog = LoadingDialog(this, layoutInflater)
|
||||
|
||||
val tabs = binding.tabs
|
||||
tabs.addTab(tabs.newTab().setText("받은내역").setTag("reward_status"))
|
||||
tabs.addTab(tabs.newTab().setText("사용내역").setTag("use_status"))
|
||||
|
||||
changeFragment("reward_status")
|
||||
|
||||
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||
override fun onTabSelected(tab: TabLayout.Tab) {
|
||||
val tag = tab.tag as String
|
||||
changeFragment(tag)
|
||||
}
|
||||
|
||||
override fun onTabUnselected(tab: TabLayout.Tab) {
|
||||
}
|
||||
|
||||
override fun onTabReselected(tab: TabLayout.Tab) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun changeFragment(tag: String) {
|
||||
val fragmentManager = supportFragmentManager
|
||||
val fragmentTransaction = fragmentManager.beginTransaction()
|
||||
|
||||
val currentFragment = fragmentManager.primaryNavigationFragment
|
||||
if (currentFragment != null) {
|
||||
fragmentTransaction.hide(currentFragment)
|
||||
}
|
||||
|
||||
var fragment = fragmentManager.findFragmentByTag(tag)
|
||||
if (fragment == null) {
|
||||
fragment = if (tag == "reward_status") {
|
||||
PointRewardStatusFragment(viewModel)
|
||||
} else {
|
||||
PointUseStatusFragment(viewModel)
|
||||
}
|
||||
|
||||
fragmentTransaction.add(R.id.container, fragment, tag)
|
||||
} else {
|
||||
fragmentTransaction.show(fragment)
|
||||
}
|
||||
|
||||
fragmentTransaction.setPrimaryNavigationFragment(fragment)
|
||||
fragmentTransaction.setReorderingAllowed(true)
|
||||
fragmentTransaction.commitNow()
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun bindData() {
|
||||
viewModel.totalPointLiveData.observe(this) {
|
||||
binding.tvTotalPoint.text = it.moneyFormat()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onClickBackButton() {
|
||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point
|
||||
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.mypage.point.reward.GetPointRewardStatusResponse
|
||||
import kr.co.vividnext.sodalive.mypage.point.use.GetPointUseStatusResponse
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface PointStatusApi {
|
||||
@GET("/point/status")
|
||||
fun getPointStatus(
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<GetPointStatusResponse>>
|
||||
|
||||
@GET("/point/status/reward")
|
||||
fun getPointRewardStatus(
|
||||
@Query("timezone") timezone: String,
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<List<GetPointRewardStatusResponse>>>
|
||||
|
||||
@GET("/point/status/use")
|
||||
fun getPointUseStatus(
|
||||
@Query("timezone") timezone: String,
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<List<GetPointUseStatusResponse>>>
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point
|
||||
|
||||
import java.util.TimeZone
|
||||
|
||||
class PointStatusRepository(private val api: PointStatusApi) {
|
||||
fun getPointStatus(token: String) = api.getPointStatus(authHeader = token)
|
||||
|
||||
fun getPointRewardStatus(token: String) = api.getPointRewardStatus(
|
||||
timezone = TimeZone.getDefault().id,
|
||||
authHeader = token
|
||||
)
|
||||
|
||||
fun getPointUseStatus(token: String) = api.getPointUseStatus(
|
||||
timezone = TimeZone.getDefault().id,
|
||||
authHeader = token
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point
|
||||
|
||||
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.mypage.point.reward.GetPointRewardStatusResponse
|
||||
import kr.co.vividnext.sodalive.mypage.point.use.GetPointUseStatusResponse
|
||||
|
||||
class PointStatusViewModel(private val repository: PointStatusRepository) : BaseViewModel() {
|
||||
private val _totalPointLiveData = MutableLiveData<Int>()
|
||||
val totalPointLiveData: LiveData<Int>
|
||||
get() = _totalPointLiveData
|
||||
|
||||
private val _pointUseStatusLiveData = MutableLiveData<List<GetPointUseStatusResponse>>()
|
||||
val pointUseStatusLiveData: LiveData<List<GetPointUseStatusResponse>>
|
||||
get() = _pointUseStatusLiveData
|
||||
|
||||
private val _pointRewardStatusLiveData = MutableLiveData<List<GetPointRewardStatusResponse>>()
|
||||
val pointRewardStatusLiveData: LiveData<List<GetPointRewardStatusResponse>>
|
||||
get() = _pointRewardStatusLiveData
|
||||
|
||||
private val _toastLiveData = MutableLiveData<String?>()
|
||||
val toastLiveData: LiveData<String?>
|
||||
get() = _toastLiveData
|
||||
|
||||
private var _isLoading = MutableLiveData(false)
|
||||
val isLoading: LiveData<Boolean>
|
||||
get() = _isLoading
|
||||
|
||||
fun getPointStatus() {
|
||||
_isLoading.value = true
|
||||
compositeDisposable.add(
|
||||
repository.getPointStatus("Bearer ${SharedPreferenceManager.token}")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
if (it.success && it.data != null) {
|
||||
_totalPointLiveData.value = it.data.point
|
||||
} 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 getPointRewardStatus() {
|
||||
_isLoading.value = true
|
||||
compositeDisposable.add(
|
||||
repository.getPointRewardStatus(("Bearer ${SharedPreferenceManager.token}"))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
if (it.success && it.data != null) {
|
||||
_pointRewardStatusLiveData.value = it.data
|
||||
} 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 getPointUseStatus() {
|
||||
_isLoading.value = true
|
||||
compositeDisposable.add(
|
||||
repository.getPointUseStatus(("Bearer ${SharedPreferenceManager.token}"))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
if (it.success && it.data != null) {
|
||||
_pointUseStatusLiveData.value = it.data
|
||||
} else {
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(it.message)
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
_isLoading.value = false
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point.reward
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@Keep
|
||||
data class GetPointRewardStatusResponse(
|
||||
@SerializedName("rewardPoint") val rewardPoint: String,
|
||||
@SerializedName("date") val date: String,
|
||||
@SerializedName("method") val method: String
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point.reward
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCanChargeStatusBinding
|
||||
|
||||
class PointRewardStatusAdapter : RecyclerView.Adapter<PointRewardStatusAdapter.ViewHolder>() {
|
||||
val items = mutableListOf<GetPointRewardStatusResponse>()
|
||||
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemCanChargeStatusBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(item: GetPointRewardStatusResponse) {
|
||||
binding.tvTitle.text = item.rewardPoint
|
||||
binding.tvDate.text = item.date
|
||||
binding.tvChargeMethod.text = item.method
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
ItemCanChargeStatusBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount() = items.count()
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point.reward
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.base.BaseFragment
|
||||
import kr.co.vividnext.sodalive.databinding.FragmentCanStatusBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.mypage.point.PointStatusViewModel
|
||||
|
||||
class PointRewardStatusFragment(
|
||||
private val viewModel: PointStatusViewModel
|
||||
) : BaseFragment<FragmentCanStatusBinding>(
|
||||
FragmentCanStatusBinding::inflate
|
||||
) {
|
||||
|
||||
private lateinit var adapter: PointRewardStatusAdapter
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupView()
|
||||
bindData()
|
||||
viewModel.getPointRewardStatus()
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun setupView() {
|
||||
val recyclerView = binding.rvCanStatus
|
||||
adapter = PointRewardStatusAdapter()
|
||||
|
||||
recyclerView.layoutManager = LinearLayoutManager(
|
||||
requireContext(),
|
||||
LinearLayoutManager.VERTICAL,
|
||||
false
|
||||
)
|
||||
|
||||
recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
|
||||
when (parent.getChildAdapterPosition(view)) {
|
||||
0 -> {
|
||||
outRect.top = 13.3f.dpToPx().toInt()
|
||||
outRect.bottom = 6.7f.dpToPx().toInt()
|
||||
}
|
||||
|
||||
adapter.itemCount - 1 -> {
|
||||
outRect.top = 6.7f.dpToPx().toInt()
|
||||
outRect.bottom = 13.3f.dpToPx().toInt()
|
||||
}
|
||||
|
||||
else -> {
|
||||
outRect.top = 6.7f.dpToPx().toInt()
|
||||
outRect.bottom = 6.7f.dpToPx().toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun bindData() {
|
||||
viewModel.pointRewardStatusLiveData.observe(viewLifecycleOwner) {
|
||||
adapter.items.addAll(it)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point.use
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@Keep
|
||||
data class GetPointUseStatusResponse(
|
||||
@SerializedName("title") val title: String,
|
||||
@SerializedName("date") val date: String,
|
||||
@SerializedName("point") val point: Int
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point.use
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.databinding.ItemPointUseStatusBinding
|
||||
|
||||
class PointUseStatusAdapter : RecyclerView.Adapter<PointUseStatusAdapter.ViewHolder>() {
|
||||
val items = mutableListOf<GetPointUseStatusResponse>()
|
||||
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemPointUseStatusBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(item: GetPointUseStatusResponse) {
|
||||
binding.tvTitle.text = item.title
|
||||
binding.tvDate.text = item.date
|
||||
binding.tvPoint.text = "${item.point}"
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
ItemPointUseStatusBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount() = items.count()
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package kr.co.vividnext.sodalive.mypage.point.use
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.base.BaseFragment
|
||||
import kr.co.vividnext.sodalive.databinding.FragmentCanStatusBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.mypage.point.PointStatusViewModel
|
||||
|
||||
class PointUseStatusFragment(
|
||||
private val viewModel: PointStatusViewModel
|
||||
) : BaseFragment<FragmentCanStatusBinding>(
|
||||
FragmentCanStatusBinding::inflate
|
||||
) {
|
||||
|
||||
private lateinit var adapter: PointUseStatusAdapter
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupView()
|
||||
bindData()
|
||||
viewModel.getPointUseStatus()
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun setupView() {
|
||||
val recyclerView = binding.rvCanStatus
|
||||
adapter = PointUseStatusAdapter()
|
||||
|
||||
recyclerView.layoutManager = LinearLayoutManager(
|
||||
requireContext(),
|
||||
LinearLayoutManager.VERTICAL,
|
||||
false
|
||||
)
|
||||
|
||||
recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
|
||||
when (parent.getChildAdapterPosition(view)) {
|
||||
0 -> {
|
||||
outRect.top = 13.3f.dpToPx().toInt()
|
||||
outRect.bottom = 6.7f.dpToPx().toInt()
|
||||
}
|
||||
|
||||
adapter.itemCount - 1 -> {
|
||||
outRect.top = 6.7f.dpToPx().toInt()
|
||||
outRect.bottom = 13.3f.dpToPx().toInt()
|
||||
}
|
||||
|
||||
else -> {
|
||||
outRect.top = 6.7f.dpToPx().toInt()
|
||||
outRect.bottom = 6.7f.dpToPx().toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun bindData() {
|
||||
viewModel.pointUseStatusLiveData.observe(viewLifecycleOwner) {
|
||||
adapter.items.addAll(it)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user