...
|
...
|
@@ -8,12 +8,18 @@ import androidx.core.content.ContextCompat |
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.br_technology.securitytrain_master.R
|
|
|
import com.br_technology.securitytrain_master.base.common.ConstantParamKey.DOC_ID
|
|
|
import com.br_technology.securitytrain_master.base.network.response.BaseResponse
|
|
|
import com.br_technology.securitytrain_master.base.network.response.CommonPage
|
|
|
import com.br_technology.securitytrain_master.databinding.ActivityDatabaseBinding
|
|
|
import com.br_technology.securitytrain_master.ui.bean.MaterialChild
|
|
|
import com.br_technology.securitytrain_master.ui.bean.MaterialChildSecond
|
|
|
import com.br_technology.securitytrain_master.ui.bean.MaterialClassify
|
|
|
import com.br_technology.securitytrain_master.ui.bean.MaterialPage
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.adapter.ClassifyAdapter
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.adapter.RecommendDataAdapter
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendBean
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.DatabaseFViewModel
|
|
|
import com.br_technology.securitytrain_master.view.DatabaseListPop
|
|
|
import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
|
|
|
import com.google.android.material.tabs.TabLayout
|
|
|
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
|
...
|
...
|
@@ -25,11 +31,28 @@ import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity |
|
|
*/
|
|
|
class DatabaseActivity :
|
|
|
BaseLifeCycleActivity<DatabaseFViewModel, ActivityDatabaseBinding>(ActivityDatabaseBinding::inflate) {
|
|
|
|
|
|
var page = 1
|
|
|
|
|
|
var mClassifyAdapter: ClassifyAdapter? = null
|
|
|
var mRecommendAdapter: RecommendDataAdapter? = null
|
|
|
private var mRecommendAdapter: RecommendDataAdapter? = null
|
|
|
|
|
|
private var popData: DatabaseListPop? = null
|
|
|
|
|
|
private fun showPopData() {
|
|
|
popData = DatabaseListPop(this)
|
|
|
val list = mViewModel.selectClassify.value?.child
|
|
|
var popChild = mViewModel.popChild.value
|
|
|
if (popChild == null) {
|
|
|
popChild = mViewModel.sortChild.value
|
|
|
}
|
|
|
mViewModel.sortSecond.value?.let { second -> popData?.addList(list!!, second, popChild!!) }
|
|
|
popData?.iClickChild = object : DatabaseListPop.IClickChild {
|
|
|
override fun child(child: MaterialChild, data: MaterialChildSecond) {
|
|
|
mViewModel.popChild.value = child
|
|
|
mViewModel.sortSecond.value = data
|
|
|
}
|
|
|
}
|
|
|
popData?.showAsDropDown(binding.type)
|
|
|
}
|
|
|
|
|
|
override fun initView() {
|
|
|
super.initView()
|
...
|
...
|
@@ -97,6 +120,10 @@ class DatabaseActivity : |
|
|
}
|
|
|
}
|
|
|
})
|
|
|
|
|
|
type.setOnClickListener {
|
|
|
showPopData()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -124,7 +151,7 @@ class DatabaseActivity : |
|
|
binding.classify.adapter = mClassifyAdapter
|
|
|
mClassifyAdapter?.addListener(object : OnItemClickListener<MaterialClassify> {
|
|
|
override fun onClick(position: Int, data: MaterialClassify) {
|
|
|
mViewModel.sortId.value = data.id
|
|
|
val list = data.child
|
|
|
mClassifyAdapter?.let { classifyAdapter ->
|
|
|
val oldIndex = classifyAdapter.index;
|
|
|
if (oldIndex != position) {
|
...
|
...
|
@@ -135,15 +162,37 @@ class DatabaseActivity : |
|
|
classifyAdapter.notifyItemChanged(position)
|
|
|
}
|
|
|
}
|
|
|
if (list.isNotEmpty()) {
|
|
|
mViewModel.selectClassify.value = data
|
|
|
} else {
|
|
|
mViewModel.classifyDataList.value = BaseResponse(
|
|
|
MaterialPage(CommonPage(0, "10", 1, 1, listOf()))
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
if (data.list.isNotEmpty()) {
|
|
|
page = 1
|
|
|
mViewModel.sortId.value = data.list[0].id
|
|
|
val dataClassify = data.list[0]
|
|
|
mViewModel.selectClassify.value = dataClassify
|
|
|
}
|
|
|
})
|
|
|
mViewModel.sortId.observe(this, {
|
|
|
mViewModel.selectClassify.observe(this, {
|
|
|
val list = it.child
|
|
|
if (list.isNotEmpty()) {
|
|
|
mViewModel.sortChild.value = list[0]
|
|
|
mViewModel.popChild.value = list[0]
|
|
|
}
|
|
|
})
|
|
|
mViewModel.sortSecond.observe(this, {
|
|
|
mViewModel.getDataList(page)
|
|
|
binding.type.text = it.name
|
|
|
})
|
|
|
mViewModel.sortChild.observe(this, {
|
|
|
val child = it.child
|
|
|
if (child != null && child.isNotEmpty()) {
|
|
|
mViewModel.sortSecond.value = child[0]
|
|
|
}
|
|
|
})
|
|
|
mViewModel.classifyDataList.observe(this, {
|
|
|
val data = it.data
|
...
|
...
|
|