Browse Source

1.优化代码

王鹏鹏 2 years ago
parent
commit
21386cd116

+ 15 - 22
push/src/main/java/com/yingyang/push/activity/MessgeListActivity.kt

@@ -64,7 +64,7 @@ class MessgeListActivity : BaseMVVMActivity<ActivityMessgeListBinding, PushViewM
                     "D", "理疗通知" -> {
                         if (TextUtils.isEmpty(bean.ext)) {
                             val messageDialog = MessageDialog()
-                            messageDialog.setContent(bean.id, bean.msgDesn, bean.msgTitle)
+                            messageDialog.setContent(bean.getMsgIdInfo(), bean.getMsgDesnInfo(), bean.getMsgTitleInfo())
                             messageDialog.show(supportFragmentManager, "messageDialog")
                         } else {
                             JumpUtil.jumpActivityWithUrl(
@@ -77,7 +77,7 @@ class MessgeListActivity : BaseMVVMActivity<ActivityMessgeListBinding, PushViewM
                     "C", "报告提醒" -> {
                         if (TextUtils.isEmpty(bean.ext)) {
                             val messageDialog = MessageDialog()
-                            messageDialog.setContent(bean.id, bean.msgDesn, bean.msgTitle)
+                            messageDialog.setContent(bean.getMsgIdInfo(), bean.getMsgDesnInfo(), bean.getMsgTitleInfo())
                             messageDialog.show(supportFragmentManager, "messageDialog")
                         } else {
                             JumpUtil.jumpActivityWithUrl(
@@ -89,7 +89,7 @@ class MessgeListActivity : BaseMVVMActivity<ActivityMessgeListBinding, PushViewM
                     }
                     else -> {
                         val messageDialog = MessageDialog()
-                        messageDialog.setContent(bean.id, bean.msgDesn, bean.msgTitle)
+                        messageDialog.setContent(bean.getMsgIdInfo(), bean.getMsgDesnInfo(), bean.getMsgTitleInfo())
                         messageDialog.show(supportFragmentManager, "messageDialog")
                     }
                 }
@@ -106,11 +106,6 @@ class MessgeListActivity : BaseMVVMActivity<ActivityMessgeListBinding, PushViewM
     }
 
     override fun initData() {
-
-    }
-
-    override fun onResume() {
-        super.onResume()
         getPushList()
         getMeaageList()
     }
@@ -119,17 +114,17 @@ class MessgeListActivity : BaseMVVMActivity<ActivityMessgeListBinding, PushViewM
      * 获取推送消息类型
      */
     private fun getPushList() {
-        pushTypeList.clear()
-        pushTypeList.add(
-            PushMessageTypeBean(
-                dictLabel = "全部消息",
-                dictValue = "",
-                dictType = "game_type"
-            )
-        )
         viewModel.getSelectByDictType(fail = {
             it.toast()
         }, success = {
+            pushTypeList.clear()
+            pushTypeList.add(
+                PushMessageTypeBean(
+                    dictLabel = "全部消息",
+                    dictValue = "",
+                    dictType = "game_type"
+                )
+            )
             if (it.isNullOrEmpty().not()) {
                 pushTypeList.addAll(it!!)
             }
@@ -141,11 +136,11 @@ class MessgeListActivity : BaseMVVMActivity<ActivityMessgeListBinding, PushViewM
      * 获取推送消息列表
      */
     private fun getMeaageList() {
-        pushList.clear()
-        pushListAdapter.clearData()
         viewModel.getPushList(msgType, fail = {
             it.toast()
         }, success = {
+            pushList.clear()
+            pushListAdapter.clearData()
             if (it.isNullOrEmpty().not()) {
                 pushList.addAll(it!!)
             }
@@ -162,10 +157,8 @@ class MessgeListActivity : BaseMVVMActivity<ActivityMessgeListBinding, PushViewM
             it.toast()
         }, success = {
             if (pushListAdapter.data.isNullOrEmpty().not()) {
-                if (pushListAdapter.data.get(position) != null) {
-                    pushListAdapter.data[position].status = "0"
-                    pushListAdapter.notifyItemChanged(position)
-                }
+                pushListAdapter.data[position].status = "0"
+                pushListAdapter.notifyItemChanged(position)
             }
         })
     }

+ 27 - 1
push/src/main/java/com/yingyang/push/entity/PushMessageBean.kt

@@ -1,5 +1,7 @@
 package com.yingyang.push.entity
 
+import android.text.TextUtils
+
 /**
  * 消息通知列表bean
  */
@@ -15,4 +17,28 @@ data class PushMessageBean(
     var updateTime: String,
     var msgDesn: String,
     var ext: String
-)
+) {
+    fun getMsgDesnInfo(): String {
+        return if (TextUtils.isEmpty(msgDesn)) {
+            ""
+        } else {
+            msgDesn
+        }
+    }
+
+    fun getMsgIdInfo(): String {
+        return if (TextUtils.isEmpty(id)) {
+            ""
+        } else {
+            id
+        }
+    }
+
+    fun getMsgTitleInfo(): String {
+        return if (TextUtils.isEmpty(msgTitle)) {
+            ""
+        } else {
+            msgTitle
+        }
+    }
+}