Quellcode durchsuchen

fix: 系统消息Im

tongmengxiao vor 4 Monaten
Ursprung
Commit
eae93dff78

+ 12 - 1
app/src/main/java/com/swago/app/SplashActivity.kt

@@ -1,6 +1,7 @@
 package com.swago.app
 
 import android.Manifest
+import android.content.Intent
 import android.os.Build
 import android.os.Bundle
 import android.os.CountDownTimer
@@ -129,6 +130,7 @@ class SplashActivity : AppCompatActivity() {
             if (it == null || TextUtils.isEmpty(it.rotation_img_url)){
                 splashVm.loginByAuto()
             } else {
+                configModel = it
                 mSplashImage?.loadNoPlaceUrl(this, it.rotation_img_url) { success ->
                     if (success){
                         mSplashTime?.visibility = View.VISIBLE
@@ -144,10 +146,11 @@ class SplashActivity : AppCompatActivity() {
 
         mSplashImage?.setOnClickListener(object : NoDoubleClickListener() {
             override fun onClick() {
+                countDownTimer.cancel()
                 configModel?.rotation_url?.let {
                     ARouter.getInstance().build(ARouteConstant.Base.webView)
                         .withString("url", it)
-                        .navigation()
+                        .navigation(this@SplashActivity,1001)
                 }
             }
         })
@@ -172,4 +175,12 @@ class SplashActivity : AppCompatActivity() {
         super.onDestroy()
         countDownTimer.cancel()
     }
+
+    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+        super.onActivityResult(requestCode, resultCode, data)
+        if (requestCode == 1001){
+            isRunning = false
+            splashVm.loginByAuto()
+        }
+    }
 }

+ 2 - 0
baseswago/src/main/java/com/swago/baseswago/activity/WebViewActivity.kt

@@ -199,10 +199,12 @@ class WebViewActivity : BaseXActivity<ActivityWebBinding>() {
                     if (it.contains(url)  || it.contains("withdrawal")) {
                         webView.goBack()
                     } else {
+                        setResult(RESULT_OK)
                         finish()
                     }
                 }
             } else {
+                setResult(RESULT_OK)
                 finish()
             }
         }

+ 10 - 1
baseswago/src/main/java/com/swago/baseswago/im/GroupMsgParser.kt

@@ -52,6 +52,7 @@ import com.swago.baseswago.im.ImConstant.room_dan_mu
 import com.swago.baseswago.im.ImConstant.send_wish_gift
 import com.swago.baseswago.im.ImConstant.set_room_admin
 import com.swago.baseswago.im.ImConstant.svg_gift
+import com.swago.baseswago.im.ImConstant.system_message
 import com.swago.baseswago.im.ImConstant.today_star_rewards
 import com.swago.baseswago.im.ImConstant.update_audience
 import com.swago.baseswago.im.ImConstant.update_mic_list_data
@@ -62,6 +63,7 @@ import com.swago.baseswago.im.ImConstant.user_join_room
 import com.swago.baseswago.im.ImConstant.user_like
 import com.swago.baseswago.im.ImConstant.user_refuse_invite_by_anchor
 import com.swago.baseswago.model.RedEnvelope
+import com.swago.baseswago.model.home.OfficialSumModel
 import com.swago.baseswago.model.im.*
 import com.swago.baseswago.model.live.ForceCloseModel
 import com.swago.baseswago.model.live.ReceiveModel
@@ -411,7 +413,14 @@ class GroupMsgParser : IGroupNewMsgParser {
                     )
                     parserModel = gson.fromJson(resultString,parameterizedTypeImpl)
                 }
