linjianpeng преди 1 месец
родител
ревизия
cccd1716b9

+ 11 - 10
module_home/src/main/res/layout/module_home_fragment_home_content.xml

@@ -1,7 +1,7 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
+    android:layout_height="match_parent">
 
     <com.scwang.smart.refresh.layout.SmartRefreshLayout
         android:id="@+id/refreshLayout"
@@ -9,14 +9,15 @@
         android:layout_height="match_parent"
         app:srlEnableAutoLoadMore="false"
         app:srlEnableLoadMore="false">
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/recyclerView"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:overScrollMode="never"
-        android:paddingLeft="@dimen/dp_9"
-        android:paddingRight="@dimen/dp_9"
-        android:clipToPadding="false"/>
+
+        <androidx.recyclerview.widget.RecyclerView
+            android:id="@+id/recyclerView"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:clipToPadding="false"
+            android:overScrollMode="never"
+            android:paddingLeft="@dimen/dp_9"
+            android:paddingRight="@dimen/dp_9" />
     </com.scwang.smart.refresh.layout.SmartRefreshLayout>
 
 </RelativeLayout>

+ 3 - 0
module_me/src/main/java/com/mita/module_me/api/UserService.kt

@@ -142,6 +142,9 @@ interface UserService {
     @POST("api/market/dressUp/prettyIDList")
     suspend fun getPrettyIDList(@Body body: PostPrettyIdListBody): Response<PrettyIdListResponse>
 
+    @POST("api/market/dressUp/prettyIDList")
+    suspend fun getPrettyIDListForActivity(@Body body: PostPrettyIdListBody): Response<ListResponse<List<PrettyId>>>
+
     @POST("api/market/dressUp/userPrettyIDList")
     suspend fun getUserPrettyIdList(): Response<List<PrettyId>>
 

+ 2 - 0
module_me/src/main/java/com/mita/module_me/view/MeRepository.kt

@@ -66,6 +66,8 @@ class MeRepository: BaseRepository(){
     suspend fun getHeadFrameList() = retrofit.getHeadFrameList()
     suspend fun getUserHeadFrameList() = retrofit.getUserHeadFrameList()
     suspend fun getPrettyIDList(body: PostPrettyIdListBody) = retrofit.getPrettyIDList(body)
+    suspend fun getPrettyIDListForActivity(body: PostPrettyIdListBody) = retrofit.getPrettyIDListForActivity(body)
+
     suspend fun getUserPrettyIdList() = retrofit.getUserPrettyIdList()
     suspend fun buyPrettyId(body: PostShopBody) = retrofit.buyPrettyId(body)
     suspend fun getUserNameplateList() = retrofit.getUserNameplateList()

+ 17 - 6
module_me/src/main/java/com/mita/module_me/view/dressup/shop/ShopVm.kt

@@ -14,6 +14,7 @@ import com.yc.baselibrary.adapter.observable.ObservableAdapterList
 import com.yc.baselibrary.models.Zip5
 import com.yc.baselibrary.net.exception.LoadingType
 import com.yc.baselibrary.net.exception.check
+import com.yc.baselibrary.net.exception.checkAndRefresh
 import com.yc.baselibrary.net.exception.checkError
 import com.yc.baselibrary.view.base.BaseVm
 import com.yc.module_base.model.PostPrettyIdListBody
@@ -212,18 +213,28 @@ class ShopVm(
         }
     }
 
-    fun loadPrettyIdList() {
-        val requestPrettyIdListReq = PostPrettyIdListBody()
+    fun loadPrettyIdList(normal: Boolean, refresh: Boolean) {
+        val reqPage = if (refresh) 1 else page + 1
+        val requestPrettyIdListReq = PostPrettyIdListBody(pageIndex = reqPage)
         requestMix({
-            meRepository.getPrettyIDList(requestPrettyIdListReq).check()
+            meRepository.getPrettyIDListForActivity(requestPrettyIdListReq).checkAndRefresh(refresh, this@ShopVm)
         }) {
+            setRefresh(refresh)
+            setNormal(normal)
             success {
-                if (it.list.isEmpty()) {
+                page = reqPage
+                if (it.data?.isEmpty() == true && refresh) {
                     showEmpty()
                     return@success
                 }
-                list.setNewData(it.list)
-                listState.postValue(RefreshType.REFRESH_FINISH)
+                it.data?.let { list1 ->
+                    if (refresh) {
+                        page = 1
+                        list.setNewData(list1)
+                    } else {
+                        list.addData(list1)
+                    }
+                }
             }
         }
     }

+ 21 - 29
module_me/src/main/java/com/mita/module_me/view/dressup/shop/prettyId/PrettyIdListActivity.kt

@@ -11,15 +11,18 @@ import com.mita.module_me.view.dressup.shop.ShopVm
 import com.mita.module_me.view.dressup.shop.chat.dialog.PrettyIdBuySuccessDialog
 import com.mita.module_me.view.dressup.shop.chat.dialog.PrettyIdDialog
 import com.mita.module_me.view.dressup.shop.prettyId.cell.PrettyIdVH
+import com.scwang.smart.refresh.layout.SmartRefreshLayout
 import com.xueyu.kotlinextlibrary.toGone
 import com.xueyu.kotlinextlibrary.toVisible
 import com.yc.baselibrary.adapter.viewHolder.MutableAdapter
 import com.yc.baselibrary.ext.bind
 import com.yc.baselibrary.ext.threadUnsafeLazy
 import com.yc.baselibrary.view.base.BaseActivity
+import com.yc.refreshlibrary.annotation.RefreshType
 import kotlinx.android.synthetic.main.module_me_more_dress.ivDressImage
 import kotlinx.android.synthetic.main.module_me_more_dress.llPretty
 import kotlinx.android.synthetic.main.module_me_more_dress.recyclerView
+import kotlinx.android.synthetic.main.module_me_more_dress.refreshLayout
 import kotlinx.android.synthetic.main.module_me_more_dress.titleBar
 import kotlinx.android.synthetic.main.module_me_more_dress.tvBuy
 import kotlinx.android.synthetic.main.module_me_more_dress.tvCoin
@@ -28,6 +31,9 @@ import kotlinx.android.synthetic.main.module_me_more_dress.tvPretty
 class PrettyIdListActivity : BaseActivity<ShopVm>() {
     override fun getLayoutId() = R.layout.module_me_more_dress
     override fun isSupportLoading() = false
+    override fun getRegisterLoading(): Any = refreshLayout
+    override fun getLoadMoreAble() = adapter
+    override fun getRefreshLayout(): SmartRefreshLayout? = refreshLayout
 
     private var selectItem: PrettyId? = null
 
@@ -41,8 +47,7 @@ class PrettyIdListActivity : BaseActivity<ShopVm>() {
         tvBuy.setOnClickListener {
             wantBuy()
         }
-
-        viewModel.loadPrettyIdList()
+        viewModel.loadPrettyIdList(normal = true, refresh = true)
     }
 
     /**
@@ -82,35 +87,18 @@ class PrettyIdListActivity : BaseActivity<ShopVm>() {
 
     override fun observe() {
         viewModel.listState.observe(this) {
-            adapter.selectedItemPosition = 0
-            adapter.notifyItemChanged(0)
-            selectItem = viewModel.list[0] as PrettyId?
-            ivDressImage.toGone()
-            llPretty.toVisible()
-            tvPretty.text = selectItem?.prettyId.toString()
-            tvCoin.text = selectItem?.coin.toString()
+            if (viewModel.listState.value == RefreshType.REFRESH_FINISH) {
+                adapter.selectedItemPosition = 0
+                adapter.notifyItemChanged(0)
+                selectItem = viewModel.list[0] as PrettyId?
+                ivDressImage.toGone()
+                llPretty.toVisible()
+                tvPretty.text = selectItem?.prettyId.toString()
+                tvCoin.text = selectItem?.coin.toString()
+            }
         }
         viewModel.buyPrettyIdSuccess.observe(this) {
-//            val position = viewModel.list.indexOf(viewModel.buyPrettyId)
-//            if (position != -1) {
-//                viewModel.list.removeAt(position)
-//                adapter.notifyItemRemoved(position)
-//
-//                // 如果移除的是当前选中的项,重置选择状态
-//                if (position > 0) {
-//                    adapter.selectedItemPosition = position - 1
-//                } else {
-//                    adapter.selectedItemPosition = 0
-//                }
-//                adapter.notifyItemChanged(adapter.selectedItemPosition)
-//                selectItem = viewModel.list[adapter.selectedItemPosition] as PrettyId?
-//                ivDressImage.toGone()
-//                llPretty.toVisible()
-//                tvPretty.text = selectItem?.prettyId.toString()
-//                tvCoin.text = selectItem?.coin.toString()
-//            }
-            viewModel.loadPrettyIdList()
-
+            viewModel.loadPrettyIdList(normal = true, refresh = true)
             val bugPrettyIdSuccessDialog =
                 PrettyIdBuySuccessDialog(this, viewModel.buyPrettyId)
             showDialogBottom(
@@ -127,4 +115,8 @@ class PrettyIdListActivity : BaseActivity<ShopVm>() {
             infoDialog
         )
     }
+
+    override fun loadData(isNormal: Boolean, isRefresh: Boolean) {
+        viewModel.loadPrettyIdList(normal = isNormal, refresh = isRefresh)
+    }
 }

+ 14 - 6
module_me/src/main/res/layout/module_me_more_dress.xml

@@ -100,16 +100,24 @@
         </androidx.constraintlayout.widget.ConstraintLayout>
     </androidx.constraintlayout.widget.ConstraintLayout>
 
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/recyclerView"
+    <com.scwang.smart.refresh.layout.SmartRefreshLayout
+        android:id="@+id/refreshLayout"
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_marginTop="@dimen/dp_280"
-        android:overScrollMode="never"
-        android:paddingTop="@dimen/dp_14"
-        android:background="@drawable/bg_base_top"
         app:layout_constraintBottom_toTopOf="@id/bottomView"
-        app:layout_constraintTop_toTopOf="parent" />
+        app:layout_constraintTop_toTopOf="parent"
+        app:srlEnableAutoLoadMore="false"
+        app:srlEnableLoadMore="false">
+
+        <androidx.recyclerview.widget.RecyclerView
+            android:id="@+id/recyclerView"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@drawable/bg_base_top"
+            android:overScrollMode="never"
+            android:paddingTop="@dimen/dp_14" />
+    </com.scwang.smart.refresh.layout.SmartRefreshLayout>
 
     <androidx.cardview.widget.CardView
         android:id="@+id/bottomView"