From 0652da23000992005ea9783dec4c6d951b161b3f Mon Sep 17 00:00:00 2001 From: juntao Date: Sat, 22 Feb 2020 17:44:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=B8=B8=E6=88=8F=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=8A=A8=E6=80=81=20tab=20=E6=8E=A5=E5=8F=A3=E7=9A=84?= =?UTF-8?q?=E5=90=88=E5=B9=B6=20https://gitlab.ghzs.com/pm/halo-app-issues?= =?UTF-8?q?/issues/783?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gh/gamecenter/entity/GameTrendEntity.kt | 20 ++ .../gamedetail/GameDetailFragment.kt | 17 +- .../gamedetail/GameDetailViewModel.kt | 39 ++++ .../gamedetail/fuli/FuLiViewModel.kt | 205 ++++++++++-------- .../retrofit/service/ApiService.java | 7 + 5 files changed, 190 insertions(+), 98 deletions(-) create mode 100644 app/src/main/java/com/gh/gamecenter/entity/GameTrendEntity.kt diff --git a/app/src/main/java/com/gh/gamecenter/entity/GameTrendEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/GameTrendEntity.kt new file mode 100644 index 0000000000..d65ce587d1 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/entity/GameTrendEntity.kt @@ -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?, + var toolkits: List?, + var libao: List?, + var community: CommunityEntity, + @SerializedName("community_column_contents") + var communityColumnContents: List) \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailFragment.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailFragment.kt index fe224178a5..60eba385d5 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailFragment.kt @@ -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_" } } diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailViewModel.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailViewModel.kt index f5d6eacaf3..938720bb52 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailViewModel.kt @@ -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() { +// 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()) diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/fuli/FuLiViewModel.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/fuli/FuLiViewModel.kt index 698114a896..9887497ffe 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/fuli/FuLiViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/fuli/FuLiViewModel.kt @@ -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? = 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>() { - override fun onResponse(response: List?) { - 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>() { - override fun onResponse(response: List?) { - 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>() { - override fun onResponse(response: List?) { - if (response != null) { - loadLiBaoStatus(response) - } else { - checkHasCommunity() + .subscribe(object : BiResponse() { + 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>() { +// override fun onResponse(response: List?) { +// 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>() { +// override fun onResponse(response: List?) { +// 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>() { +// override fun onResponse(response: List?) { +// if (response != null) { +// loadLiBaoStatus(response) +// } else { +// checkHasCommunity() +// } +// } +// +// override fun onFailure(e: HttpException?) { +// checkHasCommunity() +// } +// }) +// } + //获取礼包状态 private fun loadLiBaoStatus(response: List) { 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?) { 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() { - 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() { +// 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>() { +// override fun onResponse(response: List?) { +// 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>() { - override fun onResponse(response: List?) { - if (response != null && response.isNotEmpty()) mAnswerList = response - transformationItemData() - } - - override fun onFailure(e: HttpException?) { - transformationItemData() - } - }) - } - - fun transformationItemData() { + fun constructItemData() { val itemList = ArrayList() var isExistServer = false var index = 0 diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index 7bbf5d52bf..037ba3784f 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -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 getGameDetail(@Path("game_id") String game_id); + /** + * 获取游戏详情的数据(与上面的接口相比是包括了动态 Tab) + */ + @GET("games/{game_id}?view=dynamic") + Single getGameDetailWithTrend(@Path("game_id") String game_id); + /** * 获取热门卡牌 */