首页游戏重做(初步完成)

This commit is contained in:
kehaoyuan
2018-06-06 18:00:50 +08:00
parent ee44b1986f
commit 02dcbdba02
26 changed files with 2754 additions and 1572 deletions

View File

@ -8,6 +8,7 @@ public class ItemViewType {
public static final int COLUMN_HEADER = 0; // 专题头部布局
public static final int GAME_SLIDE = 1; // 滚动图布局
public static final int GAME_NORMAL = 2; // 正常游戏布局
public static final int GAME_SUBJECT = 19;
public static final int GAME_TEST = 3; // 测试游戏布局
public static final int GAME_IMAGE = 4; // 游戏大图布局
public static final int NEWS_HEADER = 5; // 新闻头部布局

View File

@ -3,6 +3,7 @@ package com.gh.common.databind;
import android.content.Intent;
import android.databinding.BindingAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -18,6 +19,8 @@ import com.gh.common.util.DataUtils;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.DisplayUtils;
import com.gh.common.util.GameUtils;
import com.gh.common.util.GameViewUtils;
import com.gh.common.util.KaiFuUtils;
import com.gh.common.util.NetworkUtils;
import com.gh.common.util.NewsUtils;
import com.gh.common.util.PackageUtils;
@ -27,6 +30,7 @@ import com.gh.common.view.DownloadProgressBar;
import com.gh.download.DownloadManager;
import com.gh.gamecenter.DownloadManagerActivity;
import com.gh.gamecenter.R;
import com.gh.gamecenter.baselist.LoadStatus;
import com.gh.gamecenter.databinding.KaifuAddItemBinding;
import com.gh.gamecenter.databinding.KaifuDetailItemRowBinding;
import com.gh.gamecenter.entity.ApkEntity;
@ -412,4 +416,34 @@ public class BindingAdapters {
Utils.toast(progressBar.getContext(), msg);
}
}
@BindingAdapter({"gameLabelList", "subjectTag"})
public static void setGameLabelList(LinearLayout layout, GameEntity gameEntity, String subjectTag) {
if (gameEntity == null) return;
if (gameEntity.getTest() != null) {
View testView = LayoutInflater.from(layout.getContext()).inflate(R.layout.game_test_label, null);
TextView testType = testView.findViewById(R.id.test_type);
TextView testTime = testView.findViewById(R.id.test_time);
String type = gameEntity.getTest().getType();
KaiFuUtils.setKaiFuType(testType, type);
if (gameEntity.getTest().getStart() == 0) {
testTime.setVisibility(View.GONE);
} else {
testTime.setText(GameViewUtils.getGameTestDate(gameEntity.getTest().getStart()));
}
} else {
GameViewUtils.setLabelList(layout.getContext(), layout, gameEntity.getTag(), subjectTag);
}
}
@BindingAdapter("isRefreshing")
public static void isRefreshing(SwipeRefreshLayout layout, LoadStatus status) {
if (status == LoadStatus.INIT_LOADING) {
layout.setRefreshing(true);
} else {
layout.setRefreshing(false);
}
}
}

View File

