캔 충전/사용 내역 UI/API 추가
This commit is contained in:
@@ -13,6 +13,9 @@ import kr.co.vividnext.sodalive.main.MainViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.MyPageViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.auth.AuthApi
|
||||
import kr.co.vividnext.sodalive.mypage.auth.AuthRepository
|
||||
import kr.co.vividnext.sodalive.mypage.can.CanApi
|
||||
import kr.co.vividnext.sodalive.mypage.can.CanRepository
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.CanStatusViewModel
|
||||
import kr.co.vividnext.sodalive.network.TokenAuthenticator
|
||||
import kr.co.vividnext.sodalive.settings.event.EventApi
|
||||
import kr.co.vividnext.sodalive.settings.event.EventRepository
|
||||
@@ -72,6 +75,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
single { ApiBuilder().build(get(), EventApi::class.java) }
|
||||
single { ApiBuilder().build(get(), LiveRecommendApi::class.java) }
|
||||
single { ApiBuilder().build(get(), AuthApi::class.java) }
|
||||
single { ApiBuilder().build(get(), CanApi::class.java) }
|
||||
}
|
||||
|
||||
private val viewModelModule = module {
|
||||
@@ -82,6 +86,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
viewModel { MainViewModel(get()) }
|
||||
viewModel { LiveViewModel(get(), get(), get()) }
|
||||
viewModel { MyPageViewModel(get(), get()) }
|
||||
viewModel { CanStatusViewModel(get()) }
|
||||
}
|
||||
|
||||
private val repositoryModule = module {
|
||||
@@ -91,6 +96,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
factory { EventRepository(get()) }
|
||||
factory { LiveRecommendRepository(get()) }
|
||||
factory { AuthRepository(get()) }
|
||||
factory { CanRepository(get()) }
|
||||
}
|
||||
|
||||
private val moduleList = listOf(
|
||||
|
@@ -19,6 +19,7 @@ import kr.co.vividnext.sodalive.extensions.moneyFormat
|
||||
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.can.status.CanStatusActivity
|
||||
import kr.co.vividnext.sodalive.settings.notification.MemberRole
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
@@ -46,7 +47,14 @@ class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflat
|
||||
|
||||
binding.ivEdit.setOnClickListener {}
|
||||
|
||||
binding.tvTotalCoin.setOnClickListener {}
|
||||
binding.llTotalCoin.setOnClickListener {
|
||||
startActivity(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
CanStatusActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
binding.tvChargeCoin.setOnClickListener {}
|
||||
|
||||
|
@@ -0,0 +1,36 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can
|
||||
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.GetCanStatusResponse
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.charge.GetCanChargeStatusResponseItem
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.use.GetCanUseStatusResponseItem
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface CanApi {
|
||||
@GET("/can/status")
|
||||
fun getCanStatus(
|
||||
@Query("container") container: String = "aos",
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<GetCanStatusResponse>>
|
||||
|
||||
@GET("/can/status/use")
|
||||
fun getCanUseStatus(
|
||||
@Query("timezone") timezone: String,
|
||||
@Query("page") page: Int,
|
||||
@Query("size") size: Int,
|
||||
@Query("container") container: String = "aos",
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<List<GetCanUseStatusResponseItem>>>
|
||||
|
||||
@GET("/can/status/charge")
|
||||
fun getCanChargeStatus(
|
||||
@Query("timezone") timezone: String,
|
||||
@Query("page") page: Int,
|
||||
@Query("size") size: Int,
|
||||
@Query("container") container: String = "aos",
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<List<GetCanChargeStatusResponseItem>>>
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can
|
||||
|
||||
import java.util.TimeZone
|
||||
|
||||
class CanRepository(private val api: CanApi) {
|
||||
fun getCanStatus(token: String) = api.getCanStatus(authHeader = token)
|
||||
|
||||
fun getCanUseStatus(
|
||||
page: Int,
|
||||
pageSize: Int,
|
||||
token: String
|
||||
) = api.getCanUseStatus(
|
||||
timezone = TimeZone.getDefault().id,
|
||||
page = page - 1,
|
||||
size = pageSize,
|
||||
authHeader = token
|
||||
)
|
||||
|
||||
fun getCanChargeStatus(
|
||||
page: Int,
|
||||
pageSize: Int,
|
||||
token: String
|
||||
) = api.getCanChargeStatus(
|
||||
timezone = TimeZone.getDefault().id,
|
||||
page = page - 1,
|
||||
size = pageSize,
|
||||
authHeader = token
|
||||
)
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status
|
||||
|
||||
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.ActivityCanStatusBinding
|
||||
import kr.co.vividnext.sodalive.extensions.moneyFormat
|
||||
import kr.co.vividnext.sodalive.main.MainActivity
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.charge.CanChargeStatusFragment
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.use.CanUseStatusFragment
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
class CanStatusActivity : BaseActivity<ActivityCanStatusBinding>(
|
||||
ActivityCanStatusBinding::inflate
|
||||
) {
|
||||
|
||||
private val viewModel: CanStatusViewModel 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.getCanStatus()
|
||||
}
|
||||
|
||||
override fun setupView() {
|
||||
binding.toolbar.tvBack.text = "코인내역"
|
||||
binding.toolbar.tvBack.setOnClickListener { onClickBackButton() }
|
||||
binding.llChargeCoin.setOnClickListener {}
|
||||
|
||||
loadingDialog = LoadingDialog(this, layoutInflater)
|
||||
|
||||
val tabs = binding.tabs
|
||||
tabs.addTab(tabs.newTab().setText("충전내역").setTag("charge_status"))
|
||||
tabs.addTab(tabs.newTab().setText("사용내역").setTag("use_status"))
|
||||
|
||||
changeFragment("charge_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 == "charge_status") {
|
||||
CanChargeStatusFragment(viewModel)
|
||||
} else {
|
||||
CanUseStatusFragment(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.totalCoinLiveData.observe(this) {
|
||||
binding.tvTotalCoin.text = it.moneyFormat()
|
||||
}
|
||||
|
||||
viewModel.paidCoinLiveData.observe(this) {
|
||||
binding.tvPaidCoin.text = it.moneyFormat()
|
||||
}
|
||||
|
||||
viewModel.rewardCoinLiveData.observe(this) {
|
||||
binding.tvRewardCoin.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,145 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status
|
||||
|
||||
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.can.CanRepository
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.charge.GetCanChargeStatusResponseItem
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.use.GetCanUseStatusResponseItem
|
||||
|
||||
class CanStatusViewModel(private val repository: CanRepository) : BaseViewModel() {
|
||||
private val _totalCoinLiveData = MutableLiveData<Int>()
|
||||
val totalCoinLiveData: LiveData<Int>
|
||||
get() = _totalCoinLiveData
|
||||
|
||||
private val _paidCoinLiveData = MutableLiveData<Int>()
|
||||
val paidCoinLiveData: LiveData<Int>
|
||||
get() = _paidCoinLiveData
|
||||
|
||||
private val _rewardCoinLiveData = MutableLiveData<Int>()
|
||||
val rewardCoinLiveData: LiveData<Int>
|
||||
get() = _rewardCoinLiveData
|
||||
|
||||
private val _coinUseStatusLiveData = MutableLiveData<List<GetCanUseStatusResponseItem>>()
|
||||
val coinUseStatusLiveData: LiveData<List<GetCanUseStatusResponseItem>>
|
||||
get() = _coinUseStatusLiveData
|
||||
|
||||
private val _coinChargeStatusLiveData = MutableLiveData<List<GetCanChargeStatusResponseItem>>()
|
||||
val coinChargeStatusLiveData: LiveData<List<GetCanChargeStatusResponseItem>>
|
||||
get() = _coinChargeStatusLiveData
|
||||
|
||||
private val _toastLiveData = MutableLiveData<String?>()
|
||||
val toastLiveData: LiveData<String?>
|
||||
get() = _toastLiveData
|
||||
|
||||
private var _isLoading = MutableLiveData(false)
|
||||
val isLoading: LiveData<Boolean>
|
||||
get() = _isLoading
|
||||
|
||||
private val pageSize = 20
|
||||
private var canUsesPage = 1
|
||||
|
||||
fun getCanStatus() {
|
||||
_isLoading.value = true
|
||||
compositeDisposable.add(
|
||||
repository.getCanStatus("Bearer ${SharedPreferenceManager.token}")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
if (it.success && it.data != null) {
|
||||
_totalCoinLiveData.postValue(it.data.chargeCan + it.data.rewardCan)
|
||||
_paidCoinLiveData.postValue(it.data.chargeCan)
|
||||
_rewardCoinLiveData.postValue(it.data.rewardCan)
|
||||
} 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 getCoinUseStatus() {
|
||||
_isLoading.value = true
|
||||
compositeDisposable.add(
|
||||
repository.getCanUseStatus(
|
||||
canUsesPage,
|
||||
pageSize,
|
||||
"Bearer ${SharedPreferenceManager.token}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
if (it.success && it.data != null) {
|
||||
_coinUseStatusLiveData.postValue(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 getCanChargeStatus() {
|
||||
_isLoading.value = true
|
||||
compositeDisposable.add(
|
||||
repository.getCanChargeStatus(
|
||||
canUsesPage,
|
||||
pageSize,
|
||||
"Bearer ${SharedPreferenceManager.token}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
if (it.success && it.data != null) {
|
||||
_coinChargeStatusLiveData.postValue(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,10 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class GetCanStatusResponse(
|
||||
@SerializedName("chargeCan")
|
||||
val chargeCan: Int,
|
||||
@SerializedName("rewardCan")
|
||||
val rewardCan: Int
|
||||
)
|
@@ -0,0 +1,37 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status.charge
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCanChargeStatusBinding
|
||||
|
||||
class CanChargeStatusAdapter : RecyclerView.Adapter<CanChargeStatusAdapter.ViewHolder>() {
|
||||
|
||||
val items = mutableListOf<GetCanChargeStatusResponseItem>()
|
||||
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemCanChargeStatusBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(item: GetCanChargeStatusResponseItem) {
|
||||
binding.tvTitle.text = item.coinTitle
|
||||
binding.tvDate.text = item.date
|
||||
binding.tvChargeMethod.text = item.chargeMethod
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
ItemCanChargeStatusBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CanChargeStatusAdapter.ViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount() = items.count()
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status.charge
|
||||
|
||||
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.BaseFragment
|
||||
import kr.co.vividnext.sodalive.databinding.FragmentCanStatusBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.CanStatusViewModel
|
||||
|
||||
class CanChargeStatusFragment(
|
||||
private val viewModel: CanStatusViewModel
|
||||
) : BaseFragment<FragmentCanStatusBinding>(
|
||||
FragmentCanStatusBinding::inflate
|
||||
) {
|
||||
|
||||
private lateinit var adapter: CanChargeStatusAdapter
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupView()
|
||||
bindData()
|
||||
viewModel.getCanChargeStatus()
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun setupView() {
|
||||
val recyclerView = binding.rvCoinStatus
|
||||
adapter = CanChargeStatusAdapter()
|
||||
|
||||
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.coinChargeStatusLiveData.observe(viewLifecycleOwner) {
|
||||
adapter.items.addAll(it)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
viewModel.toastLiveData.observe(viewLifecycleOwner) {
|
||||
it?.let { Toast.makeText(requireContext(), it, Toast.LENGTH_LONG).show() }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status.charge
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class GetCanChargeStatusResponseItem(
|
||||
@SerializedName("coinTitle")
|
||||
val coinTitle: String,
|
||||
@SerializedName("date")
|
||||
val date: String,
|
||||
@SerializedName("chargeMethod")
|
||||
val chargeMethod: String
|
||||
)
|
@@ -0,0 +1,37 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status.use
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCanUseStatusBinding
|
||||
|
||||
class CanUseStatusAdapter : RecyclerView.Adapter<CanUseStatusAdapter.ViewHolder>() {
|
||||
|
||||
val items = mutableListOf<GetCanUseStatusResponseItem>()
|
||||
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemCanUseStatusBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(item: GetCanUseStatusResponseItem) {
|
||||
binding.tvTitle.text = item.title
|
||||
binding.tvDate.text = item.date
|
||||
binding.tvCoin.text = "${item.can}"
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
ItemCanUseStatusBinding.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,83 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status.use
|
||||
|
||||
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.BaseFragment
|
||||
import kr.co.vividnext.sodalive.databinding.FragmentCanStatusBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.mypage.can.status.CanStatusViewModel
|
||||
|
||||
class CanUseStatusFragment(
|
||||
private val viewModel: CanStatusViewModel
|
||||
) : BaseFragment<FragmentCanStatusBinding>(
|
||||
FragmentCanStatusBinding::inflate
|
||||
) {
|
||||
|
||||
private lateinit var adapter: CanUseStatusAdapter
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupView()
|
||||
bindData()
|
||||
viewModel.getCoinUseStatus()
|
||||
}
|
||||
|
||||
private fun setupView() {
|
||||
val recyclerView = binding.rvCoinStatus
|
||||
adapter = CanUseStatusAdapter()
|
||||
|
||||
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.coinUseStatusLiveData.observe(viewLifecycleOwner) {
|
||||
adapter.items.addAll(it)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
viewModel.toastLiveData.observe(viewLifecycleOwner) {
|
||||
it?.let { Toast.makeText(requireContext(), it, Toast.LENGTH_LONG).show() }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package kr.co.vividnext.sodalive.mypage.can.status.use
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class GetCanUseStatusResponseItem(
|
||||
@SerializedName("title")
|
||||
val title: String,
|
||||
@SerializedName("date")
|
||||
val date: String,
|
||||
@SerializedName("can")
|
||||
val can: Int
|
||||
)
|
Reference in New Issue
Block a user