Quellcode durchsuchen

feat: home refresh

tongmengxiao vor 4 Monaten
Ursprung
Commit
c03be2b9fb

+ 5 - 7
home/src/main/java/com/swago/home/innerhome/FollowFragment.kt

@@ -26,8 +26,6 @@ class FollowFragment : BaseListFragment<FragmentHotBinding, MomentModel>(){
 
     private val homeVm  by viewModels<HomeVm>()
     private var isFirstLoadData = true
-    //点击position
-    private var mCurrentPosition = 0
     override val smartRecyclerView: SwagoRecyclerView<MomentModel> by lazy {
         binding.rv as SwagoRecyclerView<MomentModel>
     }
@@ -42,12 +40,11 @@ class FollowFragment : BaseListFragment<FragmentHotBinding, MomentModel>(){
     }
 
     override fun initViewData() {
-        SpUtil.putInt("followCloseRoomed" , 0)
+        SpUtil.putString("followCloseRoomed" , "0")
         binding.rvLabel.visibility = View.GONE
         smartRecyclerView.recyclerView?.addItemDecoration(ComGridItemDecoration())
         adapter.setOnItemClickListener { _, _, position ->
             if (adapter.data.size>position){
-                mCurrentPosition = position
                 ARouter.getInstance()
                     .build(ARouteConstant.Room.user)
                     .withInt("position",position)
@@ -80,10 +77,11 @@ class FollowFragment : BaseListFragment<FragmentHotBinding, MomentModel>(){
 
     override fun onResume() {
         super.onResume()
-        if (SpUtil.readInt("followCloseRoomed") == 1 && adapter.data.size > mCurrentPosition){
-            adapter.data.removeAt(mCurrentPosition)
+        val followCloseRoomed = SpUtil.readString("followCloseRoomed")
+        if (followCloseRoomed != "0"){
+            adapter.data.removeAll { it.id == followCloseRoomed }
             adapter.notifyDataSetChanged()
-            SpUtil.putInt("followCloseRoomed" , 0)
+            SpUtil.putString("followCloseRoomed" , "0")
         }
         isFirstLoadData = false
     }

+ 5 - 8
home/src/main/java/com/swago/home/innerhome/HotFragment.kt

@@ -44,9 +44,6 @@ class HotFragment : BaseListFragment<FragmentHotBinding, MomentModel>() {
     //印尼,马来默认印尼;阿拉伯语默认阿拉伯语;其他语默认打开是展示全球
     private var matchLanguageId = 0
 
-    //点击position
-    private var mCurrentPosition = 0
-
     override val loadData: (page: Int) -> Unit = {
         homeVm.getHotList(1, it + 1,labelValue)
     }
@@ -64,7 +61,7 @@ class HotFragment : BaseListFragment<FragmentHotBinding, MomentModel>() {
 
 
     override fun initViewData() {
-        SpUtil.putInt("hotCloseRoomed" , 0)
+        SpUtil.putString("hotCloseRoomed" , "0")
         UrlConstant.getConfigModel()?.let {
             if (!it.language_lables.isNullOrEmpty()){
                 matchLanguageId = when(SwagoInfo.languageId){
@@ -122,7 +119,6 @@ class HotFragment : BaseListFragment<FragmentHotBinding, MomentModel>() {
 
         smartRecyclerView.recyclerView?.addItemDecoration(HomeGridItemDecoration())
         adapter.setOnItemClickListener { _, _, position ->
-            mCurrentPosition = position
             ARouter.getInstance()
                 .build(ARouteConstant.Room.user)
                 .withInt("position", position)
@@ -165,10 +161,11 @@ class HotFragment : BaseListFragment<FragmentHotBinding, MomentModel>() {
 
     override fun onResume() {
         super.onResume()
-        if (SpUtil.readInt("hotCloseRoomed") == 1 && adapter.data.size > mCurrentPosition){
-            adapter.data.removeAt(mCurrentPosition)
+        val hotCloseRoomed = SpUtil.readString("hotCloseRoomed")
+        if (hotCloseRoomed != "0"){
+            adapter.data.removeAll { it.id == hotCloseRoomed }
             adapter.notifyDataSetChanged()
-            SpUtil.putInt("hotCloseRoomed" , 0)
+            SpUtil.putString("hotCloseRoomed" , "0")
         }
         isFirstLoadData = false
     }

+ 5 - 8
home/src/main/java/com/swago/home/innerhome/NewFragment.kt

@@ -44,15 +44,12 @@ class NewFragment  : BaseListFragment<FragmentHotBinding, MomentModel>(){
     //印尼,马来默认印尼;阿拉伯语默认阿拉伯语;其他语默认打开是展示全球
     private var matchLanguageId = 0
 
-    //点击position
-    private var mCurrentPosition = 0
-
     override val loadData: (page: Int) -> Unit = {
         homeVm.getHomeList(2, it+1,labelValue)
     }
 
     override fun initViewData() {
-        SpUtil.putInt("newCloseRoomed" , 0)
+        SpUtil.putString("newCloseRoomed" , "0")
         UrlConstant.getConfigModel()?.let {
             if (!it.language_lables.isNullOrEmpty()){
                 matchLanguageId = when(SwagoInfo.languageId){
@@ -96,7 +93,6 @@ class NewFragment  : BaseListFragment<FragmentHotBinding, MomentModel>(){
 
         smartRecyclerView.recyclerView?.addItemDecoration(ComGridItemDecoration())
         adapter.setOnItemClickListener { _, _, position ->
-            mCurrentPosition = position
             ARouter.getInstance()
                 .build(ARouteConstant.Room.user)
                 .withInt("position",position)
@@ -123,10 +119,11 @@ class NewFragment  : BaseListFragment<FragmentHotBinding, MomentModel>(){
 
     override fun onResume() {
         super.onResume()
-        if (SpUtil.readInt("newCloseRoomed") == 1 && adapter.data.size > mCurrentPosition){
-            adapter.data.removeAt(mCurrentPosition)
+        val newCloseRoomed = SpUtil.readString("newCloseRoomed")
+        if (newCloseRoomed != "0"){
+            adapter.data.removeAll { it.id == newCloseRoomed }
             adapter.notifyDataSetChanged()
-            SpUtil.putInt("newCloseRoomed" , 0)
+            SpUtil.putString("newCloseRoomed" , "0")
         }
         isFirstLoadData = false
     }

+ 3 - 3
room/src/main/java/com/swago/room/vm/RoomVm.kt

@@ -103,9 +103,9 @@ class RoomVm(application: Application) : AbsRoomVm(application) {
             requestError {
                 if (it is SwagoException) {
                     if (it.code == 504) {
-                        SpUtil.putInt("hotCloseRoomed",1)
-                        SpUtil.putInt("newCloseRoomed",1)
-                        SpUtil.putInt("followCloseRoomed",1)
+                        SpUtil.putString("hotCloseRoomed",iRoomInfo.getRoomId())
+                        SpUtil.putString("newCloseRoomed",iRoomInfo.getRoomId())
+                        SpUtil.putString("followCloseRoomed",iRoomInfo.getRoomId())
                         Toast.makeText(AppContext.getContext(), it.message, Toast.LENGTH_SHORT)
                             .show()
                         if (SwagoRoomManager.iRoomInfo == null){

+ 6 - 0
room/src/main/java/com/swago/room/widget/UserShowAnchorCloseView.kt

@@ -11,6 +11,7 @@ import com.swago.baseswago.baseroom.SwagoRoomManager
 import com.swago.baseswago.model.im.AnchorRoomClosedBean
 import com.swago.baseswago.util.AppContext
 import com.swago.baseswago.util.NoDoubleClickListener
+import com.swago.baseswago.util.SpUtil
 import com.swago.room.R
 import com.swago.room.databinding.DialogUserForAnchorCloseBinding
 import jp.wasabeef.glide.transformations.BlurTransformation
@@ -22,6 +23,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation
 class UserShowAnchorCloseView : ConstraintLayout {
 
     private lateinit var binding : DialogUserForAnchorCloseBinding
+    private var anchorRoomClosedBean:AnchorRoomClosedBean?= null
 
     constructor(context: Context) : this(context, null)
     constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
@@ -37,12 +39,16 @@ class UserShowAnchorCloseView : ConstraintLayout {
         binding = DialogUserForAnchorCloseBinding.inflate(LayoutInflater.from(context), this, true)
         binding.tvBack.setOnClickListener(object : NoDoubleClickListener() {
             override fun onClick() {
+                SpUtil.putString("hotCloseRoomed",anchorRoomClosedBean?.roomId ?: "0")
+                SpUtil.putString("newCloseRoomed",anchorRoomClosedBean?.roomId ?: "0")
+                SpUtil.putString("followCloseRoomed",anchorRoomClosedBean?.roomId ?: "0")
                 SwagoRoomManager.closeRoom()
             }
         })
     }
 
     fun setData(anchorRoomClosedBean: AnchorRoomClosedBean){
+        this.anchorRoomClosedBean = anchorRoomClosedBean
         RoomTimer.clear()
         binding.tvName.text = anchorRoomClosedBean.senderName
         binding.tvID.text = AppContext.getContext().resources.getString(R.string.id_x)