瀏覽代碼

feat: 选中装扮

tongmengxiao 5 月之前
父節點
當前提交
2ac0b9dd58

+ 12 - 0
baseswago/src/main/java/com/swago/baseswago/inter/UserApi.kt

@@ -131,12 +131,24 @@ interface UserApi {
     @POST("/v1/user/coin/product/list")
     suspend fun getProductList(): StoreProductModel
 
+    /**
+     * 购买
+     * */
     @FormUrlEncoded
     @POST("/v1/user/buy/product")
     suspend fun buyProduct(@Field("product_id") product_id: Long):Any
 
+    /**
+     * 装扮列表
+     * */
     @POST("/v1/user/exist/product/list")
     suspend fun exitProductList():StoreProductModel
 
+    /**
+     * 选中装扮
+     * */
+    @FormUrlEncoded
+    @POST("/v1/user/exist/product/chose")
+    suspend fun choseProduct(@Field("product_id") product_id: Long):Any
 
 }

+ 36 - 0
baseswago/src/main/java/com/swago/baseswago/model/UserInfoModel.java

@@ -98,6 +98,10 @@ public class UserInfoModel {
      * 是否充值用户
      */
     private int is_recharge;
+    private String join_special;
+    private String head_special;
+    private String badge_special;
+    private String chat_special;
 
     public String getUser_constellation() {
         return user_constellation;
@@ -394,4 +398,36 @@ public class UserInfoModel {
     public void setIs_recharge(int is_recharge) {
         this.is_recharge = is_recharge;
     }
+
+    public String getJoin_special() {
+        return join_special;
+    }
+
+    public void setJoin_special(String join_special) {
+        this.join_special = join_special;
+    }
+
+    public String getHead_special() {
+        return head_special;
+    }
+
+    public void setHead_special(String head_special) {
+        this.head_special = head_special;
+    }
+
+    public String getBadge_special() {
+        return badge_special;
+    }
+
+    public void setBadge_special(String badge_special) {
+        this.badge_special = badge_special;
+    }
+
+    public String getChat_special() {
+        return chat_special;
+    }
+
+    public void setChat_special(String chat_special) {
+        this.chat_special = chat_special;
+    }
 }

+ 4 - 1
baseswago/src/main/java/com/swago/baseswago/model/mine/StoreProductModel.kt

@@ -12,8 +12,9 @@ data class StoreItemBean (
     val product_url: String?,
     val product_category: Int,
     val product_coin: Long,
+    val expire_at: Long,
     val id: Long,
-    val product_status: Int
+    var product_status: Int
 ) :Parcelable{
     constructor(parcel: Parcel) : this(
         parcel.readString(),
@@ -21,6 +22,7 @@ data class StoreItemBean (
         parcel.readInt(),
         parcel.readLong(),
         parcel.readLong(),
+        parcel.readLong(),
         parcel.readInt()
     )
 
@@ -29,6 +31,7 @@ data class StoreItemBean (
         parcel.writeString(product_url)
         parcel.writeInt(product_category)
         parcel.writeLong(product_coin)
+        parcel.writeLong(expire_at)
         parcel.writeLong(id)
         parcel.writeInt(product_status)
     }

+ 42 - 0
baseswago/src/main/java/com/swago/baseswago/util/DianJiuUtil.kt

@@ -0,0 +1,42 @@
+package com.swago.baseswago.util
+
+import android.app.Activity
+import android.content.Context
+import android.graphics.Bitmap
+import android.graphics.NinePatch
+import android.graphics.drawable.Drawable
+import android.graphics.drawable.NinePatchDrawable
+import android.widget.Toast
+import com.bumptech.glide.Glide
+import com.bumptech.glide.request.target.CustomTarget
+import com.bumptech.glide.request.transition.Transition
+
+object DianJiuUtil {
+
+    fun loadDian9Tu(context: Context, url: String, drawable: (e: Drawable?) -> Unit){
+        if (context is Activity){
+            if (context.isDestroyed)
+                return
+        }
+        Glide.with(context)
+            .asBitmap()
+            .load(url)
+            .into(object : CustomTarget<Bitmap>() {
+                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
+                    drawable.invoke(setNinePatchImage(context , resource))
+                }
+
+                override fun onLoadCleared(placeholder: Drawable?) {
+
+                }
+            })
+    }
+
+    fun setNinePatchImage(context: Context, bitmap: Bitmap): NinePatchDrawable? {
+        val chunk = bitmap.ninePatchChunk
+        if (NinePatch.isNinePatchChunk(chunk)){
+            return NinePatchDrawable(context.resources,bitmap,chunk,NinePatchChunk.deserialize(chunk)?.mPaddings,null)
+        }
+        return null
+    }
+}

+ 0 - 47
baseswago/src/main/java/com/swago/glide.kt

@@ -1,12 +1,6 @@
 package com.swago
 
-import android.app.Activity
 import android.content.Context
-import android.graphics.Bitmap
-import android.graphics.BitmapFactory
-import android.graphics.NinePatch
-import android.graphics.drawable.Drawable
-import android.graphics.drawable.NinePatchDrawable
 import android.os.Build
 import android.text.BidiFormatter
 import android.text.TextDirectionHeuristics
@@ -15,14 +9,8 @@ import androidx.annotation.DrawableRes
 import androidx.annotation.RequiresApi
 import com.bumptech.glide.Glide
 import com.bumptech.glide.request.RequestOptions
-import com.bumptech.glide.request.target.CustomTarget
-import com.bumptech.glide.request.transition.Transition
 import com.swago.baseswago.R
 import jp.wasabeef.glide.transformations.BlurTransformation
-import java.io.File
-import java.io.FileInputStream
-import java.io.FileNotFoundException
-import java.io.IOException
 import java.util.*
 
 /**
@@ -84,39 +72,4 @@ fun CharSequence.formatAr(): CharSequence {
         this,
         TextDirectionHeuristics.LOCALE
     )
-}
-
-fun loadDian9Tu(context: Context, imageView: ImageView, url: String){
-    if (context is Activity){
-        if (context.isDestroyed)
-            return
-    }
-    Glide.with(context)
-        .asFile()
-        .load(url)
-        .into(object : CustomTarget<File>() {
-            override fun onResourceReady(resource: File, transition: Transition<in File>?) {
-                try {
-                    FileInputStream(resource).use { inputStream ->
-                        val bitmap = BitmapFactory.decodeStream(inputStream)
-                        imageView.setNinePatchImage(context , bitmap)
-                    }
-                } catch (e: FileNotFoundException) {
-                    e.printStackTrace()
-                } catch (e: IOException) {
-                    e.printStackTrace()
-                }
-            }
-
-            override fun onLoadCleared(placeholder: Drawable?) {
-
-            }
-        })
-}
-
-fun ImageView.setNinePatchImage(context: Context, bitmap: Bitmap) {
-    val chunk = bitmap.ninePatchChunk
-    val ninePatch = NinePatch(bitmap, chunk, null)
-    val ninePatchDrawable = NinePatchDrawable(context.resources, ninePatch)
-    this.setImageDrawable(ninePatchDrawable)
 }

+ 23 - 3
home/src/main/java/com/swago/home/ChatDetailActivity.kt

@@ -1,10 +1,14 @@
 package com.swago.home
 
+import android.graphics.BitmapFactory
+import android.graphics.NinePatch
+import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.Drawable
+import android.graphics.drawable.NinePatchDrawable
 import android.os.Bundle
 import android.view.View
 import androidx.activity.viewModels
 import androidx.core.content.ContextCompat
-import androidx.fragment.app.viewModels
 import com.alibaba.android.arouter.facade.annotation.Autowired
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.alibaba.android.arouter.launcher.ARouter
@@ -12,9 +16,12 @@ import com.google.gson.Gson
 import com.gyf.immersionbar.ImmersionBar
 import com.swago.baseswago.PersonDataDFragment
 import com.swago.baseswago.UserVm
-import com.swago.baseswago.dialog.ReportBlockDialogFragment
 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.DianJiuUtil
+import com.swago.baseswago.util.NinePatchChunk
 import com.swago.baseswago.util.NoDoubleClickListener
 import com.swago.baseswago.util.SpUtil
 import com.swago.baseswago.util.UserInfo
@@ -23,7 +30,8 @@ import com.tencent.imsdk.v2.V2TIMConversation
 import com.tencent.qcloud.tim.uikit.modules.chat.base.ChatInfo
 import com.tencent.qcloud.tim.uikit.modules.chat.layout.message.MessageLayout
 import com.tencent.qcloud.tim.uikit.modules.message.MessageInfo
-import com.tencent.qcloud.tim.uikit.utils.ToastUtil
+import java.io.FileInputStream
+
 
 /**
  *@date 2021/8/24 15:01
@@ -111,6 +119,18 @@ 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
+//        }
+
+
     }
 
     override fun initLiveData() {

+ 4 - 0
user/src/main/java/com/swago/user/store/StoreBuyDialog.kt

@@ -10,7 +10,9 @@ import com.opensource.svgaplayer.SVGAParser
 import com.opensource.svgaplayer.SVGAVideoEntity
 import com.swago.baseswago.dialog.BaseXDFragment
 import com.swago.baseswago.model.mine.StoreItemBean
+import com.swago.baseswago.util.AppContext
 import com.swago.baseswago.util.NoDoubleClickListener
+import com.swago.loadUrl
 import com.swago.user.databinding.DialogStoreDetailBinding
 import com.swago.user.vm.StoreVm
 import java.io.File
@@ -46,6 +48,7 @@ class StoreBuyDialog : BaseXDFragment<DialogStoreDetailBinding>(){
         storeBean?.let {
             binding.tvName.text = it.product_name
             binding.tvCoin.text = "${it.product_coin}"
+//            binding.ivIcon.loadUrl(AppContext.getContext(),it.product_url?:"")
             svgaParser?.let { svgaParser ->
                 svgaParser.decodeFromURL(URL(it.product_url), object : SVGAParser.ParseCompletion{
                     override fun onComplete(videoItem: SVGAVideoEntity) {
@@ -81,6 +84,7 @@ class StoreBuyDialog : BaseXDFragment<DialogStoreDetailBinding>(){
             override fun onClick() {
                 storeBean?.let {
                     storeVm.buyProduct(it.id)
+                    dismissAllowingStateLoss()
                 }
 
             }

+ 7 - 2
user/src/main/java/com/swago/user/store/StoreItemAdapter.kt

@@ -13,12 +13,17 @@ class StoreItemAdapter(private val type: Int) : BaseQuickAdapter<StoreItemBean,
 
     override fun convert(helper: BaseViewHolder?, item: StoreItemBean?) {
         helper?.apply {
-            setVisible(R.id.tvUsing , type != 1)
             setVisible(R.id.tv_coin , type == 1)
+            setVisible(R.id.tv_time , type == 2)
 
             item?.let {
+                setVisible(R.id.tvUsing , type ==2 && item.product_status == 1)
                 setText(R.id.tv_name ,item.product_name)
-                setText(R.id.tv_coin ,"${item.product_coin}")
+                if (type == 1){
+                    setText(R.id.tv_coin ,"${item.product_coin}")
+                } else if (type == 2){
+                    setText(R.id.tv_time ,if (item.expire_at == 0L)"Unlimited time" else "${item.expire_at}days")
+                }
                 itemView.findViewById<CircleImageView>(R.id.iv_svg).loadUrl(mContext,item.product_url?: "")
             }
 

+ 55 - 1
user/src/main/java/com/swago/user/store/StoreListActivity.kt

@@ -14,6 +14,7 @@ import com.swago.baseswago.constant.ARouteConstant
 import com.swago.baseswago.model.live.audio.PositionBean
 import com.swago.baseswago.model.mine.StoreItemBean
 import com.swago.baseswago.util.AppContext
+import com.swago.baseswago.util.SpUtil
 import com.swago.user.R
 import com.swago.user.databinding.ActivityStoreListBinding
 import com.swago.user.vm.StoreVm
@@ -178,6 +179,10 @@ class StoreListActivity : BaseXActivity<ActivityStoreListBinding>() {
             if (it.isNullOrEmpty()){
                 binding.clEmpty.visibility = View.VISIBLE
             } else {
+                enterList.clear()
+                avatarList.clear()
+                badgeList.clear()
+                bubbleList.clear()
                 it.forEach { item ->
                     when (item.product_category){
                         1 -> {
@@ -274,7 +279,56 @@ class StoreListActivity : BaseXActivity<ActivityStoreListBinding>() {
             isBubbleExpanded = !isBubbleExpanded
         }
         enterAdapter.setOnItemClickListener { _, _, position ->
-            StoreBuyDialog.newInstance(enterAdapter.data[position]).show(supportFragmentManager ,"StoreBuyDialog")
+            if (type == 1){
+                StoreBuyDialog.newInstance(enterAdapter.data[position]).show(supportFragmentManager ,"StoreBuyDialog")
+            } else if (type == 2){
+                storeVm.chooseProduct(enterAdapter.data[position].id)
+                enterList.forEachIndexed { index, storeItemBean ->
+                    enterList[index].product_status = 0
+                    return@forEachIndexed
+                }
+                enterList[position].product_status = 1
+                enterAdapter.notifyDataSetChanged()
+            }
+        }
+        avatarAdapter.setOnItemClickListener { _, _, position ->
+            if (type == 1){
+                StoreBuyDialog.newInstance(avatarAdapter.data[position]).show(supportFragmentManager ,"StoreBuyDialog")
+            } else if (type == 2){
+                storeVm.chooseProduct(avatarAdapter.data[position].id)
+                avatarList.forEachIndexed { index, storeItemBean ->
+                    avatarList[index].product_status = 0
+                    return@forEachIndexed
+                }
+                avatarList[position].product_status = 1
+                avatarAdapter.notifyDataSetChanged()
+            }
+        }
+        badgeAdapter.setOnItemClickListener { _, _, position ->
+            if (type == 1){
+                StoreBuyDialog.newInstance(badgeAdapter.data[position]).show(supportFragmentManager ,"StoreBuyDialog")
+            } else if (type == 2){
+                storeVm.chooseProduct(badgeAdapter.data[position].id)
+                badgeList.forEachIndexed { index, storeItemBean ->
+                    badgeList[index].product_status = 0
+                    return@forEachIndexed
+                }
+                badgeList[position].product_status = 1
+                badgeAdapter.notifyDataSetChanged()
+            }
+        }
+        bubbleAdapter.setOnItemClickListener { _, _, position ->
+            if (type == 1){
+                StoreBuyDialog.newInstance(bubbleAdapter.data[position]).show(supportFragmentManager ,"StoreBuyDialog")
+            } else if (type == 2){
+                storeVm.chooseProduct(bubbleAdapter.data[position].id)
+                bubbleList.forEachIndexed { index, storeItemBean ->
+                    bubbleList[index].product_status = 0
+                    return@forEachIndexed
+                }
+                bubbleList[position].product_status = 1
+                bubbleAdapter.notifyDataSetChanged()
+            }
         }
     }
 

+ 10 - 1
user/src/main/java/com/swago/user/vm/StoreVm.kt

@@ -28,7 +28,7 @@ class StoreVm(application: Application) : BaseViewModel(application){
     }
 
     fun buyProduct(productId:Long){
-        requestData2 (){
+        requestData2 {
             requestData {
                 ApiManager.userApi.buyProduct(productId)
             }
@@ -51,4 +51,13 @@ class StoreVm(application: Application) : BaseViewModel(application){
             }
         }
     }
+
+    fun chooseProduct(productId:Long){
+        requestData2 {
+            requestData {
+                ApiManager.userApi.choseProduct(productId)
+            }
+
+        }
+    }
 }

+ 10 - 2
user/src/main/res/layout/dialog_store_detail.xml

@@ -24,17 +24,25 @@
             android:paddingBottom="24dp"
             app:layout_constraintBottom_toBottomOf="parent">
 
+            <ImageView
+                android:id="@+id/ivIcon"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toStartOf="parent"
+                android:layout_marginTop="12dp"
+                app:layout_constraintTop_toTopOf="parent"/>
+
             <com.swago.baseswago.cusview.MediumTextView
                 android:id="@+id/tv_name"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:layout_marginTop="18dp"
                 android:maxWidth="120dp"
                 android:textColor="#ffffff"
                 android:textSize="16sp"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintTop_toTopOf="parent"
+                app:layout_constraintTop_toBottomOf="@+id/ivIcon"
                 tools:text="fgg" />
 
             <com.swago.baseswago.cusview.MediumTextView

+ 13 - 0
user/src/main/res/layout/item_store.xml

@@ -49,6 +49,19 @@
             android:drawableStart="@mipmap/ic_coin_store"
             android:textSize="10sp"
             android:textColor="#A3FFFFFF"/>
+        <com.swago.baseswago.cusview.MediumTextView
+            android:id="@+id/tv_time"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="2dp"
+            android:drawablePadding="2dp"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/tv_name"
+            android:visibility="gone"
+            tools:text="fgg"
+            android:textSize="10sp"
+            android:textColor="#A3FFFFFF"/>
         <TextView
             android:id="@+id/tvUsing"
             android:layout_width="51dp"