@ -72,11 +72,12 @@ public class ExpendTextView extends android.support.v7.widget.AppCompatTextView
content = content.toString().trim() + mExpendText;
} else {
CharSequence lastText = mSnapshotText.subSequence(lastLineStart, lastLineEnd);
for (int i = 0; i < lastText.length(); i++) {
for (int i = lastText.length() - 1; i > 0; i--) {
CharSequence sequence = lastText.subSequence(0, i);
float w = paint.measureText(sequence.toString());
if (viewWidth - w > expendTextWidth) {
content = mSnapshotText.subSequence(start, lastLineStart + i) + mExpendText;
break;
}
}
}

View File

@ -1,36 +1,33 @@
package com.gh.gamecenter.adapter.viewholder;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.gh.base.BaseRecyclerViewHolder;
import com.gh.gamecenter.R;
import butterknife.BindView;
import com.gh.gamecenter.databinding.GameHeadItemBinding;
/**
* Created by LGT on 2016/7/5.
*/
public class GameHeadViewHolder extends BaseRecyclerViewHolder {
@BindView(R.id.head_title)
public TextView title;
// @BindView(R.id.head_title)
// public TextView title;
//
// @BindView(R.id.head_more)
// public TextView more;
//
// @BindView(R.id.head_pb)
// public ProgressBar progressBar;
//
// @BindView(R.id.head_line)
// public View line;
//
// @BindView(R.id.head_line_top)
// public View lineTop;
@BindView(R.id.head_more)
public TextView more;
public GameHeadItemBinding binding;
@BindView(R.id.head_pb)
public ProgressBar progressBar;
@BindView(R.id.head_line)
public View line;
@BindView(R.id.head_line_top)
public View lineTop;
public GameHeadViewHolder(View itemView) {
super(itemView);
public GameHeadViewHolder(GameHeadItemBinding bind) {
super(bind.getRoot());
binding = bind;
}
}

View File

@ -1,26 +1,15 @@
package com.gh.gamecenter.adapter.viewholder;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.gh.common.util.DownloadItemUtils;
import com.gh.common.util.GameViewUtils;
import com.gh.common.util.ImageUtils;
import com.gh.common.util.KaiFuUtils;
import com.gh.common.util.StringUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.entity.SubjectEntity;
import com.halo.assistant.fragment.game.GameFragmentAdapter;
import java.util.Date;
import java.util.List;
import butterknife.BindView;
@ -61,80 +50,80 @@ public class GameTestViewHolder extends GameViewHolder {
}
public void initGameTestViewHolder(Context context, GameFragmentAdapter adapter, List<SubjectEntity> subjectList,
List<GameEntity> pluginList, int position,
final OnGameTestItemClickListener onGameTestItemClickListener) {
int offset = 1;
if (!pluginList.isEmpty()) {
offset += 1;
}
for (int i = 0, size = subjectList.size(); i < size; i++) {
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
final GameEntity gameEntity = subjectList.get(i).getData().get(position - offset - 1);
if (gameEntity.getTest() != null) {
int order = position - offset - 1;
if (subjectList.get(i).getData().get(0).getImage() != null) {
order--;
}
final SubjectEntity subjectEntity = subjectList.get(i);
if (subjectEntity.isOrder()) {
gameOrder.setVisibility(View.VISIBLE);
gameOrder.setText(String.valueOf(order + 1));
} else {
gameOrder.setVisibility(View.GONE);
}
ImageUtils.Companion.display(gameThumb, gameEntity.getIcon());
gameName.setText(gameEntity.getName());
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
gameDes.setText(gameEntity.getBrief());
} else {
gameDes.setText(String.format("%s %s", gameEntity.getApk().get(0).getSize(), gameEntity.getBrief()));
}
String type = gameEntity.getTest().getType();
KaiFuUtils.setKaiFuType(gameTestType, type);
if (gameEntity.getTest().getStart() == 0) {
gameTestTime.setVisibility(View.GONE);
} else {
gameTestTime.setText(GameViewUtils.getGameTestDate(gameEntity.getTest().getStart()));
}
final int finalI = i;
itemView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onGameTestItemClickListener != null) {
onGameTestItemClickListener.onClick(gameEntity, subjectEntity, finalI);
}
}
});
if (gameEntity.getTest().getEnd() != 0) {
long endTime = Long.valueOf(gameEntity.getTest().getEnd() + "000");
long todayTime = new Date().getTime();
if (todayTime > endTime) {
// 测试时间已过
gameEntity.setApk(null);
}
}
DownloadItemUtils.setOnClickListener(context,
gameDownloadBtn, gameEntity, i, adapter,
StringUtils.buildString("(游戏-专题:",
subjectEntity.getName(), "-列表[", String.valueOf(i + 1), "])"),
StringUtils.buildString("游戏-专题-",
subjectEntity.getName(), ":", gameEntity.getName()));
DownloadItemUtils.updateItem(context, gameEntity, this, true);
// adapter.initGameTest(this, gameEntity, order, subjectEntity);
break;
}
}
offset = subjectList.get(i).getData().size() + offset + 1;
}
}
// public void initGameTestViewHolder(Context context, GameFragmentAdapter adapter, List<SubjectEntity> subjectList,
// List<GameEntity> pluginList, int position,
// final OnGameTestItemClickListener onGameTestItemClickListener) {
// int offset = 1;
// if (!pluginList.isEmpty()) {
// offset += 1;
// }
// for (int i = 0, size = subjectList.size(); i < size; i++) {
// if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
// final GameEntity gameEntity = subjectList.get(i).getData().get(position - offset - 1);
// if (gameEntity.getTest() != null) {
// int order = position - offset - 1;
// if (subjectList.get(i).getData().get(0).getImage() != null) {
// order--;
// }
// final SubjectEntity subjectEntity = subjectList.get(i);
// if (subjectEntity.isOrder()) {
// gameOrder.setVisibility(View.VISIBLE);
// gameOrder.setText(String.valueOf(order + 1));
// } else {
// gameOrder.setVisibility(View.GONE);
// }
//
// ImageUtils.Companion.display(gameThumb, gameEntity.getIcon());
// gameName.setText(gameEntity.getName());
// if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
// gameDes.setText(gameEntity.getBrief());
// } else {
// gameDes.setText(String.format("%s %s", gameEntity.getApk().get(0).getSize(), gameEntity.getBrief()));
// }
//
// String type = gameEntity.getTest().getType();
// KaiFuUtils.setKaiFuType(gameTestType, type);
//
// if (gameEntity.getTest().getStart() == 0) {
// gameTestTime.setVisibility(View.GONE);
// } else {
// gameTestTime.setText(GameViewUtils.getGameTestDate(gameEntity.getTest().getStart()));
// }
//
// final int finalI = i;
// itemView.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// if (onGameTestItemClickListener != null) {
// onGameTestItemClickListener.onClick(gameEntity, subjectEntity, finalI);
// }
// }
// });
//
// if (gameEntity.getTest().getEnd() != 0) {
// long endTime = Long.valueOf(gameEntity.getTest().getEnd() + "000");
// long todayTime = new Date().getTime();
// if (todayTime > endTime) {
// // 测试时间已过
// gameEntity.setApk(null);
// }
// }
//
// DownloadItemUtils.setOnClickListener(context,
// gameDownloadBtn, gameEntity, i, adapter,
// StringUtils.buildString("(游戏-专题:",
// subjectEntity.getName(), "-列表[", String.valueOf(i + 1), "])"),
// StringUtils.buildString("游戏-专题-",
// subjectEntity.getName(), ":", gameEntity.getName()));
//
// DownloadItemUtils.updateItem(context, gameEntity, this, true);
//// adapter.initGameTest(this, gameEntity, order, subjectEntity);
// break;
// }
// }
// offset = subjectList.get(i).getData().size() + offset + 1;
// }
// }
public interface OnGameTestItemClickListener {
void onClick(GameEntity gameEntity, SubjectEntity subjectEntity, int position);

View File

@ -12,6 +12,7 @@ import com.facebook.drawee.view.SimpleDraweeView;
import com.gh.base.BaseRecyclerViewHolder;
import com.gh.common.util.DisplayUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.databinding.GameItemBinding;
import com.gh.gamecenter.entity.GameEntity;
@ -34,6 +35,17 @@ public class GameViewHolder extends BaseRecyclerViewHolder {
super(itemView);
}
public GameViewHolder(GameItemBinding binding) {
super(binding.getRoot());
gameDownloadBtn = binding.downloadBtn;
gameProgressbar = binding.gameProgressbar;
gameInfo = binding.gameInfo;
gameLibaoIcon = binding.gameLibaoIcon;
gameDownloadPercentage = binding.downloadPercentage;
gameDes = binding.gameDes;
gameDownloadSpeed = binding.downloadSpeed;
}
public void initServerType(GameEntity gameEntity, Context context) {
int paddRight = 0;
String serverType = gameEntity.getServerType();

View File

@ -1,340 +1,340 @@
package com.gh.gamecenter.fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
import com.gh.base.OnRequestCallBackListener;
import com.gh.base.fragment.BaseFragment;
import com.gh.common.util.DownloadItemUtils;
import com.gh.download.DownloadManager;
import com.gh.gamecenter.MainActivity;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.ApkEntity;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.entity.SubjectEntity;
import com.gh.gamecenter.eventbus.EBDownloadStatus;
import com.gh.gamecenter.eventbus.EBNetworkState;
import com.gh.gamecenter.eventbus.EBPackage;
import com.gh.gamecenter.eventbus.EBReuse;
import com.gh.gamecenter.eventbus.EBUISwitch;
import com.halo.assistant.fragment.game.GameFragmentAdapter;
import com.lightgame.download.DataWatcher;
import com.lightgame.download.DownloadEntity;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
/**
* Created by khy on 2016/12/6.
* 新主界面
*/
public class GameFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, OnRequestCallBackListener {
private SwipeRefreshLayout mGameSwipeRefresh;
private RecyclerView mGameRv;
private GameFragmentAdapter adapter;
private LinearLayout mReuseNoConn;
private ProgressBarCircularIndeterminate mGameLoading;
private boolean isEverpause;
Runnable initPluginRunnable = new Runnable() {
@Override
public void run() {
if (adapter.isInitPlugin()) {
postDelayedRunnable(initPluginRunnable, 100);
} else {
adapter.initPlugin();
}
}
};
Runnable runnable = new Runnable() {
@Override
public void run() {
adapter = new GameFragmentAdapter(GameFragment.this, mGameSwipeRefresh);
mGameRv.setAdapter(adapter);
}
};
private DataWatcher dataWatcher = new DataWatcher() {
@Override
public void onDataChanged(DownloadEntity downloadEntity) {
if (!mGameSwipeRefresh.isRefreshing()) {
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
if (locationList != null && locationList.size() != 0) {
GameEntity gameEntity;
for (int location : locationList) {
if (location == 1) { // 刷新插件化模块
ArrayList<Integer> locationPluginList = adapter.getPluginLocationMap().get(downloadEntity.getPackageName());
for (Integer locationPlugin : locationPluginList) {
gameEntity = adapter.getPluginList().get(locationPlugin);
RecyclerView.Adapter<? extends RecyclerView.ViewHolder> pluginAdapter = adapter.getPluginAdapter();
if (gameEntity != null && pluginAdapter != null) {
DownloadItemUtils.processDate(getActivity(), gameEntity,
downloadEntity, pluginAdapter, locationPlugin);
}
}
} else {
gameEntity = adapter.getGameEntityByLocation(location);
if (gameEntity != null) {
DownloadItemUtils.processDate(getActivity(), gameEntity,
downloadEntity, adapter, location);
}
}
}
}
}
}
};
private LinearLayoutManager mLayoutManager;
@Override
protected int getLayoutId() {
return R.layout.fragment_game;
}
@Override
protected void initView(final View view) {
super.initView(view);
mReuseNoConn = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
mGameSwipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.fm_game_swipe_refresh);
mGameRv = (RecyclerView) view.findViewById(R.id.fm_game_rv_list);
mGameLoading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.fm_game_pb_loading);
mReuseNoConn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mGameSwipeRefresh.setRefreshing(true);
mGameRv.setVisibility(View.VISIBLE);
mGameLoading.setVisibility(View.VISIBLE);
mReuseNoConn.setVisibility(View.GONE);
view.postDelayed(runnable, 1000);
}
});
mGameSwipeRefresh.setColorSchemeResources(R.color.theme);
mGameSwipeRefresh.setOnRefreshListener(this);
((DefaultItemAnimator) mGameRv.getItemAnimator()).setSupportsChangeAnimations(false);
mGameRv.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
mGameRv.setLayoutManager(mLayoutManager);
adapter = new GameFragmentAdapter(this, mGameSwipeRefresh);
mGameRv.setAdapter(adapter);
mGameRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Fresco.getImagePipeline().resume();
} else {
Fresco.getImagePipeline().pause();
}
if (mLayoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1
&& newState == RecyclerView.SCROLL_STATE_IDLE) adapter.initSubjectList();
}
});
}
// 打开下载按钮事件
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBReuse reuse) {
if (("Refresh".equals(reuse.getType()) || "PlatformChanged".equals(reuse.getType()))
&& adapter != null) {
adapter.notifyItemRangeChanged(0, adapter.getItemCount());
}
}
//下载被删除事件
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBDownloadStatus status) {
if ("delete".equals(status.getStatus())) {
DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform());
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
GameEntity gameEntity;
if (locationList != null && locationList.size() != 0) {
for (int location : locationList) {
if (location == 1) { // 刷新插件化模块
ArrayList<Integer> locationPluginList = adapter.getPluginLocationMap().get(status.getPackageName());
for (Integer locationPlugin : locationPluginList) {
gameEntity = adapter.getPluginList().get(locationPlugin);
if (gameEntity != null && gameEntity.getEntryMap() != null) {
gameEntity.getEntryMap().remove(status.getPlatform());
}
}
} else {
gameEntity = adapter.getGameEntityByLocation(location);
if (gameEntity != null && gameEntity.getEntryMap() != null) {
gameEntity.getEntryMap().remove(status.getPlatform());
}
}
adapter.notifyItemChanged(location);
}
}
} else if ("plugin".equals(status.getStatus())) {
postDelayedRunnable(initPluginRunnable, 100);
}
}
@Override
public void loadDone() {
if (mGameSwipeRefresh != null && mGameSwipeRefresh.isRefreshing()) {
mGameSwipeRefresh.setRefreshing(false);
}
if (mGameLoading != null && mGameLoading.getVisibility() == View.VISIBLE) {
mGameLoading.setVisibility(View.GONE);
}
}
@Override
public void loadDone(Object obj) {
if ("scrollTop".equals(obj)) {
mLayoutManager.smoothScrollToPosition(mGameRv, null, 0);
}
}
@Override
public void loadError() {
mGameRv.setVisibility(View.GONE);
mGameLoading.setVisibility(View.GONE);
mReuseNoConn.setVisibility(View.VISIBLE);
}
@Override
public void loadEmpty() {
}
//安装、卸载事件
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBPackage busFour) {
ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
if (locationList != null) {
GameEntity gameEntity;
for (int location : locationList) {
if (location == 1) {
List<GameEntity> pluginList = adapter.getPluginList();
for (int i = 0; i < pluginList.size(); i++) {
final GameEntity entity = pluginList.get(i);
final ArrayList<ApkEntity> apkEntities = entity.getApk();
final ApkEntity pluginApkEntity = apkEntities.get(0);
if (pluginApkEntity.getPackageName().equals(busFour.getPackageName())) {
if ("卸载".equals(busFour.getType()) && // 插件化过程中 卸载卸载原包后 更新下载按钮
DownloadManager.getInstance(getContext()).getDownloadEntityByUrl(pluginApkEntity.getUrl()) != null) {
adapter.notifyItemChanged(1);
} else {
// 安装完成 插件化区域消失
pluginList.remove(i);
if (pluginList.isEmpty()) {
adapter.initItemCount();
adapter.notifyItemRemoved(1);
} else {
adapter.initPlugin();
adapter.initLocationMap();
adapter.notifyItemChanged(1);
}
}
break;
}
}
} else {
gameEntity = adapter.getGameEntityByLocation(location);
if ("安装".equals(busFour.getType())) {
for (ApkEntity apkEntity : gameEntity.getApk()) {
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
if (gameEntity.getEntryMap() != null) {
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
}
adapter.notifyItemChanged(location);
break;
}
}
} else if ("卸载".equals(busFour.getType())) {
adapter.notifyItemChanged(location);
}
}
}
adapter.initLocationMap();
}
}
//连接上网络事件
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBNetworkState busNetworkState) {
if (busNetworkState.isNetworkConnected()) {
if (mReuseNoConn.getVisibility() == View.VISIBLE) {
mGameSwipeRefresh.setRefreshing(true);
mGameRv.setVisibility(View.VISIBLE);
mGameLoading.setVisibility(View.GONE);
mReuseNoConn.setVisibility(View.GONE);
postDelayedRunnable(runnable, 1000);
} else if (adapter.isNetworkError()) {
adapter.setNetworkError(false);
adapter.notifyItemChanged(adapter.getItemCount() - 1);
adapter.initSubjectDigest(true);
}
}
}
//Fragment界面切换事件
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBUISwitch busNine) {
if (MainActivity.EB_MAINACTIVITY_TAG.equals(busNine.getFrom())) {
if (busNine.getPosition() == 0) {
adapter.startAutoScroll();
} else {
adapter.stopAutoScroll();
}
}
}
@Override
public void onResume() {
super.onResume();
isEverpause = false;
for (SubjectEntity subjectEntity : adapter.getSubjectList()) {
for (GameEntity entity : subjectEntity.getData()) {
entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName()));
}
}
for (GameEntity entity : adapter.getPluginList()) {
entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName()));
}
adapter.notifyDataSetChanged();
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
adapter.startAutoScroll();
}
@Override
public void onPause() {
super.onPause();
isEverpause = true;
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
adapter.stopAutoScroll();
}
public boolean isEverpause() {
return isEverpause;
}
@Override
public void onRefresh() {
postDelayedRunnable(runnable, 1000);
}
}
//package com.gh.gamecenter.fragment;
//
//import android.support.v4.widget.SwipeRefreshLayout;
//import android.support.v7.widget.DefaultItemAnimator;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.view.View;
//import android.widget.LinearLayout;
//
//import com.facebook.drawee.backends.pipeline.Fresco;
//import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
//import com.gh.base.OnRequestCallBackListener;
//import com.gh.base.fragment.BaseFragment;
//import com.gh.common.util.DownloadItemUtils;
//import com.gh.download.DownloadManager;
//import com.gh.gamecenter.MainActivity;
//import com.gh.gamecenter.R;
//import com.gh.gamecenter.entity.ApkEntity;
//import com.gh.gamecenter.entity.GameEntity;
//import com.gh.gamecenter.entity.SubjectEntity;
//import com.gh.gamecenter.eventbus.EBDownloadStatus;
//import com.gh.gamecenter.eventbus.EBNetworkState;
//import com.gh.gamecenter.eventbus.EBPackage;
//import com.gh.gamecenter.eventbus.EBReuse;
//import com.gh.gamecenter.eventbus.EBUISwitch;
//import com.halo.assistant.fragment.game.GameFragmentAdapter;
//import com.lightgame.download.DataWatcher;
//import com.lightgame.download.DownloadEntity;
//
//import org.greenrobot.eventbus.Subscribe;
//import org.greenrobot.eventbus.ThreadMode;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by khy on 2016/12/6.
// * 新主界面
// */
//public class GameFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, OnRequestCallBackListener {
//
// private SwipeRefreshLayout mGameSwipeRefresh;
// private RecyclerView mGameRv;
// private GameFragmentAdapter adapter;
// private LinearLayout mReuseNoConn;
// private ProgressBarCircularIndeterminate mGameLoading;
//
// private boolean isEverpause;
//
// Runnable initPluginRunnable = new Runnable() {
// @Override
// public void run() {
// if (adapter.isInitPlugin()) {
// postDelayedRunnable(initPluginRunnable, 100);
// } else {
// adapter.initPlugin();
// }
// }
// };
//
// Runnable runnable = new Runnable() {
// @Override
// public void run() {
// adapter = new GameFragmentAdapter(GameFragment.this, mGameSwipeRefresh);
// mGameRv.setAdapter(adapter);
// }
// };
//
// private DataWatcher dataWatcher = new DataWatcher() {
// @Override
// public void onDataChanged(DownloadEntity downloadEntity) {
// if (!mGameSwipeRefresh.isRefreshing()) {
// ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
// if (locationList != null && locationList.size() != 0) {
// GameEntity gameEntity;
// for (int location : locationList) {
// if (location == 1) { // 刷新插件化模块
// ArrayList<Integer> locationPluginList = adapter.getPluginLocationMap().get(downloadEntity.getPackageName());
// for (Integer locationPlugin : locationPluginList) {
// gameEntity = adapter.getPluginList().get(locationPlugin);
// RecyclerView.Adapter<? extends RecyclerView.ViewHolder> pluginAdapter = adapter.getPluginAdapter();
// if (gameEntity != null && pluginAdapter != null) {
// DownloadItemUtils.processDate(getActivity(), gameEntity,
// downloadEntity, pluginAdapter, locationPlugin);
// }
// }
// } else {
// gameEntity = adapter.getGameEntityByLocation(location);
// if (gameEntity != null) {
// DownloadItemUtils.processDate(getActivity(), gameEntity,
// downloadEntity, adapter, location);
// }
// }
// }
// }
// }
// }
// };
// private LinearLayoutManager mLayoutManager;
//
// @Override
// protected int getLayoutId() {
// return R.layout.fragment_game;
// }
//
// @Override
// protected void initView(final View view) {
// super.initView(view);
//
// mReuseNoConn = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
// mGameSwipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.fm_game_swipe_refresh);
// mGameRv = (RecyclerView) view.findViewById(R.id.fm_game_rv_list);
// mGameLoading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.fm_game_pb_loading);
//
// mReuseNoConn.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// mGameSwipeRefresh.setRefreshing(true);
// mGameRv.setVisibility(View.VISIBLE);
// mGameLoading.setVisibility(View.VISIBLE);
// mReuseNoConn.setVisibility(View.GONE);
// view.postDelayed(runnable, 1000);
// }
// });
//
// mGameSwipeRefresh.setColorSchemeResources(R.color.theme);
// mGameSwipeRefresh.setOnRefreshListener(this);
//
// ((DefaultItemAnimator) mGameRv.getItemAnimator()).setSupportsChangeAnimations(false);
// mGameRv.setHasFixedSize(true);
// mLayoutManager = new LinearLayoutManager(getActivity());
// mGameRv.setLayoutManager(mLayoutManager);
// adapter = new GameFragmentAdapter(this, mGameSwipeRefresh);
// mGameRv.setAdapter(adapter);
//
// mGameRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
// @Override
// public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
// if (newState == RecyclerView.SCROLL_STATE_IDLE) {
// Fresco.getImagePipeline().resume();
// } else {
// Fresco.getImagePipeline().pause();
// }
//
// if (mLayoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1
// && newState == RecyclerView.SCROLL_STATE_IDLE) adapter.initSubjectList();
// }
// });
//
// }
//
// // 打开下载按钮事件
// @Subscribe(threadMode = ThreadMode.MAIN)
// public void onEventMainThread(EBReuse reuse) {
// if (("Refresh".equals(reuse.getType()) || "PlatformChanged".equals(reuse.getType()))
// && adapter != null) {
// adapter.notifyItemRangeChanged(0, adapter.getItemCount());
// }
// }
//
// //下载被删除事件
// @Subscribe(threadMode = ThreadMode.MAIN)
// public void onEventMainThread(EBDownloadStatus status) {
// if ("delete".equals(status.getStatus())) {
// DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform());
//
// ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
// GameEntity gameEntity;
// if (locationList != null && locationList.size() != 0) {
// for (int location : locationList) {
// if (location == 1) { // 刷新插件化模块
// ArrayList<Integer> locationPluginList = adapter.getPluginLocationMap().get(status.getPackageName());
// for (Integer locationPlugin : locationPluginList) {
// gameEntity = adapter.getPluginList().get(locationPlugin);
// if (gameEntity != null && gameEntity.getEntryMap() != null) {
// gameEntity.getEntryMap().remove(status.getPlatform());
// }
// }
// } else {
// gameEntity = adapter.getGameEntityByLocation(location);
// if (gameEntity != null && gameEntity.getEntryMap() != null) {
// gameEntity.getEntryMap().remove(status.getPlatform());
// }
// }
// adapter.notifyItemChanged(location);
// }
// }
// } else if ("plugin".equals(status.getStatus())) {
// postDelayedRunnable(initPluginRunnable, 100);
// }
// }
//
// @Override
// public void loadDone() {
// if (mGameSwipeRefresh != null && mGameSwipeRefresh.isRefreshing()) {
// mGameSwipeRefresh.setRefreshing(false);
// }
// if (mGameLoading != null && mGameLoading.getVisibility() == View.VISIBLE) {
// mGameLoading.setVisibility(View.GONE);
// }
// }
//
// @Override
// public void loadDone(Object obj) {
// if ("scrollTop".equals(obj)) {
// mLayoutManager.smoothScrollToPosition(mGameRv, null, 0);
// }
// }
//
// @Override
// public void loadError() {
// mGameRv.setVisibility(View.GONE);
// mGameLoading.setVisibility(View.GONE);
// mReuseNoConn.setVisibility(View.VISIBLE);
// }
//
// @Override
// public void loadEmpty() {
//
// }
//
// //安装、卸载事件
// @Subscribe(threadMode = ThreadMode.MAIN)
// public void onEventMainThread(EBPackage busFour) {
// ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
// if (locationList != null) {
// GameEntity gameEntity;
// for (int location : locationList) {
// if (location == 1) {
// List<GameEntity> pluginList = adapter.getPluginList();
// for (int i = 0; i < pluginList.size(); i++) {
// final GameEntity entity = pluginList.get(i);
// final ArrayList<ApkEntity> apkEntities = entity.getApk();
// final ApkEntity pluginApkEntity = apkEntities.get(0);
//
// if (pluginApkEntity.getPackageName().equals(busFour.getPackageName())) {
// if ("卸载".equals(busFour.getType()) && // 插件化过程中 卸载卸载原包后 更新下载按钮
// DownloadManager.getInstance(getContext()).getDownloadEntityByUrl(pluginApkEntity.getUrl()) != null) {
// adapter.notifyItemChanged(1);
// } else {
// // 安装完成 插件化区域消失
// pluginList.remove(i);
// if (pluginList.isEmpty()) {
// adapter.initItemCount();
// adapter.notifyItemRemoved(1);
// } else {
// adapter.initPlugin();
// adapter.initLocationMap();
// adapter.notifyItemChanged(1);
// }
// }
// break;
// }
// }
// } else {
// gameEntity = adapter.getGameEntityByLocation(location);
// if ("安装".equals(busFour.getType())) {
// for (ApkEntity apkEntity : gameEntity.getApk()) {
// if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
// if (gameEntity.getEntryMap() != null) {
// gameEntity.getEntryMap().remove(apkEntity.getPlatform());
// }
// adapter.notifyItemChanged(location);
// break;
// }
// }
// } else if ("卸载".equals(busFour.getType())) {
// adapter.notifyItemChanged(location);
// }
// }
// }
// adapter.initLocationMap();
// }
// }
//
// //连接上网络事件
// @Subscribe(threadMode = ThreadMode.MAIN)
// public void onEventMainThread(EBNetworkState busNetworkState) {
// if (busNetworkState.isNetworkConnected()) {
// if (mReuseNoConn.getVisibility() == View.VISIBLE) {
// mGameSwipeRefresh.setRefreshing(true);
// mGameRv.setVisibility(View.VISIBLE);
// mGameLoading.setVisibility(View.GONE);
// mReuseNoConn.setVisibility(View.GONE);
// postDelayedRunnable(runnable, 1000);
// } else if (adapter.isNetworkError()) {
// adapter.setNetworkError(false);
// adapter.notifyItemChanged(adapter.getItemCount() - 1);
// adapter.initSubjectDigest(true);
// }
// }
// }
//
// //Fragment界面切换事件
// @Subscribe(threadMode = ThreadMode.MAIN)
// public void onEventMainThread(EBUISwitch busNine) {
// if (MainActivity.EB_MAINACTIVITY_TAG.equals(busNine.getFrom())) {
// if (busNine.getPosition() == 0) {
// adapter.startAutoScroll();
// } else {
// adapter.stopAutoScroll();
// }
// }
// }
//
// @Override
// public void onResume() {
// super.onResume();
// isEverpause = false;
// for (SubjectEntity subjectEntity : adapter.getSubjectList()) {
// for (GameEntity entity : subjectEntity.getData()) {
// entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName()));
// }
// }
// for (GameEntity entity : adapter.getPluginList()) {
// entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName()));
// }
// adapter.notifyDataSetChanged();
// DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
// adapter.startAutoScroll();
// }
//
// @Override
// public void onPause() {
// super.onPause();
// isEverpause = true;
// DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
// adapter.stopAutoScroll();
// }
//
// public boolean isEverpause() {
// return isEverpause;
// }
//
// @Override
// public void onRefresh() {
// postDelayedRunnable(runnable, 1000);
// }
//
//}

