Merge branch 'dev' of gitlab.ghzs.com:halo/assistant-android into dev
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
This commit is contained in:
@ -9,10 +9,6 @@ import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.databinding.BindingAdapter;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.OnViewClickListener;
|
||||
import com.gh.common.constant.Config;
|
||||
@ -40,8 +36,8 @@ import com.gh.gamecenter.databinding.KaifuAddItemBinding;
|
||||
import com.gh.gamecenter.databinding.KaifuDetailItemRowBinding;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.ServerCalendarEntity;
|
||||
import com.gh.gamecenter.entity.PluginLocation;
|
||||
import com.gh.gamecenter.entity.ServerCalendarEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.PackagesManager;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
@ -54,6 +50,10 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.databinding.BindingAdapter;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
/**
|
||||
* Created by khy on 12/02/18.
|
||||
*/
|
||||
@ -319,8 +319,18 @@ public class BindingAdapters {
|
||||
}
|
||||
|
||||
// 显示下载按钮状态
|
||||
if (gameEntity.getApk().isEmpty()) {
|
||||
progressBar.setText("暂无下载");
|
||||
if (gameEntity.getApk().isEmpty() || gameEntity.getDownloadOffStatus() != null) {
|
||||
String offStatus = gameEntity.getDownloadOffStatus();
|
||||
if (offStatus != null && !"off".equals(offStatus)) {
|
||||
progressBar.setText("查看");
|
||||
if (offStatus.equals("dialog")) {
|
||||
// TODO 设置背景为深色
|
||||
} else if (offStatus.equals("toast")) {
|
||||
// TODO 设置背景为浅色
|
||||
}
|
||||
} else {
|
||||
progressBar.setText("暂无下载");
|
||||
}
|
||||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.NONE);
|
||||
} else {
|
||||
String status = GameUtils.getDownloadBtnText(progressBar.getContext(), gameEntity, PluginLocation.only_game);
|
||||
|
||||
@ -7,12 +7,6 @@ import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.collection.ArrayMap;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.dialog.ReserveDialogFragment;
|
||||
import com.gh.common.exposure.ExposureEvent;
|
||||
@ -35,6 +29,12 @@ import com.lightgame.utils.Utils;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.collection.ArrayMap;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class DownloadItemUtils {
|
||||
|
||||
// 更新下载进度条
|
||||
@ -167,13 +167,25 @@ public class DownloadItemUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
if (gameEntity.getApk().isEmpty() || gameEntity.getDownloadOffStatus() != null) {
|
||||
holder.gameDes.setVisibility(View.VISIBLE);
|
||||
holder.gameProgressbar.setVisibility(View.GONE);
|
||||
holder.gameInfo.setVisibility(View.GONE);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.news_detail_comment);
|
||||
holder.gameDownloadBtn.setText("暂无");
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.button_gray));
|
||||
|
||||
String offStatus = gameEntity.getDownloadOffStatus();
|
||||
if (offStatus != null && !"off".equals(offStatus)) {
|
||||
holder.gameDownloadBtn.setText("查看");
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.white));
|
||||
if (offStatus.equals("dialog")) {
|
||||
// TODO 设置背景为深色
|
||||
} else if (offStatus.equals("toast")) {
|
||||
// TODO 设置背景为浅色
|
||||
}
|
||||
} else {
|
||||
holder.gameDownloadBtn.setText("暂无");
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.button_gray));
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.news_detail_comment);
|
||||
}
|
||||
holder.gameDownloadBtn.setClickable(false);
|
||||
} else if (gameEntity.getApk().size() == 1) {
|
||||
updateNormalItem(context, holder, gameEntity, isShowPlatform, pluginLocation);
|
||||
|
||||
@ -5,9 +5,6 @@ import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.gh.common.dialog.ReserveDialogFragment;
|
||||
import com.gh.common.exposure.ExposureEvent;
|
||||
import com.gh.common.exposure.ExposureUtils;
|
||||
@ -29,10 +26,17 @@ import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.gamedetail.GameDetailFragment;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
/**
|
||||
* Created by khy on 27/06/17.
|
||||
* 详情页面下载ViewHolder
|
||||
@ -140,7 +144,17 @@ public class DetailViewHolder {
|
||||
mViewHolder.context.startActivity(intent);
|
||||
break;
|
||||
case NONE:
|
||||
Utils.toast(mViewHolder.context, "该游戏已关闭下载");
|
||||
String offStatus = mGameEntity.getDownloadOffStatus();
|
||||
if (offStatus != null && !"off".equals(offStatus)) {
|
||||
if ("dialog".equals(offStatus)) {
|
||||
showOffServiceDialog();
|
||||
} else if ("toast".equals(offStatus)) {
|
||||
EventBus.getDefault().post(new EBReuse(GameDetailFragment.SKIP_RATING));
|
||||
Utils.toast(mViewHolder.context, "该游戏因故暂不提供下载,具体详情可在相关评论中查看,敬请谅解~");
|
||||
}
|
||||
} else {
|
||||
Utils.toast(mViewHolder.context, "该游戏已关闭下载");
|
||||
}
|
||||
break;
|
||||
case NORMAL:
|
||||
DataLogUtils.uploadGameLog(mViewHolder.context, mGameEntity.getId(), mGameEntity.getName(), mEntrance);
|
||||
@ -214,7 +228,12 @@ public class DetailViewHolder {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void showOffServiceDialog() {
|
||||
// TODO showOffserviceDialog
|
||||
Utils.toast(mViewHolder.context, "显示弹窗");
|
||||
}
|
||||
|
||||
private void download(boolean isSubscribe) {
|
||||
String str = mViewHolder.mDownloadPb.getText();
|
||||
String method;
|
||||
|
||||
@ -55,6 +55,12 @@ data class GameEntity(
|
||||
@SerializedName("download_off_text")
|
||||
var downloadOffText: String? = null,
|
||||
|
||||
@SerializedName("download_off_status")
|
||||
var downloadOffStatus: String? = null, // "off/dialog/toast", 只关闭、关闭且弹窗、关闭且toast
|
||||
|
||||
@SerializedName("download_off_dialog")
|
||||
var downloadOffDialog: Dialog? = null,
|
||||
|
||||
@SerializedName("libao_exists")
|
||||
var isLibaoExists: Boolean = false,
|
||||
|
||||
@ -284,6 +290,7 @@ data class GameEntity(
|
||||
data class Dialog(var title: String = "",
|
||||
var content: String = "",
|
||||
@SerializedName("close_button_text")
|
||||
var sites: List<Site> = listOf(),
|
||||
var closeButtonText: String = "",
|
||||
@SerializedName("confirm_button")
|
||||
var confirmButton: LinkEntity = LinkEntity(),
|
||||
@ -297,6 +304,12 @@ data class GameEntity(
|
||||
var models: ArrayList<String> = arrayListOf(),
|
||||
@SerializedName("system_versions")
|
||||
var systemVersions: ArrayList<String> = arrayListOf()) : Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class Site(
|
||||
var url: String = "",
|
||||
var text: String = ""
|
||||
) : Parcelable
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.gh.gamecenter.mygame
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
@ -42,7 +41,7 @@ class MyFollowedGameFragment : ListFragment<GameEntity, MyFollowedGameViewModel>
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (TextUtils.isEmpty(UserManager.getInstance().userId)) {
|
||||
if (!UserManager.getInstance().isLoggedIn) {
|
||||
noDataTv.text = getString(R.string.login_hint)
|
||||
noDataTv.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme))
|
||||
} else {
|
||||
|
||||
@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.util.DisplayUtils
|
||||
import com.gh.common.util.DownloadItemUtils
|
||||
import com.gh.common.util.StringUtils
|
||||
import com.gh.common.util.visibleIf
|
||||
import com.gh.common.view.DrawableView
|
||||
import com.gh.gamecenter.GameDetailActivity
|
||||
@ -21,10 +22,29 @@ import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.baselist.LoadType
|
||||
import com.gh.gamecenter.databinding.ItemPlayedGameBinding
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus
|
||||
import com.lightgame.download.DownloadEntity
|
||||
|
||||
class MyPlayedGameAdapter(context: Context, private val mViewModel: MyPlayedGameViewModel)
|
||||
: ListAdapter<GameEntity>(context) {
|
||||
|
||||
private val mPositionAndPackageMap = HashMap<String, Int>()
|
||||
|
||||
override fun setListData(updateData: MutableList<GameEntity>?) {
|
||||
// 记录游戏位置
|
||||
if (updateData != null) {
|
||||
for (i in 0 until updateData.size) {
|
||||
val gameEntity = updateData[i]
|
||||
var packages = gameEntity.id
|
||||
for (apkEntity in gameEntity.getApk()) {
|
||||
packages += apkEntity.packageName
|
||||
}
|
||||
mPositionAndPackageMap[packages + i] = i
|
||||
}
|
||||
}
|
||||
super.setListData(updateData)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return when (viewType) {
|
||||
ItemViewType.GAME_NORMAL -> {
|
||||
@ -47,6 +67,13 @@ class MyPlayedGameAdapter(context: Context, private val mViewModel: MyPlayedGame
|
||||
holder.binding.gameItemIncluded.subjectTag = "type"
|
||||
holder.binding.executePendingBindings()
|
||||
|
||||
DownloadItemUtils.setOnClickListener(mContext,
|
||||
holder.binding.gameItemIncluded.downloadBtn,
|
||||
gameEntity,
|
||||
position,
|
||||
this,
|
||||
"(我的玩过)",
|
||||
StringUtils.buildString("我的玩过", ":", gameEntity.name))
|
||||
DownloadItemUtils.updateItem(mContext, gameEntity, GameViewHolder(holder.binding.gameItemIncluded), true)
|
||||
|
||||
holder.binding.optionsIv.setOnClickListener {
|
||||
@ -109,6 +136,34 @@ class MyPlayedGameAdapter(context: Context, private val mViewModel: MyPlayedGame
|
||||
return if (mEntityList == null || mEntityList.isEmpty()) return 0 else mEntityList.size + 1
|
||||
}
|
||||
|
||||
fun notifyItemByDownload(download: DownloadEntity) {
|
||||
for (key in mPositionAndPackageMap.keys) {
|
||||
if (key.contains(download.packageName) && key.contains(download.gameId)) {
|
||||
val position = mPositionAndPackageMap[key]
|
||||
if (position != null && mEntityList != null && position < mEntityList.size) {
|
||||
mEntityList[position].getEntryMap()[download.platform] = download
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun notifyItemAndRemoveDownload(status: EBDownloadStatus) {
|
||||
for (key in mPositionAndPackageMap.keys) {
|
||||
if (key.contains(status.packageName) && key.contains(status.gameId)) {
|
||||
val position = mPositionAndPackageMap[key]
|
||||
if (position != null && mEntityList != null && position < mEntityList.size) {
|
||||
mEntityList[position].getEntryMap().remove(status.platform)
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun clearPositionAndPackageMap() {
|
||||
mPositionAndPackageMap.clear()
|
||||
}
|
||||
|
||||
class MyPlayedGameViewHolder(var binding: ItemPlayedGameBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun initServerType(gameEntity: GameEntity) {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.gh.gamecenter.mygame
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
@ -8,13 +7,18 @@ import butterknife.BindView
|
||||
import butterknife.OnClick
|
||||
import com.gh.common.util.ifLogin
|
||||
import com.gh.common.util.viewModelProvider
|
||||
import com.gh.download.DownloadManager
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.baselist.ListFragment
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus
|
||||
import com.gh.gamecenter.eventbus.EBPackage
|
||||
import com.gh.gamecenter.eventbus.EBReuse
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.personal.PersonalFragment
|
||||
import com.lightgame.download.DataWatcher
|
||||
import com.lightgame.download.DownloadEntity
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
@ -26,9 +30,15 @@ class MyPlayedGameFragment : ListFragment<GameEntity, MyPlayedGameViewModel>() {
|
||||
@BindView(R.id.reuse_tv_none_data)
|
||||
lateinit var noDataTv: TextView
|
||||
|
||||
private val mDataWatcher = object : DataWatcher() {
|
||||
override fun onDataChanged(downloadEntity: DownloadEntity) {
|
||||
mAdapter?.notifyItemByDownload(downloadEntity)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (TextUtils.isEmpty(UserManager.getInstance().userId)) {
|
||||
if (!UserManager.getInstance().isLoggedIn) {
|
||||
noDataTv.text = getString(R.string.login_hint)
|
||||
noDataTv.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme))
|
||||
} else {
|
||||
@ -37,6 +47,17 @@ class MyPlayedGameFragment : ListFragment<GameEntity, MyPlayedGameViewModel>() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
if (isEverPause && mAdapter != null) mAdapter?.notifyDataSetChanged()
|
||||
super.onResume()
|
||||
DownloadManager.getInstance(context).addObserver(mDataWatcher)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
DownloadManager.getInstance(context).removeObserver(mDataWatcher)
|
||||
}
|
||||
|
||||
override fun provideListViewModel(): MyPlayedGameViewModel {
|
||||
mViewModel = viewModelProvider()
|
||||
return mViewModel
|
||||
@ -66,4 +87,27 @@ class MyPlayedGameFragment : ListFragment<GameEntity, MyPlayedGameViewModel>() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
mAdapter?.clearPositionAndPackageMap()
|
||||
|
||||
super.onRefresh()
|
||||
}
|
||||
|
||||
// 下载被删除事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onEventMainThread(status: EBDownloadStatus) {
|
||||
if ("delete" == status.status) {
|
||||
mAdapter?.notifyItemAndRemoveDownload(status)
|
||||
}
|
||||
}
|
||||
|
||||
// 安装/卸载 事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onEventMainThread(busFour: EBPackage) {
|
||||
if ("安装" == busFour.type || "卸载" == busFour.type) {
|
||||
mAdapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user