diff --git a/app/src/main/java/com/gh/common/view/DownloadDialog.java b/app/src/main/java/com/gh/common/view/DownloadDialog.java index f65157fc77..eb9b35672c 100644 --- a/app/src/main/java/com/gh/common/view/DownloadDialog.java +++ b/app/src/main/java/com/gh/common/view/DownloadDialog.java @@ -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 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 locationMap; private ArrayMap entryMap; private SparseArray adapterMap; + private SparseArray collectionAdapterMap;//存储合集的adapter private ArrayMap urlMap; private List gameApk; + private List gameCollection;//游戏合集 + private List 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(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 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 saveApkList = new ArrayList<>(); + List 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 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 platforms; private int position; private int count; + private int colseCollectionPosition = -1; + private int clickCollectionPosition = -1; public RecyclerViewAdapter(List 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 kv = new HashMap(); @@ -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 saveApkEntity; + + public CollectionPlatformAdapter(List 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; + } + + } + } diff --git a/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.java b/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.java index 22876493bc..3029eabca0 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.java +++ b/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.java @@ -22,6 +22,16 @@ public class ApkEntity { private String etag; + private GameCollectionEntity apkCollection; + + public GameCollectionEntity getApkCollection() { + return apkCollection; + } + + public void setApkCollection(GameCollectionEntity apkCollection) { + this.apkCollection = apkCollection; + } + public String getPackageName() { return packageName; } diff --git a/app/src/main/java/com/gh/gamecenter/entity/GameCollectionEntity.java b/app/src/main/java/com/gh/gamecenter/entity/GameCollectionEntity.java index ee34e4e5d5..c338d944d1 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/GameCollectionEntity.java +++ b/app/src/main/java/com/gh/gamecenter/entity/GameCollectionEntity.java @@ -1,5 +1,7 @@ package com.gh.gamecenter.entity; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** @@ -13,8 +15,19 @@ public class GameCollectionEntity { private String name; + @SerializedName("package") private List packages; + private List saveApkEntity; + + public List getSaveApkEntity() { + return saveApkEntity; + } + + public void setSaveApkEntity(List saveApkEntity) { + this.saveApkEntity = saveApkEntity; + } + public void setColor(String color) { this.color = color; } diff --git a/app/src/main/res/drawable-hdpi/colse_collection.png b/app/src/main/res/drawable-hdpi/colse_collection.png new file mode 100644 index 0000000000..6d7bb065d5 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/colse_collection.png differ diff --git a/app/src/main/res/drawable-hdpi/open_collection.png b/app/src/main/res/drawable-hdpi/open_collection.png new file mode 100644 index 0000000000..b87c018222 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/open_collection.png differ diff --git a/app/src/main/res/drawable/oval_hint_gray_bg.xml b/app/src/main/res/drawable/oval_hint_gray_bg.xml index bb16f3cfab..f1a227ef8d 100644 --- a/app/src/main/res/drawable/oval_hint_gray_bg.xml +++ b/app/src/main/res/drawable/oval_hint_gray_bg.xml @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/game_download_dialog.xml b/app/src/main/res/layout/game_download_dialog.xml index 405df46507..44603ceb5d 100644 --- a/app/src/main/res/layout/game_download_dialog.xml +++ b/app/src/main/res/layout/game_download_dialog.xml @@ -9,7 +9,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" - android:background="@android:color/white" + android:background="#ffffff" android:orientation="vertical" > + android:layout_height="1dp" + android:background="#ededed" /> + android:background="#F6F6F6" + android:visibility="gone"> + + \ No newline at end of file