-
+                system_message -> {
+                    parameterizedTypeImpl = ParameterizedTypeImpl(
+                        arrayOf<Type>(OfficialSumModel::class.java),
+                        CusNewMsgBean::class.java,
+                        CusNewMsgBean::class.java
+                    )
+                    parserModel = gson.fromJson(resultString,parameterizedTypeImpl)
+                }
             }
             parserModel?.v2TIMMessage = v2TIMMessage
         }catch (e:Exception){

+ 4 - 0
baseswago/src/main/java/com/swago/baseswago/im/ImConstant.kt

@@ -262,6 +262,10 @@ object ImConstant {
      * 砸金蛋奖池金额
      * */
     const val break_egg_sum = 508
+    /**
+     * 系统消息
+     * */
+    const val system_message = 509
 
 
     /**********游戏相关IM********/

+ 9 - 1
baseswago/src/main/java/com/swago/baseswago/model/UnreadMessageVm.kt

@@ -6,11 +6,19 @@ import com.swago.baseswago.util.BaseViewModel
 
 class UnreadMessageVm (application: Application) : BaseViewModel(application){
 
+    var imMessage = 0L
+    var systemMessage = 0L
+
     val unreadMessageData by lazy {
         MutableLiveData<Long>()
     }
 
     fun setTotalUnreadCount(count: Long) {
-        unreadMessageData.value = count
+        imMessage = count
+        unreadMessageData.value = imMessage + systemMessage
+    }
+    fun setSystemUnreadCount(count: Long){
+        systemMessage = count
+        unreadMessageData.value = imMessage + systemMessage
     }
 }

+ 2 - 1
baseswago/src/main/java/com/swago/baseswago/model/home/OfficialSumModel.kt

@@ -7,5 +7,6 @@ package com.swago.baseswago.model.home
 data class OfficialSumModel(
     val message_content:String,
     val unread_total:String,
-    val message_time:String
+    val message_time:String,
+    val unreadTotal:Long
 )

+ 5 - 15
baseswago/src/main/java/com/swago/baseswago/util/IMUtil.kt

@@ -89,21 +89,11 @@ object IMUtil {
     /**
      * 未读消息数
      * */
-    fun updateUnreadMessageCount(call:(total:Long)->Unit){
-        V2TIMManager.getConversationManager().getTotalUnreadMessageCount(object :V2TIMValueCallback<Long>{
-            override fun onSuccess(totalUnreadCount: Long) {
-                call.invoke(totalUnreadCount)
-            }
-
-            override fun onError(code: Int, desc: String?) {
+    fun updateUnreadMessageCount(conversationListener: V2TIMConversationListener){
+        V2TIMManager.getConversationManager().addConversationListener(conversationListener)
+    }
 
-            }
-        })
-        V2TIMManager.getConversationManager().addConversationListener(object :V2TIMConversationListener(){
-            override fun onTotalUnreadMessageCountChanged(totalUnreadCount: Long) {
-                super.onTotalUnreadMessageCountChanged(totalUnreadCount)
-                call.invoke(totalUnreadCount)
-            }
-        })
+    fun removeConversationListener(conversationListener: V2TIMConversationListener){
+        V2TIMManager.getConversationManager().removeConversationListener(conversationListener)
     }
 }

+ 3 - 3
baseswago/src/main/res/values-in/strings.xml

@@ -126,9 +126,9 @@
     <string name="live_room_black">Daftar hitam live room</string>
     <string name="anchor_black">Daftar hitam host</string>
     <string name="edit">mengubah</string>
-    <string name="level">tingkatan</string>
-    <string name="withdrawal">withdraw</string>
-    <string name="top_up">isi ulang</string>
+    <string name="level">Tingkatan</string>
+    <string name="withdrawal">Withdraw</string>
+    <string name="top_up">Isi ulang</string>
     <string name="app_settings">App Settings</string>
     <string name="nickname">Nickname</string>
     <string name="confirm">Konfirmasi</string>

+ 4 - 4
baseswago/src/main/res/values-ms/strings.xml

@@ -126,10 +126,10 @@
     <string name="live_room_black">senarai hitam siaran langsung</string>
     <string name="anchor_black">senarai hitam host</string>
     <string name="edit">edit</string>
-    <string name="level">tahap</string>
-    <string name="withdrawal">pengeluaran</string>
-    <string name="top_up">tambah nilai</string>
-    <string name="app_settings">sediakan</string>
+    <string name="level">Tahap</string>
+    <string name="withdrawal">Pengeluaran</string>
+    <string name="top_up">Tambah nilai</string>
+    <string name="app_settings">Sediakan</string>
     <string name="nickname">nama pangilan</string>
     <string name="confirm">mengesahkan</string>
     <string name="say_hi">kata hi</string>

+ 1 - 1
baseswago/src/main/res/values/strings.xml

@@ -332,7 +332,7 @@
     <string name="Password_rooms_do_not_count_as_hours">Lock room times didn\'t count into</string>
     <string name="clear_cache">clear cache</string>
     <string name="clear_cache_success">Clearance successful</string>
-    <string name="dress_up">my decorations</string>
+    <string name="dress_up">My decorations</string>
     <string name="mall">Mall</string>
     <string name="buy_it_now">Buy it now</string>
     <string name="entrance_effects">Entrance effects</string>

+ 19 - 4
home/src/main/java/com/swago/home/HomeActivity.kt

@@ -29,6 +29,7 @@ import com.swago.home.databinding.ActivityHomeBinding
 import com.swago.home.innerhome.HomeVm
 import com.swago.home.official.OfficialVm
 import com.swago.home.update.UpdateDialog
+import com.tencent.imsdk.v2.V2TIMConversationListener
 import com.tencent.qcloud.tim.uikit.TUIKit
 import com.tencent.qcloud.tim.uikit.base.IUIKitCallBack
 import com.tencent.qcloud.tim.uikit.config.TUIKitConfigs
@@ -49,6 +50,7 @@ class HomeActivity : BaseXActivity<ActivityHomeBinding>(), IPayCallback {
     private val payVm by viewModels<PayVm>()
     private lateinit var unreadMessageVm: UnreadMessageVm
     private var messageFragment: MessageFragment? = null
+    private var conversationListener: V2TIMConversationListener?=null
 
     private val listFragment =
         arrayListOf(HomeFragment(), MessageFragment(), MineFragment())
@@ -131,7 +133,16 @@ class HomeActivity : BaseXActivity<ActivityHomeBinding>(), IPayCallback {
             }
 
         }
-
+        conversationListener = object : V2TIMConversationListener(){
+            override fun onTotalUnreadMessageCountChanged(totalUnreadCount: Long) {
+                super.onTotalUnreadMessageCountChanged(totalUnreadCount)
+                unreadMessageVm.setTotalUnreadCount(totalUnreadCount)
+            }
+        }
+        IMUtil.updateUnreadMessageCount(conversationListener!!)
+        homeVm.systemMessageFun = {
+            unreadMessageVm.setSystemUnreadCount(it.unreadTotal)
+        }
     }
 
     /**
@@ -284,9 +295,6 @@ class HomeActivity : BaseXActivity<ActivityHomeBinding>(), IPayCallback {
                 IUIKitCallBack {
                 override fun onSuccess(data: Any?) {
                     IMUtil.joinGroup(null)
-                    IMUtil.updateUnreadMessageCount {unread->
-                        unreadMessageVm.setTotalUnreadCount(unread)
-                    }
                 }
 
                 override fun onError(module: String?, errCode: Int, errMsg: String?) {
@@ -300,4 +308,11 @@ class HomeActivity : BaseXActivity<ActivityHomeBinding>(), IPayCallback {
             })
         }
     }
+    override fun onDestroy() {
+        super.onDestroy()
+        if (conversationListener != null) {
+            IMUtil.removeConversationListener(conversationListener!!)
+            conversationListener = null
+        }
+    }
 }

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

@@ -4,11 +4,13 @@ import android.app.Application
 import androidx.lifecycle.MutableLiveData
 import com.swago.baseswago.http.SwagoException
 import com.swago.baseswago.im.IMGroupNewMsgListener
+import com.swago.baseswago.im.ImConstant
 import com.swago.baseswago.im.ImConstant.change_user_name
 import com.swago.baseswago.im.ImConstant.close_account
 import com.swago.baseswago.inter.ApiManager
 import com.swago.baseswago.model.MomentModel
 import com.swago.baseswago.model.home.BannerModel
+import com.swago.baseswago.model.home.OfficialSumModel
 import com.swago.baseswago.model.im.ChangeNameData
 import com.swago.baseswago.model.im.CloseAccountData
 import com.swago.baseswago.model.im.CusNewMsgBean
@@ -24,6 +26,7 @@ class HomeVm(application: Application) : BaseViewModel(application) {
     var closeAccountFun:((data: CloseAccountData) -> Unit)? = null
 
     val imGroupNewMsgListener = IMGroupNewMsgListener()
+    var systemMessageFun:((data: OfficialSumModel) -> Unit)? = null
 
     init {
         imGroupNewMsgListener.attach()
@@ -44,6 +47,13 @@ class HomeVm(application: Application) : BaseViewModel(application) {
 
             }
         }
+        imGroupNewMsgListener.handleMsgType<CusNewMsgBean<OfficialSumModel>>(
+            ImConstant.system_message
+        ){
+            it.data?.let {model ->
+                systemMessageFun?.invoke(model)
+            }
+        }
     }
 
     override fun onCleared() {

+ 5 - 0
home/src/main/java/com/swago/home/official/OfficialMessageActivity.kt

@@ -6,6 +6,8 @@ import androidx.recyclerview.widget.RecyclerView
 import com.chad.library.adapter.base.BaseQuickAdapter
 import com.swago.baseswago.activity.BaseListActivity
 import com.swago.baseswago.cusview.SwagoRecyclerView
+import com.swago.baseswago.model.UnreadMessageVm
+import com.swago.baseswago.model.ViewModelProviderUtil
 import com.swago.baseswago.model.home.OfficialMsgModel
 import com.swago.baseswago.util.AppContext
 import com.swago.home.R
@@ -18,6 +20,7 @@ import com.swago.home.databinding.ActivityOfficialMessageBinding
 class OfficialMessageActivity : BaseListActivity<ActivityOfficialMessageBinding, OfficialMsgModel.ListBean>() {
 
     private val officialVm by viewModels<OfficialVm>()
+    private lateinit var unreadMessageVm: UnreadMessageVm
 
     override val smartRecyclerView: SwagoRecyclerView<OfficialMsgModel.ListBean> by lazy {
         binding.swagoRv as SwagoRecyclerView<OfficialMsgModel.ListBean>
@@ -45,5 +48,7 @@ class OfficialMessageActivity : BaseListActivity<ActivityOfficialMessageBinding,
                 smartRecyclerView.onFetchDataFinish(it,true)
             }
         }
+        unreadMessageVm = ViewModelProviderUtil.getUnreadMessageViewModel(application)
+        unreadMessageVm.setSystemUnreadCount(0)
     }
 }

+ 4 - 0
login/src/main/java/com/swago/login/FBLogin.kt

@@ -44,6 +44,10 @@ object FBLogin {
         LoginManager.getInstance().logInWithReadPermissions(activity, listOf("public_profile"))
     }
 
+    fun unregisterCallback(){
+        LoginManager.getInstance().unregisterCallback(manager)
+    }
+
     fun onActivityResult(requestCoe: Int, resultCode: Int, data: Intent) {
         manager.onActivityResult(requestCoe, resultCode, data)
     }

+ 5 - 0
login/src/main/java/com/swago/login/LoginActivity.kt

@@ -338,4 +338,9 @@ class LoginActivity : BaseXActivity<ActivityLoginBinding>() {
             }
         }
     }
+
+    override fun onDestroy() {
+        super.onDestroy()
+        FBLogin.unregisterCallback()
+    }
 }