Browse Source

feat : 头像

tongmengxiao 6 months ago
parent
commit
f5bf0641c6

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

@@ -46,8 +46,8 @@ class UserVm(application: Application) : BaseViewModel(application) {
         requestData {
             val data = ApiManager.userApi.getUserInfo()
             userInfoLiveData.value = data
-            BitmapUtils.loadFile(AppContext.getContext() , data.badge_special)
-            BitmapUtils.loadFile(AppContext.getContext() , data.chat_special)
+            BitmapUtils.loadFile(AppContext.getContext() , data.badge_special,207,60)
+            BitmapUtils.loadFile(AppContext.getContext() , data.chat_special,134,134)
         }
     }
 

+ 17 - 38
baseswago/src/main/java/com/swago/baseswago/util/BitmapUtils.kt

@@ -5,6 +5,7 @@ import android.content.Context
 import android.graphics.Bitmap
 import android.graphics.BitmapFactory
 import android.graphics.drawable.Drawable
+import android.text.TextUtils
 import com.bumptech.glide.Glide
 import com.bumptech.glide.request.target.CustomTarget
 import com.bumptech.glide.request.transition.Transition
@@ -19,28 +20,33 @@ import java.io.IOException
 
 object BitmapUtils {
 
-    fun getBitmapFromPath(url:String?):Bitmap?{
-            val path = "${AppContext.getContext().getExternalFilesDir(null)!!.path}/swagoFile"
-            val pathFile = File("$path/${url?.substring(url.lastIndexOf("/"))}")
-            return if (pathFile.exists()) {
-                BitmapFactory.decodeFile(pathFile.absolutePath)
-            } else {
-                null
-            }
+    fun getBitmapFromPath(url: String?): Bitmap? {
+        if (TextUtils.isEmpty(url)) {
+            return null
+        }
+        val path = "${AppContext.getContext().getExternalFilesDir(null)!!.path}/swagoFile"
+        val pathFile = File("$path/${url?.substring(url.lastIndexOf("/"))}")
+        return if (pathFile.exists()) {
+            BitmapFactory.decodeFile(pathFile.absolutePath)
+        } else {
+            null
+        }
 
     }
 
-    fun loadFile(context: Context, url: String) {
-        if (context is Activity){
+    fun loadFile(context: Context, url: String,width:Int,height:Int) {
+        if (context is Activity) {
             if (context.isDestroyed)
                 return
         }
         Glide.with(context)
             .asBitmap()
+            .override(width,height)
             .load(url)
             .into(object : CustomTarget<Bitmap>() {
                 override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
-                    val pathFile = File("${UrlConstant.specialResourcePath}/${url.substring(url.lastIndexOf("/"))}")
+                    val pathFile =
+                        File("${UrlConstant.specialResourcePath}/${url.substring(url.lastIndexOf("/"))}")
                     var outputStream: FileOutputStream? = null
                     try {
                         outputStream = FileOutputStream(pathFile)
@@ -58,31 +64,4 @@ object BitmapUtils {
                 }
             })
     }
-
-     fun downLoadLottie(downloadUrl: String, name: String) {
-         val pathFile = File(UrlConstant.specialResourcePath)
-         pathFile.mkdirs()
-        GlobalScope.launch {
-            try {
-                val responseBody = ApiManager.homeApi.downFile(downloadUrl)
-                dowload(AppContext.getContext(), responseBody) {
-                    hasSelfPath = {
-                        UrlConstant.specialResourcePath
-                    }
-                    setFileName = {
-                        File.separator + name
-                    }
-                    success {
-                        LogUtil.d("资源","下载成功")
-                    }
-                    error {
-                        LogUtil.d("资源","下载失败")
-                    }
-
-                }.startDowload()
-            } catch (e: Exception) {
-                LogUtil.d("资源","下载失败")
-            }
-        }
-    }
 }

+ 7 - 12
home/src/main/java/com/swago/home/ChatDetailActivity.kt

@@ -6,6 +6,7 @@ import android.graphics.drawable.BitmapDrawable
 import android.graphics.drawable.Drawable
 import android.graphics.drawable.NinePatchDrawable
 import android.os.Bundle
+import android.text.TextUtils
 import android.view.View
 import androidx.activity.viewModels
 import androidx.core.content.ContextCompat
@@ -20,6 +21,7 @@ import com.swago.baseswago.activity.BaseXActivity
 import com.swago.baseswago.constant.ARouteConstant
 import com.swago.baseswago.dialog.ReportBlockDialogFragment
 import com.swago.baseswago.util.AppContext
+import com.swago.baseswago.util.BitmapUtils
 import com.swago.baseswago.util.DianJiuUtil
 import com.swago.baseswago.util.NinePatchChunk
 import com.swago.baseswago.util.NoDoubleClickListener
@@ -119,18 +121,11 @@ class ChatDetailActivity  : BaseXActivity<ActivityChatDetailBinding>() {
 
             }
         })
-//        val path = "${AppContext.getContext().getExternalFilesDir(null)!!.path}/swagoFile/mmexport1718256766828.png"
-//        val bitmap = BitmapFactory.decodeStream(FileInputStream(path))
-//        val chunk = bitmap.ninePatchChunk
-//        if (NinePatch.isNinePatchChunk(chunk)){
-//            val patchy = NinePatchDrawable(resources,bitmap,chunk,NinePatchChunk.deserialize(chunk)?.mPaddings,null)
-//            messageRecyclerView.rightBubble = patchy
-//        }
-//        DianJiuUtil.loadDian9Tu(this ,"https://apple-1304432552.cos.ap-shanghai.myqcloud.com/android.png") {
-//            messageRecyclerView.rightBubble = it
-//        }
-
-
+        val path = "${AppContext.getContext().getExternalFilesDir(null)!!.path}/swagoFile/mmexport1718256766828.png"
+        val bitmap = BitmapUtils.getBitmapFromPath(path)
+        bitmap?.let {
+            messageRecyclerView.leftBubble =   DianJiuUtil.setNinePatchImage(this , it)
+        }
     }
 
     override fun initLiveData() {

+ 22 - 2
home/src/main/java/com/swago/home/MineFragment.kt

@@ -5,6 +5,9 @@ import androidx.fragment.app.viewModels
 import com.alibaba.android.arouter.launcher.ARouter
 import com.bumptech.glide.Glide
 import com.google.gson.Gson
+import com.opensource.svgaplayer.SVGADrawable
+import com.opensource.svgaplayer.SVGAParser
+import com.opensource.svgaplayer.SVGAVideoEntity
 import com.swago.baseswago.PayVm
 import com.swago.baseswago.R
 import com.swago.baseswago.UserVm
@@ -15,6 +18,7 @@ import com.swago.baseswago.fragment.BaseXFragment
 import com.swago.baseswago.model.ConfigModel
 import com.swago.baseswago.util.*
 import com.swago.home.databinding.FragmentMineBinding
+import java.net.URL
 
 /**
  *@date 2021/11/20 10:32
@@ -24,8 +28,10 @@ class MineFragment : BaseXFragment<FragmentMineBinding>() {
 
     private val userVm by viewModels<UserVm>()
     private val payVm by viewModels<PayVm>()
-
-    override fun loadData() {}
+    private var svgaParser: SVGAParser? = null
+    override fun loadData() {
+        svgaParser = SVGAParser(activity)
+    }
 
     override fun initOther() {
         if (SwagoInfo.isGooglePackage()){
@@ -38,6 +44,20 @@ class MineFragment : BaseXFragment<FragmentMineBinding>() {
             }
         }
 
+        UserInfo.getUserInfo()?.head_special?.let {
+            svgaParser?.decodeFromURL(URL("https://apple-1304432552.cos.ap-shanghai.myqcloud.com/7.svga"), object :SVGAParser.ParseCompletion{
+                override fun onComplete(videoItem: SVGAVideoEntity) {
+                    val drawable = SVGADrawable(videoItem)
+                    binding.svgAvatar.setImageDrawable(drawable)
+                    binding.svgAvatar.startAnimation()
+                }
+
+                override fun onError() {
+
+                }
+            })
+        }
+
         binding.llFans.setOnClickListener(object: NoDoubleClickListener(){
             override fun onClick() {
                 ARouter.getInstance()

+ 0 - 1
home/src/main/res/layout/fragment_mine.xml

@@ -60,7 +60,6 @@
             android:layout_width="50dp"
             android:layout_height="50dp"
             android:visibility="visible"
-            app:source="avatar.svga"
             app:autoPlay="true"
             app:loopCount="0"
             app:layout_constraintStart_toStartOf="parent"

+ 9 - 3
room/src/main/java/com/swago/room/adapter/RoomChatAdapter.kt

@@ -27,7 +27,9 @@ import com.swago.baseswago.model.im.FollowSuccessMsgBean
 import com.swago.baseswago.model.im.IMLevelUpMsgBean
 import com.swago.baseswago.model.im.RoomChatMsgBean
 import com.swago.baseswago.model.im.UserJoinRoomBean
+import com.swago.baseswago.util.AppContext
 import com.swago.baseswago.util.BitmapUtils
+import com.swago.baseswago.util.DianJiuUtil
 import com.swago.baseswago.util.UserInfo
 import com.swago.formatAr
 import com.swago.room.R
@@ -53,7 +55,8 @@ class RoomChatAdapter :
         BitmapUtils.getBitmapFromPath(UserInfo.getUserInfo()?.badge_special)
     }
     private val bubbleChat by lazy {
-       BitmapUtils.getBitmapFromPath(UserInfo.getUserInfo()?.chat_special)
+        val path = "${AppContext.getContext().getExternalFilesDir(null)!!.path}/swagoFile/mmexport1718256766828.png"
+         BitmapUtils.getBitmapFromPath(path)
     }
     private val userid by lazy {
         UserInfo.getUserInfo()?.id
@@ -456,8 +459,11 @@ class RoomChatAdapter :
 
                 }
             }
-            if (bubbleChat != null && item.getSenderId() == userid){
-                tvContent.background =  BitmapDrawable(mContext.resources , bubbleChat)
+            if (item.getSenderId() == userid){
+                bubbleChat?.let {
+                    tvContent.background =  DianJiuUtil.setNinePatchImage(mContext , it)
+                }
+
             }
             tvContent.movementMethod = LinkMovementMethod.getInstance()
             tvContent.highlightColor = Color.TRANSPARENT