浏览代码

feat: 游戏推荐

tongmengxiao 6 月之前
父节点
当前提交
82be40ac55

+ 2 - 2
app/build.gradle

@@ -15,8 +15,8 @@ android {
         applicationId "com.swago.app"
         minSdkVersion 21
         targetSdkVersion 33
-        versionCode 1402
-        versionName "1.4.0.2"
+        versionCode 1403
+        versionName "1.4.0.3"
         multiDexEnabled true
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 

+ 2 - 2
app/src/main/java/com/swago/app/SplashVm.kt

@@ -112,9 +112,9 @@ class SplashVm(application: Application) : BaseViewModel(application) {
 
     private fun setBaseUrl(baseUrl: String) {
         if (BuildConfig.DEBUG) {
-//            UrlConstant.BASE_URL =   "http:test-api.swago.cn"
+            UrlConstant.BASE_URL =   "http:test-api.swago.cn"
 //            UrlConstant.BASE_URL =   "http:huawei.swago.cn"
-            UrlConstant.BASE_URL =   "https://pro-api.swago.cn"
+//            UrlConstant.BASE_URL =   "https://pro-api.swago.cn"
         } else {
             UrlConstant.BASE_URL = baseUrl
         }

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

@@ -14,9 +14,9 @@ import java.io.File
 object UrlConstant {
 
     var BASE_URL = if (BuildConfig.DEBUG) {
-//            "http:test-api.swago.cn"
+            "http:test-api.swago.cn"
 //          "http:huawei.swago.cn"
-        "https://pro-api.swago.cn"
+//        "https://pro-api.swago.cn"
     } else {
         "https://pro-api.swago.cn"
     }

+ 7 - 0
baseswago/src/main/java/com/swago/baseswago/inter/RoomApi.kt

@@ -7,6 +7,7 @@ import com.swago.baseswago.model.UploadInfo
 import com.swago.baseswago.model.live.*
 import com.swago.baseswago.model.live.audio.*
 import com.swago.baseswago.model.live.game.GameListModel
+import com.swago.baseswago.model.live.game.RecommendGameListModel
 import com.swago.baseswago.model.live.gift.GiftAllModel
 import com.swago.baseswago.model.live.gift.GiftSendModel
 import com.swago.baseswago.model.live.mic.ApplyLianMaiResultModel
@@ -30,6 +31,12 @@ interface RoomApi {
     @POST("/v2/rtc/game/list")
     suspend fun getGameList(): GameListModel
 
+    /**
+     * 推荐游戏列表
+     * */
+    @POST("/v3/home/recommend/game/list")
+    suspend fun getRecommendGameList(): RecommendGameListModel
+
     /**
      * 开播
      * broadcast_type 直播间类型(1视频2语音)

+ 16 - 0
baseswago/src/main/java/com/swago/baseswago/model/live/game/RecommendGameListModel.kt

@@ -0,0 +1,16 @@
+package com.swago.baseswago.model.live.game
+
+import java.util.ArrayList
+
+data class RecommendGameListModel(
+    var list: ArrayList<RecommendGameModel>
+)
+
+data class RecommendGameModel(
+    var id: Int,
+    var sort_id: Int,
+    var game_icon_url: String,
+    var game_api_url: String,
+    var game_full_url: String,
+    var game_full_down_url: String
+)

+ 1 - 1
baseswago/src/main/java/com/swago/baseswago/util/SwagoInfo.kt

@@ -12,7 +12,7 @@ import java.util.*
  *description:
  */
 object SwagoInfo {
-    var key = "MDEyOTQ1Njc4OWFiY2RlZzAxMjM0NTY3ODlhZGNkZWY="
+    var key = "MTQwMzQ1Njc4OWFiY2RlZzAxMjM0NTY3ODlhZGNkZWY="
     private var versionCode = ""
     private var languageCode = "en"
     var languageId = 0

+ 38 - 0
room/src/main/java/com/swago/room/adapter/RecommendBannerViewAdapter.kt

@@ -0,0 +1,38 @@
+package com.swago.room.adapter
+
+import android.view.ViewGroup
+import android.widget.ImageView
+import androidx.recyclerview.widget.RecyclerView
+import com.swago.baseswago.model.live.RoomConfig
+import com.swago.baseswago.model.live.game.RecommendGameModel
+import com.swago.loadUrl
+import com.youth.banner.adapter.BannerAdapter
+
+class RecommendBannerViewAdapter(data:List<RecommendGameModel>) :  BannerAdapter<RecommendGameModel, RecommendBannerViewAdapter.BannerViewHolder>(data){
+
+    class BannerViewHolder(var imageView: ImageView) : RecyclerView.ViewHolder(
+        imageView
+    )
+
+    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
+        val imageView = ImageView(parent.context)
+        //注意,必须设置为match_parent,这个是viewpager2强制要求的
+        imageView.layoutParams = ViewGroup.LayoutParams(
+            ViewGroup.LayoutParams.MATCH_PARENT,
+            ViewGroup.LayoutParams.MATCH_PARENT
+        )
+        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
+        return BannerViewHolder(imageView)
+    }
+
+    override fun onBindView(
+        holder: BannerViewHolder?,
+        data: RecommendGameModel,
+        position: Int,
+        size: Int
+    ) {
+        holder?.let {
+            it.imageView.loadUrl(holder.imageView.context,data.game_icon_url)
+        }
+    }
+}

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

@@ -464,6 +464,17 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
             }
         }
 
+        //推荐游戏列表
+        roomVm.recommendGameListModelLiveData.observe(this){
+            binding.playBannerView.setData(it.list)
+            binding.playBannerView.jumpToWebFun = { game ->
+                    ARouter.getInstance().build(ARouteConstant.Base.webView)
+                        .withString("url", game.game_api_url)
+                        .navigation()
+
+            }
+        }
+
         //直播间配置
         roomVm.roomConfigLiveData.observe(this) {
             this.roomConfig = it

+ 9 - 0
room/src/main/java/com/swago/room/vm/RoomVm.kt

@@ -15,6 +15,7 @@ import com.swago.baseswago.model.live.*
 import com.swago.baseswago.model.live.audio.AudioInviteUserModel
 import com.swago.baseswago.model.live.audio.AudioSeatModel
 import com.swago.baseswago.model.live.game.GameListModel
+import com.swago.baseswago.model.live.game.RecommendGameListModel
 import com.swago.baseswago.util.*
 import com.swago.room.R
 import com.swago.room.audio.AudioRoomManager
@@ -269,9 +270,17 @@ class RoomVm(application: Application) : AbsRoomVm(application) {
         MutableLiveData<GameListModel>()
     }
 
+    /**
+     * 推荐游戏列表
+     */
+    val recommendGameListModelLiveData by lazy {
+        MutableLiveData<RecommendGameListModel>()
+    }
+
     fun getRoomConfig(){
         requestData {
             //首先获取游戏列表 然后获取直播间配置
+            recommendGameListModelLiveData.value = ApiManager.roomApi.getRecommendGameList()
             gameListModelLiveData.value = ApiManager.roomApi.getGameList()
             roomConfigLiveData.value = ApiManager.roomApi.getRoomConfig()
         }

+ 72 - 0
room/src/main/java/com/swago/room/widget/RecommendBannerView.kt

@@ -0,0 +1,72 @@
+package com.swago.room.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.FrameLayout
+import androidx.lifecycle.findViewTreeLifecycleOwner
+import com.swago.baseswago.baseroom.IRoomActiveListener
+import com.swago.baseswago.baseroom.IRoomInfo
+import com.swago.baseswago.baseroom.SwagoRoomManager
+import com.swago.baseswago.model.live.RoomConfig
+import com.swago.baseswago.model.live.game.RecommendGameModel
+import com.swago.room.adapter.BannerViewAdapter
+import com.swago.room.adapter.RecommendBannerViewAdapter
+import com.swago.room.databinding.ViewBannerBinding
+import com.youth.banner.indicator.CircleIndicator
+
+class RecommendBannerView : FrameLayout,IRoomActiveListener {
+
+    private val mData by lazy {
+        ArrayList<RecommendGameModel>()
+    }
+
+    var jumpToWebFun:((RecommendGameModel)->Unit)? = null
+
+    private val bannerViewAdapter  = RecommendBannerViewAdapter(mData)
+
+    private var binding:ViewBannerBinding? = null
+
+    constructor(context: Context) : super(context)
+    constructor(context: Context, mAttributeSet: AttributeSet?) : super(context, mAttributeSet){
+        initView(context)
+    }
+
+    private fun initView(context: Context) {
+        SwagoRoomManager.addListener(this)
+        binding = ViewBannerBinding.inflate(LayoutInflater.from(context),this,true)
+    }
+
+    override fun changeRoom(iRoomInfo: IRoomInfo) {
+        visibility = View.GONE
+    }
+
+    override fun leaveRoom(iRoomInfo: IRoomInfo) {
+    }
+
+    override fun joinedRoom(iRoomInfo: IRoomInfo) {
+        visibility = View.VISIBLE
+    }
+
+    override fun endRoom(iRoomInfo: IRoomInfo?) {
+    }
+
+    override fun closeRoomed() {
+        SwagoRoomManager.removeListener(this)
+    }
+
+    fun setData(data:ArrayList<RecommendGameModel>){
+        binding?.let {
+            mData.addAll(data)
+            it.banner.setAdapter(bannerViewAdapter)
+                .setIndicator(CircleIndicator(context))
+                .addBannerLifecycleObserver(findViewTreeLifecycleOwner())
+                .setOnBannerListener { data, _ ->
+                    val bannerData = data as RecommendGameModel
+                    jumpToWebFun?.invoke(bannerData)
+                }
+        }
+    }
+
+}

+ 12 - 0
room/src/main/res/layout/fragment_base_com.xml

@@ -95,6 +95,18 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
 
+    <com.swago.room.widget.RecommendBannerView
+        android:id="@+id/playBannerView"
+        app:layout_constraintTop_toTopOf="parent"
+        android:layout_marginTop="300dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        android:layout_marginEnd="10dp"
+        tools:visibility="visible"
+        android:visibility="gone"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"/>
+
     <com.swago.room.widget.BannerView
         android:id="@+id/bannerView"
         android:layout_marginTop="100dp"