下载合集
This commit is contained in:
@ -16,6 +16,7 @@ import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
@ -50,6 +51,7 @@ import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameCollectionEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
||||
@ -66,6 +68,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
@ -100,7 +103,6 @@ public class DownloadDialog {
|
||||
for (Map.Entry<String, DownloadEntry> entry : downloadingEntries.entrySet()) {
|
||||
if (entry.getValue().getName().equals(gameName)
|
||||
&& !"delete".equals(statusMap.get(entry.getValue().getUrl()))) {
|
||||
|
||||
entryMap.put(entry.getValue().getUrl(), entry.getValue());
|
||||
|
||||
Integer location = locationMap.get(entry.getValue().getUrl());
|
||||
@ -109,6 +111,9 @@ public class DownloadDialog {
|
||||
|
||||
if (position - 1 < adapterMap.size()) {
|
||||
adapterMap.get(position - 1).notifyItemChanged(location % (row * column));
|
||||
if (collectionAdapterMap != null && collectionAdapterMap.size() >= position - 1){
|
||||
collectionAdapterMap.get(position - 1).notifyItemChanged(location % (row * column));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,9 +126,12 @@ public class DownloadDialog {
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, DownloadEntry> entryMap;
|
||||
private SparseArray<RecyclerViewAdapter> adapterMap;
|
||||
private SparseArray<RecyclerViewAdapter> collectionAdapterMap;//存储合集的adapter
|
||||
private ArrayMap<String, String> urlMap;
|
||||
|
||||
private List<ApkEntity> gameApk;
|
||||
private List<GameCollectionEntity> gameCollection;//游戏合集
|
||||
private List<ApkEntity> gameCollectionApk; //和合集合并后的apk集合
|
||||
private String gameName;
|
||||
private String gameIcon;
|
||||
private String gameId;
|
||||
@ -136,6 +144,8 @@ public class DownloadDialog {
|
||||
private LinearLayout linearLayout;
|
||||
private ViewPager viewPager;
|
||||
private LinearLayout llCollection;
|
||||
private ViewPager collectionViewPager;
|
||||
private LinearLayout collectionLinearLayout;
|
||||
|
||||
private int row;
|
||||
private int column;
|
||||
@ -193,17 +203,21 @@ public class DownloadDialog {
|
||||
|
||||
gameApk = sortApk(new ArrayList<ApkEntity>(game.getApk()));
|
||||
|
||||
if (game.getCollection() != null){
|
||||
mergeApkCollection(game);
|
||||
}
|
||||
|
||||
// 一个自定义的布局,作为显示的内容
|
||||
View contentView = View.inflate(context, R.layout.game_download_dialog, null);
|
||||
|
||||
TextView textView = (TextView) contentView.findViewById(R.id.dialog_title);
|
||||
textView.setText(gameName);
|
||||
|
||||
int size = game.getApk().size();
|
||||
int count = game.getApk().size();
|
||||
int vpHeight = 0;
|
||||
if (size<=3){
|
||||
if (count <= 3){
|
||||
vpHeight = 72;
|
||||
}else if (size<=6){
|
||||
}else if (count <= 6){
|
||||
vpHeight = 136;
|
||||
}else {
|
||||
vpHeight = 200;
|
||||
@ -212,6 +226,8 @@ public class DownloadDialog {
|
||||
linearLayout = (LinearLayout) contentView.findViewById(R.id.dialog_ll_hint);
|
||||
viewPager = (ViewPager) contentView.findViewById(R.id.dialog_viewPager);
|
||||
llCollection = (LinearLayout) contentView.findViewById(R.id.dialog_collection);
|
||||
collectionLinearLayout = (LinearLayout) contentView.findViewById(R.id.dialog_ll_collection_hint);
|
||||
collectionViewPager = (ViewPager) contentView.findViewById(R.id.dialog_collection_viewPager);
|
||||
ViewGroup.LayoutParams layoutParams = viewPager.getLayoutParams();
|
||||
layoutParams.height = DisplayUtils.dip2px(context,vpHeight);
|
||||
viewPager.setLayoutParams(layoutParams);
|
||||
@ -302,6 +318,73 @@ public class DownloadDialog {
|
||||
DownloadManager.getInstance(context).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
// 合并ApkCollection
|
||||
private void mergeApkCollection(GameEntity game) {
|
||||
collectionAdapterMap = new SparseArray<>();
|
||||
gameCollection = new ArrayList<>();
|
||||
gameCollectionApk = new ArrayList<>();
|
||||
if (game.getCollection() != null){
|
||||
gameCollection = game.getCollection();
|
||||
}
|
||||
ConcurrentHashMap<String ,Integer> hashMap = new ConcurrentHashMap<>();
|
||||
|
||||
StringBuffer collectionName = new StringBuffer();
|
||||
|
||||
boolean isCollection = false;
|
||||
String collectionApkName = null;
|
||||
String collectionApkIcon = null;
|
||||
String collectionApkColor = null;
|
||||
String collectionApkPackage = null;
|
||||
ApkEntity saveApk = null;
|
||||
int apkPositon = 0;//排序后的位置
|
||||
|
||||
for (int j = 0; j < gameApk.size(); j++) {
|
||||
for (GameCollectionEntity gameCollectionEntity : gameCollection){
|
||||
for (int i = 0; i < gameCollectionEntity.getPackage().size(); i++){
|
||||
if (gameCollectionEntity.getPackage().get(i).equals(gameApk.get(j).getPackageName())){
|
||||
isCollection = true;
|
||||
collectionApkName = gameCollectionEntity.getName();
|
||||
collectionApkIcon = gameCollectionEntity.getIcon();
|
||||
collectionApkColor = gameCollectionEntity.getColor();
|
||||
saveApk = gameApk.get(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isCollection){
|
||||
for (String s : hashMap.keySet()) {
|
||||
collectionName.append(s);
|
||||
}
|
||||
if (collectionName.toString().contains(collectionApkName)){
|
||||
gameCollectionApk.get(hashMap.get(collectionApkName)).getApkCollection().getSaveApkEntity().add(saveApk);
|
||||
}else {
|
||||
List<ApkEntity> saveApkList = new ArrayList<>();
|
||||
List<String> strings = new ArrayList<>();
|
||||
ApkEntity apkEntity = new ApkEntity();
|
||||
GameCollectionEntity collectionEntity = new GameCollectionEntity();
|
||||
apkEntity.setApkCollection(collectionEntity);
|
||||
strings.add(collectionApkPackage);
|
||||
saveApkList.add(saveApk);
|
||||
collectionEntity.setSaveApkEntity(saveApkList);
|
||||
collectionEntity.setName(collectionApkName);
|
||||
collectionEntity.setIcon(collectionApkIcon);
|
||||
collectionEntity.setColor(collectionApkColor);
|
||||
gameCollectionApk.add(apkEntity);
|
||||
hashMap.put(collectionApkName,apkPositon);
|
||||
|
||||
apkPositon++;
|
||||
}
|
||||
isCollection = false;
|
||||
}else {
|
||||
gameCollectionApk.add(gameApk.get(j));
|
||||
apkPositon++;
|
||||
}
|
||||
}
|
||||
|
||||
gameApk.clear();
|
||||
gameApk = gameCollectionApk;
|
||||
|
||||
}
|
||||
|
||||
private boolean isLoadPlatform;
|
||||
|
||||
private void init(List<ApkEntity> apkList) {
|
||||
@ -333,12 +416,12 @@ public class DownloadDialog {
|
||||
for (int i = 0; i < size; i++) {
|
||||
ImageView imageView = new ImageView(context);
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
DisplayUtils.dip2px(context, 5), DisplayUtils.dip2px(context, 5));
|
||||
DisplayUtils.dip2px(context, 6), DisplayUtils.dip2px(context, 6));
|
||||
if (i == 0) {
|
||||
lparams.leftMargin = 0;
|
||||
imageView.setImageResource(R.drawable.oval_hint_up);
|
||||
} else {
|
||||
lparams.leftMargin = DisplayUtils.dip2px(context, 8);
|
||||
lparams.leftMargin = DisplayUtils.dip2px(context, 9);
|
||||
imageView.setImageResource(R.drawable.oval_hint_gray_bg);
|
||||
}
|
||||
imageView.setLayoutParams(lparams);
|
||||
@ -427,9 +510,15 @@ public class DownloadDialog {
|
||||
entryMap.remove(url);
|
||||
int position = (int) Math.ceil((location + 1) / (double) (row * column));
|
||||
adapterMap.get(position - 1).notifyItemChanged(location % (row * column));
|
||||
if (collectionAdapterMap != null && collectionAdapterMap.size() >= position - 1){
|
||||
collectionAdapterMap.get(position - 1).notifyItemChanged(location % (row * column));
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
int position = (int) Math.ceil((location + 1) / (double) (row * column));
|
||||
adapterMap.get(position - 1).notifyItemChanged(location % (row * column));
|
||||
if (collectionAdapterMap != null && collectionAdapterMap.size() >= position - 1){
|
||||
collectionAdapterMap.get(position - 1).notifyItemChanged(location % (row * column));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -442,6 +531,9 @@ public class DownloadDialog {
|
||||
entryMap.remove(url);
|
||||
int position = (int) Math.ceil((location + 1) / (double) (row * column));
|
||||
adapterMap.get(position - 1).notifyItemChanged(location % (row * column));
|
||||
if (collectionAdapterMap != null && collectionAdapterMap.size() >= position - 1){
|
||||
collectionAdapterMap.get(position - 1).notifyItemChanged(location % (row * column));
|
||||
}
|
||||
}
|
||||
|
||||
// 接收platform数据改变消息,更新界面
|
||||
@ -510,6 +602,7 @@ public class DownloadDialog {
|
||||
private TextView download_item_tv_name;
|
||||
private TextView download_item_tv_status;
|
||||
private TextView download_item_tv_hint;
|
||||
private ImageView download_item_open_collection;
|
||||
private ProgressBar download_item_progressbar;
|
||||
private ImageView download_item_iv_pic;
|
||||
|
||||
@ -526,6 +619,8 @@ public class DownloadDialog {
|
||||
.findViewById(R.id.download_item_iv_pic);
|
||||
download_item_tv_hint = (TextView) convertView
|
||||
.findViewById(R.id.download_item_tv_hint);
|
||||
download_item_open_collection = (ImageView) convertView
|
||||
.findViewById(R.id.download_item_open_collection);
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,6 +654,8 @@ public class DownloadDialog {
|
||||
private List<ApkEntity> platforms;
|
||||
private int position;
|
||||
private int count;
|
||||
private int colseCollectionPosition = -1;
|
||||
private int clickCollectionPosition = -1;
|
||||
|
||||
public RecyclerViewAdapter(List<ApkEntity> list, int p) {
|
||||
platforms = list;
|
||||
@ -579,15 +676,26 @@ public class DownloadDialog {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onBindViewHolder(final RecyclerViewHolder viewHolder, int location) {
|
||||
public void onBindViewHolder(final RecyclerViewHolder viewHolder, final int location) {
|
||||
|
||||
final ApkEntity apkEntity = platforms.get((row * column) * position + location);
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
llCollection.setVisibility(View.VISIBLE);
|
||||
if (viewHolder.download_item_tv_status.getVisibility() == View.GONE) {
|
||||
if (apkEntity.getApkCollection() != null){
|
||||
if (llCollection.getVisibility() == View.GONE
|
||||
|| clickCollectionPosition != location && clickCollectionPosition != -1){
|
||||
llCollection.setVisibility(View.VISIBLE);
|
||||
showCollectionLayout(apkEntity.getApkCollection());
|
||||
viewHolder.download_item_open_collection.setImageResource(R.drawable.colse_collection);
|
||||
colseCollectionPosition = location;
|
||||
notifyDataSetChanged();
|
||||
} else {
|
||||
llCollection.setVisibility(View.GONE);
|
||||
viewHolder.download_item_open_collection.setImageResource(R.drawable.open_collection);
|
||||
}
|
||||
clickCollectionPosition = location;
|
||||
} else if (viewHolder.download_item_tv_status.getVisibility() == View.GONE) {
|
||||
//下载游戏
|
||||
addDownloadEntry(apkEntity, viewHolder.download_item_tv_status);
|
||||
} else {
|
||||
@ -808,6 +916,15 @@ public class DownloadDialog {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (apkEntity.getApkCollection() != null){
|
||||
ImageUtils.getInstance(context).display(apkEntity.getApkCollection().getIcon(),viewHolder.download_item_iv_pic);
|
||||
viewHolder.download_item_open_collection.setVisibility(View.VISIBLE);
|
||||
if (colseCollectionPosition == location){
|
||||
viewHolder.download_item_open_collection.setImageResource(R.drawable.colse_collection);
|
||||
}else {
|
||||
viewHolder.download_item_open_collection.setImageResource(R.drawable.open_collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -947,7 +1064,7 @@ public class DownloadDialog {
|
||||
}
|
||||
|
||||
//添加游戏下载
|
||||
private void addDownloadEntry(ApkEntity apkEntity, TextView download_item_tv_status) {
|
||||
public void addDownloadEntry(ApkEntity apkEntity, TextView download_item_tv_status) {
|
||||
String msg = FileUtils.isCanDownload(apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
@ -1038,4 +1155,135 @@ public class DownloadDialog {
|
||||
return new RecyclerViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
private void showCollectionLayout(GameCollectionEntity gameCollectionEntity) {
|
||||
int count = gameCollectionEntity.getSaveApkEntity().size();
|
||||
int vpHeight = 0;
|
||||
if (count <= 3){
|
||||
vpHeight = 72;
|
||||
}else if (count <= 6){
|
||||
vpHeight = 136;
|
||||
}else {
|
||||
vpHeight = 200;
|
||||
}
|
||||
ViewGroup.LayoutParams layoutParams = collectionViewPager.getLayoutParams();
|
||||
layoutParams.height = DisplayUtils.dip2px(context, vpHeight);
|
||||
collectionViewPager.setLayoutParams(layoutParams);
|
||||
|
||||
for (int i = 0, size = gameCollectionEntity.getSaveApkEntity().size(); i < size; i++) {
|
||||
locationMap.put(gameCollectionEntity.getSaveApkEntity().get(i).getUrl(), i);
|
||||
urlMap.put(gameCollectionEntity.getSaveApkEntity().get(i).getPackageName(), gameCollectionEntity.getSaveApkEntity().get(i).getUrl());
|
||||
}
|
||||
|
||||
collectionLinearLayout.removeAllViews();
|
||||
int size = (int) Math.ceil(gameCollectionEntity.getSaveApkEntity().size() / (double) (row * column));
|
||||
Log.e("============",":::"+size);
|
||||
if (size > 1) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
ImageView imageView = new ImageView(context);
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
DisplayUtils.dip2px(context, 6), DisplayUtils.dip2px(
|
||||
context, 6));
|
||||
if (i == 0) {
|
||||
lparams.leftMargin = 0;
|
||||
imageView.setImageResource(R.drawable.oval_hint_up);
|
||||
} else {
|
||||
lparams.leftMargin = DisplayUtils.dip2px(context, 9);
|
||||
imageView.setImageResource(R.drawable.oval_hint_gray_bg);
|
||||
}
|
||||
imageView.setLayoutParams(lparams);
|
||||
collectionLinearLayout.addView(imageView);
|
||||
}
|
||||
}
|
||||
int currentItem = 0;
|
||||
if (viewPager != null) {
|
||||
currentItem = viewPager.getCurrentItem();
|
||||
}
|
||||
viewPager.setCurrentItem(currentItem);
|
||||
|
||||
collectionViewPager.setAdapter(new CollectionPlatformAdapter(gameCollectionEntity.getSaveApkEntity()));
|
||||
|
||||
collectionViewPager.addOnPageChangeListener(new OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
Log.e("+++++++++",collectionLinearLayout.getChildCount()+"");
|
||||
for (int i = 0, size = collectionLinearLayout.getChildCount(); i < size; i++) {
|
||||
if (i == position % size) {
|
||||
((ImageView) collectionLinearLayout.getChildAt(i))
|
||||
.setImageResource(R.drawable.oval_hint_up);
|
||||
} else {
|
||||
((ImageView) collectionLinearLayout.getChildAt(i))
|
||||
.setImageResource(R.drawable.oval_hint_gray_bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int i) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
private class CollectionPlatformAdapter extends PagerAdapter {
|
||||
|
||||
private List<ApkEntity> saveApkEntity;
|
||||
|
||||
public CollectionPlatformAdapter(List<ApkEntity> saveApkEntity) {
|
||||
this.saveApkEntity = saveApkEntity;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return (int) Math.ceil(saveApkEntity.size() / (double) (row * column));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
|
||||
RecyclerView recyclerView = new RecyclerView(context);
|
||||
|
||||
int padding = DisplayUtils.dip2px(context, 10);
|
||||
|
||||
recyclerView.setPadding(padding, padding, padding, padding);
|
||||
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
recyclerView.setLayoutParams(params);
|
||||
|
||||
recyclerView.setHasFixedSize(true);
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(
|
||||
context, column);
|
||||
recyclerView.setLayoutManager(gridLayoutManager);
|
||||
recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
|
||||
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(saveApkEntity,
|
||||
position);
|
||||
|
||||
collectionAdapterMap.put(position, adapter);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
container.addView(recyclerView);
|
||||
return recyclerView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
container.removeView((View) object);
|
||||
object = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user