View File

@ -8,6 +8,7 @@ import com.gh.base.fragment.BaseFragment;
import com.gh.common.constant.Config;
import com.gh.gamecenter.R;
import com.gh.gamecenter.eventbus.EBReuse;
import com.gh.gamecenter.game.GameFragment;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

View File

@ -0,0 +1,97 @@
package com.gh.gamecenter.game
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import com.gh.base.fragment.BaseFragment
import com.gh.download.DownloadManager
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.FragmentGameBinding
import com.lightgame.download.DataWatcher
import com.lightgame.download.DownloadEntity
class GameFragment : BaseFragment<Any>() {
private var mBinding: FragmentGameBinding? = null
// private val mNoConn by bindView<View>(R.id.reuse_no_connection)
private var mViewModel: GameViewModel? = null
private var mListAdapter: GameFragmentAdapter? = null
private var mLayoutManager: LinearLayoutManager? = null
private val dataWatcher = object : DataWatcher() {
override fun onDataChanged(downloadEntity: DownloadEntity) {
mListAdapter?.notifyItemByDownload(downloadEntity)
}
}
override fun getLayoutId(): Int {
return R.layout.fragment_game
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mViewModel = ViewModelProviders.of(this).get(GameViewModel::class.java)
mViewModel?.slideList?.observe(this, Observer {
if (it != null) mListAdapter?.setSlideList(it)
})
mViewModel?.subjectDigestList?.observe(this, Observer {
if (it != null) mListAdapter?.setSubjectDigestList(it)
})
mViewModel?.pluginList?.observe(this, Observer {
if (it != null) mListAdapter?.setPluginList(it)
})
mViewModel?.subjectList?.observe(this, Observer {
if (it != null) {
mListAdapter?.setSubjectList(it)
}
})
mViewModel?.loadStatus?.observe(this, Observer {
if (it != null) mBinding?.loadStatus = it
})
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mBinding = FragmentGameBinding.bind(view)
mListAdapter = GameFragmentAdapter(context!!, mViewModel!!)
mLayoutManager = LinearLayoutManager(context)
(mBinding?.gameList?.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
mBinding?.gameList?.layoutManager = mLayoutManager
mBinding?.gameList?.adapter = mListAdapter
mBinding?.gameList?.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (mLayoutManager!!.findLastVisibleItemPosition() == mListAdapter!!.itemCount - 1
&& RecyclerView.SCROLL_STATE_IDLE == newState) mViewModel?.getSubjectList(false)
}
})
mBinding?.gameRefresh?.setOnRefreshListener {
mViewModel?.initData()
}
mBinding?.gameRefresh?.isRefreshing
}
override fun onPause() {
super.onPause()
DownloadManager.getInstance(context).removeObserver(dataWatcher)
}
override fun onResume() {
super.onResume()
DownloadManager.getInstance(context).addObserver(dataWatcher)
}
}

