完成游戏详情动态 tab 接口的合并 https://gitlab.ghzs.com/pm/halo-app-issues/issues/783
This commit is contained in:
@ -0,0 +1,20 @@
|
||||
package com.gh.gamecenter.entity
|
||||
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
// "game": {},// 游戏详情数据
|
||||
// "articles": [],// 游戏文章
|
||||
// "toolkits": [],// 游戏工具箱
|
||||
// "libao": [],// 游戏礼包
|
||||
// "community": {},// 社区,无数据时,此字段不存在
|
||||
// "community_column_contents": []// 社区专题内容(热门回答),无数据时,此字段不存在
|
||||
|
||||
data class GameTrendEntity(
|
||||
var game: GameDetailEntity,
|
||||
var articles: List<NewsEntity>?,
|
||||
var toolkits: List<ToolBoxEntity>?,
|
||||
var libao: List<LibaoEntity>?,
|
||||
var community: CommunityEntity,
|
||||
@SerializedName("community_column_contents")
|
||||
var communityColumnContents: List<AnswerEntity>)
|
||||
@ -662,11 +662,6 @@ class GameDetailFragment : NormalFragment() {
|
||||
.setUrl(topVideo.url)
|
||||
.setCacheWithPlay(true)
|
||||
.setVideoAllCallBack(object : GSYSampleCallBack() {
|
||||
override fun onPrepared(url: String?, vararg objects: Any?) {
|
||||
super.onPrepared(url, *objects)
|
||||
//GSYVideoManager.instance().isNeedMute = true
|
||||
}
|
||||
|
||||
override fun onQuitFullscreen(url: String?, vararg objects: Any) {
|
||||
mOrientationUtils?.backToProtVideo()
|
||||
}
|
||||
@ -680,8 +675,14 @@ class GameDetailFragment : NormalFragment() {
|
||||
mTopVideoView.updateThumb(topVideo.poster)
|
||||
|
||||
val trafficVideo = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SettingsFragment.TRAFFIC_VIDEO_SP_KEY, false)
|
||||
if (NetworkUtils.isWifiConnected(requireContext())||!trafficVideo) {
|
||||
mTopVideoView.startPlayLogic(isAutoPlay = true)
|
||||
if (NetworkUtils.isWifiConnected(requireContext()) || !trafficVideo) {
|
||||
// 为不影响页面加载,延迟1秒加载视频
|
||||
// TODO 判断本地是否有缓存
|
||||
postDelayedRunnable({
|
||||
if (activity != null && activity?.isFinishing != true) {
|
||||
mTopVideoView.startPlayLogic(isAutoPlay = true)
|
||||
}
|
||||
}, INITIAL_DELAY)
|
||||
}
|
||||
|
||||
mTopVideoView.fullscreenButton.setOnClickListener {
|
||||
@ -918,6 +919,8 @@ class GameDetailFragment : NormalFragment() {
|
||||
const val OPEN_APPBAR = "openappbar"
|
||||
const val SCROLL_TO_KAIFU = "scrollToKaiFu"
|
||||
|
||||
const val INITIAL_DELAY = 1000L
|
||||
|
||||
private const val SP_OPENED_DIALOG_TIME_PREFIX = "opened_dialog_time_prefix_"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.gamecenter.gamedetail
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.os.Build
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
@ -70,7 +71,45 @@ class GameDetailViewModel(application: Application,
|
||||
}
|
||||
|
||||
// 获取游戏详情
|
||||
@SuppressLint("CheckResult")
|
||||
private fun getGameDetail() {
|
||||
// TODO 待后端API同步至正式环境后游戏详情切换到下面的请求来实现
|
||||
// mApi.getGameDetailWithTrend(game?.id)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(object : BiResponse<GameTrendEntity>() {
|
||||
// override fun onSuccess(data: GameTrendEntity) {
|
||||
// val gameDetail = data.game
|
||||
//
|
||||
// // 过滤过期公告
|
||||
// if (gameDetail.notice != null && gameDetail.notice!!.isNotEmpty()) {
|
||||
// val l = System.currentTimeMillis()
|
||||
// var i = 0
|
||||
// while (i < gameDetail.notice!!.size) {
|
||||
// if (l > gameDetail.notice!![i].overtime * 1000) {
|
||||
// gameDetail.notice!!.removeAt(i)
|
||||
// i--
|
||||
// }
|
||||
// i++
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 4.4以下设备不显示顶部视频
|
||||
// displayTopVideo = gameDetail.topVideo != null
|
||||
// && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
|
||||
//
|
||||
// gameDetailLiveData.postValue(Resource.success(gameDetail))
|
||||
// }
|
||||
//
|
||||
// override fun onFailure(exception: Exception) {
|
||||
// if (exception is HttpException) {
|
||||
// gameDetailLiveData.postValue(Resource.error(exception))
|
||||
// } else {
|
||||
// gameDetailLiveData.postValue(Resource.error(null))
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
mApi.getGameDetail(game?.id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.gamecenter.gamedetail.fuli
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.text.TextUtils
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
@ -13,13 +14,12 @@ import com.gh.gamecenter.entity.*
|
||||
import com.gh.gamecenter.eventbus.EBReuse
|
||||
import com.gh.gamecenter.gamedetail.GameDetailFragment
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity
|
||||
import com.gh.gamecenter.retrofit.BiResponse
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import okhttp3.ResponseBody
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.json.JSONObject
|
||||
import retrofit2.HttpException
|
||||
import java.util.*
|
||||
|
||||
@ -41,64 +41,87 @@ class FuLiViewModel(application: Application,
|
||||
private var mAnswerList: List<AnswerEntity>? = null
|
||||
|
||||
init {
|
||||
loadGameArticle()
|
||||
loadTrendData()
|
||||
}
|
||||
|
||||
private fun loadGameArticle() {
|
||||
mApi
|
||||
.getGameNews(UrlFilterUtils.getFilterQuery("game_id", game.id), 3, 1)
|
||||
@SuppressLint("CheckResult")
|
||||
private fun loadTrendData() {
|
||||
mApi.getGameDetailWithTrend(game.id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<List<NewsEntity>>() {
|
||||
override fun onResponse(response: List<NewsEntity>?) {
|
||||
Config.filterPluginArticle(response)
|
||||
if (response != null && response.isNotEmpty()) mArticleList = response
|
||||
loadToolsKit()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
loadToolsKit()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun loadToolsKit() {
|
||||
mApi
|
||||
.getGameToolBoxData(1, UrlFilterUtils.getFilterQuery("game_id", game.id))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<List<ToolBoxEntity>>() {
|
||||
override fun onResponse(response: List<ToolBoxEntity>?) {
|
||||
if (response != null && response.isNotEmpty()) mToolsList = response
|
||||
loadLiBao()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
loadLiBao()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun loadLiBao() {
|
||||
mApi
|
||||
.getLibaoByGame(UrlFilterUtils.getFilterQuery("game_id", game.id), 1, 128)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<List<LibaoEntity>>() {
|
||||
override fun onResponse(response: List<LibaoEntity>?) {
|
||||
if (response != null) {
|
||||
loadLiBaoStatus(response)
|
||||
} else {
|
||||
checkHasCommunity()
|
||||
.subscribe(object : BiResponse<GameTrendEntity>() {
|
||||
override fun onSuccess(data: GameTrendEntity) {
|
||||
mArticleList = data.articles?.apply { Config.filterPluginArticle(this) }
|
||||
mToolsList = data.toolkits
|
||||
mAnswerList = data.communityColumnContents
|
||||
gameCommunity = data.community
|
||||
data.libao?.let {
|
||||
loadLiBaoStatus(it)
|
||||
}
|
||||
constructItemData()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
checkHasCommunity()
|
||||
override fun onFailure(exception: Exception) {
|
||||
constructItemData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// private fun loadGameArticle() {
|
||||
// mApi
|
||||
// .getGameNews(UrlFilterUtils.getFilterQuery("game_id", game.id), 3, 1)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(object : Response<List<NewsEntity>>() {
|
||||
// override fun onResponse(response: List<NewsEntity>?) {
|
||||
// Config.filterPluginArticle(response)
|
||||
// if (response != null && response.isNotEmpty()) mArticleList = response
|
||||
// loadToolsKit()
|
||||
// }
|
||||
//
|
||||
// override fun onFailure(e: HttpException?) {
|
||||
// loadToolsKit()
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// private fun loadToolsKit() {
|
||||
// mApi
|
||||
// .getGameToolBoxData(1, UrlFilterUtils.getFilterQuery("game_id", game.id))
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(object : Response<List<ToolBoxEntity>>() {
|
||||
// override fun onResponse(response: List<ToolBoxEntity>?) {
|
||||
// if (response != null && response.isNotEmpty()) mToolsList = response
|
||||
// loadLiBao()
|
||||
// }
|
||||
//
|
||||
// override fun onFailure(e: HttpException?) {
|
||||
// loadLiBao()
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// private fun loadLiBao() {
|
||||
// mApi
|
||||
// .getLibaoByGame(UrlFilterUtils.getFilterQuery("game_id", game.id), 1, 128)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(object : Response<List<LibaoEntity>>() {
|
||||
// override fun onResponse(response: List<LibaoEntity>?) {
|
||||
// if (response != null) {
|
||||
// loadLiBaoStatus(response)
|
||||
// } else {
|
||||
// checkHasCommunity()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onFailure(e: HttpException?) {
|
||||
// checkHasCommunity()
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
//获取礼包状态
|
||||
private fun loadLiBaoStatus(response: List<LibaoEntity>) {
|
||||
val builder = StringBuilder()
|
||||
@ -110,7 +133,7 @@ class FuLiViewModel(application: Application,
|
||||
i++
|
||||
}
|
||||
if (builder.isEmpty()) {
|
||||
checkHasCommunity()
|
||||
// checkHasCommunity()
|
||||
return
|
||||
}
|
||||
builder.deleteCharAt(builder.length - 1)
|
||||
@ -123,56 +146,56 @@ class FuLiViewModel(application: Application,
|
||||
override fun onResponse(list: List<LibaoStatusEntity>?) {
|
||||
LibaoUtils.initLiBaoEntity(list, response)
|
||||
if (response.isNotEmpty()) mLiBaoList = response
|
||||
checkHasCommunity()
|
||||
// checkHasCommunity()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
checkHasCommunity()
|
||||
// checkHasCommunity()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun checkHasCommunity() {
|
||||
mApi.checkHasCommunity(game.id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
if (response != null) {
|
||||
val json = JSONObject(response.string())
|
||||
val communityId = json.getString("community_id")
|
||||
val communityName = json.getString("community_name")
|
||||
gameCommunity = CommunityEntity(communityId, communityName)
|
||||
loadGameCommunity(communityId, json.getString("column_id"))
|
||||
return
|
||||
}
|
||||
transformationItemData()
|
||||
}
|
||||
// fun checkHasCommunity() {
|
||||
// mApi.checkHasCommunity(game.id)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(object : Response<ResponseBody>() {
|
||||
// override fun onResponse(response: ResponseBody?) {
|
||||
// if (response != null) {
|
||||
// val json = JSONObject(response.string())
|
||||
// val communityId = json.getString("community_id")
|
||||
// val communityName = json.getString("community_name")
|
||||
// gameCommunity = CommunityEntity(communityId, communityName)
|
||||
// loadGameCommunity(communityId, json.getString("column_id"))
|
||||
// return
|
||||
// }
|
||||
// constructItemData()
|
||||
// }
|
||||
//
|
||||
// override fun onFailure(e: HttpException?) {
|
||||
// constructItemData()
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// }
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
transformationItemData()
|
||||
}
|
||||
})
|
||||
// fun loadGameCommunity(communityId: String, columnId: String) {
|
||||
// mApi.getAskSubjectColumnAnswers(communityId, columnId, 1, "gamedetail", Int.MAX_VALUE)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(object : Response<List<AnswerEntity>>() {
|
||||
// override fun onResponse(response: List<AnswerEntity>?) {
|
||||
// if (response != null && response.isNotEmpty()) mAnswerList = response
|
||||
// constructItemData()
|
||||
// }
|
||||
//
|
||||
// override fun onFailure(e: HttpException?) {
|
||||
// constructItemData()
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
fun loadGameCommunity(communityId: String, columnId: String) {
|
||||
mApi.getAskSubjectColumnAnswers(communityId, columnId, 1, "gamedetail", Int.MAX_VALUE)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<List<AnswerEntity>>() {
|
||||
override fun onResponse(response: List<AnswerEntity>?) {
|
||||
if (response != null && response.isNotEmpty()) mAnswerList = response
|
||||
transformationItemData()
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
transformationItemData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun transformationItemData() {
|
||||
fun constructItemData() {
|
||||
val itemList = ArrayList<FuLiItemData>()
|
||||
var isExistServer = false
|
||||
var index = 0
|
||||
|
||||
@ -15,6 +15,7 @@ import com.gh.gamecenter.entity.GameColumnCollection;
|
||||
import com.gh.gamecenter.entity.GameDetailEntity;
|
||||
import com.gh.gamecenter.entity.GameDigestEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameTrendEntity;
|
||||
import com.gh.gamecenter.entity.GameVideoInfo;
|
||||
import com.gh.gamecenter.entity.HelpCategoryEntity;
|
||||
import com.gh.gamecenter.entity.HelpEntity;
|
||||
@ -145,6 +146,12 @@ public interface ApiService {
|
||||
@GET("games/{game_id}?view=detail")
|
||||
Observable<GameDetailEntity> getGameDetail(@Path("game_id") String game_id);
|
||||
|
||||
/**
|
||||
* 获取游戏详情的数据(与上面的接口相比是包括了动态 Tab)
|
||||
*/
|
||||
@GET("games/{game_id}?view=dynamic")
|
||||
Single<GameTrendEntity> getGameDetailWithTrend(@Path("game_id") String game_id);
|
||||
|
||||
/**
|
||||
* 获取热门卡牌
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user