1359 lines
46 KiB
Java
1359 lines
46 KiB
Java
package com.gh.gamecenter.personal;
|
|
|
|
import android.content.Intent;
|
|
import android.graphics.Color;
|
|
import android.graphics.Rect;
|
|
import android.graphics.drawable.ClipDrawable;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.graphics.drawable.GradientDrawable;
|
|
import android.graphics.drawable.LayerDrawable;
|
|
import android.os.Build;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.support.v4.app.FragmentActivity;
|
|
import android.support.v4.util.ArrayMap;
|
|
import android.support.v4.widget.ContentLoadingProgressBar;
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
import android.support.v7.widget.RecyclerView;
|
|
import android.support.v7.widget.RecyclerView.ViewHolder;
|
|
import android.text.TextUtils;
|
|
import android.util.DisplayMetrics;
|
|
import android.util.SparseArray;
|
|
import android.util.SparseBooleanArray;
|
|
import android.view.Gravity;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View.OnClickListener;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.RelativeLayout.LayoutParams;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
|
|
import com.android.volley.NoConnectionError;
|
|
import com.android.volley.Response;
|
|
import com.android.volley.TimeoutError;
|
|
import com.android.volley.VolleyError;
|
|
import com.gh.base.AppController;
|
|
import com.gh.common.constant.Config;
|
|
import com.gh.common.constant.Constants;
|
|
import com.gh.common.util.DataUtils;
|
|
import com.gh.common.util.DialogUtils;
|
|
import com.gh.common.util.DisplayUtils;
|
|
import com.gh.common.util.FileUtils;
|
|
import com.gh.common.util.ImageUtils;
|
|
import com.gh.common.util.MD5Utils;
|
|
import com.gh.common.util.PackageUtils;
|
|
import com.gh.common.util.PlatformUtils;
|
|
import com.gh.common.util.TimestampUtils;
|
|
import com.gh.common.util.TrafficUtils;
|
|
import com.gh.common.view.HorizontalItemDecoration;
|
|
import com.gh.common.view.MyGame_LinearLayout;
|
|
import com.gh.download.DataWatcher;
|
|
import com.gh.download.DownloadEntry;
|
|
import com.gh.download.DownloadManager;
|
|
import com.gh.gamecenter.ConcernActivity;
|
|
import com.gh.gamecenter.DownloadManagerActivity;
|
|
import com.gh.gamecenter.GameDetailsActivity;
|
|
import com.gh.gamecenter.MainActivity;
|
|
import com.gh.gamecenter.R;
|
|
import com.gh.gamecenter.SettingActivity;
|
|
import com.gh.gamecenter.db.info.ConcernInfo;
|
|
import com.gh.gamecenter.db.info.GameInfo;
|
|
import com.gh.gamecenter.entity.ApkEntity;
|
|
import com.gh.gamecenter.entity.GameDigestEntity;
|
|
import com.gh.gamecenter.entity.GameEntity;
|
|
import com.gh.gamecenter.entity.GameUpdateEntity;
|
|
import com.gh.gamecenter.entity.MyGameInfo;
|
|
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
|
import com.gh.gamecenter.eventbus.EBPutUrl;
|
|
import com.gh.gamecenter.eventbus.EBRedDot;
|
|
import com.gh.gamecenter.manager.ConcernManager;
|
|
import com.gh.gamecenter.manager.DataCollectionManager;
|
|
import com.gh.gamecenter.manager.GameManager;
|
|
import com.gh.gamecenter.manager.PackageManager;
|
|
import com.gh.gamecenter.manager.SuspectedGameManager;
|
|
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
|
import com.google.gson.Gson;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
|
|
import de.greenrobot.event.EventBus;
|
|
|
|
public class PersonalFragmentAdapter extends
|
|
RecyclerView.Adapter<ViewHolder> {
|
|
|
|
private FragmentActivity fragmentActivity;
|
|
private RecyclerView gameRecyclerView;
|
|
|
|
private ArrayList<GameEntity> gameDetailedList;
|
|
private ArrayList<MyGameInfo> sortedList;
|
|
private SparseBooleanArray isShowMap;
|
|
|
|
private ArrayMap<String, Integer> locationMap;
|
|
private SparseArray<RecyclerView> recyclerViewMap;
|
|
|
|
private int oldClickViewPosition = -1;
|
|
|
|
private boolean isLoading;
|
|
private boolean isNetworkError;
|
|
|
|
private ArrayMap<String, String> statusMap;
|
|
|
|
private Handler handler = new Handler() {
|
|
@Override
|
|
public void handleMessage(Message msg) {
|
|
if (msg.what == 0) {
|
|
notifyDataSetChanged();
|
|
}
|
|
}
|
|
};
|
|
|
|
public PersonalFragmentAdapter(FragmentActivity activity,
|
|
RecyclerView gRecyclerView) {
|
|
fragmentActivity = activity;
|
|
gameRecyclerView = gRecyclerView;
|
|
gameDetailedList = new ArrayList<GameEntity>();
|
|
isShowMap = new SparseBooleanArray();
|
|
|
|
isLoading = true;
|
|
isNetworkError = false;
|
|
|
|
locationMap = new ArrayMap<String, Integer>();
|
|
recyclerViewMap = new SparseArray<RecyclerView>();
|
|
|
|
statusMap = new ArrayMap<String, String>();
|
|
|
|
new Thread(runnable).start();
|
|
|
|
}
|
|
|
|
Runnable runnable = new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
sortGameList();
|
|
|
|
if (sortedList.isEmpty()) {
|
|
isLoading = false;
|
|
handler.sendEmptyMessage(0);
|
|
} else {
|
|
List<String> ids = new ArrayList<String>();
|
|
for (MyGameInfo info : sortedList) {
|
|
ids.add(info.getGame_id());
|
|
}
|
|
initGameList(ids);
|
|
}
|
|
}
|
|
};
|
|
|
|
private void sortGameList() {
|
|
|
|
sortedList = new ArrayList<MyGameInfo>();
|
|
|
|
ArrayList<MyGameInfo> signatureList = new ArrayList<MyGameInfo>();
|
|
ArrayList<MyGameInfo> unsignatureList = new ArrayList<MyGameInfo>();
|
|
ArrayList<MyGameInfo> noopenList = new ArrayList<MyGameInfo>();
|
|
ArrayList<MyGameInfo> oftenuseList = new ArrayList<MyGameInfo>();
|
|
|
|
PackageManager pManager = new PackageManager(fragmentActivity);
|
|
|
|
TrafficUtils tUtils = TrafficUtils.getInstance(fragmentActivity);
|
|
|
|
ConcernManager cManager = new ConcernManager(fragmentActivity);
|
|
List<ConcernInfo> runnableGame = cManager.getInstalledGame();
|
|
|
|
for (ConcernInfo concernEntity : runnableGame) {
|
|
for (Entry<String, Boolean> entry : concernEntity.getPackageNames()
|
|
.entrySet()) {
|
|
if (entry.getValue()) {
|
|
MyGameInfo info = new MyGameInfo();
|
|
info.setGame_id(concernEntity.getId());
|
|
info.setPackage_name(entry.getKey());
|
|
info.setTraffic(tUtils.getTraffice(entry.getKey()));
|
|
info.setSignature(pManager.isSignature(entry.getKey()));
|
|
info.setInstalledTime(pManager.getInstalledTime(entry
|
|
.getKey()));
|
|
if (info.isSignature()) {
|
|
signatureList.add(info);
|
|
} else {
|
|
unsignatureList.add(info);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (MyGameInfo info : signatureList) {
|
|
if (info.getTraffic() == 0) {
|
|
noopenList.add(info);
|
|
} else {
|
|
oftenuseList.add(info);
|
|
}
|
|
}
|
|
|
|
Comparator<MyGameInfo> comparator = new Comparator<MyGameInfo>() {
|
|
@Override
|
|
public int compare(MyGameInfo lhs, MyGameInfo rhs) {
|
|
|
|
if (rhs.getInstalledTime() > lhs.getInstalledTime()) {
|
|
return 1;
|
|
} else if (rhs.getInstalledTime() < lhs.getInstalledTime()) {
|
|
return -1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
};
|
|
|
|
Collections.sort(noopenList, comparator);
|
|
|
|
comparator = new Comparator<MyGameInfo>() {
|
|
@Override
|
|
public int compare(MyGameInfo lhs, MyGameInfo rhs) {
|
|
|
|
if (rhs.getTraffic() > lhs.getTraffic()) {
|
|
return 1;
|
|
} else if (isLoading) {
|
|
return -1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
};
|
|
|
|
Collections.sort(oftenuseList, comparator);
|
|
|
|
Collections.sort(unsignatureList, comparator);
|
|
|
|
for (int i = 0, sizei = noopenList.size(); i < sizei; i++) {
|
|
boolean flag = true;
|
|
for (int j = 0, sizej = sortedList.size(); j < sizej; j++) {
|
|
if (sortedList.get(j).getGame_id()
|
|
.equals(noopenList.get(i).getGame_id())) {
|
|
flag = false;
|
|
MyGameInfo gameInfo = sortedList.get(j);
|
|
ArrayList<String> list = gameInfo.getPackageList();
|
|
if (list == null) {
|
|
list = new ArrayList<String>();
|
|
list.add(gameInfo.getPackage_name());
|
|
}
|
|
list.add(noopenList.get(i).getPackage_name());
|
|
gameInfo.setPackageList(list);
|
|
sortedList.set(j, gameInfo);
|
|
break;
|
|
}
|
|
}
|
|
if (flag) {
|
|
sortedList.add(noopenList.get(i));
|
|
}
|
|
}
|
|
for (int i = 0, size = oftenuseList.size(); i < size; i++) {
|
|
boolean flag = true;
|
|
for (int j = 0, sizej = sortedList.size(); j < sizej; j++) {
|
|
if (sortedList.get(j).getGame_id()
|
|
.equals(oftenuseList.get(i).getGame_id())) {
|
|
flag = false;
|
|
MyGameInfo gameInfo = sortedList.get(j);
|
|
ArrayList<String> list = gameInfo.getPackageList();
|
|
if (list == null) {
|
|
list = new ArrayList<String>();
|
|
list.add(gameInfo.getPackage_name());
|
|
}
|
|
list.add(oftenuseList.get(i).getPackage_name());
|
|
gameInfo.setPackageList(list);
|
|
sortedList.set(j, gameInfo);
|
|
break;
|
|
}
|
|
}
|
|
if (flag) {
|
|
sortedList.add(oftenuseList.get(i));
|
|
}
|
|
}
|
|
for (int i = 0, size = unsignatureList.size(); i < size; i++) {
|
|
boolean flag = true;
|
|
for (int j = 0, sizej = sortedList.size(); j < sizej; j++) {
|
|
if (sortedList.get(j).getGame_id()
|
|
.equals(unsignatureList.get(i).getGame_id())) {
|
|
flag = false;
|
|
MyGameInfo gameInfo = sortedList.get(j);
|
|
ArrayList<String> list = gameInfo.getPackageList();
|
|
if (list == null) {
|
|
list = new ArrayList<String>();
|
|
list.add(gameInfo.getPackage_name());
|
|
}
|
|
list.add(unsignatureList.get(i).getPackage_name());
|
|
gameInfo.setPackageList(list);
|
|
sortedList.set(j, gameInfo);
|
|
break;
|
|
}
|
|
}
|
|
if (flag) {
|
|
sortedList.add(unsignatureList.get(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void initGameList(List<String> ids) {
|
|
final List<JSONObject> result = new ArrayList<JSONObject>();
|
|
final int count = ids.size();
|
|
for (int i = 0, size = ids.size(); i < size; i++) {
|
|
JsonObjectExtendedRequest objectRequest = new JsonObjectExtendedRequest(
|
|
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/"
|
|
+ ids.get(i) + "/digest", Constants.GAME_CD),
|
|
new Response.Listener<JSONObject>() {
|
|
|
|
@Override
|
|
public void onResponse(JSONObject response) {
|
|
result.add(response);
|
|
if (result.size() == count) {
|
|
processingData(result);
|
|
}
|
|
}
|
|
}, new Response.ErrorListener() {
|
|
|
|
@Override
|
|
public void onErrorResponse(VolleyError error) {
|
|
// 无网络连接和访问超时
|
|
if (error.getClass()
|
|
.equals(NoConnectionError.class)
|
|
|| error.getClass().equals(
|
|
TimeoutError.class)) {
|
|
Toast.makeText(fragmentActivity, "网络错误",
|
|
Toast.LENGTH_SHORT).show();
|
|
isNetworkError = true;
|
|
notifyItemChanged(getItemCount() - 1);
|
|
}
|
|
}
|
|
});
|
|
AppController.addToRequestQueue(objectRequest,
|
|
PersonalFragmentAdapter.class);
|
|
}
|
|
}
|
|
|
|
private void processingData(List<JSONObject> data) {
|
|
Gson gson = new Gson();
|
|
List<GameEntity> gameList = new ArrayList<GameEntity>();
|
|
for (int i = 0, size = data.size(); i < size; i++) {
|
|
gameList.add(gson
|
|
.fromJson(data.get(i).toString(), GameEntity.class));
|
|
}
|
|
if (gameList != null && !gameList.isEmpty()) {
|
|
for (int i = 0, size = sortedList.size(); i < size; i++) {
|
|
String id = sortedList.get(i).getGame_id();
|
|
for (GameEntity entity : gameList) {
|
|
if (entity.getId().equals(id)) {
|
|
gameDetailedList.add(entity);
|
|
}
|
|
}
|
|
}
|
|
GameManager manager = new GameManager(fragmentActivity);
|
|
for (GameEntity entity : gameDetailedList) {
|
|
for (ApkEntity apkEntity : entity.getApk()) {
|
|
manager.addOrUpdate(new GameInfo(
|
|
apkEntity.getPackageName(), entity.getId(), entity
|
|
.getName()));
|
|
}
|
|
}
|
|
}
|
|
|
|
isLoading = false;
|
|
// notifyDataSetChanged();
|
|
handler.sendEmptyMessage(0);
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return 1 + 1 + gameDetailedList.size();
|
|
}
|
|
|
|
@Override
|
|
public int getItemViewType(int position) {
|
|
return position;
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
|
|
if (viewHolder instanceof FunctionViewHolder) {
|
|
final FunctionViewHolder holder = (FunctionViewHolder) viewHolder;
|
|
DisplayMetrics outMetrics = new DisplayMetrics();
|
|
fragmentActivity.getWindowManager().getDefaultDisplay()
|
|
.getMetrics(outMetrics);
|
|
LayoutParams rparams = new LayoutParams(
|
|
DisplayUtils.dip2px(fragmentActivity, 140),
|
|
DisplayUtils.dip2px(fragmentActivity, 140));
|
|
rparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
|
|
rparams.topMargin = outMetrics.widthPixels / 5;
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
|
Rect frame = new Rect();
|
|
fragmentActivity.getWindow().getDecorView()
|
|
.getWindowVisibleDisplayFrame(frame);
|
|
rparams.topMargin -= frame.top;
|
|
}
|
|
holder.me_iv_icon.setLayoutParams(rparams);
|
|
int downloadSize = DownloadManager.getInstance(fragmentActivity)
|
|
.getAll().size();
|
|
int updateSize = PackageManager.getUpdateList().size();
|
|
if (downloadSize == 0) {
|
|
holder.me_tv_download.setVisibility(View.GONE);
|
|
} else {
|
|
holder.me_tv_download.setVisibility(View.VISIBLE);
|
|
holder.me_tv_download.setText("" + downloadSize);
|
|
}
|
|
if (updateSize == 0) {
|
|
holder.me_tv_update.setVisibility(View.GONE);
|
|
} else {
|
|
holder.me_tv_update.setVisibility(View.VISIBLE);
|
|
holder.me_tv_update.setText("" + updateSize);
|
|
}
|
|
} else if (viewHolder instanceof MultiFunctionViewHolder) {
|
|
MultiFunctionViewHolder holder = (MultiFunctionViewHolder) viewHolder;
|
|
if (isNetworkError) {
|
|
holder.personal_progressbar.setVisibility(View.GONE);
|
|
holder.personal_loading.setText("加载失败,点击重试");
|
|
holder.rootView.setClickable(true);
|
|
holder.rootView.setOnClickListener(new OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
reload();
|
|
}
|
|
});
|
|
} else {
|
|
holder.personal_progressbar.setVisibility(View.VISIBLE);
|
|
holder.personal_loading.setText("加载中...");
|
|
holder.rootView.setClickable(false);
|
|
if (isLoading) {
|
|
holder.personal_ll_loading.setVisibility(View.VISIBLE);
|
|
holder.personal_tv_none.setVisibility(View.GONE);
|
|
holder.personal_rl_label.setVisibility(View.GONE);
|
|
} else if (gameDetailedList.isEmpty()) {
|
|
holder.personal_ll_loading.setVisibility(View.GONE);
|
|
holder.personal_tv_none.setVisibility(View.VISIBLE);
|
|
holder.personal_rl_label.setVisibility(View.GONE);
|
|
} else {
|
|
holder.personal_ll_loading.setVisibility(View.GONE);
|
|
holder.personal_tv_none.setVisibility(View.GONE);
|
|
holder.personal_rl_label.setVisibility(View.VISIBLE);
|
|
}
|
|
}
|
|
} else if (viewHolder instanceof MyGameViewHolder) {
|
|
final MyGameViewHolder holder = (MyGameViewHolder) viewHolder;
|
|
|
|
final GameEntity entity = gameDetailedList.get(position - 2);
|
|
|
|
holder.gameName.setText(entity.getName());
|
|
ImageUtils.getInstance(fragmentActivity).display(entity.getIcon(),
|
|
holder.gameIco);
|
|
holder.gameDetail.setText(entity.getBrief());
|
|
|
|
Boolean isShow = isShowMap.get(position);
|
|
if (isShow != null && isShow.booleanValue()) {
|
|
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
|
LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(
|
|
fragmentActivity, 136));
|
|
holder.mygame_ll.setLayoutParams(lparams);
|
|
holder.mygame_rv_show.setVisibility(View.VISIBLE);
|
|
holder.gameBtn.setText("收起");
|
|
} else {
|
|
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
|
LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(
|
|
fragmentActivity, 66));
|
|
holder.mygame_ll.setLayoutParams(lparams);
|
|
holder.mygame_rv_show.setVisibility(View.GONE);
|
|
holder.gameBtn.setText("打开");
|
|
}
|
|
|
|
ArrayList<String> list = sortedList.get(position - 2)
|
|
.getPackageList();
|
|
if (list != null) {
|
|
ArrayList<ApkEntity> platformList = new ArrayList<ApkEntity>();
|
|
GameEntity gameInfoEntity = gameDetailedList.get(position - 2);
|
|
for (int i = 0, size = list.size(); i < size; i++) {
|
|
String packageName = list.get(i);
|
|
for (ApkEntity apkEntity : gameInfoEntity.getApk()) {
|
|
if (packageName.equals(apkEntity.getPackageName())) {
|
|
platformList.add(apkEntity);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < platformList.size(); i++) {
|
|
String platformName = PlatformUtils.getInstance(
|
|
fragmentActivity).getPlatformName(
|
|
platformList.get(i).getPlatform());
|
|
if (platformName == null) {
|
|
platformList.remove(i);
|
|
i--;
|
|
}
|
|
}
|
|
((PlatformViewAdapter) holder.mygame_rv_show.getAdapter())
|
|
.setList(platformList, entity, position);
|
|
|
|
if (platformList.size() == 1) {
|
|
PackageManager mPackageManager = new PackageManager(
|
|
fragmentActivity);
|
|
if (entity.getTag() != null
|
|
&& entity.getTag().size() != 0
|
|
&& !mPackageManager.isSignature(platformList.get(0)
|
|
.getPackageName())) {
|
|
holder.gameBtn.setText("插件化");
|
|
} else {
|
|
holder.gameBtn.setText("启动");
|
|
}
|
|
}
|
|
|
|
String url = null;
|
|
for (int i = 0, size = platformList.size(); i < size; i++) {
|
|
url = platformList.get(i).getUrl();
|
|
if (DownloadManager.getInstance(fragmentActivity).get(url) != null) {
|
|
locationMap.put(url, position);
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
ApkEntity mApkEntity = null;
|
|
GameEntity gameInfoEntity = gameDetailedList.get(position - 2);
|
|
String packageName = sortedList.get(position - 2)
|
|
.getPackage_name();
|
|
for (ApkEntity apkEntity : gameInfoEntity.getApk()) {
|
|
if (packageName.equals(apkEntity.getPackageName())) {
|
|
mApkEntity = apkEntity;
|
|
break;
|
|
}
|
|
}
|
|
if (mApkEntity != null) {
|
|
PackageManager mPackageManager = new PackageManager(
|
|
fragmentActivity);
|
|
if (entity.getTag() != null
|
|
&& entity.getTag().size() != 0
|
|
&& !mPackageManager.isSignature(mApkEntity
|
|
.getPackageName())) {
|
|
holder.gameBtn.setText("插件化");
|
|
ArrayList<ApkEntity> platformList = new ArrayList<ApkEntity>();
|
|
platformList.add(mApkEntity);
|
|
((PlatformViewAdapter) holder.mygame_rv_show
|
|
.getAdapter()).setList(platformList, entity,
|
|
position);
|
|
|
|
String url = null;
|
|
for (int i = 0, size = platformList.size(); i < size; i++) {
|
|
url = platformList.get(i).getUrl();
|
|
if (DownloadManager.getInstance(fragmentActivity)
|
|
.get(url) != null) {
|
|
locationMap.put(url, position);
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
holder.gameBtn.setText("启动");
|
|
}
|
|
}
|
|
}
|
|
recyclerViewMap.put(position, holder.mygame_rv_show);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
if (i == 0) {
|
|
return new FunctionViewHolder(LayoutInflater.from(
|
|
viewGroup.getContext()).inflate(
|
|
R.layout.home3_fragment_function, viewGroup, false));
|
|
} else if (i == 1) {
|
|
return new MultiFunctionViewHolder(LayoutInflater.from(
|
|
viewGroup.getContext()).inflate(
|
|
R.layout.personal_footer_none_head, viewGroup, false));
|
|
} else {
|
|
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
|
R.layout.mygame_item, viewGroup, false);
|
|
view.setTag(i);
|
|
return new MyGameViewHolder(view);
|
|
}
|
|
}
|
|
|
|
public class FunctionViewHolder extends ViewHolder implements
|
|
OnClickListener {
|
|
|
|
private TextView me_tv_download, me_tv_update;
|
|
private ImageView me_iv_icon;
|
|
|
|
public FunctionViewHolder(View convertView) {
|
|
super(convertView);
|
|
|
|
convertView.findViewById(R.id.me_ll_concern).setOnClickListener(this);
|
|
convertView.findViewById(R.id.me_ll_download).setOnClickListener(this);
|
|
convertView.findViewById(R.id.me_ll_setting).setOnClickListener(this);
|
|
convertView.findViewById(R.id.me_ll_update).setOnClickListener(this);
|
|
me_tv_download = (TextView) convertView.findViewById(R.id.me_tv_download);
|
|
me_tv_update = (TextView) convertView.findViewById(R.id.me_tv_update);
|
|
me_iv_icon = (ImageView) convertView.findViewById(R.id.me_iv_icon);
|
|
me_iv_icon.setOnClickListener(this);
|
|
if (Config.isShow) {
|
|
convertView.findViewById(R.id.me_ll_download).setVisibility(View.VISIBLE);
|
|
convertView.findViewById(R.id.me_ll_update).setVisibility(View.VISIBLE);
|
|
} else {
|
|
convertView.findViewById(R.id.me_ll_download).setVisibility(View.GONE);
|
|
convertView.findViewById(R.id.me_ll_update).setVisibility(View.GONE);
|
|
}
|
|
// me_tv_nickname = (TextView) convertView.findViewById(R.id.me_tv_nickname);
|
|
// me_tv_sign = (TextView) convertView.findViewById(R.id.me_tv_sign);
|
|
// me_cutting_line = convertView.findViewById(R.id.me_cutting_line);
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
final int id = v.getId();
|
|
if (id == R.id.me_ll_concern) {
|
|
DataUtils.onEvent(fragmentActivity, "我的光环", "我的关注");
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "我的关注");
|
|
map.put("createOn", System.currentTimeMillis() / 1000);
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity, "click-item",
|
|
map);
|
|
|
|
fragmentActivity.startActivity(new Intent(fragmentActivity,
|
|
ConcernActivity.class));
|
|
} else if (id == R.id.me_ll_download) {
|
|
DataUtils.onEvent(fragmentActivity, "我的光环", "下载管理");
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "下载管理");
|
|
map.put("createOn", System.currentTimeMillis() / 1000);
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity, "click-item",
|
|
map);
|
|
|
|
me_tv_download.setVisibility(View.GONE);
|
|
Intent downloadIntent = new Intent(fragmentActivity,
|
|
DownloadManagerActivity.class);
|
|
downloadIntent.putExtra("currentItem", 0);
|
|
fragmentActivity.startActivity(downloadIntent);
|
|
} else if (id == R.id.me_ll_setting) {
|
|
DataUtils.onEvent(fragmentActivity, "我的光环", "设置");
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "设置");
|
|
map.put("createOn", System.currentTimeMillis() / 1000);
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity, "click-item",
|
|
map);
|
|
|
|
fragmentActivity.startActivity(new Intent(fragmentActivity,
|
|
SettingActivity.class));
|
|
} else if (id == R.id.me_ll_update) {
|
|
DataUtils.onEvent(fragmentActivity, "我的光环", "更新管理");
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "更新管理");
|
|
map.put("createOn", System.currentTimeMillis() / 1000);
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity, "click-item",
|
|
map);
|
|
|
|
me_tv_update.setVisibility(View.GONE);
|
|
Intent updateIntent = new Intent(fragmentActivity,
|
|
DownloadManagerActivity.class);
|
|
updateIntent.putExtra("currentItem", 1);
|
|
fragmentActivity.startActivity(updateIntent);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private DataWatcher dataWatcher = new DataWatcher() {
|
|
@Override
|
|
public void onDataChanged(
|
|
HashMap<String, DownloadEntry> downloadingEntries) {
|
|
for (Entry<String, DownloadEntry> entry : downloadingEntries
|
|
.entrySet()) {
|
|
DownloadEntry downloadEntry = entry.getValue();
|
|
Integer location = locationMap.get(downloadEntry.getUrl());
|
|
if (location != null) {
|
|
int position = location.intValue();
|
|
RecyclerView recyclerView = recyclerViewMap.get(position);
|
|
if (recyclerView != null) {
|
|
PlatformViewAdapter adapter = (PlatformViewAdapter) recyclerView
|
|
.getAdapter();
|
|
ArrayList<ApkEntity> list = adapter.getList();
|
|
if (list != null) {
|
|
String paltform = downloadEntry.getMeta().get(
|
|
"platform");
|
|
for (int i = 0, size = list.size(); i < size; i++) {
|
|
if (list.get(i).getPlatform().equals(paltform)) {
|
|
String status = statusMap.get(downloadEntry
|
|
.getUrl());
|
|
if (!"pause".equals(status)) {
|
|
adapter.notifyItemChanged(i);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
public DataWatcher getDataWatcher() {
|
|
return dataWatcher;
|
|
}
|
|
|
|
public class MultiFunctionViewHolder extends ViewHolder {
|
|
|
|
private LinearLayout personal_ll_loading;
|
|
private TextView personal_tv_none;
|
|
private RelativeLayout personal_rl_label;
|
|
private ContentLoadingProgressBar personal_progressbar;
|
|
private TextView personal_loading;
|
|
private View rootView;
|
|
|
|
public MultiFunctionViewHolder(View convertView) {
|
|
super(convertView);
|
|
|
|
rootView = convertView;
|
|
personal_ll_loading = (LinearLayout) convertView
|
|
.findViewById(R.id.personal_ll_loading);
|
|
personal_tv_none = (TextView) convertView
|
|
.findViewById(R.id.personal_tv_none);
|
|
personal_rl_label = (RelativeLayout) convertView
|
|
.findViewById(R.id.personal_rl_label);
|
|
personal_progressbar = (ContentLoadingProgressBar) convertView
|
|
.findViewById(R.id.personal_progressbar);
|
|
personal_loading = (TextView) convertView
|
|
.findViewById(R.id.personal_loading);
|
|
}
|
|
|
|
}
|
|
|
|
public class MyGameViewHolder extends ViewHolder implements
|
|
OnClickListener {
|
|
|
|
public ImageView gameIco;
|
|
public TextView gameName;
|
|
public TextView gameDetail;
|
|
public TextView gameBtn;
|
|
public RecyclerView mygame_rv_show;
|
|
public LinearLayout mygame_rl_info;
|
|
|
|
public MyGame_LinearLayout rootItem;
|
|
|
|
public LinearLayout mygame_ll;
|
|
|
|
public MyGameViewHolder(View v) {
|
|
super(v);
|
|
rootItem = (MyGame_LinearLayout) v;
|
|
gameIco = (ImageView) v.findViewById(R.id.mygame_game_thumb);
|
|
gameName = (TextView) v.findViewById(R.id.mygame_game_name);
|
|
gameDetail = (TextView) v.findViewById(R.id.mygame_game_detail);
|
|
gameBtn = (TextView) v.findViewById(R.id.mygame_game_btn);
|
|
gameBtn.setOnClickListener(this);
|
|
mygame_rl_info = (LinearLayout) v.findViewById(R.id.mygame_rl_info);
|
|
mygame_rl_info.setOnClickListener(this);
|
|
|
|
mygame_ll = (LinearLayout) v.findViewById(R.id.mygame_ll);
|
|
|
|
mygame_rv_show = (RecyclerView) v.findViewById(R.id.mygame_rv_show);
|
|
mygame_rv_show.setHasFixedSize(true);
|
|
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(
|
|
fragmentActivity);
|
|
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
mygame_rv_show.setLayoutManager(linearLayoutManager);
|
|
|
|
mygame_rv_show.setAdapter(new PlatformViewAdapter());
|
|
mygame_rv_show.addItemDecoration(new HorizontalItemDecoration(
|
|
fragmentActivity, 6, mygame_rv_show.getAdapter()
|
|
.getItemCount()));
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
int position = getPosition();
|
|
if (v == mygame_rl_info) {
|
|
GameEntity entity = gameDetailedList.get(position - 2);
|
|
Map<String, Object> kv = new HashMap<String, Object>();
|
|
kv.put("入口", "我的光环-我的游戏");
|
|
DataUtils.onEvent(fragmentActivity, "游戏详情", entity.getName(), kv);
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "我的游戏");
|
|
map.put("createOn", System.currentTimeMillis() / 1000);
|
|
map.put("game", entity.getName());
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity, "click-item",
|
|
map);
|
|
|
|
AppController.put("GameEntity", entity);
|
|
Intent intent = new Intent(fragmentActivity,
|
|
GameDetailsActivity.class);
|
|
intent.putExtra("entrance", "我的光环-我的游戏");
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
fragmentActivity.startActivity(intent);
|
|
} else if (v == gameBtn) {
|
|
String str = gameBtn.getText().toString();
|
|
GameEntity entity = gameDetailedList.get(position - 2);
|
|
MyGameInfo gameInfo = sortedList.get(position - 2);
|
|
if ("启动".equals(str)) {
|
|
String packageName = null;
|
|
if (gameInfo.getPackageList() == null) {
|
|
packageName = gameInfo.getPackage_name();
|
|
} else {
|
|
packageName = gameInfo.getPackageList().get(0);
|
|
}
|
|
Map<String, Object> kv = new HashMap<String, Object>();
|
|
for (ApkEntity apkEntity : entity.getApk()) {
|
|
if (packageName.equals(apkEntity.getPackageName())) {
|
|
kv.put("版本", apkEntity.getPlatform());
|
|
break;
|
|
}
|
|
}
|
|
DataUtils.onEvent(fragmentActivity, "游戏启动", entity.getName(),
|
|
kv);
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "我的游戏-游戏启动");
|
|
map.put("createOn", System.currentTimeMillis() / 1000);
|
|
map.put("game", entity.getName());
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity,
|
|
"click-item", map);
|
|
|
|
PackageUtils.launchApplicationByPackageName(
|
|
fragmentActivity, packageName);
|
|
} else if ("打开".equals(str)) {
|
|
if (oldClickViewPosition != position
|
|
&& oldClickViewPosition != -1) {
|
|
if (((LinearLayoutManager) gameRecyclerView
|
|
.getLayoutManager())
|
|
.findViewByPosition(oldClickViewPosition) != null) {
|
|
((MyGame_LinearLayout) ((LinearLayoutManager) gameRecyclerView
|
|
.getLayoutManager())
|
|
.findViewByPosition(oldClickViewPosition))
|
|
.hideRecyclerView();
|
|
}
|
|
isShowMap.put(oldClickViewPosition, false);
|
|
}
|
|
rootItem.showRecyclerView(position);
|
|
isShowMap.put(position, true);
|
|
oldClickViewPosition = position;
|
|
gameBtn.setText("收起");
|
|
} else if ("收起".equals(str)) {
|
|
rootItem.hideRecyclerView();
|
|
isShowMap.put(position, false);
|
|
oldClickViewPosition = -1;
|
|
gameBtn.setText("打开");
|
|
} else if ("插件化".equals(str)) {
|
|
if (mygame_rv_show.getVisibility() == View.VISIBLE) {
|
|
rootItem.hideRecyclerView();
|
|
isShowMap.put(position, false);
|
|
oldClickViewPosition = -1;
|
|
} else {
|
|
if (oldClickViewPosition != position
|
|
&& oldClickViewPosition != -1) {
|
|
View view = ((LinearLayoutManager) gameRecyclerView
|
|
.getLayoutManager())
|
|
.findViewByPosition(oldClickViewPosition);
|
|
if (view != null) {
|
|
((MyGame_LinearLayout) view).hideRecyclerView();
|
|
((TextView) view
|
|
.findViewById(R.id.mygame_game_btn))
|
|
.setText("打开");
|
|
}
|
|
isShowMap.put(oldClickViewPosition, false);
|
|
}
|
|
rootItem.showRecyclerView(position);
|
|
isShowMap.put(position, true);
|
|
oldClickViewPosition = position;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private class PlatformViewHolder extends ViewHolder {
|
|
|
|
private TextView platform_item_tv_hint, platform_item_tv_name,
|
|
platform_item_tv_status;
|
|
private ImageView platform_item_iv_pic;
|
|
private View view;
|
|
private ProgressBar platform_item_progressbar;
|
|
|
|
public PlatformViewHolder(View convertView) {
|
|
super(convertView);
|
|
view = convertView;
|
|
platform_item_iv_pic = (ImageView) convertView
|
|
.findViewById(R.id.platform_item_iv_pic);
|
|
platform_item_tv_hint = (TextView) convertView
|
|
.findViewById(R.id.platform_item_tv_hint);
|
|
platform_item_tv_name = (TextView) convertView
|
|
.findViewById(R.id.platform_item_tv_name);
|
|
platform_item_tv_status = (TextView) convertView
|
|
.findViewById(R.id.platform_item_tv_status);
|
|
platform_item_progressbar = (ProgressBar) convertView
|
|
.findViewById(R.id.platform_item_progressbar);
|
|
}
|
|
|
|
}
|
|
|
|
private class PlatformViewAdapter extends
|
|
RecyclerView.Adapter<PlatformViewHolder> {
|
|
|
|
private ArrayList<ApkEntity> pList;
|
|
private GameEntity gEntity;
|
|
private int mLocation;
|
|
|
|
public void setList(ArrayList<ApkEntity> list, GameEntity entity,
|
|
int position) {
|
|
pList = list;
|
|
gEntity = entity;
|
|
mLocation = position;
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
public ArrayList<ApkEntity> getList() {
|
|
return pList;
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
if (pList == null) {
|
|
return 0;
|
|
}
|
|
return pList.size();
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(final PlatformViewHolder viewHolder,
|
|
int location) {
|
|
int id = PlatformUtils.getInstance(fragmentActivity)
|
|
.getPlatformPic(pList.get(location).getPlatform());
|
|
if (id != 0) {
|
|
viewHolder.platform_item_iv_pic.setVisibility(View.VISIBLE);
|
|
viewHolder.platform_item_iv_pic.setImageResource(id);
|
|
viewHolder.platform_item_tv_hint.setVisibility(View.GONE);
|
|
} else {
|
|
String path = PlatformUtils.getInstance(fragmentActivity)
|
|
.getPlatformPicPath(pList.get(location).getPlatform());
|
|
if (path != null) {
|
|
viewHolder.platform_item_iv_pic.setVisibility(View.VISIBLE);
|
|
ImageUtils.getInstance(fragmentActivity).display(
|
|
"file://" + path, viewHolder.platform_item_iv_pic);
|
|
viewHolder.platform_item_tv_hint.setVisibility(View.GONE);
|
|
} else {
|
|
viewHolder.platform_item_tv_hint
|
|
.setVisibility(View.VISIBLE);
|
|
viewHolder.platform_item_tv_hint.setText(PlatformUtils
|
|
.getInstance(fragmentActivity).getPlatformName(
|
|
pList.get(location).getPlatform()));
|
|
viewHolder.platform_item_iv_pic.setVisibility(View.GONE);
|
|
}
|
|
}
|
|
viewHolder.view.setOnClickListener(new OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
if (viewHolder.platform_item_iv_pic.getVisibility() == View.VISIBLE) {
|
|
Map<String, Object> kv = new HashMap<String, Object>();
|
|
kv.put("版本", pList.get(viewHolder.getPosition()).getPlatform());
|
|
DataUtils.onEvent(fragmentActivity, "游戏启动", gEntity.getName(), kv);
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "我的游戏-游戏启动");
|
|
map.put("createOn", System.currentTimeMillis() / 1000);
|
|
map.put("game", gEntity.getName());
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity,
|
|
"click-item", map);
|
|
|
|
PackageUtils.launchApplicationByPackageName(
|
|
fragmentActivity, pList.get(viewHolder.getPosition())
|
|
.getPackageName());
|
|
} else {
|
|
String str = viewHolder.platform_item_tv_status
|
|
.getText().toString();
|
|
ApkEntity apkEntity = pList.get(viewHolder.getPosition());
|
|
if ("插件化".equals(str)) {
|
|
// 下载插件版游戏
|
|
String msg = FileUtils.isCanDownload(apkEntity
|
|
.getSize());
|
|
if (TextUtils.isEmpty(msg)) {
|
|
Map<String, Object> kv = new HashMap<String, Object>();
|
|
kv.put("版本", apkEntity.getPlatform());
|
|
kv.put("状态", "下载开始");
|
|
DataUtils.onEvent(fragmentActivity, "游戏下载",
|
|
gEntity.getName(), kv);
|
|
|
|
Map<String, Object> kv2 = new HashMap<String, Object>();
|
|
kv2.put("版本", apkEntity.getPlatform());
|
|
kv2.put("状态", "下载开始");
|
|
kv2.put("位置", "我的关注-开始");
|
|
DataUtils.onEvent(fragmentActivity, "游戏下载位置",
|
|
gEntity.getName(), kv2);
|
|
|
|
Map<String, Object> kv3 = new HashMap<String, Object>();
|
|
kv3.put("我的关注", "下载数");
|
|
kv3.put("我的关注", "下载开始");
|
|
DataUtils.onEvent(fragmentActivity, "应用数据",
|
|
gEntity.getName(), kv3);
|
|
|
|
Map<String, Object> kv6 = new HashMap<String, Object>();
|
|
kv6.put("下载", "下载开始");
|
|
kv6.put("版本", apkEntity.getPlatform());
|
|
DataUtils.onEvent(fragmentActivity, "插件化",
|
|
gEntity.getName(), kv6);
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "我的游戏-插件化");
|
|
map.put("createOn",
|
|
System.currentTimeMillis() / 1000);
|
|
map.put("game", gEntity.getName());
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity,
|
|
"click-item", map);
|
|
|
|
DownloadEntry entry = new DownloadEntry();
|
|
|
|
entry.setUrl(apkEntity.getUrl());
|
|
entry.setName(gEntity.getName());
|
|
entry.setPath(FileUtils.getDownloadPath(
|
|
fragmentActivity,
|
|
MD5Utils.getContentMD5(gEntity
|
|
.getName()
|
|
+ "_"
|
|
+ System.currentTimeMillis())
|
|
+ ".apk"));
|
|
HashMap<String, String> meta = new HashMap<String, String>();
|
|
meta.put("ETag", apkEntity.getEtag());
|
|
meta.put("icon", gEntity.getIcon());
|
|
meta.put(
|
|
"platform", apkEntity.getPlatform());
|
|
meta.put("gameId", gEntity.getId());
|
|
meta.put("entrance", "我的关注");
|
|
meta.put("isPlugin", "true");
|
|
meta.put("package_name",
|
|
apkEntity.getPackageName());
|
|
meta.put("size", apkEntity.getSize());
|
|
meta.put("version", apkEntity.getVersion());
|
|
meta.put("gh_version", apkEntity.getGhVersion());
|
|
entry.setMeta(meta);
|
|
|
|
DownloadManager.getInstance(fragmentActivity)
|
|
.add(entry);
|
|
|
|
EventBus.getDefault().post(new EBRedDot(1));
|
|
|
|
GameUpdateEntity game = new GameUpdateEntity(
|
|
gEntity.getId(), gEntity.getName(),
|
|
gEntity.getIcon(), apkEntity
|
|
.getPackageName(), apkEntity
|
|
.getSize(), apkEntity
|
|
.getVersion(), apkEntity
|
|
.getGhVersion(), apkEntity
|
|
.getUrl(), apkEntity
|
|
.getPlatform(), true);
|
|
PackageManager.addUpdate(game);
|
|
|
|
locationMap.put(apkEntity.getUrl(), mLocation);
|
|
|
|
statusMap.put(entry.getUrl(), "downloading");
|
|
} else {
|
|
Toast.makeText(fragmentActivity, msg,
|
|
Toast.LENGTH_SHORT).show();
|
|
}
|
|
} else if ("插件化中".equals(str)) {
|
|
// 暂停下载
|
|
statusMap.put(apkEntity.getUrl(), "pause");
|
|
|
|
viewHolder.platform_item_tv_status.setText("继续");
|
|
DownloadManager.getInstance(fragmentActivity)
|
|
.pause(apkEntity.getUrl());
|
|
|
|
Message msg = Message.obtain();
|
|
msg.what = Constants.PAUSE_DOWNLOAD_TASK;
|
|
msg.obj = apkEntity.getUrl();
|
|
DownloadManager.getInstance(fragmentActivity).put(apkEntity.getUrl(),
|
|
System.currentTimeMillis());
|
|
DownloadManager.getInstance(fragmentActivity).sendMessageDelayed(msg, 1000);
|
|
} else if ("插件化安装".equals(str)) {
|
|
// 安装插件
|
|
showPluginDialog(apkEntity, gEntity.getName(),
|
|
PlatformViewAdapter.this, viewHolder.getPosition());
|
|
} else if ("等待".equals(str)) {
|
|
Toast.makeText(fragmentActivity, "最多同时有3个下载任务",
|
|
Toast.LENGTH_SHORT).show();
|
|
} else {
|
|
// 继续下载
|
|
statusMap.put(apkEntity.getUrl(), "downloading");
|
|
|
|
viewHolder.platform_item_tv_status.setText("插件化中");
|
|
DownloadManager.getInstance(fragmentActivity)
|
|
.resume(apkEntity.getUrl());
|
|
|
|
Message msg = Message.obtain();
|
|
msg.what = Constants.CONTINUE_DOWNLOAD_TASK;
|
|
msg.obj = apkEntity.getUrl();
|
|
DownloadManager.getInstance(fragmentActivity).put(apkEntity.getUrl(),
|
|
System.currentTimeMillis());
|
|
DownloadManager.getInstance(fragmentActivity).sendMessageDelayed(msg, 1000);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
viewHolder.view.setBackgroundDrawable(null);
|
|
viewHolder.view.setPadding(0, 0, 0, 0);
|
|
|
|
PackageManager mPackageManager = new PackageManager(
|
|
fragmentActivity);
|
|
if (!mPackageManager.isSignature(pList.get(location)
|
|
.getPackageName())) {
|
|
viewHolder.platform_item_iv_pic.setVisibility(View.GONE);
|
|
viewHolder.platform_item_tv_hint.setVisibility(View.GONE);
|
|
|
|
viewHolder.platform_item_tv_name.setVisibility(View.VISIBLE);
|
|
viewHolder.platform_item_tv_status.setVisibility(View.VISIBLE);
|
|
viewHolder.platform_item_progressbar
|
|
.setVisibility(View.VISIBLE);
|
|
viewHolder.platform_item_progressbar.setProgress(1000);
|
|
|
|
int color = Color.parseColor(PlatformUtils.getInstance(
|
|
fragmentActivity).getPlatformColor(
|
|
pList.get(location).getPlatform()));
|
|
GradientDrawable gradientDrawable = new GradientDrawable();
|
|
gradientDrawable.setColor(0xffffffff);
|
|
gradientDrawable.setStroke(
|
|
DisplayUtils.dip2px(fragmentActivity, 1), color);
|
|
int padding = DisplayUtils.dip2px(fragmentActivity, 1);
|
|
viewHolder.view.setPadding(padding, padding, padding, padding);
|
|
viewHolder.view.setBackgroundDrawable(gradientDrawable);
|
|
viewHolder.platform_item_tv_name.setTextColor(color);
|
|
String paltform = PlatformUtils.getInstance(fragmentActivity)
|
|
.getPlatformName(pList.get(location).getPlatform());
|
|
viewHolder.platform_item_tv_name.setText(paltform);
|
|
viewHolder.platform_item_tv_status.setText("插件化");
|
|
Drawable[] layers = new Drawable[2];
|
|
GradientDrawable drawable = new GradientDrawable();
|
|
drawable.setColor(0xFFDCDCDC);
|
|
layers[0] = drawable;
|
|
ClipDrawable clipDrawable = new ClipDrawable(new ColorDrawable(
|
|
color), Gravity.LEFT, ClipDrawable.HORIZONTAL);
|
|
layers[1] = clipDrawable;
|
|
LayerDrawable layerDrawable = new LayerDrawable(layers);
|
|
layerDrawable.setId(0, android.R.id.background);
|
|
layerDrawable.setId(1, android.R.id.progress);
|
|
viewHolder.platform_item_progressbar
|
|
.setProgressDrawable(layerDrawable);
|
|
}
|
|
|
|
DownloadEntry downloadEntry = DownloadManager.getInstance(
|
|
fragmentActivity).get(pList.get(location).getUrl());
|
|
if (downloadEntry != null) {
|
|
viewHolder.platform_item_progressbar
|
|
.setProgress((int) (downloadEntry.getPercent() * 10));
|
|
switch (downloadEntry.getStatus()) {
|
|
case pause:
|
|
case timeout:
|
|
case neterror:
|
|
viewHolder.platform_item_tv_status.setText("继续");
|
|
break;
|
|
case downloading:
|
|
if (!"pause".equals(statusMap.get(downloadEntry.getUrl()))) {
|
|
viewHolder.platform_item_tv_status.setText("插件化中");
|
|
}
|
|
break;
|
|
case done:
|
|
EventBus.getDefault().post(
|
|
new EBPutUrl(PackageUtils.getPackageNameByPath(
|
|
fragmentActivity, downloadEntry.getPath()),
|
|
downloadEntry.getUrl()));
|
|
viewHolder.platform_item_tv_status.setText("插件化安装");
|
|
break;
|
|
case waiting:
|
|
viewHolder.platform_item_tv_status.setText("等待");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getItemViewType(int position) {
|
|
|
|
return position;
|
|
}
|
|
|
|
@Override
|
|
public PlatformViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
|
R.layout.mygame_platform_item, viewGroup, false);
|
|
DisplayMetrics outMetrics = new DisplayMetrics();
|
|
fragmentActivity.getWindowManager().getDefaultDisplay()
|
|
.getMetrics(outMetrics);
|
|
int width = (outMetrics.widthPixels - DisplayUtils.dip2px(
|
|
fragmentActivity, 30)) / 3;
|
|
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width,
|
|
LayoutParams.WRAP_CONTENT);
|
|
view.setLayoutParams(params);
|
|
return new PlatformViewHolder(view);
|
|
}
|
|
}
|
|
|
|
// 显示插件化
|
|
private void showPluginDialog(final ApkEntity apkEntity,
|
|
final String gameName, final PlatformViewAdapter adapter,
|
|
final int location) {
|
|
DialogUtils.showPluginDialog(fragmentActivity, new DialogUtils.ConfiremListener() {
|
|
@Override
|
|
public void onConfirem() {
|
|
Map<String, Object> kv6 = new HashMap<String, Object>();
|
|
kv6.put("操作", "点击插件化安装完成");
|
|
DataUtils.onEvent(fragmentActivity, "插件化", gameName, kv6);
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
map.put("location", "我的游戏-插件化安装");
|
|
map.put("createOn", System.currentTimeMillis() / 1000);
|
|
map.put("game", gameName);
|
|
map.put("page", "我的光环");
|
|
DataCollectionManager.onEvent(fragmentActivity, "click-item", map);
|
|
|
|
String path = DownloadManager.getInstance(fragmentActivity).get(apkEntity.getUrl()).getPath();
|
|
if (FileUtils.isEmptyFile(path)) {
|
|
Toast.makeText(fragmentActivity, "解析包错误", Toast.LENGTH_SHORT).show();
|
|
DownloadManager.getInstance(fragmentActivity).cancel(apkEntity.getUrl());
|
|
adapter.notifyItemChanged(location);
|
|
} else {
|
|
MainActivity.uninstallMap.put(PackageUtils.getPackageNameByPath(fragmentActivity, path), path);
|
|
fragmentActivity.startActivity(PackageUtils.getUninstallIntent(fragmentActivity, path));
|
|
}
|
|
}
|
|
}, null);
|
|
}
|
|
|
|
public void updateItem(EBDownloadDelete busThree) {
|
|
notifyItemChanged(0);
|
|
Integer location = locationMap.get(busThree.getUrl());
|
|
if (location != null) {
|
|
int position = location.intValue();
|
|
RecyclerView recyclerView = recyclerViewMap.get(position);
|
|
if (recyclerView != null) {
|
|
notifyItemChanged(position);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void clearStatusMap() {
|
|
statusMap.clear();
|
|
}
|
|
|
|
public boolean isNetworkError() {
|
|
return isNetworkError;
|
|
}
|
|
|
|
public void setNetworkError(boolean isNetworkError) {
|
|
this.isNetworkError = isNetworkError;
|
|
}
|
|
|
|
public void hidePlatformView() {
|
|
if (isShowMap.size() != 0) {
|
|
isShowMap.clear();
|
|
notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
public void reload() {
|
|
isNetworkError = false;
|
|
notifyItemChanged(getItemCount() - 1);
|
|
gameDetailedList.clear();
|
|
isShowMap.clear();
|
|
new Thread(runnable).start();
|
|
}
|
|
|
|
// 卸载则移除列表中数据
|
|
public void delete(String packageName) {
|
|
hidePlatformView();
|
|
for (int i = 0, size = sortedList.size(); i < size; i++) {
|
|
boolean flag = false;
|
|
List<String> list = sortedList.get(i).getPackageList();
|
|
if (list != null) {
|
|
for (int j = 0; j < list.size(); j++) {
|
|
if (packageName.equals(list.get(j))) {
|
|
flag = true;
|
|
list.remove(j);
|
|
if (list.size() == 1) {
|
|
sortedList.get(i).setPackage_name(list.get(0));
|
|
sortedList.get(i).setPackageList(null);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
} else if (packageName.equals(sortedList.get(i).getPackage_name())) {
|
|
flag = true;
|
|
}
|
|
if (flag) {
|
|
if (list == null || list.isEmpty()) {
|
|
sortedList.remove(i);
|
|
gameDetailedList.remove(i);
|
|
notifyItemRemoved(i + 2);
|
|
break;
|
|
} else {
|
|
notifyItemChanged(i + 2);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
// 安装则获取疑似表,更新游戏列表
|
|
public void install(final String packageName) {
|
|
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
|
TimestampUtils.addTimestamp(Config.HOST
|
|
+ "v1d45/support/package/" + packageName
|
|
+ "/game/digest", Constants.GAME_CD),
|
|
new Response.Listener<JSONObject>() {
|
|
|
|
@Override
|
|
public void onResponse(JSONObject response) {
|
|
if (response.length() != 0) {
|
|
Gson gson = new Gson();
|
|
GameDigestEntity gameDigestEntity = gson.fromJson(
|
|
response.toString(), GameDigestEntity.class);
|
|
|
|
ConcernManager manager = new ConcernManager(
|
|
fragmentActivity);
|
|
GameInfo gameEntity = new GameInfo();
|
|
gameEntity.setId(gameDigestEntity.getId());
|
|
gameEntity.setPackageName(packageName);
|
|
manager.updateByEntity(gameEntity, false);
|
|
// 移除疑似游戏数据库中所有数据
|
|
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
|
|
fragmentActivity);
|
|
suspectedGameManager
|
|
.deleteSuspectedGame(packageName);
|
|
|
|
gameDetailedList.clear();
|
|
isShowMap.clear();
|
|
new Thread(runnable).start();
|
|
}
|
|
}
|
|
}, new Response.ErrorListener() {
|
|
|
|
@Override
|
|
public void onErrorResponse(VolleyError error) {
|
|
|
|
}
|
|
});
|
|
AppController.addToRequestQueue(request, PersonalFragment.class);
|
|
}
|
|
}
|