View File

@ -0,0 +1,270 @@
package com.gh.gamecenter.game
import android.content.Context
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.gh.common.constant.ItemViewType
import com.gh.common.util.DownloadItemUtils
import com.gh.common.util.StringUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.*
import com.gh.gamecenter.baselist.LoadStatus
import com.gh.gamecenter.databinding.GameHeadItemBinding
import com.gh.gamecenter.databinding.GameItemBinding
import com.gh.gamecenter.databinding.GameSubjectItemBinding
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.entity.SlideEntity
import com.gh.gamecenter.entity.SubjectDigestEntity
import com.gh.gamecenter.entity.SubjectEntity
import com.halo.assistant.fragment.game.GamePluginAdapter
import com.halo.assistant.fragment.game.GamePluginViewHolder
import com.lightgame.adapter.BaseRecyclerAdapter
import com.lightgame.download.DownloadEntity
import java.util.*
class GameFragmentAdapter(context: Context, model: GameViewModel) : BaseRecyclerAdapter<RecyclerView.ViewHolder>(context) {
data class PositionMap(val columnIndex: Int, val dataIndex: Int?)
private val mViewModel: GameViewModel = model
private var slideList: List<SlideEntity> = ArrayList() // 轮播图
private var pluginList: List<GameEntity> = ArrayList() // 插件化
private var subjectList: List<SubjectEntity> = ArrayList() // 专题
private var subjectDigestList: List<SubjectDigestEntity> = ArrayList() // 专题入口
private var mPositionAndIdMap = HashMap<String, Int>() // key: gameId + position, value: position
private var mLoadStatus: LoadStatus? = null
private var mSubjectAdapterMap: MutableMap<String, GameSubjectAdapter> = HashMap()
private var mPluginAdapter: GamePluginAdapter? = null
private var mIsOpenPluginList: Boolean = false
fun setSubjectList(subjectList: List<SubjectEntity>) {
this.subjectList = subjectList
notifyDataSetChanged()
}
fun setPluginList(pluginList: List<GameEntity>) {
this.pluginList = pluginList
notifyDataSetChanged()
}
fun setSlideList(slideList: List<SlideEntity>) {
this.slideList = slideList
notifyDataSetChanged()
}
fun setSubjectDigestList(subjectDigestList: List<SubjectDigestEntity>) {
this.subjectDigestList = subjectDigestList
notifyDataSetChanged()
}
override fun getItemViewType(position: Int): Int {
if (position == 0) {
return ItemViewType.GAME_SLIDE
}
if (!pluginList.isEmpty() && position == 1) {
return ItemViewType.GAME_PULGIN
}
if (position == itemCount - 1) {
return ItemViewType.LOADING
}
val positionMap = getColumnPositionMap(position)
if (positionMap.dataIndex == null) {
return ItemViewType.COLUMN_HEADER
}
val entity = subjectList[positionMap.columnIndex].data!![positionMap.dataIndex]
if (!entity.image.isNullOrEmpty()) {
return ItemViewType.GAME_IMAGE
} else {
return ItemViewType.GAME_NORMAL
}
return ItemViewType.GAME_SUBJECT
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder? {
return when (viewType) {
ItemViewType.GAME_SLIDE -> {
val displayMetrics = mContext.resources.displayMetrics.widthPixels
GameViewPagerViewHolder(mLayoutInflater.inflate(R.layout.game_viewpager_item, parent, false), displayMetrics)
}
ItemViewType.LOADING -> {
FooterViewHolder(mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false))
}
ItemViewType.GAME_SUBJECT -> {
val inflate = mLayoutInflater.inflate(R.layout.game_subject_item, parent, false)
GameSubjectItemViewHolder(GameSubjectItemBinding.bind(inflate))
}
ItemViewType.GAME_NORMAL -> {
GameItemViewHolder(GameItemBinding.bind(mLayoutInflater.inflate(R.layout.game_item, parent, false)))
}
ItemViewType.GAME_IMAGE -> {
GameImageViewHolder(mLayoutInflater.inflate(R.layout.game_image_item, parent, false))
}
ItemViewType.COLUMN_HEADER -> {
GameHeadViewHolder(GameHeadItemBinding.bind(mLayoutInflater.inflate(R.layout.game_head_item, parent, false)))
}
ItemViewType.GAME_PULGIN -> {
GamePluginViewHolder(mLayoutInflater.inflate(R.layout.game_plugin_item, parent, false))
}
else -> null
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (getItemViewType(position)) {
ItemViewType.COLUMN_HEADER -> {
if (holder is GameHeadViewHolder) {
val positionMap = getColumnPositionMap(position)
holder.binding.subject = subjectList[positionMap.columnIndex]
}
}
ItemViewType.GAME_PULGIN -> {
if (holder is GamePluginViewHolder) {
if (mPluginAdapter == null) {
holder.mPluginRv.layoutManager = LinearLayoutManager(mContext)
(holder.mPluginRv.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
mPluginAdapter = GamePluginAdapter(mContext, pluginList)
mPluginAdapter!!.openList(mIsOpenPluginList)
holder.mPluginRv.adapter = mPluginAdapter
} else {
mPluginAdapter!!.openList(mIsOpenPluginList)
mPluginAdapter!!.notifyDataSetChanged()
}
holder.mHeadTitle.text = String.format(Locale.getDefault(), "你有%d个游戏可以升级插件版", pluginList.size)
holder.mPluginHead.setOnClickListener({
if (mIsOpenPluginList) {
mIsOpenPluginList = false
holder.mHeadOpen.setImageResource(R.drawable.gamedetail_open_icon)
} else {
mIsOpenPluginList = true
holder.mHeadOpen.setImageResource(R.drawable.gamedetail_colse_icon)
}
notifyItemChanged(holder.adapterPosition)
})
}
}
ItemViewType.GAME_NORMAL -> {
if (holder is GameItemViewHolder) {
val positionMap = getColumnPositionMap(position)
val subjectEntity = subjectList[positionMap.columnIndex]
val gameEntity = subjectEntity.data!![positionMap.dataIndex!!]
holder.binding.game = gameEntity
holder.binding.executePendingBindings()
holder.binding.subjectTag = subjectEntity.tag
if (subjectEntity.isOrder) {
holder.binding.gameOrder.visibility = View.VISIBLE
holder.binding.gameOrder.text = (positionMap.dataIndex +
if (subjectEntity.data!![0].image.isNullOrEmpty()) 1 else 0).toString()
} else {
holder.binding.gameOrder.visibility = View.GONE
}
DownloadItemUtils.setOnClickListener(mContext, holder.binding.downloadBtn, gameEntity, position,
this@GameFragmentAdapter,
StringUtils.buildString("(游戏-专题:", subjectEntity.name, "-列表[", (position + 1).toString(), "])"),
StringUtils.buildString("游戏-专题-", subjectEntity.name, ":", gameEntity.name))
DownloadItemUtils.updateItem(mContext, gameEntity, GameViewHolder(holder.binding), !gameEntity.isPluggable)
}
}
ItemViewType.GAME_SLIDE -> {
}
ItemViewType.LOADING -> {
if (holder is FooterViewHolder) {
}
}
ItemViewType.GAME_SUBJECT -> {
if (holder is GameSubjectItemViewHolder) {
// val subjectEntity = subjectList[position - 1]
// var subjectAdapter: GameSubjectAdapter? = mSubjectAdapterMap[subjectEntity.id]
// if (subjectAdapter == null) {
// subjectAdapter = GameSubjectAdapter(mContext, subjectEntity.data!!)
// mSubjectAdapterMap[subjectEntity.id!!] = subjectAdapter
// }
//
// holder.binding.subjectRv.layoutManager = LinearLayoutManager(mContext)
// holder.binding.subjectRv.adapter = subjectAdapter
//
// holder.binding.subject = subjectEntity
}
}
}
}
override fun getItemCount(): Int {
var index = 0
for (entity in subjectList) {
index += if (entity.data == null) 1 else entity.data?.size!! + 1
}
if (!pluginList.isEmpty()) index++
return index + 2
}
private fun getColumnPositionMap(position: Int): PositionMap {
var index = 1
if (pluginList.isNotEmpty()) index++
for (i in 0 until subjectList.size) {
if (!subjectList[i].data!![0].image.isNullOrEmpty()) {
if (index == position) {
return PositionMap(i, 0)
}
index++
}
if (index == position) {
return PositionMap(i, null)
}
index++
val data = subjectList[i].data
for (j in 0 until data?.size!!) {
if (j == 0 && data[0].image != null) continue
if (index == position) {
mPositionAndIdMap[data[j].id!!] = position
return PositionMap(i, j)
}
index++
}
}
return PositionMap(-1, null)
}
fun notifyItemByDownload(entity: DownloadEntity) {
for (id in mPositionAndIdMap.keys) {
if (id.contains(entity.gameId)) {
val position = mPositionAndIdMap[id]!!
val positionMap = getColumnPositionMap(position)
if (positionMap.dataIndex == null) return
val entryMap = subjectList[positionMap.columnIndex].data!![positionMap.dataIndex].getEntryMap()
entryMap[entity.platform] = entity
notifyItemChanged(position)
}
}
}
}

View File

@ -0,0 +1,26 @@
package com.gh.gamecenter.game
import android.content.Context
import android.view.ViewGroup
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.GameHorizontalItemBinding
import com.gh.gamecenter.entity.GameEntity
import com.lightgame.adapter.BaseRecyclerAdapter
class GameHorizontalAdapter(context: Context, gameList: List<GameEntity>) : BaseRecyclerAdapter<GameHorizontalItemViewHolder>(context) {
private val mGameList: List<GameEntity> = gameList
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): GameHorizontalItemViewHolder {
val binding: GameHorizontalItemBinding = GameHorizontalItemBinding.bind(mLayoutInflater.inflate(R.layout.game_horizontal_item, parent, false))
return GameHorizontalItemViewHolder(binding)
}
override fun getItemCount(): Int {
return if (mGameList.size > 4) 4 else mGameList.size
}
override fun onBindViewHolder(holder: GameHorizontalItemViewHolder?, position: Int) {
holder?.binding?.game = mGameList[position]
}
}

View File

@ -0,0 +1,9 @@
package com.gh.gamecenter.game
import com.gh.base.BaseRecyclerViewHolder
import com.gh.gamecenter.databinding.GameHorizontalItemBinding
import com.gh.gamecenter.entity.GameEntity
class GameHorizontalItemViewHolder(bind: GameHorizontalItemBinding) : BaseRecyclerViewHolder<GameEntity>(bind.root) {
val binding: GameHorizontalItemBinding = bind
}

View File

@ -0,0 +1,9 @@
package com.gh.gamecenter.game
import com.gh.base.BaseRecyclerViewHolder
import com.gh.gamecenter.databinding.GameHorizontalListBinding
import com.gh.gamecenter.entity.GameEntity
class GameHorizontalListViewHolder(bind: GameHorizontalListBinding) : BaseRecyclerViewHolder<GameEntity>(bind.root) {
val binding: GameHorizontalListBinding = bind
}

View File

@ -0,0 +1,8 @@
package com.gh.gamecenter.game
import com.gh.base.BaseRecyclerViewHolder
import com.gh.gamecenter.databinding.GameItemBinding
class GameItemViewHolder(bind: GameItemBinding) : BaseRecyclerViewHolder<Any>(bind.root) {
var binding = bind
}

View File

@ -0,0 +1,25 @@
package com.gh.gamecenter.game
import android.content.Context
import android.view.ViewGroup
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.GameItemBinding
import com.gh.gamecenter.entity.GameEntity
import com.lightgame.adapter.BaseRecyclerAdapter
class GameSubjectAdapter(context: Context, gameList: List<GameEntity>) : BaseRecyclerAdapter<GameItemViewHolder>(context) {
private val mGameList = gameList
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameItemViewHolder? {
return GameItemViewHolder(GameItemBinding.bind(mLayoutInflater.inflate(R.layout.game_item, parent, false)))
}
override fun onBindViewHolder(holder: GameItemViewHolder, position: Int) {
holder.binding.game = mGameList[position]
}
override fun getItemCount(): Int {
return if (mGameList[0].id.isNullOrEmpty()) mGameList.size else mGameList.size - 1
}
}

View File

@ -0,0 +1,8 @@
package com.gh.gamecenter.game
import com.gh.base.BaseRecyclerViewHolder
import com.gh.gamecenter.databinding.GameSubjectItemBinding
class GameSubjectItemViewHolder(bind: GameSubjectItemBinding) : BaseRecyclerViewHolder<Any>(bind.root) {
var binding = bind
}

View File

@ -0,0 +1,236 @@
package com.gh.gamecenter.game
import android.app.Application
import android.arch.lifecycle.AndroidViewModel
import android.arch.lifecycle.MutableLiveData
import android.support.v4.util.ArrayMap
import android.text.TextUtils
import android.view.View
import android.widget.ProgressBar
import com.gh.common.util.ApkActiveUtils
import com.gh.common.util.GameUtils
import com.gh.common.util.RandomUtils
import com.gh.download.DownloadManager
import com.gh.gamecenter.baselist.LoadStatus
import com.gh.gamecenter.entity.*
import com.gh.gamecenter.manager.PackageManager
import com.gh.gamecenter.retrofit.Response
import com.gh.gamecenter.retrofit.RetrofitManager
import com.lightgame.utils.Utils
import retrofit2.HttpException
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
class GameViewModel(application: Application) : AndroidViewModel(application) {
var mApi = RetrofitManager.getInstance(getApplication()).api
var slideList: MutableLiveData<List<SlideEntity>> = MutableLiveData() // 轮播图
var pluginList: MutableLiveData<List<GameEntity>> = MutableLiveData() // 插件化
var subjectList: MutableLiveData<MutableList<SubjectEntity>> = MutableLiveData() // 专题
var subjectDigestList: MutableLiveData<List<SubjectDigestEntity>> = MutableLiveData() // 专题入口
val loadStatus = MutableLiveData<LoadStatus>()
private val mSubjectChangedMap: ArrayMap<String, List<GameEntity>> = ArrayMap() //存储换一换的数据
private var mSubjectPage = 1 // 专分页
private var mIsLoading = false
private var mIsInitPlugin = false
init {
initData()
}
fun initData() {
loadStatus.postValue(LoadStatus.INIT_LOADED)
getSlideData(true)
initPlugin()
}
private fun initPlugin() {
if (mIsInitPlugin) {
return
}
mIsInitPlugin = true
val updateList = PackageManager.getUpdateList()
if (updateList.isEmpty()) {
mIsInitPlugin = false
return
}
val list = java.util.ArrayList<GameEntity>()
var gameUpdateEntity: GameUpdateEntity
var i = 0
val size = updateList.size
while (i < size) {
gameUpdateEntity = updateList[i]
if (gameUpdateEntity.isPluggable) {
val gameEntity = GameEntity()
gameEntity.id = gameUpdateEntity.id
gameEntity.name = gameUpdateEntity.name
gameEntity.icon = gameUpdateEntity.icon
gameEntity.setTag(gameUpdateEntity.tag)
gameEntity.brief = gameUpdateEntity.brief
gameEntity.isPluggable = true
val apkEntity = ApkEntity()
apkEntity.url = gameUpdateEntity.url
apkEntity.packageName = gameUpdateEntity.packageName
apkEntity.size = gameUpdateEntity.size
apkEntity.version = gameUpdateEntity.version
apkEntity.ghVersion = gameUpdateEntity.ghVersion
apkEntity.setPlatform(gameUpdateEntity.platform!!)
apkEntity.etag = gameUpdateEntity.etag
val apk = java.util.ArrayList<ApkEntity>()
apk.add(apkEntity)
gameEntity.setApk(apk)
list.add(gameEntity)
}
i++
}
if (!list.isEmpty()) {
for (gEntity in list) {
gEntity.setEntryMap(DownloadManager.getInstance(getApplication()).getEntryMap(gEntity.name))
}
pluginList.postValue(list)
}
mIsInitPlugin = false
}
private fun getSlideData(initData: Boolean) {
mApi.slide
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Response<List<SlideEntity>>() {
override fun onResponse(response: List<SlideEntity>) {
slideList.postValue(response)
if (initData) getSubjectDigest(initData)
}
override fun onFailure(e: HttpException) {
if (initData) getSubjectDigest(initData)
}
})
}
private fun getSubjectDigest(initData: Boolean) {
mApi
.subjectDigest
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Response<List<SubjectDigestEntity>>() {
override fun onResponse(response: List<SubjectDigestEntity>) {
subjectDigestList.postValue(response)
if (initData) getSubjectList(initData)
}
override fun onFailure(e: HttpException) {
if (initData) getSubjectList(initData)
}
})
}
fun getSubjectList(initData: Boolean) {
if (mIsLoading) return
mIsLoading = true
if (initData) mSubjectPage = 1
mApi
.getColumn(mSubjectPage)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Response<List<SubjectEntity>>() {
override fun onResponse(response: List<SubjectEntity>) {
when {
initData -> {
subjectList.postValue(response as MutableList<SubjectEntity>?)
loadStatus.postValue(LoadStatus.INIT_LOADED)
}
response.isEmpty() -> {
loadStatus.postValue(LoadStatus.LIST_OVER)
}
else -> {
val value = if (subjectList.value == null) ArrayList() else subjectList.value
value?.addAll(response)
subjectList.postValue(value)
}
}
mSubjectPage++
mIsLoading = false
}
override fun onFailure(e: HttpException) {
if (initData && slideList.value == null && subjectDigestList.value == null) {
loadStatus.postValue(LoadStatus.INIT_FAILED)
} else {
loadStatus.postValue(LoadStatus.LIST_FAILED)
}
mIsLoading = false
}
})
}
//换一换
fun changeSubjectGame(progressBar: ProgressBar, subjectEntity: SubjectEntity) {
mApi
.getSubjectGame(subjectEntity.id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Response<List<GameEntity>>() {
override fun onResponse(response: List<GameEntity>) {
progressBar.visibility = View.GONE
if (response.size < subjectEntity.data!!.size) {
Utils.toast(getApplication(), "数据异常")
} else {
mSubjectChangedMap[subjectEntity.id] = response
initRandomGame((subjectEntity.data as MutableList<GameEntity>?)!!, java.util.ArrayList(response))
}
}
override fun onFailure(e: HttpException) {
progressBar.visibility = View.GONE
Utils.toast(getApplication(), "网络异常")
}
})
}
// 随机产生专题数据(换一换)
private fun initRandomGame(rawList: MutableList<GameEntity>, sourceList: List<GameEntity>?) {
var sourceList = sourceList
var size = rawList.size // 判断是否有大图
var i = 0
while (i < rawList.size) { //删除原数据,排除大图
if (TextUtils.isEmpty(rawList[i].image)) {
rawList.removeAt(i)
i--
} else {
size--
}
i++
}
if (size * 2 <= sourceList!!.size) {
sourceList = GameUtils.removeDuplicateData(rawList, sourceList)//排除重复
}
val indexes = RandomUtils.getRandomArray(size, sourceList!!.size)
for (index in indexes) {
val gameEntity = sourceList[index]
ApkActiveUtils.filterHideApk(gameEntity)
rawList.add(gameEntity)
}
}
}

