|
|
@@ -0,0 +1,272 @@
|
|
|
+package cn.muchinfo.rma.view.base.home.commodity.newcommodity
|
|
|
+
|
|
|
+import android.content.Intent
|
|
|
+import android.os.Bundle
|
|
|
+import android.view.View
|
|
|
+import android.view.ViewGroup
|
|
|
+import androidx.appcompat.app.AppCompatActivity
|
|
|
+import androidx.viewpager.widget.PagerAdapter
|
|
|
+import androidx.viewpager.widget.ViewPager
|
|
|
+import cn.muchinfo.rma.R
|
|
|
+import cn.muchinfo.rma.global.data.MiddleGoodsData
|
|
|
+import cn.muchinfo.rma.lifecycle.bindOptional
|
|
|
+import cn.muchinfo.rma.view.autoWidget.*
|
|
|
+import cn.muchinfo.rma.view.base.BaseActivity
|
|
|
+import cn.muchinfo.rma.view.base.home.commodity.AddHedgeGoodsActivity
|
|
|
+import cn.muchinfo.rma.view.base.home.commodity.AddSpotGoodsActivity
|
|
|
+import cn.muchinfo.rma.view.base.home.commodity.CommodityMiddleViewHolder
|
|
|
+import cn.muchinfo.rma.view.base.home.commodity.newcommodity.newhedge.HedgeSpeciesData
|
|
|
+import cn.muchinfo.rma.view.base.home.commodity.newcommodity.newhedge.NewHedgeSpeciesViewHolder
|
|
|
+import com.blankj.utilcode.util.ActivityUtils
|
|
|
+import com.blankj.utilcode.util.ConvertUtils
|
|
|
+import com.qmuiteam.qmui.util.QMUIDisplayHelper
|
|
|
+import com.qmuiteam.qmui.widget.tab.QMUITabIndicator
|
|
|
+import com.qmuiteam.qmui.widget.tab.QMUITabSegment
|
|
|
+import mtp.polymer.com.autowidget.adapter.BaseAdapter
|
|
|
+import org.jetbrains.anko._FrameLayout
|
|
|
+import org.jetbrains.anko.matchParent
|
|
|
+import org.jetbrains.anko.support.v4.viewPager
|
|
|
+import org.jetbrains.anko.verticalLayout
|
|
|
+import org.jetbrains.anko.view
|
|
|
+
|
|
|
+class NewCommodityInformationActivity : BaseActivity<NewCommodityInformationViewModel>() {
|
|
|
+
|
|
|
+
|
|
|
+ lateinit var segment: QMUITabSegment
|
|
|
+ var selectedTabIndex: Int = 0
|
|
|
+ private lateinit var viewPager: ViewPager
|
|
|
+
|
|
|
+ private val tabsArray: List<String> by lazy {
|
|
|
+ arrayListOf(
|
|
|
+ "现货品种", "套保品种"
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新版现货品种UI
|
|
|
+ */
|
|
|
+ private val newSpotVarietiesUI by lazy { NewSpotVarietiesUI(this, viewModel) }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新版套保品种UI
|
|
|
+ */
|
|
|
+ private val newHedgeSpeciesUI by lazy { NewHedgeSpeciesUI(this, viewModel) }
|
|
|
+
|
|
|
+ private val pagerAdapter: PagerAdapter by lazy {
|
|
|
+ object : PagerAdapter() {
|
|
|
+
|
|
|
+ override fun getPageTitle(position: Int): CharSequence? = tabsArray[position]
|
|
|
+
|
|
|
+ override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
|
|
+ when (position) {
|
|
|
+ 0 -> {
|
|
|
+ return newSpotVarietiesUI.root.apply {
|
|
|
+ container.addView(
|
|
|
+ this,
|
|
|
+ ViewGroup.LayoutParams(matchParent, matchParent)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 1 -> {
|
|
|
+ return newHedgeSpeciesUI.root.apply {
|
|
|
+ container.addView(
|
|
|
+ this,
|
|
|
+ ViewGroup.LayoutParams(matchParent, matchParent)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else -> return super.instantiateItem(container, position)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
|
|
|
+ (`object` as? View)?.let { container.removeView(it) }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun isViewFromObject(view: View, `object`: Any): Boolean = view == `object`
|
|
|
+
|
|
|
+ override fun getCount(): Int = tabsArray.size
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
+ verticalLayout {
|
|
|
+ topBar {
|
|
|
+ commonLeftButton()
|
|
|
+ commonTitle {
|
|
|
+ text = "商品信息"
|
|
|
+ }
|
|
|
+ commonMenuButton(R.mipmap.add_new) {
|
|
|
+ if (selectedTabIndex == 0){
|
|
|
+ val intent = Intent()
|
|
|
+ intent.putExtra("type","1")
|
|
|
+ intent.setClass(context, AddSpotGoodsActivity::class.java)
|
|
|
+ ActivityUtils.startActivity(intent)
|
|
|
+ }else if (selectedTabIndex == 1){
|
|
|
+ val intent = Intent()
|
|
|
+ intent.putExtra("type","1")
|
|
|
+ intent.setClass(context, AddHedgeGoodsActivity::class.java)
|
|
|
+ ActivityUtils.startActivity(intent)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tabSegment {
|
|
|
+ segment = this
|
|
|
+ background = resources.getDrawable(R.color.segtabment_bg_color)
|
|
|
+ addOnTabSelectedListener(object :
|
|
|
+ QMUITabSegment.OnTabSelectedListener {
|
|
|
+ override fun onDoubleTap(index: Int) {}
|
|
|
+ override fun onTabReselected(index: Int) {}
|
|
|
+ override fun onTabUnselected(index: Int) {}
|
|
|
+ override fun onTabSelected(index: Int) {
|
|
|
+ selectedTabIndex = index
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setIndicator(
|
|
|
+ QMUITabIndicator(
|
|
|
+ QMUIDisplayHelper.dp2px(context, 2),
|
|
|
+ false,
|
|
|
+ true
|
|
|
+ )
|
|
|
+ )
|
|
|
+ setDefaultTextSize(ConvertUtils.sp2px(16f), ConvertUtils.sp2px(16f))
|
|
|
+ }.lparams(matchParent, autoSize(80))
|
|
|
+
|
|
|
+ view {
|
|
|
+ background = resources.getDrawable(R.color.main_hit_bg_color)
|
|
|
+ }.lparams(matchParent, autoSize(1)) {
|
|
|
+ marginStart = autoSize(32)
|
|
|
+ marginEnd = autoSize(32)
|
|
|
+ }
|
|
|
+ viewPager {
|
|
|
+ background = resources.getDrawable(R.color.white)
|
|
|
+ viewPager = this
|
|
|
+ adapter = pagerAdapter
|
|
|
+ }.lparams(matchParent, matchParent)
|
|
|
+
|
|
|
+ segment.setupWithViewPager(viewPager)
|
|
|
+ segment.selectTab(selectedTabIndex)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 新版现货品种UI
|
|
|
+ * @property activity AppCompatActivity
|
|
|
+ * @property viewModel NewCommodityInformationViewModel
|
|
|
+ * @constructor
|
|
|
+ */
|
|
|
+class NewSpotVarietiesUI(
|
|
|
+ private val activity: AppCompatActivity,
|
|
|
+ private val viewModel: NewCommodityInformationViewModel
|
|
|
+) {
|
|
|
+
|
|
|
+ private lateinit var swipeToLayout: SwipeToLoadLayout
|
|
|
+ private lateinit var statusLayout: StatusLayout
|
|
|
+
|
|
|
+ private val spotVarietiesNormalAdapter: BaseAdapter<DemoData, DemoViewHolder> = BaseAdapter { _, _ -> DemoViewHolder(activity, viewModel) }
|
|
|
+
|
|
|
+ init {
|
|
|
+ viewModel.setDemoDataList()
|
|
|
+ }
|
|
|
+
|
|
|
+ val root = _FrameLayout(activity).apply {
|
|
|
+ verticalLayout {
|
|
|
+ statusLayout(contentBlock = {
|
|
|
+ statusLayout = this
|
|
|
+// bindTaskStatus(viewModule.status)
|
|
|
+ swipeToLoadLayout {
|
|
|
+ swipeToLayout = this
|
|
|
+ setEnableRefresh(true)
|
|
|
+ setEnableLoadMore(false)
|
|
|
+ setOnRefreshListener {
|
|
|
+
|
|
|
+ }
|
|
|
+ setEnableScrollContentWhenLoaded(false)
|
|
|
+ setEnableLoadMoreWhenContentNotFull(false)
|
|
|
+ recyclerView {
|
|
|
+ background = resources.getDrawable(R.color.white)
|
|
|
+ adapter = spotVarietiesNormalAdapter
|
|
|
+ }.lparams(matchParent, matchParent)
|
|
|
+ }
|
|
|
+ }, emptyBlock = {
|
|
|
+ emptyView(hint = resources.getString(R.string.now_no_data))
|
|
|
+ }).lparams(matchParent, matchParent)
|
|
|
+
|
|
|
+ viewModel.demoDataList.bindOptional(context){
|
|
|
+ if (it?.isEmpty() == true || it?.size == 0){
|
|
|
+ statusLayout.showEmpty()
|
|
|
+ }else {
|
|
|
+ if (swipeToLayout.getIsRefreshing()){
|
|
|
+ swipeToLayout.finishRefresh()
|
|
|
+ }
|
|
|
+ statusLayout.showSuccess()
|
|
|
+ spotVarietiesNormalAdapter.setNewData(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 新版套保品种UI
|
|
|
+ * @property activity AppCompatActivity
|
|
|
+ * @property viewModel NewCommodityInformationViewModel
|
|
|
+ * @property root _FrameLayout
|
|
|
+ * @constructor
|
|
|
+ */
|
|
|
+class NewHedgeSpeciesUI(
|
|
|
+ private val activity: AppCompatActivity,
|
|
|
+ private val viewModel: NewCommodityInformationViewModel
|
|
|
+) {
|
|
|
+ private lateinit var swipeToLayout: SwipeToLoadLayout
|
|
|
+ private lateinit var statusLayout: StatusLayout
|
|
|
+
|
|
|
+ private val hedgeSpeciesAdapter: BaseAdapter<HedgeSpeciesData, NewHedgeSpeciesViewHolder> = BaseAdapter { _, _ -> NewHedgeSpeciesViewHolder(activity, viewModel) }
|
|
|
+
|
|
|
+ init {
|
|
|
+ viewModel.setDemoDataList()
|
|
|
+ }
|
|
|
+
|
|
|
+ val root = _FrameLayout(activity).apply {
|
|
|
+ verticalLayout {
|
|
|
+ statusLayout(contentBlock = {
|
|
|
+ statusLayout = this
|
|
|
+// bindTaskStatus(viewModule.status)
|
|
|
+ swipeToLoadLayout {
|
|
|
+ swipeToLayout = this
|
|
|
+ setEnableRefresh(true)
|
|
|
+ setEnableLoadMore(false)
|
|
|
+ setOnRefreshListener {
|
|
|
+
|
|
|
+ }
|
|
|
+ setEnableScrollContentWhenLoaded(false)
|
|
|
+ setEnableLoadMoreWhenContentNotFull(false)
|
|
|
+ recyclerView {
|
|
|
+ background = resources.getDrawable(R.color.white)
|
|
|
+ adapter = hedgeSpeciesAdapter
|
|
|
+ }.lparams(matchParent, matchParent)
|
|
|
+ }
|
|
|
+ }, emptyBlock = {
|
|
|
+ emptyView(hint = resources.getString(R.string.now_no_data))
|
|
|
+ }).lparams(matchParent, matchParent)
|
|
|
+
|
|
|
+ viewModel.hedgeSpeciesList.bindOptional(context){
|
|
|
+ if (it?.isEmpty() == true || it?.size == 0){
|
|
|
+ statusLayout.showEmpty()
|
|
|
+ }else {
|
|
|
+ if (swipeToLayout.getIsRefreshing()){
|
|
|
+ swipeToLayout.finishRefresh()
|
|
|
+ }
|
|
|
+ statusLayout.showSuccess()
|
|
|
+ hedgeSpeciesAdapter.setNewData(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|