DownloadEntry修改为DownloadEntity
This commit is contained in:
@ -17,7 +17,7 @@ import android.widget.Toast;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
@ -36,38 +36,38 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
public class DownloadItemUtils {
|
||||
|
||||
// 初始化gameMap
|
||||
public static void initializeGameMap(Context context, ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap) {
|
||||
public static void initializeGameMap(Context context, ArrayMap<String, ArrayMap<String, DownloadEntity>> gameMap) {
|
||||
gameMap.clear();
|
||||
List<DownloadEntry> list = DownloadManager.getInstance(context).getAll();
|
||||
List<DownloadEntity> list = DownloadManager.getInstance(context).getAll();
|
||||
String name;
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
name = list.get(i).getName();
|
||||
ArrayMap<String, DownloadEntry> map = gameMap.get(name);
|
||||
ArrayMap<String, DownloadEntity> map = gameMap.get(name);
|
||||
if (map == null) {
|
||||
map = new ArrayMap<>();
|
||||
gameMap.put(name, map);
|
||||
}
|
||||
map.put(list.get(i).getMeta().get("platform"), list.get(i));
|
||||
map.put(list.get(i).getPlatform(), list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// 更新下载进度条
|
||||
public static void processDate(Context context,
|
||||
GameEntity detailedEntity,
|
||||
DownloadEntry downloadEntry,
|
||||
DownloadEntity downloadEntity,
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
|
||||
int index) {
|
||||
|
||||
LinkedBlockingQueue<String> queue = DownloadManager.getInstance(context).getQueue(downloadEntry.getName());
|
||||
LinkedBlockingQueue<String> queue = DownloadManager.getInstance(context).getQueue(downloadEntity.getName());
|
||||
if (queue == null) {
|
||||
queue = new LinkedBlockingQueue<>();
|
||||
DownloadManager.getInstance(context).putQueue(downloadEntry.getName(), queue);
|
||||
DownloadManager.getInstance(context).putQueue(downloadEntity.getName(), queue);
|
||||
}
|
||||
|
||||
String platform = downloadEntry.getMeta().get("platform");
|
||||
ArrayMap<String, DownloadEntry> entryMap = detailedEntity.getEntryMap();
|
||||
String platform = downloadEntity.getPlatform();
|
||||
ArrayMap<String, DownloadEntity> entryMap = detailedEntity.getEntryMap();
|
||||
|
||||
DownloadStatus status = downloadEntry.getStatus();
|
||||
DownloadStatus status = downloadEntity.getStatus();
|
||||
if (status.equals(DownloadStatus.pause)
|
||||
|| status.equals(DownloadStatus.cancel)
|
||||
|| status.equals(DownloadStatus.done)) {
|
||||
@ -76,8 +76,8 @@ public class DownloadItemUtils {
|
||||
entryMap = new ArrayMap<>();
|
||||
detailedEntity.setEntryMap(entryMap);
|
||||
}
|
||||
entryMap.put(platform, downloadEntry);
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntry.getUrl()))) {
|
||||
entryMap.put(platform, downloadEntity);
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) {
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
} else {
|
||||
@ -85,7 +85,7 @@ public class DownloadItemUtils {
|
||||
queue.offer(platform);
|
||||
if (queue.size() == 2) {
|
||||
Message msg = Message.obtain();
|
||||
msg.obj = downloadEntry.getName();
|
||||
msg.obj = downloadEntity.getName();
|
||||
msg.what = Constants.DOWNLOAD_ROLL;
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 3000);
|
||||
}
|
||||
@ -95,8 +95,8 @@ public class DownloadItemUtils {
|
||||
entryMap = new ArrayMap<>();
|
||||
detailedEntity.setEntryMap(entryMap);
|
||||
}
|
||||
entryMap.put(platform, downloadEntry);
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntry.getUrl()))) {
|
||||
entryMap.put(platform, downloadEntity);
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) {
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
}
|
||||
@ -114,19 +114,17 @@ public class DownloadItemUtils {
|
||||
GameEntity entity,
|
||||
boolean isShowPlatform) {
|
||||
|
||||
String pluginPlatform = entity.getPluginPlatform();
|
||||
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity.getEntryMap();
|
||||
ArrayMap<String, DownloadEntity> entryMap = entity.getEntryMap();
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry = entryMap.get(entity.getApk().get(0).getPlatform());
|
||||
DownloadEntity downloadEntity = entryMap.get(entity.getApk().get(0).getPlatform());
|
||||
|
||||
if (downloadEntry != null && (pluginPlatform == null
|
||||
|| pluginPlatform.equals(PlatformUtils.getInstance(context)
|
||||
.getPlatformName(downloadEntry.getMeta().get("platform"))))) {
|
||||
if (downloadEntity != null && (!entity.isPluggable()
|
||||
|| entity.getApk().get(0).getPlatform().equals(
|
||||
downloadEntity.getPlatform()))) {
|
||||
// 更改进度条和提示文本的状态
|
||||
changeStatus(context, textView, game_progressbar, game_ll_info, download_speed, download_percentage, downloadBtn,
|
||||
downloadEntry, isShowPlatform, true);
|
||||
downloadEntity, isShowPlatform, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -136,7 +134,7 @@ public class DownloadItemUtils {
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
|
||||
downloadBtn.setTextColor(Color.WHITE);
|
||||
if (pluginPlatform != null) {
|
||||
if (entity.isPluggable()) {
|
||||
downloadBtn.setText("插件化");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else if (PackageManager.isInstalled(entity.getApk().get(0).getPackageName())) {
|
||||
@ -165,7 +163,7 @@ public class DownloadItemUtils {
|
||||
GameEntity entity,
|
||||
boolean isShowPlatform) {
|
||||
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity.getEntryMap();
|
||||
ArrayMap<String, DownloadEntity> entryMap = entity.getEntryMap();
|
||||
|
||||
// 更新下载按钮状态
|
||||
int doneCount = 0; // 下载完成数量
|
||||
@ -217,19 +215,19 @@ public class DownloadItemUtils {
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
DownloadEntity downloadEntity;
|
||||
|
||||
LinkedBlockingQueue<String> queue = DownloadManager.getInstance(context).getQueue(entity.getName());
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
downloadEntity = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
downloadEntity = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
if (downloadEntity != null) {
|
||||
// 更改进度条和提示文本的状态
|
||||
changeStatus(context, textView, game_progressbar, game_ll_info, download_speed,
|
||||
download_percentage, downloadBtn, downloadEntry, isShowPlatform, false);
|
||||
download_percentage, downloadBtn, downloadEntity, isShowPlatform, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -247,7 +245,7 @@ public class DownloadItemUtils {
|
||||
TextView download_speed,
|
||||
TextView download_percentage,
|
||||
TextView downloadBtn,
|
||||
DownloadEntry downloadEntry,
|
||||
DownloadEntity downloadEntity,
|
||||
boolean isShowPlatform,
|
||||
boolean isNormal) {
|
||||
textView.setVisibility(View.GONE);
|
||||
@ -255,7 +253,7 @@ public class DownloadItemUtils {
|
||||
game_ll_info.setVisibility(View.VISIBLE);
|
||||
|
||||
String platform = PlatformUtils.getInstance(context)
|
||||
.getPlatformName(downloadEntry.getMeta().get("platform"));
|
||||
.getPlatformName(downloadEntity.getPlatform());
|
||||
|
||||
int[] btn_colors = new int[] { Color.WHITE
|
||||
, context.getResources().getColor(R.color.theme) };
|
||||
@ -264,19 +262,19 @@ public class DownloadItemUtils {
|
||||
states[1] = new int[] {};
|
||||
ColorStateList btn_sl = new ColorStateList(states, btn_colors);
|
||||
|
||||
DownloadStatus status = downloadEntry.getStatus();
|
||||
DownloadStatus status = downloadEntity.getStatus();
|
||||
if (status.equals(DownloadStatus.downloading)) {
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntry.getUrl()))) {
|
||||
game_progressbar.setProgress((int) (downloadEntry.getPercent() * 10));
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) {
|
||||
game_progressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (isShowPlatform && platform != null) {
|
||||
download_speed.setText(String.format("%s - %s(剩%s)", platform,
|
||||
SpeedUtils.getSpeed(downloadEntry.getSpeed()),
|
||||
SpeedUtils.getRemainTime(downloadEntry.getSize(), downloadEntry.getProgress(), downloadEntry.getSpeed() * 1024)));
|
||||
SpeedUtils.getSpeed(downloadEntity.getSpeed()),
|
||||
SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
|
||||
} else {
|
||||
download_speed.setText(String.format("%s(剩%s)", SpeedUtils.getSpeed(downloadEntry.getSpeed()),
|
||||
SpeedUtils.getRemainTime(downloadEntry.getSize(), downloadEntry.getProgress(), downloadEntry.getSpeed() * 1024)));
|
||||
download_speed.setText(String.format("%s(剩%s)", SpeedUtils.getSpeed(downloadEntity.getSpeed()),
|
||||
SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
|
||||
}
|
||||
download_percentage.setText(downloadEntry.getPercent() + "%");
|
||||
download_percentage.setText(downloadEntity.getPercent() + "%");
|
||||
}
|
||||
|
||||
if (isNormal) {
|
||||
@ -285,13 +283,13 @@ public class DownloadItemUtils {
|
||||
downloadBtn.setTextColor(btn_sl);
|
||||
}
|
||||
} else if (status.equals(DownloadStatus.waiting)) {
|
||||
game_progressbar.setProgress((int) (downloadEntry.getPercent() * 10));
|
||||
game_progressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (isShowPlatform && platform != null) {
|
||||
download_speed.setText(String.format("%s - 等待", platform));
|
||||
} else {
|
||||
download_speed.setText("等待");
|
||||
}
|
||||
download_percentage.setText(downloadEntry.getPercent() + "%");
|
||||
download_percentage.setText(downloadEntity.getPercent() + "%");
|
||||
|
||||
if (isNormal) {
|
||||
downloadBtn.setText("下载中");
|
||||
@ -301,13 +299,13 @@ public class DownloadItemUtils {
|
||||
} else if (status.equals(DownloadStatus.pause)
|
||||
|| status.equals(DownloadStatus.timeout)
|
||||
|| status.equals(DownloadStatus.neterror)) {
|
||||
game_progressbar.setProgress((int) (downloadEntry.getPercent() * 10));
|
||||
game_progressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (isShowPlatform && platform != null) {
|
||||
download_speed.setText(String.format("%s - 暂停", platform));
|
||||
} else {
|
||||
download_speed.setText("暂停");
|
||||
}
|
||||
download_percentage.setText(downloadEntry.getPercent() + "%");
|
||||
download_percentage.setText(downloadEntity.getPercent() + "%");
|
||||
|
||||
if (isNormal) {
|
||||
downloadBtn.setText("下载中");
|
||||
@ -469,27 +467,25 @@ public class DownloadItemUtils {
|
||||
}
|
||||
|
||||
//更新
|
||||
private static void update(Context context, GameEntity entity) {
|
||||
ApkEntity apkEntity = entity.getApk().get(0);
|
||||
private static void update(Context context, GameEntity gameEntity) {
|
||||
ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||||
//下载可更新游戏
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏更新", entity.getName(), kv);
|
||||
DataUtils.onEvent(context, "游戏更新", gameEntity.getName(), kv);
|
||||
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(entity.getName());
|
||||
entry.setPath(FileUtils.getDownloadPath(context,
|
||||
DownloadEntity downloadEntity = new DownloadEntity();
|
||||
downloadEntity.setUrl(apkEntity.getUrl());
|
||||
downloadEntity.setName(gameEntity.getName());
|
||||
downloadEntity.setPath(FileUtils.getDownloadPath(context,
|
||||
MD5Utils.getContentMD5(
|
||||
entity.getName() + "_" + System.currentTimeMillis()) + ".apk"));
|
||||
HashMap<String, String> meta = new HashMap<>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", entity.getIcon());
|
||||
meta.put("platform", apkEntity.getPlatform());
|
||||
meta.put("isUpdate", "true");
|
||||
entry.setMeta(meta);
|
||||
DownloadManager.getInstance(context).add(entry);
|
||||
gameEntity.getName() + "_" + System.currentTimeMillis()) + ".apk"));
|
||||
downloadEntity.setPlatform(apkEntity.getPlatform());
|
||||
downloadEntity.setIcon(gameEntity.getIcon());
|
||||
downloadEntity.setUpdate(true);
|
||||
downloadEntity.setETag(apkEntity.getEtag());
|
||||
DownloadManager.getInstance(context).add(downloadEntity);
|
||||
}
|
||||
|
||||
//下载
|
||||
@ -660,29 +656,27 @@ public class DownloadItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addDownloadEntry(Context context, GameEntity game, int position, String entrance) {
|
||||
private static void addDownloadEntry(Context context,
|
||||
GameEntity gameEntity,
|
||||
int position,
|
||||
String entrance) {
|
||||
|
||||
ApkEntity apkEntity = game.getApk().get(position);
|
||||
ApkEntity apkEntity = gameEntity.getApk().get(position);
|
||||
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(game.getName());
|
||||
entry.setPath(FileUtils.getDownloadPath(context,
|
||||
MD5Utils.getContentMD5(game.getName() + "_" + System.currentTimeMillis()) + ".apk"));
|
||||
HashMap<String, String> meta = new HashMap<>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", game.getIcon());
|
||||
meta.put("platform", apkEntity.getPlatform());
|
||||
meta.put("gameId", game.getId());
|
||||
meta.put("entrance", entrance);
|
||||
meta.put("location", "游戏详情:" + game.getName());
|
||||
if (game.getPluginPlatform() != null) {
|
||||
meta.put("PluginPlatform", game.getPluginPlatform());
|
||||
meta.put("isPlugin", "true");
|
||||
}
|
||||
entry.setMeta(meta);
|
||||
DownloadEntity downloadEntity = new DownloadEntity();
|
||||
downloadEntity.setUrl(apkEntity.getUrl());
|
||||
downloadEntity.setName(gameEntity.getName());
|
||||
downloadEntity.setPath(FileUtils.getDownloadPath(context, MD5Utils.getContentMD5(
|
||||
gameEntity.getName() + "_" + System.currentTimeMillis()) + ".apk"));
|
||||
downloadEntity.setIcon(gameEntity.getIcon());
|
||||
downloadEntity.setETag(apkEntity.getEtag());
|
||||
downloadEntity.setPlatform(apkEntity.getPlatform());
|
||||
downloadEntity.setGameId(gameEntity.getId());
|
||||
downloadEntity.setPluggable(gameEntity.isPluggable());
|
||||
downloadEntity.setEntrance(entrance);
|
||||
downloadEntity.setLocation("游戏详情:" + gameEntity.getName());
|
||||
|
||||
DownloadManager.getInstance(context).add(entry);
|
||||
DownloadManager.getInstance(context).add(downloadEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user