View File

@ -18,13 +18,13 @@ import butterknife.BindView;
public class GamePluginViewHolder extends BaseRecyclerViewHolder {
@BindView(R.id.plugin_head_title)
TextView mHeadTitle;
public TextView mHeadTitle;
@BindView(R.id.plugin_head_open)
ImageView mHeadOpen;
public ImageView mHeadOpen;
@BindView(R.id.plugin_rv)
RecyclerView mPluginRv;
public RecyclerView mPluginRv;
@BindView(R.id.plugin_head)
LinearLayout mPluginHead;
public LinearLayout mPluginHead;
public GamePluginViewHolder(View itemView) {
super(itemView);

View File

@ -1,28 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:focusableInTouchMode="true">
<android.support.v4.widget.SwipeRefreshLayout
android:id = "@+id/fm_game_swipe_refresh"
<layout >
<data >
<import type = "com.gh.gamecenter.baselist.LoadStatus" />
<variable
name = "loadStatus"
type = "com.gh.gamecenter.baselist.LoadStatus" />
</data >
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "match_parent" >
android:layout_height = "match_parent"
android:focusableInTouchMode = "true" >
<android.support.v7.widget.RecyclerView
android:id = "@+id/fm_game_rv_list"
<android.support.v4.widget.SwipeRefreshLayout
android:id = "@+id/game_refresh"
visibleGone = "@{loadStatus == LoadStatus.INIT_FAILED? false: true}"
android:layout_width = "match_parent"
android:layout_height = "wrap_content" />
android:layout_height = "match_parent"
isRefreshing="@{loadStatus}">
</android.support.v4.widget.SwipeRefreshLayout >
<android.support.v7.widget.RecyclerView
android:id = "@+id/game_list"
android:layout_width = "match_parent"
android:layout_height = "wrap_content" />
<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
android:id = "@+id/fm_game_pb_loading"
android:layout_width = "40dp"
android:layout_height = "40dp"
android:layout_centerInParent = "true"
android:background = "@color/theme" />
</android.support.v4.widget.SwipeRefreshLayout >
<include layout = "@layout/reuse_no_connection" />
<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
android:id = "@+id/game_loading"
visibleGone = "@{loadStatus == LoadStatus.LIST_LOADING? true: false}"
android:layout_width = "40dp"
android:layout_height = "40dp"
android:layout_centerInParent = "true"
android:background = "@color/theme" />
</RelativeLayout >
<include
layout = "@layout/reuse_no_connection"
visibleGone = "@{loadStatus == LoadStatus.INIT_FAILED? false: true}" />
</RelativeLayout >
</layout >

View File

@ -1,67 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "@android:color/white"
android:orientation = "vertical" >
<layout >
<View
android:id = "@+id/head_line_top"
android:layout_width = "match_parent"
android:layout_height = "8dp"
android:background = "@color/background" />
<data >
<LinearLayout
<import type = "android.text.TextUtils" />
<variable
name = "subject"
type = "com.gh.gamecenter.entity.SubjectEntity" />
</data >
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "45dp"
android:gravity = "center_vertical"
android:orientation = "horizontal"
android:paddingLeft = "18dp"
android:paddingRight = "18dp" >
android:layout_height = "wrap_content"
android:background = "@android:color/white"
android:orientation = "vertical" >
<View
android:id = "@+id/head_line"
android:layout_width = "2dp"
android:layout_height = "15dp"
android:layout_marginBottom = "11dp"
android:layout_marginRight = "20dp"
android:layout_marginLeft="2dp"
android:layout_marginTop = "11dp"
android:background = "@color/theme" />
android:id = "@+id/head_line_top"
android:layout_width = "match_parent"
android:layout_height = "8dp"
visibleGone="@{TextUtils.isEmpty(subject.getData().get(0).getImage())?true:false}"
android:background = "@color/background" />
<TextView
android:id = "@+id/head_title"
android:layout_width = "0dp"
android:layout_height = "match_parent"
android:layout_weight = "1"
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "45dp"
android:gravity = "center_vertical"
android:textColor = "@color/title"
android:textSize = "15sp" />
android:orientation = "horizontal"
android:paddingLeft = "18dp"
android:paddingRight = "18dp" >
<ProgressBar
android:id = "@+id/head_pb"
style = "@style/android:Widget.Holo.ProgressBar"
android:layout_width = "25dp"
android:layout_height = "25dp"
android:layout_marginRight = "10dp"
android:visibility = "gone" />
<View
android:id = "@+id/head_line"
android:layout_width = "2dp"
android:layout_height = "15dp"
android:layout_marginBottom = "11dp"
android:layout_marginLeft = "2dp"
android:layout_marginRight = "20dp"
android:layout_marginTop = "11dp"
android:background = "@color/theme" />
<TextView
android:id = "@+id/head_more"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:gravity = "center"
android:text = "全部"
android:textColor = "@color/theme"
android:textSize = "12sp" />
<TextView
android:id = "@+id/head_title"
android:layout_width = "0dp"
android:layout_height = "match_parent"
android:layout_weight = "1"
android:gravity = "center_vertical"
android:text = "@{subject.name}"
android:textColor = "@color/title"
android:textSize = "15sp" />
<ProgressBar
android:id = "@+id/head_pb"
style = "@style/android:Widget.Holo.ProgressBar"
android:layout_width = "25dp"
android:layout_height = "25dp"
android:layout_marginRight = "10dp"
android:visibility = "gone" />
<!--visibleGone = "@{(TextUtils.isEmpty(subject.getData().get(0).getImage()) &lt; (subject.data.size >= Integer.parseInt(subject.more)) ||!TextUtils.isEmpty(subject.getData().get(0).getImage()) &lt; (subject.data.size >= (Integer.parseInt(subject.more) + 1)))? true: false}"-->
<TextView
android:id = "@+id/head_more"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:gravity = "center"
android:text = "@{subject.home == `change`? `换一批`: `全部`}"
android:textColor = "@color/theme"
android:textSize = "12sp" />
</LinearLayout >
<View
android:layout_width = "match_parent"
android:layout_height = "0.5dp"
android:layout_marginLeft = "20dp"
android:layout_marginRight = "20dp"
android:background = "@color/cutting_line" />
</LinearLayout >
<View
android:layout_width = "match_parent"
android:layout_height = "0.5dp"
android:layout_marginLeft = "20dp"
android:layout_marginRight = "20dp"
android:background = "@color/cutting_line" />
</LinearLayout >
</layout >

View File

@ -11,13 +11,14 @@
<android.support.constraint.ConstraintLayout
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_height = "wrap_content"
android:orientation = "horizontal"
android:paddingBottom = "15dp"
android:paddingTop = "15dp" >
<com.facebook.drawee.view.SimpleDraweeView
android:id = "@+id/game_icon"
imageUrl = "@{game.icon}"
android:layout_width = "60dp"
android:layout_height = "60dp"
app:layout_constraintLeft_toLeftOf = "parent"
@ -28,6 +29,11 @@
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "8dp"
android:gravity = "center"
android:singleLine = "true"
android:text = "@{game.name}"
android:textColor = "@color/black"
android:textSize = "13sp"
app:layout_constraintTop_toBottomOf = "@id/game_icon" />
<com.gh.common.view.DownloadProgressBar
@ -39,7 +45,6 @@
app:layout_constraintLeft_toLeftOf = "parent"
app:layout_constraintRight_toRightOf = "parent"
app:layout_constraintTop_toBottomOf = "@id/game_name"
app:rectStyle = "true"
app:textSize = "12sp" />

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto" >
<data >
<variable
name = "subject"
type = "com.gh.gamecenter.entity.SubjectEntity" />
</data >
<android.support.constraint.ConstraintLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "@android:color/white" >
<View
android:id = "@+id/horizontal_line_top"
android:layout_width = "match_parent"
android:layout_height = "8dp"
android:background = "@color/background" />
<LinearLayout
android:id = "@+id/horizontal_head"
android:layout_width = "match_parent"
android:layout_height = "45dp"
android:gravity = "center_vertical"
android:orientation = "horizontal"
android:paddingLeft = "18dp"
android:paddingRight = "18dp"
app:layout_constraintTop_toBottomOf = "@id/horizontal_line_top" >
<TextView
android:id = "@+id/horizontal_head_title"
android:layout_width = "0dp"
android:layout_height = "match_parent"
android:layout_weight = "1"
android:gravity = "center_vertical"
android:textColor = "@color/title"
android:text="@{subject.name}"
android:textSize = "15sp" />
<TextView
android:id = "@+id/horizontal_head_more"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:gravity = "center"
android:text = "全部"
android:textColor = "@color/theme"
android:textSize = "12sp" />
</LinearLayout >
<View
android:id = "@+id/horizontal_line"
android:layout_width = "match_parent"
android:layout_height = "0.5dp"
android:layout_marginLeft = "20dp"
android:layout_marginRight = "20dp"
android:background = "@color/cutting_line"
app:layout_constraintTop_toBottomOf = "@id/horizontal_head" />
<android.support.v7.widget.RecyclerView
android:id = "@+id/horizontal_rv"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
app:layout_constraintTop_toBottomOf = "@id/horizontal_line" />
</android.support.constraint.ConstraintLayout >
</layout >

View File

@ -0,0 +1,192 @@
<?xml version="1.0" encoding="utf-8"?>
<layout >
<data >
<variable
name = "subjectTag"
type = "String" />
<variable
name = "game"
type = "com.gh.gamecenter.entity.GameEntity" />
</data >
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:fresco = "http://schemas.android.com/apk/res-auto"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "@drawable/reuse_listview_item_style"
android:gravity = "center_vertical"
android:orientation = "horizontal"
android:paddingBottom = "8dp"
android:paddingLeft = "11dp"
android:paddingRight = "18dp"
android:paddingTop = "8dp" >
<TextView
android:id = "@+id/game_order"
android:layout_width = "25dp"
android:layout_height = "wrap_content"
android:layout_marginLeft = "-3dp"
android:layout_marginRight = "0dp"
android:gravity = "center"
android:maxLength = "3"
android:textColor = "@color/title"
android:textSize = "15sp"
android:visibility = "gone" />
<RelativeLayout
android:layout_width = "68dp"
android:layout_height = "74dp" >
<com.facebook.drawee.view.SimpleDraweeView
android:id = "@+id/game_icon"
style = "@style/frescoStyle"
imageUrl = "@{game.icon}"
android:layout_width = "60dp"
android:layout_height = "60dp"
android:layout_alignParentRight = "true"
android:layout_centerVertical = "true"
fresco:roundedCornerRadius = "10dp" />
<ImageView
android:id = "@+id/game_libao_icon"
android:layout_width = "25dp"
android:layout_height = "25dp"
android:src = "@drawable/game_libao_icon"
android:visibility = "gone" />
</RelativeLayout >
<LinearLayout
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:layout_marginLeft = "10dp"
android:layout_marginRight = "18dp"
android:layout_weight = "1"
android:orientation = "vertical" >
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content" >
<TextView
android:id = "@+id/game_name"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_centerVertical = "true"
android:ellipsize = "end"
android:includeFontPadding = "false"
android:lineSpacingMultiplier = "0.9"
android:singleLine = "true"
android:text = "@{game.name}"
android:textColor = "@color/text_3a3a3a"
android:textSize = "14sp" />
<TextView
android:id = "@+id/game_kaifu_type"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignRight = "@+id/game_name"
android:layout_centerVertical = "true"
android:maxLines = "1"
android:paddingBottom = "0.5dp"
android:paddingLeft = "3dp"
android:paddingRight = "3dp"
android:textColor = "@android:color/white"
android:textSize = "9sp"
android:visibility = "gone" />
</RelativeLayout >
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "28dp" >
<TextView
android:id = "@+id/game_des"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginBottom = "8dp"
android:layout_marginTop = "8dp"
android:ellipsize = "end"
android:includeFontPadding = "false"
android:lineSpacingMultiplier = "0.9"
android:singleLine = "true"
android:text = "@{game.apk.size>0?game.getApk().get(0).getSize() + game.brief : game.brief }"
android:textColor = "@color/text_9a9a9a"
android:textSize = "10sp" />
<LinearLayout
android:id = "@+id/game_info"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginBottom = "2.5dp"
android:layout_marginTop = "3dp"
android:orientation = "horizontal"
android:visibility = "gone" >
<TextView
android:id = "@+id/download_speed"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:layout_weight = "4"
android:ellipsize = "end"
android:singleLine = "true"
android:text = "@string/game_downloading_formattable"
android:textColor = "@color/text_9a9a9a"
android:textSize = "9sp" />
<TextView
android:id = "@+id/download_percentage"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:layout_weight = "1"
android:ellipsize = "end"
android:gravity = "right"
android:singleLine = "true"
android:text = "@string/game_percentage"
android:textColor = "@color/content"
android:textSize = "9sp" />
</LinearLayout >
<ProgressBar
android:id = "@+id/game_progressbar"
style = "?android:attr/progressBarStyleHorizontal"
android:layout_width = "match_parent"
android:layout_height = "3dp"
android:layout_below = "@+id/game_info"
android:layout_marginBottom = "4dp"
android:layout_marginRight = "5dp"
android:max = "1000"
android:progress = "500"
android:progressDrawable = "@drawable/progressbar_bg_style"
android:visibility = "gone" />
</RelativeLayout >
<LinearLayout
android:id = "@+id/label_list"
gameLabelList = "@{game}"
subjectTag="@{subjectTag}"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_gravity = "fill_vertical"
android:orientation = "horizontal" />
</LinearLayout >
<TextView
android:id = "@+id/download_btn"
android:layout_width = "60dp"
android:layout_height = "28.5dp"
android:background = "@drawable/game_item_btn_download_style"
android:gravity = "center"
android:text = "@string/download_down"
android:textColor = "@android:color/white"
android:textSize = "12sp" />
</LinearLayout >
</layout >

View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:fresco = "http://schemas.android.com/tools" >
<data >
<variable
name = "subject"
type = "com.gh.gamecenter.entity.SubjectEntity" />
</data >
<android.support.constraint.ConstraintLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "@android:color/white" >
<View
android:id = "@+id/subject_line_top"
android:layout_width = "match_parent"
android:layout_height = "8dp"
android:background = "@color/background" />
<com.facebook.drawee.view.SimpleDraweeView
android:id = "@+id/subject_image"
imageUrl = "@{subject.data.get(0).image}"
visibleGone = "@{subject.data.get(0).image == null? false: true}"
android:layout_width = "match_parent"
android:layout_height = "180dp"
android:scaleType = "centerCrop"
app:layout_constraintTop_toBottomOf = "@id/subject_line_top"
fresco:backgroundImage = "@color/placeholder_bg"
fresco:fadeDuration = "500"
fresco:placeholderImage = "@drawable/preload"
fresco:pressedStateOverlayImage = "@color/pressed_bg"
fresco:viewAspectRatio = "2.28" />
<LinearLayout
android:id = "@+id/subject_head"
android:layout_width = "match_parent"
android:layout_height = "45dp"
android:gravity = "center_vertical"
android:orientation = "horizontal"
android:paddingLeft = "18dp"
android:paddingRight = "18dp"
app:layout_constraintTop_toBottomOf = "@id/subject_image" >
<View
android:id = "@+id/subject_head_line"
android:layout_width = "2dp"
android:layout_height = "15dp"
android:layout_marginBottom = "11dp"
android:layout_marginLeft = "2dp"
android:layout_marginRight = "20dp"
android:layout_marginTop = "11dp"
android:background = "@color/theme" />
<TextView
android:id = "@+id/subject_head_title"
android:layout_width = "0dp"
android:layout_height = "match_parent"
android:layout_weight = "1"
android:gravity = "center_vertical"
android:textColor = "@color/title"
android:textSize = "15sp" />
<ProgressBar
android:id = "@+id/subject_head_pb"
style = "@style/android:Widget.Holo.ProgressBar"
android:layout_width = "25dp"
android:layout_height = "25dp"
android:layout_marginRight = "10dp"
android:visibility = "gone" />
<TextView
android:id = "@+id/subject_head_more"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:gravity = "center"
android:text = "全部"
android:textColor = "@color/theme"
android:textSize = "12sp" />
</LinearLayout >
<View
android:id = "@+id/subject_line"
android:layout_width = "match_parent"
android:layout_height = "0.5dp"
android:layout_marginLeft = "20dp"
android:layout_marginRight = "20dp"
android:background = "@color/cutting_line"
app:layout_constraintTop_toBottomOf = "@id/subject_head" />
<android.support.v7.widget.RecyclerView
android:id = "@+id/subject_rv"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
app:layout_constraintTop_toBottomOf = "@id/subject_line" />
</android.support.constraint.ConstraintLayout >
</layout >

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/home2_label_list"
android:layout_width = "wrap_content"
android:layout_height = "16dp"
android:layout_gravity = "fill_vertical"
android:orientation = "horizontal"
android:visibility = "visible" >
<TextView
android:id = "@+id/test_type"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:layout_marginRight = "6dp"
android:paddingBottom = "1dp"
android:paddingLeft = "3dp"
android:paddingRight = "3dp"
android:paddingTop = "1dp"
android:singleLine = "true"
android:textColor = "@android:color/white"
android:textSize = "10sp" />
<TextView
android:id = "@+id/test_time"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:layout_marginRight = "5dp"
android:background = "@color/btn_plugin"
android:paddingBottom = "1dp"
android:paddingLeft = "3dp"
android:paddingRight = "3dp"
android:paddingTop = "1dp"
android:singleLine = "true"
android:textColor = "@android:color/white"
android:textSize = "10sp" />
</LinearLayout >