tongmengxiao 5 місяців тому
батько
коміт
59b11c9cf8

+ 0 - 10
home/src/main/java/com/swago/home/HomeActivity.kt

@@ -49,7 +49,6 @@ class HomeActivity : BaseXActivity<ActivityHomeBinding>(), IPayCallback {
     private val officialVm by viewModels<OfficialVm>()
     private val homeVm by viewModels<HomeVm>()
     private val payVm by viewModels<PayVm>()
-    private val userVm by viewModels<UserVm>()
 
     private val listFragment =
         arrayListOf(HomeFragment(), MessageFragment(), MineFragment())
@@ -190,21 +189,12 @@ class HomeActivity : BaseXActivity<ActivityHomeBinding>(), IPayCallback {
     }
 
     override fun initLiveData() {
-        homeVm.changeNameChangeFun = {
-            userVm.getUserInfo()
-        }
-
         homeVm.closeAccountFun = {
             val currentActivity = ActivityManagerUtil.get().currentActivity()
             if (currentActivity is FragmentActivity){
                 CloseAccountDialog.newInstance().show(currentActivity.supportFragmentManager,"CloseAccountDialog")
             }
         }
-
-        userVm.userInfoLiveData.observe(this) {
-            UserInfo.setUserInfo(it)
-            SpUtil.putString("user_info", Gson().toJson(it))
-        }
     }
 
     override fun onResume() {

+ 0 - 8
home/src/main/java/com/swago/home/innerhome/HomeVm.kt

@@ -21,7 +21,6 @@ import com.swago.baseswago.util.UserInfo
  */
 class HomeVm(application: Application) : BaseViewModel(application) {
 
-    var changeNameChangeFun:((data: ChangeNameData) -> Unit)? = null
     var closeAccountFun:((data: CloseAccountData) -> Unit)? = null
 
     val imGroupNewMsgListener = IMGroupNewMsgListener()
@@ -32,13 +31,6 @@ class HomeVm(application: Application) : BaseViewModel(application) {
     }
 
     private fun receiveMsg() {
-        imGroupNewMsgListener.handleMsgType<CusNewMsgBean<ChangeNameData>>(
-            change_user_name
-        ){
-            it.data?.let {
-                changeNameChangeFun?.invoke(it)
-            }
-        }
 
         imGroupNewMsgListener.handleMsgType<CusNewMsgBean<CloseAccountData>>(
             close_account

+ 9 - 0
room/src/main/java/com/swago/room/base/BaseComFragment.kt

@@ -16,6 +16,7 @@ import androidx.recyclerview.widget.GridLayoutManager
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import com.alibaba.android.arouter.launcher.ARouter
+import com.google.gson.Gson
 import com.gyf.immersionbar.ImmersionBar
 import com.liulishuo.okdownload.DownloadListener
 import com.liulishuo.okdownload.DownloadTask
@@ -581,6 +582,14 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
 
         }
 
+        msgVm.changeNameChangeFun = {
+            userVm.getUserInfo()
+        }
+
+        userVm.userInfoLiveData.observe(this) {
+            UserInfo.setUserInfo(it)
+            SpUtil.putString("user_info", Gson().toJson(it))
+        }
 
         //打开红包
         binding.ivRedEnvelopeView.openRedEnvelope = {

+ 15 - 0
room/src/main/java/com/swago/room/vm/MsgVm.kt

@@ -7,6 +7,7 @@ import com.swago.baseswago.baseroom.RoleType
 import com.swago.baseswago.baseroom.SwagoRoomManager
 import com.swago.baseswago.baseroom.viewmodel.AbsMsgVm
 import com.swago.baseswago.im.IRoomChat
+import com.swago.baseswago.im.ImConstant
 import com.swago.baseswago.im.ImConstant.anchor_close_room
 import com.swago.baseswago.im.ImConstant.cancel_forbid_speak
 import com.swago.baseswago.im.ImConstant.delete_room_admin
@@ -152,6 +153,8 @@ class MsgVm(application: Application) : AbsMsgVm(application) {
      */
     var openHouseOpenLiveDialog:((houseOpenLiveData: HouseOpenLiveData)->Unit)? = null
 
+    var changeNameChangeFun:((data: ChangeNameData) -> Unit)? = null
+
     val joinRoomManager by lazy {
         JoinRoomManager()
     }
@@ -756,6 +759,18 @@ class MsgVm(application: Application) : AbsMsgVm(application) {
             }
         }
 
+        imGroupNewMsgListener.handleMsgType<CusNewMsgBean<ChangeNameData>>(
+            ImConstant.change_user_name
+        ){
+            it.data?.let {
+                UserInfo.getUserInfo()?.let { userInfo ->
+                    if (it.userId == userInfo.id){
+                        changeNameChangeFun?.invoke(it)
+                    }
+                }
+            }
+        }
+
     }