tongmengxiao 5 сар өмнө
parent
commit
6320b6038c

+ 18 - 0
baseswago/src/main/java/com/swago/baseswago/UserVm.kt

@@ -3,6 +3,7 @@ package com.swago.baseswago
 import android.app.Application
 import android.widget.Toast
 import androidx.lifecycle.MutableLiveData
+import com.bumptech.glide.load.engine.GlideException
 import com.huantansheng.easyphotos.ui.dialog.LoadingDialog
 import com.swago.baseswago.inter.ApiManager
 import com.swago.baseswago.model.*
@@ -13,6 +14,7 @@ import com.swago.baseswago.util.*
 import okhttp3.MediaType.Companion.toMediaTypeOrNull
 import okhttp3.MultipartBody
 import okhttp3.RequestBody
+import org.json.JSONObject
 import java.io.File
 
 /**
@@ -86,6 +88,22 @@ class UserVm(application: Application) : BaseViewModel(application) {
         }
     }
 
+    fun pushError(ex: GlideException?){
+        requestData2(false) {
+            requestData{
+                val jsonObject = JSONObject()
+                UserInfo.getUserInfo()?.let {
+                    jsonObject.put("id" , it.id)
+                }
+                jsonObject.put("version", SwagoInfo.getVersionCode())
+                jsonObject.put("device" , SwagoInfo.getDeviceInfo())
+                jsonObject.put("message","${ex?.message}")
+                jsonObject.put("detail", ex?.stackTraceToString())
+                ApiManager.configApi.pushCrash(jsonObject.toString())
+            }
+        }
+    }
+
     val followFansListLiveData by lazy {
         MutableLiveData<BlackListModel>()
     }

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

@@ -433,6 +433,10 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
             }
         }
 
+        (iHeader as ComHeaderView).glideImageFun = {
+            userVm.pushError(it)
+        }
+
         (iHeader as ComHeaderView).reportAnchorFun = {
             SwagoRoomManager.iRoomInfo?.let {
                 ReportDialog.newInstance(it.getAnchorCode())

+ 29 - 1
room/src/main/java/com/swago/room/widget/ComHeaderView.kt

@@ -1,6 +1,7 @@
 package com.swago.room.widget
 
 import android.content.Context
+import android.graphics.drawable.Drawable
 import android.util.AttributeSet
 import android.util.Log
 import android.util.TimeUtils
@@ -11,6 +12,10 @@ import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import com.alibaba.android.arouter.launcher.ARouter
 import com.bumptech.glide.Glide
+import com.bumptech.glide.load.DataSource
+import com.bumptech.glide.load.engine.GlideException
+import com.bumptech.glide.request.RequestListener
+import com.bumptech.glide.request.target.Target
 import com.swago.baseswago.R
 import com.swago.baseswago.baseroom.*
 import com.swago.baseswago.constant.ARouteConstant
@@ -34,6 +39,7 @@ class ComHeaderView  : ConstraintLayout, IRoomActiveListener, IHeader, RoomTimer
 
     lateinit var binding: LayoutUserHeaderViewBinding
 
+    var glideImageFun:((id:GlideException?)->Unit)? = null
     var followFun:((id:String)->Unit)? = null
     var showUserInfo:((id:String)->Unit)? = null
     var openAudienceListDialog:(()->Unit)? = null
@@ -150,7 +156,29 @@ class ComHeaderView  : ConstraintLayout, IRoomActiveListener, IHeader, RoomTimer
         binding.clRoot.visibility = View.VISIBLE
         Glide.with(context).load(iRoomInfo.getRoomCover())
             .placeholder(R.mipmap.default_avatar)
-            .error(R.mipmap.default_avatar).into(binding.ivAvatar)
+            .error(R.mipmap.default_avatar)
+            .listener(object : RequestListener<Drawable>{
+                override fun onLoadFailed(
+                    ex: GlideException?,
+                    p1: Any?,
+                    p2: Target<Drawable>?,
+                    p3: Boolean
+                ): Boolean {
+                    glideImageFun?.invoke(ex)
+                    return false
+                }
+
+                override fun onResourceReady(
+                    p0: Drawable?,
+                    p1: Any?,
+                    p2: Target<Drawable>?,
+                    p3: DataSource?,
+                    p4: Boolean
+                ): Boolean {
+                    return false
+                }
+            })
+            .into(binding.ivAvatar)
         binding.tvName.text =iRoomInfo.getAnchorName()
         binding.tvId.text = "Likes:${iRoomInfo.getLikeNum()}"
         binding.tvHot.text = iRoomInfo.getRoomHot()