|
|
@@ -1,206 +1,84 @@
|
|
|
package com.adealink.weparty.wallet.coin
|
|
|
|
|
|
-import android.os.Bundle
|
|
|
-import androidx.activity.viewModels
|
|
|
-import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
+import androidx.fragment.app.Fragment
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
-import com.adealink.frame.aab.util.getCompatColor
|
|
|
-import com.adealink.frame.base.Rlt
|
|
|
-import com.adealink.frame.base.fastLazy
|
|
|
+import com.adealink.frame.aab.util.getCompatString
|
|
|
import com.adealink.frame.mvvm.view.viewBinding
|
|
|
import com.adealink.frame.router.annotation.RouterUri
|
|
|
-import com.adealink.frame.util.timeToEnYM
|
|
|
import com.adealink.weparty.commonui.BaseActivity
|
|
|
-import com.adealink.weparty.commonui.datepicker.CustomDatePicker
|
|
|
-import com.adealink.weparty.commonui.recycleview.adapter.MultiTypeListAdapter
|
|
|
-import com.adealink.weparty.commonui.recycleview.commonviewholder.CommonListEmptyItemData
|
|
|
-import com.adealink.weparty.commonui.recycleview.commonviewholder.CommonListEmptyViewBinder
|
|
|
-import com.adealink.weparty.commonui.recycleview.commonviewholder.CommonListErrorEmptyType
|
|
|
-import com.adealink.weparty.commonui.recycleview.diffutil.BaseListDiffUtil
|
|
|
+import com.adealink.weparty.commonui.ext.setOverScrollModeToNever
|
|
|
+import com.adealink.weparty.commonui.recycleview.adapter.BaseActivityTabFragmentStateAdapter
|
|
|
+import com.adealink.weparty.commonui.viewpager.Tab
|
|
|
+import com.adealink.weparty.commonui.widget.EmptyFragment
|
|
|
import com.adealink.weparty.module.wallet.Wallet
|
|
|
import com.adealink.weparty.stat.constant.Page
|
|
|
import com.adealink.weparty.stat.reportEnterPage
|
|
|
-import com.adealink.weparty.wallet.data.CurrencyCategory
|
|
|
-import com.adealink.weparty.wallet.data.CurrencyHistoryListItemData
|
|
|
-import com.adealink.weparty.wallet.data.CurrencySource
|
|
|
+import com.adealink.weparty.wallet.R
|
|
|
import com.adealink.weparty.wallet.databinding.ActivityCoinHistoryBinding
|
|
|
-import com.adealink.weparty.wallet.diamond.CategorySelectDialog
|
|
|
-import com.adealink.weparty.wallet.view.CurrencyHistoryListItemViewBinder
|
|
|
-import com.adealink.weparty.wallet.viewmodel.WalletViewModel
|
|
|
-import com.adealink.weparty.wallet.viewmodel.WalletViewModelFactory
|
|
|
+import com.adealink.weparty.wallet.orderhistory.OrderHistoryActivity.HistoryPageAdapter
|
|
|
+import com.adealink.weparty.webview.datasource.local.WebLocalService
|
|
|
import com.qmuiteam.qmui.widget.util.QMUIStatusBarHelper
|
|
|
-import java.text.SimpleDateFormat
|
|
|
-import java.util.Calendar
|
|
|
-import java.util.Date
|
|
|
-import java.util.Locale
|
|
|
-import com.adealink.weparty.R as APP_R
|
|
|
|
|
|
/**
|
|
|
* Created by PengWuLiang on 2025/3/12
|
|
|
*/
|
|
|
@RouterUri(path = [Wallet.CoinHistory.PATH], desc = "金币流水")
|
|
|
-class CoinHistoryListActivity: BaseActivity() {
|
|
|
+class CoinHistoryListActivity : BaseActivity() {
|
|
|
|
|
|
companion object {
|
|
|
const val PAGE_SIZE = 20
|
|
|
}
|
|
|
+
|
|
|
private val binding by viewBinding(ActivityCoinHistoryBinding::inflate)
|
|
|
- private val walletViewModel by viewModels<WalletViewModel> { WalletViewModelFactory() }
|
|
|
- private val listAdapter by fastLazy { MultiTypeListAdapter(BaseListDiffUtil()) }
|
|
|
- private val coinSource = arrayListOf(
|
|
|
- CurrencySource(CurrencyCategory.ALL.value, CurrencyCategory.ALL.detail),
|
|
|
- CurrencySource(CurrencyCategory.OTHER.value, CurrencyCategory.OTHER.detail),
|
|
|
- CurrencySource(CurrencyCategory.COIN_CHAT.value, CurrencyCategory.COIN_CHAT.detail),
|
|
|
- CurrencySource(CurrencyCategory.COIN_SEND_GIFT.value, CurrencyCategory.COIN_SEND_GIFT.detail),
|
|
|
- CurrencySource(CurrencyCategory.COIN_SHOPPING.value, CurrencyCategory.COIN_SHOPPING.detail),
|
|
|
- CurrencySource(CurrencyCategory.COIN_RECHARGE.value, CurrencyCategory.COIN_RECHARGE.detail),
|
|
|
- CurrencySource(CurrencyCategory.COIN_TASK_REWARD.value, CurrencyCategory.COIN_TASK_REWARD.detail),
|
|
|
- CurrencySource(CurrencyCategory.COIN_EVENT.value, CurrencyCategory.COIN_EVENT.detail),
|
|
|
- CurrencySource(CurrencyCategory.COIN_EXCHANGE.value, CurrencyCategory.COIN_EXCHANGE.detail)
|
|
|
- )
|
|
|
-
|
|
|
- private var category: Int? = null
|
|
|
- private var date = SimpleDateFormat("yyyyMM", Locale.ENGLISH).format(Date())
|
|
|
- private var selectTime = System.currentTimeMillis()
|
|
|
-
|
|
|
- private var currentPage = 0
|
|
|
- private var isLoading = false
|
|
|
- private var hasMore = true
|
|
|
+ private lateinit var historyPageAdapter: HistoryPageAdapter
|
|
|
+
|
|
|
|
|
|
override fun initViews() {
|
|
|
QMUIStatusBarHelper.setStatusBarLightMode(this)
|
|
|
setContentView(binding.root)
|
|
|
- binding.tvTime.text = timeToEnYM(System.currentTimeMillis())
|
|
|
- binding.tvTime.setOnClickListener {
|
|
|
- showDatePicker()
|
|
|
- }
|
|
|
- binding.tvFilter.text = CurrencyCategory.getCategoryById(CurrencyCategory.ALL.detail)
|
|
|
- binding.tvFilter.setOnClickListener {
|
|
|
- CategorySelectDialog().apply {
|
|
|
- arguments = Bundle().apply {
|
|
|
- putParcelableArrayList(CategorySelectDialog.TYPE_LIST, coinSource)
|
|
|
- }
|
|
|
- selectCallback = {
|
|
|
- category = it.category
|
|
|
- coinSource.forEach { source ->
|
|
|
- source.isSelected = it.category == source.category
|
|
|
- }
|
|
|
- if(it.category == CurrencyCategory.ALL.value) {
|
|
|
- category = null
|
|
|
- binding.tvFilter.isSelected = false
|
|
|
- binding.tvFilter.setTextColor(getCompatColor(APP_R.color.color_222222))
|
|
|
- } else {
|
|
|
- binding.tvFilter.isSelected = true
|
|
|
- binding.tvFilter.setTextColor(getCompatColor(APP_R.color.color_FF9352FC))
|
|
|
- }
|
|
|
- binding.tvFilter.text = CurrencyCategory.getCategoryById(it.detail)
|
|
|
- resetAndReload()
|
|
|
- }
|
|
|
- }.show(supportFragmentManager)
|
|
|
- }
|
|
|
- listAdapter.register(CurrencyHistoryListItemViewBinder(true))
|
|
|
- listAdapter.register(CommonListEmptyViewBinder())
|
|
|
- binding.refreshLayout.setOnRefreshListener {
|
|
|
- resetAndReload()
|
|
|
- }
|
|
|
- binding.refreshLayout.setEnableLoadMore(true)
|
|
|
- setupRecyclerView()
|
|
|
- }
|
|
|
|
|
|
- override fun loadData() {
|
|
|
- super.loadData()
|
|
|
- requestData()
|
|
|
- }
|
|
|
+ val tabList = mutableListOf<Tab>()
|
|
|
+ tabList.add(TAB_GOLD_COIN)
|
|
|
|
|
|
- private fun setupRecyclerView() {
|
|
|
- binding.rvRecord.apply {
|
|
|
- adapter = listAdapter
|
|
|
- layoutManager = LinearLayoutManager(context)
|
|
|
- addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
|
- override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
|
- super.onScrolled(recyclerView, dx, dy)
|
|
|
- val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
|
|
- val visibleItemCount = layoutManager.childCount
|
|
|
- val totalItemCount = layoutManager.itemCount
|
|
|
- val firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition()
|
|
|
-
|
|
|
- if (!isLoading && hasMore && (visibleItemCount + firstVisibleItemPosition) >= totalItemCount) {
|
|
|
- requestData()
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
+ if (WebLocalService.luckCoinRegionEnable == "true") {
|
|
|
+ tabList.add(TAB_LUCKY_COINS)
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- private fun resetAndReload() {
|
|
|
- currentPage = 0
|
|
|
- hasMore = true
|
|
|
- listAdapter.clear()
|
|
|
- requestData()
|
|
|
- }
|
|
|
+ historyPageAdapter = HistoryPageAdapter(tabList)
|
|
|
+ binding.historyViewPage.adapter = historyPageAdapter
|
|
|
+ binding.historyViewPage.isSaveEnabled = false
|
|
|
+ (binding.historyViewPage.getChildAt(0) as? RecyclerView)?.setOverScrollModeToNever()
|
|
|
+ binding.commonTabLayout.createMediatorAndAttach(
|
|
|
+ binding.historyViewPage,
|
|
|
+ historyPageAdapter,
|
|
|
+ 0
|
|
|
+ )
|
|
|
|
|
|
- private fun requestData() {
|
|
|
- if(!hasMore || isLoading) return
|
|
|
- isLoading = true
|
|
|
- walletViewModel.getCoinHistoryList(date, currentPage, PAGE_SIZE, category)
|
|
|
}
|
|
|
|
|
|
- override fun observeViewModel() {
|
|
|
- super.observeViewModel()
|
|
|
- walletViewModel.coinHistoryListLd.observe(this) {
|
|
|
- isLoading = false
|
|
|
- binding.refreshLayout.finishRefresh()
|
|
|
- if (it is Rlt.Success) {
|
|
|
- if (it.data.isEmpty()) {
|
|
|
- listAdapter.submitList(
|
|
|
- listOf(
|
|
|
- CommonListEmptyItemData(
|
|
|
- CommonListErrorEmptyType.NoData
|
|
|
- )
|
|
|
- )
|
|
|
- )
|
|
|
- } else {
|
|
|
- val newItems = it.data.map { data ->
|
|
|
- CurrencyHistoryListItemData(data)
|
|
|
- }
|
|
|
- hasMore = newItems.size >= PAGE_SIZE
|
|
|
- if(hasMore) {
|
|
|
- currentPage++
|
|
|
- }
|
|
|
- val currentList = listAdapter.getCurrentList().toMutableList().apply { addAll(newItems) }
|
|
|
- listAdapter.submitList(currentList)
|
|
|
- }
|
|
|
- } else {
|
|
|
- listAdapter.submitList(
|
|
|
- listOf(
|
|
|
- CommonListEmptyItemData(
|
|
|
- CommonListErrorEmptyType.NetError
|
|
|
- )
|
|
|
- )
|
|
|
- )
|
|
|
- }
|
|
|
+ internal inner class HistoryPageAdapter(val tabList: List<Tab>) :
|
|
|
+ BaseActivityTabFragmentStateAdapter(this) {
|
|
|
+
|
|
|
+ override fun getTabName(pos: Int): String {
|
|
|
+ return tabList.getOrNull(pos)?.let { getCompatString(it.titleResId) } ?: ""
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- private fun showDatePicker() {
|
|
|
- val currentTime = System.currentTimeMillis()
|
|
|
- val twoMonthAgo = Calendar.getInstance().apply {
|
|
|
- add(Calendar.MONTH, -2)
|
|
|
- }.timeInMillis
|
|
|
- val dialog = CustomDatePicker.newInstance(twoMonthAgo, currentTime, selectTime,false, false)
|
|
|
- dialog.mCallback = object : CustomDatePicker.Callback {
|
|
|
- override fun onTimeSelected(timestamp: Long) {
|
|
|
- binding.tvTime.text = timeToEnYM(timestamp)
|
|
|
- selectTime = timestamp
|
|
|
- date = SimpleDateFormat("yyyyMM", Locale.ENGLISH).format(timestamp)
|
|
|
- resetAndReload()
|
|
|
- }
|
|
|
+
|
|
|
+ override fun getItemCount(): Int {
|
|
|
+ return tabList.size
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun createFragment(position: Int): Fragment {
|
|
|
+ return tabList.getOrNull(position)?.instance?.invoke() ?: EmptyFragment()
|
|
|
}
|
|
|
- dialog.show(supportFragmentManager)
|
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
reportEnterPage(Page.COIN_HISTORY_LIST)
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+val TAB_GOLD_COIN = Tab(R.string.wallet_gold_coin) { CoinHistoryFragment() }
|
|
|
+
|
|
|
+val TAB_LUCKY_COINS = Tab(R.string.wallet_lucky_coins) { LuckyCoinsFragment() }
|