游戏模块,整理完成
This commit is contained in:
@ -40,11 +40,9 @@ public class DownloadItemUtils {
|
||||
public static void initializeGameMap(Context context,
|
||||
ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap) {
|
||||
gameMap.clear();
|
||||
List<DownloadEntry> list = DownloadManager.getInstance(context)
|
||||
.getAll();
|
||||
List<DownloadEntry> list = DownloadManager.getInstance(context).getAll();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
ArrayMap<String, DownloadEntry> map = gameMap.get(list.get(i)
|
||||
.getName());
|
||||
ArrayMap<String, DownloadEntry> map = gameMap.get(list.get(i).getName());
|
||||
if (map == null) {
|
||||
map = new ArrayMap<String, DownloadEntry>();
|
||||
}
|
||||
@ -147,7 +145,12 @@ public class DownloadItemUtils {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
String pluginPlatform = entity.getPluginPlatform();
|
||||
|
||||
if (downloadEntry != null && (pluginPlatform == null
|
||||
|| pluginPlatform.equals(PlatformUtils.getInstance(context)
|
||||
.getPlatformName(downloadEntry.getMeta().get("platform"))))) {
|
||||
|
||||
labelList.setVisibility(View.GONE);
|
||||
game_progressbar.setVisibility(View.VISIBLE);
|
||||
game_ll_info.setVisibility(View.VISIBLE);
|
||||
@ -304,6 +307,19 @@ public class DownloadItemUtils {
|
||||
}
|
||||
game_progressbar.setProgress((int) (downloadEntry
|
||||
.getPercent() * 10));
|
||||
} else {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
if (entity.getApk() != null) {
|
||||
if (entity.getPluginPlatform() != null) {
|
||||
downloadBtn.setText("插件化");
|
||||
} else {
|
||||
downloadBtn.setText("下载");
|
||||
}
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
@ -729,7 +745,7 @@ public class DownloadItemUtils {
|
||||
meta.put("entrance", entrance);
|
||||
meta.put("location", "游戏详情:" + game.getName());
|
||||
if (game.getPluginPlatform() != null) {
|
||||
meta.put("PluginPlatform", PlatformUtils.getInstance(context).getPlatformName(game.getApk().get(0).getPlatform()));
|
||||
meta.put("PluginPlatform", game.getPluginPlatform());
|
||||
}
|
||||
entry.setMeta(meta);
|
||||
return entry;
|
||||
|
||||
202
app/src/main/java/com/gh/gamecenter/PluginActivity.java
Normal file
202
app/src/main/java/com/gh/gamecenter/PluginActivity.java
Normal file
@ -0,0 +1,202 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.PluginAdapter;
|
||||
import com.gh.gamecenter.adapter.SubjectAdapter;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.game.Game1Fragment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/6.
|
||||
*/
|
||||
public class PluginActivity extends BaseActivity {
|
||||
|
||||
private RecyclerView plugin_list;
|
||||
private PluginAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate plugin_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (!isDestroy) {
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (adapter != null) {
|
||||
LinkedBlockingQueue<String> queue = adapter.getPlatformMap().get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
msg2.obj = name;
|
||||
msg2.what = Constants.DOWNLOAD_ROLL;
|
||||
sendMessageDelayed(msg2, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
//特殊 插件化update
|
||||
if (downloadEntry.getMeta().get("PluginPlatform") != null) {
|
||||
Integer location = adapter.getLocationMap().get(
|
||||
downloadEntry.getName() + " - " + downloadEntry.getMeta().get("PluginPlatform"));
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, adapter.getPlatformMap(), handler, adapter, index, adapter.getStatusMap());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_plugin, null);
|
||||
|
||||
init(contentView, "插件化");
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
plugin_pb_loading.setVisibility(View.VISIBLE);
|
||||
plugin_list.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new PluginAdapter(PluginActivity.this, plugin_list,
|
||||
plugin_pb_loading, reuse_no_connection);
|
||||
plugin_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
plugin_list.setHasFixedSize(true);
|
||||
plugin_list.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new PluginAdapter(this, plugin_list, plugin_pb_loading, reuse_no_connection);
|
||||
plugin_list.setAdapter(adapter);
|
||||
plugin_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (adapter != null) {
|
||||
adapter.getDismissEntity().setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
plugin_list.setVisibility(View.VISIBLE);
|
||||
plugin_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new PluginAdapter(this, plugin_list, plugin_pb_loading, reuse_no_connection);
|
||||
plugin_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
//特殊 插件化
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = adapter.getLocationMap().get(name);
|
||||
if (location != null) {
|
||||
if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) {
|
||||
List<GameEntity> list = adapter.getPluginList();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
if (list.get(i).getApk().get(0).getPackageName()
|
||||
.equals(busFour.getPackageName())) {
|
||||
list.remove(i);
|
||||
adapter.notifyItemRemoved(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int position) {
|
||||
return adapter.getPluginList().get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
adapter.getStatusMap().clear();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
//修改游戏下载状态
|
||||
DownloadItemUtils.initializeGameMap(this, adapter.getGameMap());
|
||||
for (GameEntity entity : adapter.getPluginList()) {
|
||||
entity.setEntryMap(adapter.getGameMap().get(entity.getName()));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(PluginActivity.class);
|
||||
plugin_list = null;
|
||||
adapter = null;
|
||||
plugin_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
}
|
||||
@ -3,74 +3,51 @@ package com.gh.gamecenter;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.SubjectAdapter;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class SubjectActivity extends BaseActivity {
|
||||
|
||||
private RecyclerView hotcard_list;
|
||||
private RecyclerView subject_list;
|
||||
private SubjectAdapter adapter;
|
||||
private LinearLayout hotcard_ll_loading;
|
||||
private ProgressBarCircularIndeterminate subject_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
// 黄壮华 添加 记录信息的map 修改2015/8/15
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private String id;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (!isDestroy) {
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (platformMap != null) {
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(name);
|
||||
if (adapter != null) {
|
||||
LinkedBlockingQueue<String> queue = adapter.getPlatformMap().get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
@ -86,7 +63,6 @@ public class SubjectActivity extends BaseActivity {
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
@ -94,16 +70,16 @@ public class SubjectActivity extends BaseActivity {
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
Integer location = adapter.getLocationMap().get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
int index = location;
|
||||
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter,
|
||||
index, statusMap);
|
||||
downloadEntry, adapter.getPlatformMap(), handler, adapter,
|
||||
index, adapter.getStatusMap());
|
||||
}
|
||||
|
||||
}
|
||||
@ -113,108 +89,48 @@ public class SubjectActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
String id = getIntent().getStringExtra("id");
|
||||
id = getIntent().getStringExtra("id");
|
||||
String name = getIntent().getStringExtra("name");
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
name = "";
|
||||
}
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_hotcard, null);
|
||||
View contentView = View.inflate(this, R.layout.activity_subject, null);
|
||||
|
||||
init(contentView, name);
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
|
||||
hotcard_list.setHasFixedSize(true);
|
||||
hotcard_list.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(this, gameMap);
|
||||
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new SubjectAdapter(this, platformMap, statusMap, dismissEntity);
|
||||
hotcard_list.setAdapter(adapter);
|
||||
hotcard_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
|
||||
addList(id);
|
||||
|
||||
}
|
||||
|
||||
private void addList(String id) {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d50/game/column/" + id, Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response);
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接
|
||||
if (error.getClass().equals(NoConnectionError.class)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, SubjectActivity.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
GameManager manager = new GameManager(getApplicationContext());
|
||||
List<GameEntity> gameList = gson.fromJson(response.toString(), listType);
|
||||
if (gameList != null && !gameList.isEmpty()) {
|
||||
for (GameEntity entity : gameList) {
|
||||
// 黄壮华 初始化游戏状态 修改2015/8/15
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
entity.getId(), entity.getName()));
|
||||
}
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, subject_list,
|
||||
subject_pb_loading, reuse_no_connection, id);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
adapter.getList().addAll(gameList);
|
||||
adapter.notifyItemRangeInserted(adapter.getList().size() - gameList.size(), gameList.size());
|
||||
}
|
||||
});
|
||||
|
||||
// 黄壮华 获取游戏位置信息 修改2015/8/15
|
||||
for (int i = 0, size = adapter.getList().size(); i < size; i++) {
|
||||
GameEntity entity = adapter.getList().get(i);
|
||||
locationMap.put(entity.getName(), i);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), entity.getName());
|
||||
}
|
||||
}
|
||||
subject_list.setHasFixedSize(true);
|
||||
subject_list.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new SubjectAdapter(this, subject_list, subject_pb_loading, reuse_no_connection, id);
|
||||
subject_list.setAdapter(adapter);
|
||||
subject_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
|
||||
hotcard_list.setVisibility(View.VISIBLE);
|
||||
hotcard_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
if (adapter != null) {
|
||||
adapter.getDismissEntity().setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = locationMap.get(name);
|
||||
int location = adapter.getLocationMap().get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity entity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
@ -231,18 +147,29 @@ public class SubjectActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, subject_list,
|
||||
subject_pb_loading, reuse_no_connection, id);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(this, gameMap);
|
||||
List<GameEntity> entities = new ArrayList<GameEntity>();
|
||||
DownloadItemUtils.initializeGameMap(this, adapter.getGameMap());
|
||||
for (GameEntity entity : adapter.getList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
entities.add(entity);
|
||||
entity.setEntryMap(adapter.getGameMap().get(entity.getName()));
|
||||
}
|
||||
adapter.setList(entities);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getApplicationContext()).addObserver(dataWatcher);
|
||||
@ -252,7 +179,7 @@ public class SubjectActivity extends BaseActivity {
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
adapter.getStatusMap().clear();
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@ -261,15 +188,10 @@ public class SubjectActivity extends BaseActivity {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(SubjectActivity.class);
|
||||
hotcard_list = null;
|
||||
subject_list = null;
|
||||
adapter = null;
|
||||
hotcard_ll_loading = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
subject_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
|
||||
290
app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java
Normal file
290
app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java
Normal file
@ -0,0 +1,290 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
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.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.game.GameFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/6.
|
||||
*/
|
||||
public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private RecyclerView plugin_list;
|
||||
private ProgressBarCircularIndeterminate plugin_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private List<GameEntity> pluginList;
|
||||
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
public PluginAdapter(Context context,
|
||||
RecyclerView recyclerView,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout linearLayout) {
|
||||
|
||||
this.context = context;
|
||||
plugin_list = recyclerView;
|
||||
plugin_pb_loading = pbLoading;
|
||||
reuse_no_connection = linearLayout;
|
||||
|
||||
pluginList = new ArrayList<GameEntity>();
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(context, gameMap);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private int count;
|
||||
|
||||
//检查可以插件化的游戏
|
||||
private void init() {
|
||||
ConcernManager concernManager = new ConcernManager(context);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
final int size = infos.size();
|
||||
final List<GameEntity> list = new ArrayList<GameEntity>();
|
||||
count = 0;
|
||||
for (ConcernInfo info : infos) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/" + info.getId() + "/digest", Constants.GAME_CD),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
list.add(gameEntity);
|
||||
count++;
|
||||
if (count == size) {
|
||||
processingData(list);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
count++;
|
||||
if (count == size) {
|
||||
if (list.isEmpty()) {
|
||||
plugin_list.setVisibility(View.GONE);
|
||||
plugin_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
processingData(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, GameFragment.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingData(List<GameEntity> list) {
|
||||
if (plugin_pb_loading != null && plugin_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
plugin_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ConcernManager concernManager = new ConcernManager(context);
|
||||
PackageManager mPackageManager = new PackageManager(context);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
HashMap<String, Boolean> map;
|
||||
GameEntity gameEntity;
|
||||
for (ConcernInfo info : infos) {
|
||||
map = info.getPackageNames();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
gameEntity = list.get(i);
|
||||
if (gameEntity.getId().equals(info.getId())
|
||||
&& gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& gameEntity.getApk() != null) {
|
||||
for (String key : map.keySet()) {
|
||||
if (map.get(key)) {
|
||||
if (!mPackageManager.isSignature(key)) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(key)) {
|
||||
GameEntity entity = gameEntity.clone();
|
||||
entity.setPluginPlatform(
|
||||
PlatformUtils.getInstance(context).getPlatformName(apkEntity.getPlatform()));
|
||||
ArrayList<ApkEntity> apkList = new ArrayList<ApkEntity>();
|
||||
apkList.add(apkEntity);
|
||||
entity.setApk(apkList);
|
||||
pluginList.add(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pluginList.isEmpty()) {
|
||||
GameManager manager = new GameManager(context);
|
||||
for (GameEntity gEntity : pluginList) {
|
||||
gEntity.setEntryMap(gameMap.get(gEntity.getName()));
|
||||
for (ApkEntity aEntity : gEntity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(aEntity.getPackageName(),
|
||||
gEntity.getId(), gEntity.getName()));
|
||||
}
|
||||
}
|
||||
notifyItemRangeInserted(0, pluginList.size());
|
||||
initLocationMap();
|
||||
}
|
||||
}
|
||||
|
||||
private void initLocationMap() {
|
||||
for (int i = 0; i < pluginList.size(); i++) {
|
||||
GameEntity gameEntity = pluginList.get(i);
|
||||
locationMap.put(gameEntity.getName() + " - " + gameEntity.getPluginPlatform(), i);
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), gameEntity.getName() + " - " + gameEntity.getPluginPlatform());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.home_game_normal_item, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof GameNormalViewHolder) {
|
||||
GameNormalViewHolder viewHolder = (GameNormalViewHolder) holder;
|
||||
|
||||
final GameEntity entity = pluginList.get(position);
|
||||
|
||||
viewHolder.home1_game_order.setVisibility(View.GONE);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), viewHolder.gameThumb);
|
||||
if (entity.getPluginPlatform() != null) {
|
||||
viewHolder.gameNameAndSize.setText(entity.getName() + " - " + entity.getPluginPlatform());
|
||||
} else {
|
||||
viewHolder.gameNameAndSize.setText(entity.getName());
|
||||
}
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
viewHolder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
viewHolder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
GameViewUtils.setLabelList(context, viewHolder.labelList, entity.getTag());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("gameId", entity.getId());
|
||||
intent.putExtra("entrance", "游戏-插件");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
final int i = position;
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context, viewHolder.downloadBtn,
|
||||
viewHolder.download_speed, viewHolder.download_percentage, entity, i,
|
||||
PluginAdapter.this,
|
||||
statusMap, platformMap, "游戏-插件",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, viewHolder.labelList,
|
||||
viewHolder.game_progressbar, viewHolder.game_ll_info, viewHolder.download_speed,
|
||||
viewHolder.download_percentage, viewHolder.downloadBtn, entity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return pluginList.size();
|
||||
}
|
||||
|
||||
public List<GameEntity> getPluginList() {
|
||||
return pluginList;
|
||||
}
|
||||
|
||||
public ArrayMap<String, Integer> getLocationMap() {
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, LinkedBlockingQueue<String>> getPlatformMap() {
|
||||
return platformMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, ArrayMap<String, DownloadEntry>> getGameMap() {
|
||||
return gameMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getNameMap() {
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getStatusMap() {
|
||||
return statusMap;
|
||||
}
|
||||
|
||||
public DismissEntity getDismissEntity() {
|
||||
return dismissEntity;
|
||||
}
|
||||
|
||||
}
|
||||
@ -7,20 +7,40 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
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.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
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.DownloadItemUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.SubjectActivity;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameTestViewHolder;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@ -40,37 +60,108 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
|
||||
private Context context;
|
||||
|
||||
private RecyclerView subject_list;
|
||||
private ProgressBarCircularIndeterminate subject_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private List<GameEntity> list;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
public SubjectAdapter(Context context,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> pMap,
|
||||
ArrayMap<String, String> sMap, DismissEntity dEntity) {
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
platformMap = pMap;
|
||||
statusMap = sMap;
|
||||
dismissEntity = dEntity;
|
||||
RecyclerView recyclerView,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout linearLayout,
|
||||
String id) {
|
||||
|
||||
this.context = context;
|
||||
subject_list = recyclerView;
|
||||
subject_pb_loading = pbLoading;
|
||||
reuse_no_connection = linearLayout;
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(context, gameMap);
|
||||
|
||||
list = new ArrayList<GameEntity>();
|
||||
|
||||
initList(id);
|
||||
}
|
||||
|
||||
public List<GameEntity> getList() {
|
||||
return list;
|
||||
private void initList(String id) {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d50/game/column/" + id, Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response);
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
subject_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
subject_list.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, SubjectActivity.class);
|
||||
}
|
||||
|
||||
public void setList(List<GameEntity> list) {
|
||||
this.list = list;
|
||||
notifyDataSetChanged();
|
||||
private void processingData(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
GameManager manager = new GameManager(context);
|
||||
List<GameEntity> gameList = gson.fromJson(response.toString(), listType);
|
||||
if (gameList != null && !gameList.isEmpty()) {
|
||||
for (GameEntity entity : gameList) {
|
||||
// 黄壮华 初始化游戏状态 修改2015/8/15
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
entity.getId(), entity.getName()));
|
||||
}
|
||||
}
|
||||
list = gameList;
|
||||
notifyItemRangeInserted(list.size() - gameList.size(), gameList.size());
|
||||
}
|
||||
|
||||
// 黄壮华 获取游戏位置信息 修改2015/8/15
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
GameEntity entity = list.get(i);
|
||||
locationMap.put(entity.getName(), i);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), entity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
subject_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,124 +169,6 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,
|
||||
int position) {
|
||||
if (position != list.size()) {
|
||||
|
||||
if (viewHolder instanceof GameNormalViewHolder) {
|
||||
GameNormalViewHolder holder = (GameNormalViewHolder) viewHolder;
|
||||
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
|
||||
GameViewUtils.setLabelList(context, holder.labelList, entity.getTag());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("入口", "热门卡牌");
|
||||
DataUtils.onEvent(context, "游戏详情", entity.getName(), kv);
|
||||
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "热门卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context, holder.downloadBtn,
|
||||
holder.download_speed, holder.download_percentage,
|
||||
entity, position, this,
|
||||
statusMap, platformMap, "热门卡牌", dismissEntity, "hotcard:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info,
|
||||
holder.download_speed, holder.download_percentage,
|
||||
holder.downloadBtn, entity, platformMap, statusMap);
|
||||
} else if (viewHolder instanceof GameTestViewHolder) {
|
||||
GameTestViewHolder holder = (GameTestViewHolder) viewHolder;
|
||||
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
holder.gameTestType.setText(entity.getTest().getType());
|
||||
if (entity.getTest().getStart() == 0) {
|
||||
holder.gameTestTime.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.gameTestTime.setText(GameViewUtils.getGameTestDate(entity.getTest().getStart()));
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(context,
|
||||
GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "主页-新测卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (entity.getTest().getEnd() == 0) {
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, entity, position,
|
||||
SubjectAdapter.this,
|
||||
statusMap, platformMap, "主页-新测卡牌",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
} else {
|
||||
long endTime = Long.valueOf(entity.getTest().getEnd()
|
||||
+ "000");
|
||||
long todayTime = new Date().getTime();
|
||||
if (todayTime > endTime) {
|
||||
// 测试时间已过
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
// 测试时间未过
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, entity, position,
|
||||
SubjectAdapter.this, statusMap, platformMap,
|
||||
"主页-新测卡牌", dismissEntity,
|
||||
"主页:" + entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info, holder.download_speed,
|
||||
holder.download_percentage, holder.downloadBtn, entity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
@ -203,21 +176,158 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
if (i != list.size()) {
|
||||
if (list.get(i).getTest() != null) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_game_test_item, viewGroup, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_game_normal_item, viewGroup, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
if (list.get(i).getTest() != null) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_game_test_item, viewGroup, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false);
|
||||
return new FooterViewHolder(view);
|
||||
R.layout.home_game_normal_item, viewGroup, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||
if (viewHolder instanceof GameNormalViewHolder) {
|
||||
initGameNormalViewHolder((GameNormalViewHolder) viewHolder, position);
|
||||
} else if (viewHolder instanceof GameTestViewHolder) {
|
||||
initGameTestViewHolder((GameTestViewHolder) viewHolder, position);
|
||||
}
|
||||
}
|
||||
|
||||
private void initGameTestViewHolder(GameTestViewHolder holder, int position) {
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
holder.gameTestType.setText(entity.getTest().getType());
|
||||
if (entity.getTest().getStart() == 0) {
|
||||
holder.gameTestTime.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.gameTestTime.setText(GameViewUtils.getGameTestDate(entity.getTest().getStart()));
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(context,
|
||||
GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "主页-新测卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (entity.getTest().getEnd() == 0) {
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, entity, position,
|
||||
SubjectAdapter.this,
|
||||
statusMap, platformMap, "主页-新测卡牌",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
} else {
|
||||
long endTime = Long.valueOf(entity.getTest().getEnd()
|
||||
+ "000");
|
||||
long todayTime = new Date().getTime();
|
||||
if (todayTime > endTime) {
|
||||
// 测试时间已过
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
// 测试时间未过
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, entity, position,
|
||||
SubjectAdapter.this, statusMap, platformMap,
|
||||
"主页-新测卡牌", dismissEntity,
|
||||
"主页:" + entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info, holder.download_speed,
|
||||
holder.download_percentage, holder.downloadBtn, entity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
|
||||
private void initGameNormalViewHolder(GameNormalViewHolder holder, int position) {
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
|
||||
GameViewUtils.setLabelList(context, holder.labelList, entity.getTag());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("入口", "热门卡牌");
|
||||
DataUtils.onEvent(context, "游戏详情", entity.getName(), kv);
|
||||
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "热门卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context, holder.downloadBtn,
|
||||
holder.download_speed, holder.download_percentage,
|
||||
entity, position, this,
|
||||
statusMap, platformMap, "热门卡牌", dismissEntity, "hotcard:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info,
|
||||
holder.download_speed, holder.download_percentage,
|
||||
holder.downloadBtn, entity, platformMap, statusMap);
|
||||
}
|
||||
|
||||
public List<GameEntity> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayMap<String, Integer> getLocationMap() {
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, LinkedBlockingQueue<String>> getPlatformMap() {
|
||||
return platformMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, ArrayMap<String, DownloadEntry>> getGameMap() {
|
||||
return gameMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getNameMap() {
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getStatusMap() {
|
||||
return statusMap;
|
||||
}
|
||||
|
||||
public DismissEntity getDismissEntity() {
|
||||
return dismissEntity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -196,7 +196,6 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
@Nullable
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
@ -487,11 +486,14 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
downloadmanager_rv_show.getAdapter().notifyItemRemoved(
|
||||
position);
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(
|
||||
new EBDownloadDelete(entry.getName(), entry.getMeta()
|
||||
.get("platform"), entry.getUrl()));
|
||||
|
||||
EBDownloadDelete delete = new EBDownloadDelete(entry.getName(),
|
||||
entry.getMeta().get("platform"), entry.getUrl());
|
||||
String PluginPlatform = entry.getMeta().get("PluginPlatform");
|
||||
if (PluginPlatform != null) {
|
||||
delete.setPluginPlatform(PluginPlatform);
|
||||
}
|
||||
EventBus.getDefault().post(delete);
|
||||
|
||||
DownloadManager.getInstance(getActivity()).cancel(
|
||||
entry.getUrl());
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ public class EBDownloadDelete {
|
||||
private String name;
|
||||
private String platform;
|
||||
private String url;
|
||||
private String PluginPlatform;
|
||||
|
||||
public EBDownloadDelete(String name, String platform, String url) {
|
||||
super();
|
||||
@ -37,4 +38,12 @@ public class EBDownloadDelete {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getPluginPlatform() {
|
||||
return PluginPlatform;
|
||||
}
|
||||
|
||||
public void setPluginPlatform(String pluginPlatform) {
|
||||
PluginPlatform = pluginPlatform;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,20 +13,27 @@ import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -41,17 +48,25 @@ import de.greenrobot.event.EventBus;
|
||||
public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
private RecyclerView mRecyclerView;
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Game1FragmentAdapter adapter;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private ProgressBarCircularIndeterminate mProgressBarCircularIndeterminate;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
//下载用到的map
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> pluginNameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private int currentItem;
|
||||
|
||||
private boolean isEverpause;
|
||||
private boolean isDestroy;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@ -61,8 +76,7 @@ public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (platformMap != null) {
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(name);
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
@ -81,29 +95,221 @@ public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (Map.Entry<String, DownloadEntry> entry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (Map.Entry<String, DownloadEntry> entry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location;
|
||||
String PluginPlatform = downloadEntry.getMeta().get("PluginPlatform");
|
||||
if (PluginPlatform != null) {
|
||||
location = locationMap.get(downloadEntry.getName() + " - " + PluginPlatform);
|
||||
} else {
|
||||
location = locationMap.get(downloadEntry.getName());
|
||||
}
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter, index, statusMap);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter, index, statusMap);
|
||||
}
|
||||
}
|
||||
|
||||
//特殊 插件化update
|
||||
if (downloadEntry.getMeta().get("PluginPlatform") != null) {
|
||||
location = locationMap.get(downloadEntry.getName() + " - " + downloadEntry.getMeta().get("PluginPlatform"));
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter, index, statusMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
pluginNameMap = new ArrayMap<String, String>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
currentItem = 0;
|
||||
|
||||
isEverpause = false;
|
||||
isDestroy = false;
|
||||
|
||||
//初始化gamemap
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new Game1FragmentAdapter(Game1Fragment.this, locationMap, gameMap,
|
||||
platformMap, nameMap, pluginNameMap, recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, false);
|
||||
recyclerview.setAdapter(adapter);
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if(container != null){
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
//下载被删除事件
|
||||
public void onEventMainThread(EBDownloadDelete busThree) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(busThree.getName());
|
||||
if (queue != null) {
|
||||
queue.remove(busThree.getPlatform());
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
if (detailedEntity != null) {
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
}
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
//特殊 插件化update
|
||||
if (busThree.getPluginPlatform() != null) {
|
||||
location = locationMap.get(busThree.getName() + " - " + busThree.getPluginPlatform());
|
||||
int index = location;
|
||||
Utils.log(location);
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
if (detailedEntity != null) {
|
||||
detailedEntity.setEntryMap(null);
|
||||
}
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
}
|
||||
|
||||
//版本选择框消失事件
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = locationMap.get(name);
|
||||
if (location != null) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
//特殊 插件化
|
||||
name = pluginNameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = locationMap.get(name);
|
||||
if (location != null) {
|
||||
if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) {
|
||||
List<GameEntity> list = adapter.getPluginList();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
if (list.get(i).getApk().get(0).getPackageName()
|
||||
.equals(busFour.getPackageName())) {
|
||||
list.remove(i);
|
||||
adapter.notifyItemRemoved(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1);
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Fragment界面切换事件
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() != 0) {
|
||||
adapter.stopAutoScroll();
|
||||
statusMap.clear();
|
||||
}
|
||||
} else if ("GameFragment".equals(busNine.getFrom())) {
|
||||
currentItem = busNine.getPosition();
|
||||
if (busNine.getPosition() == 0) {
|
||||
adapter.startAutoScroll();
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
} else {
|
||||
adapter.stopAutoScroll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int position) {
|
||||
List<GameEntity> pluginList = adapter.getPluginList();
|
||||
List<SubjectEntity> subjectList = adapter.getSubjectList();
|
||||
@ -127,52 +333,50 @@ public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
|
||||
mSwipeRefreshLayout = (SwipeRefreshLayout) view
|
||||
.findViewById(R.id.game_swipe_refresh);
|
||||
mSwipeRefreshLayout.setColorSchemeResources(R.color.theme_colors);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
mProgressBarCircularIndeterminate = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
mProgressBarCircularIndeterminate.setVisibility(View.GONE);
|
||||
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new Game1FragmentAdapter(getActivity(), locationMap, statusMap,
|
||||
platformMap, dismissEntity, mSwipeRefreshLayout);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
//修改游戏下载状态
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
for (SubjectEntity subjectEntity : adapter.getSubjectList()) {
|
||||
for (GameEntity entity :subjectEntity.getData()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
}
|
||||
}
|
||||
for (GameEntity entity : adapter.getPluginList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
if (currentItem == 0) {
|
||||
adapter.startAutoScroll();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if(container != null){
|
||||
container.removeView(view);
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
if (currentItem == 0) {
|
||||
adapter.stopAutoScroll();
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
adapter = new Game1FragmentAdapter(Game1Fragment.this, locationMap, gameMap,
|
||||
platformMap, nameMap, pluginNameMap, recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, true);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
};
|
||||
|
||||
@ -181,46 +385,26 @@ public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBDownloadDelete busThree) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(busThree.getName());
|
||||
if (queue != null) {
|
||||
queue.remove(busThree.getPlatform());
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(Game1Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
adapter = null;
|
||||
reuse_no_connection = null;
|
||||
game_swipe_refresh = null;
|
||||
game_pb_loading = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
pluginNameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -2,133 +2,279 @@ package com.gh.gamecenter.game;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/28.
|
||||
*/
|
||||
public class Game2Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
private View view;
|
||||
private RecyclerView mRecyclerView;
|
||||
private Game2FragmentAdapter game2FragmentAdapter;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private ProgressBarCircularIndeterminate mProgressBarCircularIndeterminate;
|
||||
|
||||
private View view;
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Game2FragmentAdapter adapter;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
//下载用到的map
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
DataWatcher dataWatcher = new DataWatcher() {
|
||||
private boolean isEverpause;
|
||||
private boolean isDestroy;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void onDataChanged(HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (Map.Entry<String, DownloadEntry> stringDownloadEntryEntry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry value = stringDownloadEntryEntry.getValue();
|
||||
Integer integer = locationMap.get(value.getName());
|
||||
if (integer!=null){
|
||||
int i = integer.intValue();
|
||||
GameEntity gameEntity = initListPosition(i);
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(gameEntity, value, platformMap, handler, game2FragmentAdapter, i, statusMap);
|
||||
public void handleMessage(Message msg) {
|
||||
if (!isDestroy) {
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (platformMap != null) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
msg2.obj = name;
|
||||
msg2.what = Constants.DOWNLOAD_ROLL;
|
||||
sendMessageDelayed(msg2, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private GameEntity initListPosition(int position) {
|
||||
List<SubjectEntity> list = game2FragmentAdapter.getList();
|
||||
int offset = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (position > offset && position <= list.get(i).getData().size() + offset) {
|
||||
return list.get(i).getData().get(position - offset - 1);
|
||||
}
|
||||
offset = offset + list.get(i).getData().size();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (Map.Entry<String, DownloadEntry> stringDownloadEntryEntry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry downloadEntry = stringDownloadEntryEntry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter, index, statusMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
isEverpause = false;
|
||||
isDestroy = false;
|
||||
|
||||
mSwipeRefreshLayout = (SwipeRefreshLayout) view
|
||||
.findViewById(R.id.game_swipe_refresh);
|
||||
mSwipeRefreshLayout.setColorSchemeResources(R.color.theme_colors);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
//初始化gamemap
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
|
||||
mProgressBarCircularIndeterminate = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
mProgressBarCircularIndeterminate.setVisibility(View.GONE);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
game2FragmentAdapter = new Game2FragmentAdapter(getActivity(), this,locationMap,gameMap,platformMap,nameMap,statusMap,true,dismissEntity);
|
||||
mRecyclerView.setAdapter(game2FragmentAdapter);
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new Game2FragmentAdapter(Game2Fragment.this, locationMap, gameMap,
|
||||
platformMap, nameMap, recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, false);
|
||||
recyclerview.setAdapter(adapter);
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
//下载被删除事件
|
||||
public void onEventMainThread(EBDownloadDelete busThree) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(busThree.getName());
|
||||
if (queue != null) {
|
||||
queue.remove(busThree.getPlatform());
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
};
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
if (detailedEntity != null) {
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
}
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
//版本选择框消失事件
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = locationMap.get(name);
|
||||
if (location != null) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Fragment界面切换事件
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() != 0) {
|
||||
statusMap.clear();
|
||||
}
|
||||
} else if ("GameFragment".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 1) {
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int position) {
|
||||
List<SubjectEntity> list = adapter.getSubectList();
|
||||
int offset = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (position > offset && position <= list.get(i).getData().size() + offset) {
|
||||
return list.get(i).getData().get(position - offset - 1);
|
||||
}
|
||||
offset = list.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
//修改游戏下载状态
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
for (SubjectEntity subjectEntity : adapter.getSubectList()) {
|
||||
for (GameEntity entity :subjectEntity.getData()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@ -139,4 +285,45 @@ public class Game2Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new Game2FragmentAdapter(Game2Fragment.this, locationMap, gameMap,
|
||||
platformMap, nameMap, recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, true);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(Game2Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
adapter = null;
|
||||
reuse_no_connection = null;
|
||||
game_swipe_refresh = null;
|
||||
game_pb_loading = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,34 +2,42 @@ package com.gh.gamecenter.game;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
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.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.NewsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SubjectActivity;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameHeadViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameImageViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameTestViewHolder;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@ -46,105 +54,195 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
* Created by khy on 2016/6/28.
|
||||
*/
|
||||
public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private final static int ITEM_XINCE = 100;//游戏布局2
|
||||
private final static int ITEM = 101;//游戏布局1
|
||||
private final static int ITEM_HEAD = 102;//专题头部
|
||||
private final static int ITEM_PIC = 103;//大图布局
|
||||
private List<SubjectEntity> subjectList = new ArrayList<SubjectEntity>();
|
||||
private Context mContext;
|
||||
|
||||
private class ITEM_TYPE {
|
||||
public final static int HEAD = 100;// 专题头部
|
||||
public final static int GAME_NORMAL = 101;// 游戏布局1
|
||||
public final static int GAME_TEST = 102;// 游戏布局2
|
||||
public final static int IMAGE = 103;// 大图布局
|
||||
}
|
||||
|
||||
private Game2Fragment fragment;
|
||||
private Context context;
|
||||
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
private List<SubjectEntity> subjectList;
|
||||
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
public Game2FragmentAdapter(FragmentActivity activity, Game2Fragment game2Fragment, ArrayMap<String, Integer> locationMap
|
||||
, ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap, ArrayMap<String, LinkedBlockingQueue<String>> platformMap
|
||||
, ArrayMap<String, String> nameMap, ArrayMap<String, String> statusMap, boolean b, DismissEntity dismissEntity) {
|
||||
this.mContext = activity;
|
||||
this.locationMap = locationMap;
|
||||
this.gameMap = gameMap;
|
||||
this.platformMap = platformMap;
|
||||
this.nameMap = nameMap;
|
||||
this.statusMap = statusMap;
|
||||
this.dismissEntity = dismissEntity;
|
||||
LoadData2();
|
||||
public Game2FragmentAdapter(Game2Fragment fragment,
|
||||
ArrayMap<String, Integer> lMap,
|
||||
ArrayMap<String, ArrayMap<String, DownloadEntry>> gMap,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> pMap,
|
||||
ArrayMap<String, String> nMap,
|
||||
RecyclerView rView,
|
||||
SwipeRefreshLayout refreshLayout,
|
||||
LinearLayout linearLayout,
|
||||
ArrayMap<String, String> sMap,
|
||||
DismissEntity dEntity,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
boolean isLoad) {
|
||||
|
||||
this.fragment = fragment;
|
||||
this.context = fragment.getActivity();
|
||||
locationMap = lMap;
|
||||
gameMap = gMap;
|
||||
platformMap = pMap;
|
||||
nameMap = nMap;
|
||||
recyclerview = rView;
|
||||
game_swipe_refresh = refreshLayout;
|
||||
reuse_no_connection = linearLayout;
|
||||
game_pb_loading = pbLoading;
|
||||
statusMap = sMap;
|
||||
dismissEntity = dEntity;
|
||||
|
||||
subjectList = new ArrayList<SubjectEntity>();
|
||||
|
||||
if (isLoad) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData2() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d50/game/tuijian",
|
||||
Constants.GAME_CD), new Response.Listener<JSONArray>() {
|
||||
|
||||
public void load() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<SubjectEntity>>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
subjectList = gson.fromJson(response.toString(), listType);
|
||||
notifyDataSetChanged();
|
||||
initLocationMap();
|
||||
public void run() {
|
||||
initSubjectList();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
private void initSubjectList() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(Config.HOST + "v1d50/game/tuijian",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
|
||||
}
|
||||
Type listType = new TypeToken<ArrayList<SubjectEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<SubjectEntity> list = gson.fromJson(response.toString(), listType);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
subjectList = list;
|
||||
GameManager manager = new GameManager(context);
|
||||
for (SubjectEntity subjectEntity : subjectList) {
|
||||
for (GameEntity gameEntity : subjectEntity.getData()) {
|
||||
gameEntity.setEntryMap(gameMap.get(gameEntity.getName()));
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
gameEntity.getId(), gameEntity.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, GameFragment.class);
|
||||
if (!fragment.isHidden() && !fragment.isEverpause()) {
|
||||
notifyItemRangeInserted(0, getItemCount());
|
||||
} else {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
initLocationMap();
|
||||
}
|
||||
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
recyclerview.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, Game1Fragment.class);
|
||||
}
|
||||
|
||||
private void initLocationMap() {
|
||||
locationMap.clear();
|
||||
|
||||
int count = 0;
|
||||
if (!subjectList.isEmpty()) {
|
||||
SubjectEntity subjectEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
subjectEntity = subjectList.get(i);
|
||||
count += 1 + subjectEntity.getData().size();
|
||||
}
|
||||
int count = getItemCount();
|
||||
GameEntity gameEntity;
|
||||
int offset;
|
||||
for (int position = 0; position < count; position++) {
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
offset = 0;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
locationMap.put(gameEntity.getName(), position);
|
||||
if (gameEntity.getApk() != null && !gameEntity.getApk().isEmpty()) {
|
||||
locationMap.put(gameEntity.getName(), position);
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), gameEntity.getName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Utils.log(locationMap.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int subjectSize = 0;
|
||||
if (!subjectList.isEmpty()) {
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
SubjectEntity subjectEntity = subjectList.get(i);
|
||||
subjectSize += subjectEntity.getData().size() + 1;
|
||||
}
|
||||
}
|
||||
return subjectSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
GameEntity gameEntity;
|
||||
if (!subjectList.isEmpty()) {
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
if (position == offset) {
|
||||
return ITEM_HEAD;
|
||||
return ITEM_TYPE.HEAD;
|
||||
}
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (!TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
return ITEM_PIC;
|
||||
return ITEM_TYPE.IMAGE;
|
||||
}
|
||||
if (gameEntity.getTest() != null) {
|
||||
return ITEM_XINCE;
|
||||
return ITEM_TYPE.GAME_TEST;
|
||||
}
|
||||
return ITEM;
|
||||
return ITEM_TYPE.GAME_NORMAL;
|
||||
}
|
||||
offset = offset + subjectList.get(i).getData().size() + 1;
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@ -152,118 +250,151 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
switch (viewType) {
|
||||
case ITEM_HEAD:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.home_game_head_item, parent, false);
|
||||
return new GameHeadViewHolder(view);
|
||||
case ITEM_PIC:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.home_game_image_item, parent, false);
|
||||
return new GameImageViewHolder(view);
|
||||
case ITEM:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.home_game_normal_item, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
case ITEM_XINCE:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.home_game_test_item, parent, false);
|
||||
return new GameTestViewHolder(view);
|
||||
default:
|
||||
return null;
|
||||
if (viewType == ITEM_TYPE.HEAD) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.home_game_head_item, parent, false);
|
||||
return new GameHeadViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.IMAGE) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.home_game_image_item, parent, false);
|
||||
return new GameImageViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.GAME_TEST) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.home_game_test_item, parent, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.home_game_normal_item, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
|
||||
if (holder instanceof GameHeadViewHolder) {
|
||||
GameHeadViewHolder viewHolder = (GameHeadViewHolder) holder;
|
||||
viewHolder.thumb.setVisibility(View.GONE);
|
||||
int offset = 0;
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
if (position == offset) {
|
||||
viewHolder.title.setText(subjectList.get(i).getName());
|
||||
}
|
||||
offset = offset + subjectList.get(i).getData().size();
|
||||
}
|
||||
initGameHeadViewHolder((GameHeadViewHolder) holder, position);
|
||||
} else if (holder instanceof GameNormalViewHolder) {
|
||||
GameNormalViewHolder viewHolder = (GameNormalViewHolder) holder;
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (TextUtils.isEmpty(gameEntity.getImage()) && gameEntity.getTest() == null) {
|
||||
initGameNormal(viewHolder, gameEntity, position - offset - 1, subjectList.get(i).getOrder());
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
|
||||
initGameNormalViewHolder((GameNormalViewHolder) holder, position);
|
||||
} else if (holder instanceof GameTestViewHolder) {
|
||||
GameTestViewHolder viewHolder = (GameTestViewHolder) holder;
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (gameEntity.getTest() != null) {
|
||||
initGameTest(viewHolder, gameEntity, position - offset - 1, subjectList.get(i).getOrder());
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
initGameTestViewHolder((GameTestViewHolder) holder, position);
|
||||
} else if (holder instanceof GameImageViewHolder) {
|
||||
GameImageViewHolder viewHolder = (GameImageViewHolder) holder;
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (!TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
final GameEntity entity = gameEntity;
|
||||
ImageUtils.getInstance(mContext).display(entity.getImage(), viewHolder.image, -1);
|
||||
viewHolder.image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if ("game".equals(entity.getType())) {
|
||||
Intent intent = new Intent(mContext, GameDetailsActivity.class);
|
||||
intent.putExtra("gameId", entity.getId());
|
||||
intent.putExtra("entrance", "插件-大图");
|
||||
mContext.startActivity(intent);
|
||||
} else if ("news".equals(entity.getType())) {
|
||||
Intent intent = new Intent(mContext, NewsActivity.class);
|
||||
intent.putExtra("newsId", entity.getId());
|
||||
intent.putExtra("entrance", "插件-大图");
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
initGameImageViewHolder((GameImageViewHolder) holder, position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initGameTest(GameTestViewHolder holder, GameEntity gameEntity, int i, boolean order) {
|
||||
private void initGameHeadViewHolder(GameHeadViewHolder holder, int position) {
|
||||
int offset = 0;
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
if (position == offset) {
|
||||
holder.thumb.setVisibility(View.GONE);
|
||||
holder.title.setText(subjectList.get(i).getName());
|
||||
final int ii = i;
|
||||
holder.link.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, SubjectActivity.class);
|
||||
intent.putExtra("id", subjectList.get(ii).getId());
|
||||
intent.putExtra("name", subjectList.get(ii).getName());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void initGameNormalViewHolder(GameNormalViewHolder holder, int position) {
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (TextUtils.isEmpty(gameEntity.getImage()) && gameEntity.getTest() == null) {
|
||||
int order = position - offset - 1;
|
||||
if (subjectList.get(i).getData().get(0).getImage() != null) {
|
||||
order--;
|
||||
}
|
||||
initGameNormal(holder, gameEntity, order, subjectList.get(i).getOrder());
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void initGameNormal(GameNormalViewHolder holder, GameEntity entity, int i, boolean order) {
|
||||
if (order) {
|
||||
holder.home1_game_order.setVisibility(View.VISIBLE);
|
||||
holder.home1_game_order.setText((i + 1) + "");
|
||||
} else {
|
||||
holder.home1_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
GameViewUtils.setLabelList(context, holder.labelList, entity.getTag());
|
||||
|
||||
final GameEntity gameInfoEntity = entity;
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", gameInfoEntity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "游戏-推荐");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
DownloadItemUtils.setOnClickListener(context, holder.downloadBtn,
|
||||
holder.download_speed, holder.download_percentage, entity, i,
|
||||
Game2FragmentAdapter.this,
|
||||
statusMap, platformMap, "游戏-推荐",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info, holder.download_speed,
|
||||
holder.download_percentage, holder.downloadBtn, entity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
|
||||
private void initGameTestViewHolder(GameTestViewHolder holder, int position) {
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
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--;
|
||||
}
|
||||
initGameTest(holder, gameEntity, order, subjectList.get(i).getOrder());
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void initGameTest(GameTestViewHolder holder, final GameEntity gameEntity, int i, boolean order) {
|
||||
if (order) {
|
||||
holder.home2_game_order.setVisibility(View.VISIBLE);
|
||||
holder.home2_game_order.setText(i + "");
|
||||
holder.home2_game_order.setText((i + 1) + "");
|
||||
} else {
|
||||
holder.home2_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(mContext).display(gameEntity.getIcon(),
|
||||
holder.gameThumb);
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(gameEntity.getName());
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(gameEntity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(gameEntity.getApk().get(0).getSize() + " | " + gameEntity.getBrief());
|
||||
holder.gameDes.setText(gameEntity.getApk().get(0).getSize() + " | " + gameEntity.getBrief());
|
||||
}
|
||||
holder.gameTestType.setText(gameEntity.getTest().getType());
|
||||
if (gameEntity.getTest().getStart() == 0) {
|
||||
@ -272,28 +403,30 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
holder.gameTestTime.setText(GameViewUtils.getGameTestDate(gameEntity.getTest().getStart()));
|
||||
}
|
||||
|
||||
final GameEntity entity = gameEntity;
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(mContext,
|
||||
GameDetailsActivity.class);
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "主页-新测卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (entity.getTest().getEnd() == 0) {
|
||||
if (gameEntity.getTest().getEnd() == 0) {
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, gameEntity, i,
|
||||
Game2FragmentAdapter.this,
|
||||
statusMap, platformMap, "游戏-推荐",
|
||||
dismissEntity, "游戏:" + gameEntity.getName());
|
||||
} else {
|
||||
long endTime = Long.valueOf(entity.getTest().getEnd()
|
||||
long endTime = Long.valueOf(gameEntity.getTest().getEnd()
|
||||
+ "000");
|
||||
long todayTime = new Date().getTime();
|
||||
if (todayTime > endTime) {
|
||||
@ -302,69 +435,62 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
} else {
|
||||
// 测试时间未过
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, gameEntity, i,
|
||||
Game2FragmentAdapter.this, statusMap, platformMap,
|
||||
"游戏-推荐", dismissEntity,
|
||||
"游戏:" + gameEntity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initGameNormal(GameNormalViewHolder holder, GameEntity entity, int i, boolean order) {
|
||||
if (order) {
|
||||
holder.home1_game_order.setVisibility(View.VISIBLE);
|
||||
holder.home1_game_order.setText(i + "");
|
||||
} else {
|
||||
holder.home1_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(mContext).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
GameViewUtils.setLabelList(mContext, holder.labelList, entity.getTag());
|
||||
|
||||
final GameEntity gameInfoEntity = entity;
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", gameInfoEntity);
|
||||
Intent intent = new Intent(mContext, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "游戏-推荐");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
DownloadItemUtils.setOnClickListener(mContext, holder.downloadBtn,
|
||||
holder.download_speed, holder.download_percentage, entity, i,
|
||||
Game2FragmentAdapter.this,
|
||||
statusMap, platformMap, "游戏-推荐",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(mContext, holder.labelList,
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info, holder.download_speed,
|
||||
holder.download_percentage, holder.downloadBtn, entity, platformMap,
|
||||
holder.download_percentage, holder.downloadBtn, gameEntity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int dataSize = 0;
|
||||
if (!subjectList.isEmpty()) {
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
SubjectEntity subjectEntity = subjectList.get(i);
|
||||
dataSize += subjectEntity.getData().size() + 1;
|
||||
private void initGameImageViewHolder(GameImageViewHolder holder, int position) {
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (!TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
final GameEntity entity = gameEntity;
|
||||
ImageUtils.getInstance(context).display(entity.getImage(), holder.image, -1);
|
||||
holder.image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if ("game".equals(entity.getType())) {
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("gameId", entity.getId());
|
||||
intent.putExtra("entrance", "插件-大图");
|
||||
context.startActivity(intent);
|
||||
} else if ("news".equals(entity.getType())) {
|
||||
Intent intent = new Intent(context, NewsActivity.class);
|
||||
intent.putExtra("newsId", entity.getId());
|
||||
intent.putExtra("entrance", "插件-大图");
|
||||
context.startActivity(intent);
|
||||
} else if ("column".equals(entity.getType())) {
|
||||
Intent intent = new Intent(context, SubjectActivity.class);
|
||||
intent.putExtra("id", entity.getId());
|
||||
// intent.putExtra("name", entity.getName());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
|
||||
public List<SubjectEntity> getList() {
|
||||
public List<SubjectEntity> getSubectList() {
|
||||
return subjectList;
|
||||
}
|
||||
|
||||
|
||||
@ -34,9 +34,7 @@ import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
@ -102,7 +100,7 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
int index = location;
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
@ -134,20 +132,9 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
isEverpause = false;
|
||||
isDestroy = false;
|
||||
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerview.setLayoutManager(layoutManager);
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -160,6 +147,16 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
}
|
||||
});
|
||||
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerview.setLayoutManager(layoutManager);
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new Game3FragmentAdapter(Game3Fragment.this, locationMap,
|
||||
gameMap, platformMap, nameMap, recyclerview,
|
||||
@ -196,6 +193,7 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
return view;
|
||||
}
|
||||
|
||||
//下载被删除事件
|
||||
public void onEventMainThread(EBDownloadDelete busThree) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(busThree.getName());
|
||||
if (queue != null) {
|
||||
@ -203,9 +201,8 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
int index = location;
|
||||
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
@ -217,12 +214,14 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
}
|
||||
}
|
||||
|
||||
//版本选择框消失事件
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
@ -242,6 +241,7 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
@ -260,12 +260,15 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() != 1) {
|
||||
if (busNine.getPosition() != 0) {
|
||||
statusMap.clear();
|
||||
}
|
||||
} else if ("GameFragment".equals(busNine.getFrom()) && busNine.getPosition() == 2
|
||||
&& game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
} else if ("GameFragment".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 2) {
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,12 +282,10 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/20
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
List<GameEntity> entities = new ArrayList<GameEntity>();
|
||||
for (GameEntity entity : adapter.getList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
entities.add(entity);
|
||||
}
|
||||
adapter.setList(entities);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
|
||||
@ -68,9 +68,8 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
public class Game3FragmentAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private Game3Fragment fragment;
|
||||
private Context context;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
@ -88,7 +87,6 @@ public class Game3FragmentAdapter extends
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
@ -106,14 +104,13 @@ public class Game3FragmentAdapter extends
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
boolean isLoad) {
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
this.fragment = fment;
|
||||
this.context = fment.getActivity();
|
||||
locationMap = lMap;
|
||||
gameMap = gMap;
|
||||
platformMap = pMap;
|
||||
nameMap = nMap;
|
||||
|
||||
statusMap = sMap;
|
||||
|
||||
recyclerView = rView;
|
||||
game_swipe_refresh = swipeRefreshLayout;
|
||||
reuse_no_connection = linearLayout;
|
||||
@ -121,9 +118,6 @@ public class Game3FragmentAdapter extends
|
||||
|
||||
dismissEntity = dEntity;
|
||||
|
||||
fragment = fment;
|
||||
context = fment.getActivity();
|
||||
|
||||
isRemove = false;
|
||||
isLoading = false;
|
||||
isNetworkError = false;
|
||||
@ -136,16 +130,14 @@ public class Game3FragmentAdapter extends
|
||||
}
|
||||
|
||||
public void load() {
|
||||
new Thread(runnable){}.start();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
}){}.start();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
};
|
||||
|
||||
public void addList(final int offset) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
@ -173,11 +165,13 @@ public class Game3FragmentAdapter extends
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (offset == 0) {
|
||||
if (game_swipe_refresh.isRefreshing()) {
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
@ -188,7 +182,7 @@ public class Game3FragmentAdapter extends
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, GameFragment.class);
|
||||
AppController.addToRequestQueue(request, Game3Fragment.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response, int offset) {
|
||||
@ -228,7 +222,7 @@ public class Game3FragmentAdapter extends
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
if (offset == 0 && game_swipe_refresh.isRefreshing()) {
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
|
||||
@ -293,8 +287,7 @@ public class Game3FragmentAdapter extends
|
||||
private void initGameNormalViewHolder(GameNormalViewHolder holder, final GameEntity entity, int position) {
|
||||
entity.getApk().get(0).setPlatform("local_plugin");
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
@ -364,11 +357,6 @@ public class Game3FragmentAdapter extends
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<GameEntity> list) {
|
||||
this.list = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public boolean isRemove() {
|
||||
return isRemove;
|
||||
}
|
||||
|
||||
@ -30,7 +30,6 @@ import android.widget.TextView;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
@ -59,9 +58,14 @@ import de.greenrobot.event.EventBus;
|
||||
public class GameFragment extends Fragment implements OnClickListener,
|
||||
OnPageChangeListener {
|
||||
|
||||
private View view, slideLine;
|
||||
private View view;
|
||||
private View slideLine;
|
||||
private ViewPager viewPager;
|
||||
private TextView jingpinText, zuixinText, danjiText, downloadHint, searchHint;
|
||||
private TextView jingpinText;
|
||||
private TextView zuixinText;
|
||||
private TextView danjiText;
|
||||
private TextView downloadHint;
|
||||
private TextView searchHint;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private int width;
|
||||
@ -69,6 +73,12 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
|
||||
private String hint;
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", currentItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
||||
@ -79,15 +89,12 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(
|
||||
Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
LinearLayout home_actionbar = (LinearLayout) view
|
||||
.findViewById(R.id.home_actionbar);
|
||||
LayoutParams params = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, sp.getInt("actionbar_height",
|
||||
DisplayUtils.dip2px(getActivity(), 48)));
|
||||
LinearLayout home_actionbar = (LinearLayout) view.findViewById(R.id.home_actionbar);
|
||||
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||
sp.getInt("actionbar_height", DisplayUtils.dip2px(getActivity(), 48)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
int top = DisplayUtils.getInternalDimensionSize(getResources(),
|
||||
"status_bar_height");
|
||||
int top = DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height");
|
||||
home_actionbar.setPadding(0, top, 0, 0);
|
||||
params.height += top;
|
||||
}
|
||||
@ -108,8 +115,7 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
danjiText.setOnClickListener(this);
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay()
|
||||
.getMetrics(outMetrics);
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 3;
|
||||
rparams = new RelativeLayout.LayoutParams(width / 2,
|
||||
DisplayUtils.dip2px(getActivity(), 2));
|
||||
@ -118,13 +124,28 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
viewPager.setAdapter(new FragmentAdapter(getChildFragmentManager()));
|
||||
viewPager.addOnPageChangeListener(this);
|
||||
|
||||
rparams.leftMargin = width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
jingpinText.setClickable(false);
|
||||
zuixinText.setClickable(true);
|
||||
danjiText.setClickable(true);
|
||||
currentItem = 0;
|
||||
|
||||
currentItem = viewPager.getCurrentItem();
|
||||
if (savedInstanceState != null) {
|
||||
currentItem = savedInstanceState.getInt("currentItem");
|
||||
}
|
||||
viewPager.setCurrentItem(currentItem);
|
||||
|
||||
rparams.leftMargin = width * currentItem + width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
if (currentItem == 0) {
|
||||
jingpinText.setClickable(false);
|
||||
zuixinText.setClickable(true);
|
||||
danjiText.setClickable(true);
|
||||
} else if (currentItem == 1) {
|
||||
jingpinText.setClickable(true);
|
||||
zuixinText.setClickable(false);
|
||||
danjiText.setClickable(true);
|
||||
} else {
|
||||
jingpinText.setClickable(true);
|
||||
zuixinText.setClickable(true);
|
||||
danjiText.setClickable(false);
|
||||
}
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
@ -206,12 +227,10 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
|
||||
public FragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
|
||||
if (position == 0) {
|
||||
return new Game1Fragment();
|
||||
} else if (position == 1) {
|
||||
@ -307,14 +326,12 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
}
|
||||
|
||||
public void updateRedDot(int type) {
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll()
|
||||
.size();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (type == 1 && downloadSize == 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText((downloadSize + type) + "");
|
||||
int width = DisplayUtils.dip2px(getActivity(), 12);
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(
|
||||
width, width);
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(width, width);
|
||||
rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8);
|
||||
rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 2);
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
@ -325,8 +342,7 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText("");
|
||||
int width = DisplayUtils.dip2px(getActivity(), 10);
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(
|
||||
width, width);
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(width, width);
|
||||
rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8);
|
||||
rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 3);
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
@ -343,12 +359,10 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
private void popUpOverflow(View view) {
|
||||
|
||||
Rect frame = new Rect();
|
||||
getActivity().getWindow().getDecorView()
|
||||
.getWindowVisibleDisplayFrame(frame);
|
||||
getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
|
||||
|
||||
int xOffset = DisplayUtils.dip2px(getActivity(), 5);
|
||||
int yOffset = frame.top + DisplayUtils.dip2px(getActivity(), 48)
|
||||
+ xOffset;
|
||||
int yOffset = frame.top + DisplayUtils.dip2px(getActivity(), 48) + xOffset;
|
||||
|
||||
View popView = View.inflate(getActivity(), R.layout.menu_popwindow,
|
||||
null);
|
||||
@ -361,8 +375,7 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
popWindow.setBackgroundDrawable(getResources().getDrawable(
|
||||
R.drawable.shape));
|
||||
|
||||
popWindow.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, xOffset,
|
||||
yOffset);
|
||||
popWindow.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, xOffset, yOffset);
|
||||
|
||||
}
|
||||
|
||||
@ -401,7 +414,6 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
} else {
|
||||
if (currentItem != viewPager.getCurrentItem()) {
|
||||
currentItem = viewPager.getCurrentItem();
|
||||
Utils.log("currentItem = " + currentItem);
|
||||
EventBus.getDefault().post(new EBUISwitch("GameFragment", currentItem));
|
||||
}
|
||||
}
|
||||
@ -439,18 +451,15 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
FragmentTransaction transaction = getChildFragmentManager()
|
||||
.beginTransaction();
|
||||
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||
List<Fragment> list = getChildFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
if (hidden) {
|
||||
for (Fragment fragment : getChildFragmentManager()
|
||||
.getFragments()) {
|
||||
for (Fragment fragment : getChildFragmentManager().getFragments()) {
|
||||
transaction.hide(fragment);
|
||||
}
|
||||
} else {
|
||||
for (Fragment fragment : getChildFragmentManager()
|
||||
.getFragments()) {
|
||||
for (Fragment fragment : getChildFragmentManager().getFragments()) {
|
||||
transaction.show(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read_tv_type, newsEntity.getType());
|
||||
}
|
||||
@ -294,7 +294,7 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read2_special2_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read2_special2_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read2_special2_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read2_special2_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special2_tv_type, newsEntity.getType());
|
||||
}
|
||||
@ -317,7 +317,7 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read2_special1_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read2_special1_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read2_special1_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read2_special1_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special1_tv_type, newsEntity.getType());
|
||||
}
|
||||
|
||||
@ -287,7 +287,7 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read_tv_type, newsEntity.getType());
|
||||
}
|
||||
@ -324,7 +324,7 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read2_special2_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read2_special2_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read2_special2_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read2_special2_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special2_tv_type, newsEntity.getType());
|
||||
}
|
||||
@ -346,7 +346,7 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read2_special1_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read2_special1_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read2_special1_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read2_special1_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special1_tv_type, newsEntity.getType());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user