|
|
@@ -1,16 +1,26 @@
|
|
|
package com.adealink.weparty.share.qrcode
|
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
+import androidx.fragment.app.viewModels
|
|
|
import com.adealink.frame.aab.util.getCompatColor
|
|
|
+import com.adealink.frame.base.Rlt
|
|
|
+import com.adealink.frame.base.fastLazy
|
|
|
import com.adealink.frame.mvvm.view.viewBinding
|
|
|
import com.adealink.frame.router.annotation.RouterUri
|
|
|
+import com.adealink.frame.util.onClick
|
|
|
import com.adealink.weparty.commonui.recycleview.adapter.BaseTabFragmentStateAdapter
|
|
|
+import com.adealink.weparty.commonui.toast.util.showFailedToast
|
|
|
import com.adealink.weparty.commonui.widget.BottomDialogFragment
|
|
|
import com.adealink.weparty.commonui.widget.EmptyFragment
|
|
|
+import com.adealink.weparty.module.account.AccountModule
|
|
|
+import com.adealink.weparty.module.playmate.PlaymateModule
|
|
|
+import com.adealink.weparty.module.playmate.data.PlaymateCategoryData
|
|
|
import com.adealink.weparty.module.share.Share
|
|
|
import com.adealink.weparty.share.R
|
|
|
import com.adealink.weparty.share.databinding.DialogQrCodeShareBinding
|
|
|
import com.adealink.weparty.share.databinding.LayoutQrCodeTabItemBinding
|
|
|
+import com.adealink.weparty.share.qrcode.viewmodel.QRCodeViewModel
|
|
|
+import com.adealink.weparty.share.viewmodel.ShareViewModelFactory
|
|
|
import com.adealink.weparty.ui.main.tab.ITabManager
|
|
|
import com.adealink.weparty.ui.main.tab.MAIN_TABS
|
|
|
import com.adealink.weparty.ui.main.tab.TabManager
|
|
|
@@ -23,10 +33,19 @@ class QRCodeShareDialog : BottomDialogFragment(R.layout.dialog_qr_code_share),
|
|
|
ITabManager by TabManager() {
|
|
|
|
|
|
private val binding by viewBinding(DialogQrCodeShareBinding::bind)
|
|
|
+
|
|
|
+ private val playmateViewModel by fastLazy { PlaymateModule.getPlaymateViewModel(this) }
|
|
|
+ private val qrCodeViewModel by viewModels<QRCodeViewModel> { ShareViewModelFactory() }
|
|
|
private lateinit var pagerAdapter: ShareOtherPageAdapter
|
|
|
|
|
|
+ private val myCategoryList = mutableListOf<PlaymateCategoryData>()
|
|
|
+
|
|
|
override fun initViews() {
|
|
|
super.initViews()
|
|
|
+ binding.clTop.onClick {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
pagerAdapter = ShareOtherPageAdapter()
|
|
|
binding.vpContent.offscreenPageLimit = 1
|
|
|
binding.vpContent.adapter = pagerAdapter
|
|
|
@@ -62,6 +81,7 @@ class QRCodeShareDialog : BottomDialogFragment(R.layout.dialog_qr_code_share),
|
|
|
}
|
|
|
|
|
|
})
|
|
|
+ binding.vpContent.currentItem = 0
|
|
|
}
|
|
|
|
|
|
fun updateTabView(
|
|
|
@@ -82,6 +102,47 @@ class QRCodeShareDialog : BottomDialogFragment(R.layout.dialog_qr_code_share),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ override fun loadData() {
|
|
|
+ super.loadData()
|
|
|
+ playmateViewModel?.getUserPlaymateCategory(AccountModule.uid, true)
|
|
|
+ ?.observe(viewLifecycleOwner) { rlt ->
|
|
|
+ when (rlt) {
|
|
|
+ is Rlt.Failed -> {
|
|
|
+ showFailedToast(rlt)
|
|
|
+ }
|
|
|
+
|
|
|
+ is Rlt.Success<List<PlaymateCategoryData>> -> {
|
|
|
+ updateMyCategory(rlt.data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun observeViewModel() {
|
|
|
+ super.observeViewModel()
|
|
|
+ qrCodeViewModel.currentCategoryLD.observe(viewLifecycleOwner) {
|
|
|
+ selectCategory(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun updateMyCategory(list: List<PlaymateCategoryData>) {
|
|
|
+ myCategoryList.clear()
|
|
|
+ myCategoryList.addAll(list)
|
|
|
+
|
|
|
+ qrCodeViewModel.selectCategory(list.firstOrNull())
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun selectCategory(category: PlaymateCategoryData?) {
|
|
|
+ //更新视图
|
|
|
+ binding.ivCategory.setImageUrl(category?.icon)
|
|
|
+ binding.tvCategory.text = category?.name
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showCategoryChooseDialog() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
internal inner class ShareOtherPageAdapter : BaseTabFragmentStateAdapter(this) {
|
|
|
override fun getTabName(pos: Int): String {
|
|
|
return ""
|
|
|
@@ -97,5 +158,4 @@ class QRCodeShareDialog : BottomDialogFragment(R.layout.dialog_qr_code_share),
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
+}
|