详情(游戏,文章,礼包)下载改造完成
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.view.DownloadProgressBar;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.DetailViewHolder;
|
||||
@ -19,118 +19,56 @@ import com.lightgame.download.DownloadEntity;
|
||||
public class DetailDownloadUtils {
|
||||
|
||||
public static void detailInitDownload(DetailViewHolder viewHolder, boolean isCheck) {
|
||||
if (Config.isShowDownload(viewHolder.gameEntity.getId())) {
|
||||
|
||||
if (viewHolder.gameEntity != null
|
||||
&& Config.isShowDownload(viewHolder.gameEntity.getId())
|
||||
&& !"光环助手".equals(viewHolder.gameEntity.getName())) {
|
||||
viewHolder.downloadBottom.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
viewHolder.downloadBottom.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
if (viewHolder.gameEntity != null && "光环助手".equals(viewHolder.gameEntity.getName())) {
|
||||
viewHolder.downloadBottom.setVisibility(View.GONE);
|
||||
} else if (viewHolder.gameEntity == null || viewHolder.gameEntity.getApk().isEmpty()) {
|
||||
viewHolder.downloadTv.setVisibility(View.VISIBLE);
|
||||
viewHolder.downloadPb.setVisibility(View.GONE);
|
||||
viewHolder.downloadPer.setVisibility(View.GONE);
|
||||
if (TextUtils.isEmpty(viewHolder.downloadOffText)) {
|
||||
viewHolder.downloadTv.setText("暂无下载");
|
||||
} else {
|
||||
viewHolder.downloadTv.setText(viewHolder.downloadOffText);
|
||||
}
|
||||
viewHolder.downloadTv.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
viewHolder.downloadTv.setTextColor(0xFF999999);
|
||||
viewHolder.downloadTv.setClickable(false);
|
||||
} else {
|
||||
viewHolder.downloadTv.setVisibility(View.VISIBLE);
|
||||
viewHolder.downloadPb.setVisibility(View.GONE);
|
||||
viewHolder.downloadPer.setVisibility(View.GONE);
|
||||
boolean isInstalled = false;
|
||||
if (viewHolder.gameEntity.getApk().size() == 1
|
||||
&& PackageManager.isInstalled(viewHolder.gameEntity.getApk().get(0).getPackageName())) {
|
||||
isInstalled = true;
|
||||
}
|
||||
if (isInstalled) {
|
||||
if (PackageManager.isCanUpdate(viewHolder.gameEntity.getId(), viewHolder.gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (viewHolder.isNewsDetail) {
|
||||
viewHolder.downloadTv.setText(R.string.update);
|
||||
} else if (TextUtils.isEmpty(viewHolder.downloadAddWord)) {
|
||||
viewHolder.downloadTv.setText(String.format("更新《%s》",
|
||||
viewHolder.gameEntity.getName()));
|
||||
} else {
|
||||
viewHolder.downloadTv.setText(String.format("更新《%s》%s",
|
||||
viewHolder.gameEntity.getName(), viewHolder.downloadAddWord));
|
||||
}
|
||||
viewHolder.downloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
} else {
|
||||
if (viewHolder.gameEntity.getTag() != null && viewHolder.gameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(viewHolder.gameEntity.getApk().get(0).getGhVersion())
|
||||
&& !PackageUtils.isSignature(viewHolder.context, viewHolder.gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (viewHolder.isNewsDetail) {
|
||||
viewHolder.downloadTv.setText(R.string.pluggable);
|
||||
} else if (TextUtils.isEmpty(viewHolder.downloadAddWord)) {
|
||||
viewHolder.downloadTv.setText(String.format("插件化《%s》",
|
||||
viewHolder.gameEntity.getName()));
|
||||
} else {
|
||||
viewHolder.downloadTv.setText(String.format("插件化《%s》%s",
|
||||
viewHolder.gameEntity.getName(), viewHolder.downloadAddWord));
|
||||
}
|
||||
viewHolder.downloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
if (viewHolder.isNewsDetail) {
|
||||
viewHolder.downloadTv.setText(R.string.launch);
|
||||
} else if (TextUtils.isEmpty(viewHolder.downloadAddWord)) {
|
||||
viewHolder.downloadTv.setText(String.format("启动《%s》",
|
||||
viewHolder.gameEntity.getName()));
|
||||
} else {
|
||||
viewHolder.downloadTv.setText(String.format("启动《%s》%s",
|
||||
viewHolder.gameEntity.getName(), viewHolder.downloadAddWord));
|
||||
}
|
||||
viewHolder.downloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String status = GameUtils.getDownloadBtnText(viewHolder.context, viewHolder.gameEntity);
|
||||
switch (status) {
|
||||
case "插件化":
|
||||
viewHolder.downloadTv.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
break;
|
||||
case "打开":
|
||||
viewHolder.downloadTv.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
break;
|
||||
default:
|
||||
viewHolder.downloadTv.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
break;
|
||||
}
|
||||
|
||||
if (viewHolder.isNewsDetail) {
|
||||
viewHolder.downloadTv.setText(status);
|
||||
} else if (TextUtils.isEmpty(viewHolder.downloadAddWord)) {
|
||||
viewHolder.downloadTv.setText(String.format(status + "《%s》",
|
||||
viewHolder.gameEntity.getName()));
|
||||
} else {
|
||||
viewHolder.downloadTv.setText(String.format(status + "《%s》%s",
|
||||
viewHolder.gameEntity.getName(), viewHolder.downloadAddWord));
|
||||
}
|
||||
if (viewHolder.gameEntity.getApk().isEmpty()) {
|
||||
viewHolder.mDownloadPb.setText(TextUtils.isEmpty(viewHolder.downloadOffText) ? "暂无下载" : viewHolder.downloadOffText);
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.NONE);
|
||||
} else {
|
||||
String status = GameUtils.getDownloadBtnText(viewHolder.context, viewHolder.gameEntity);
|
||||
switch (status) {
|
||||
case "插件化":
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.PLUGIN);
|
||||
break;
|
||||
case "打开":
|
||||
if (viewHolder.gameEntity.getApk().size() == 1) {
|
||||
status = "启动";
|
||||
}
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.LAUNCH_OR_OPEN);
|
||||
break;
|
||||
default:
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.NORMAL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (viewHolder.isNewsDetail) {
|
||||
viewHolder.mDownloadPb.setText(status);
|
||||
} else if (TextUtils.isEmpty(viewHolder.downloadAddWord)) {
|
||||
viewHolder.mDownloadPb.setText(String.format(status + "《%s》", viewHolder.gameEntity.getName()));
|
||||
} else {
|
||||
viewHolder.mDownloadPb.setText(String.format(status + "《%s》%s", viewHolder.gameEntity.getName(), viewHolder.downloadAddWord));
|
||||
}
|
||||
}
|
||||
if (isCheck && viewHolder.gameEntity != null
|
||||
&& viewHolder.gameEntity.getApk().size() == 1) {
|
||||
if (isCheck && viewHolder.gameEntity.getApk().size() == 1) {
|
||||
String url = viewHolder.gameEntity.getApk().get(0).getUrl();
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(viewHolder.context).getDownloadEntityByUrl(url);
|
||||
if (downloadEntity != null) {
|
||||
viewHolder.downloadEntity = downloadEntity;
|
||||
viewHolder.downloadTv.setVisibility(View.GONE);
|
||||
viewHolder.downloadPb.setVisibility(View.VISIBLE);
|
||||
viewHolder.downloadPer.setVisibility(View.VISIBLE);
|
||||
detailInvalidate(viewHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void detailInvalidate(DetailViewHolder viewHolder) {
|
||||
viewHolder.downloadPb.setProgress((int) (viewHolder.downloadEntity.getPercent() * 10));
|
||||
viewHolder.downloadPer.setTextColor(0xFFFFFFFF);
|
||||
viewHolder.mDownloadPb.setProgress((int) (viewHolder.downloadEntity.getPercent() * 10));
|
||||
DownloadEntity downloadEntity = viewHolder.downloadEntity;
|
||||
switch (downloadEntity.getStatus()) {
|
||||
case downloading:
|
||||
@ -138,15 +76,20 @@ public class DetailDownloadUtils {
|
||||
case timeout:
|
||||
case neterror:
|
||||
case waiting:
|
||||
viewHolder.downloadPer.setText(R.string.downloading);
|
||||
viewHolder.mDownloadPb.setText(R.string.downloading);
|
||||
if (downloadEntity.isPluggable() && PackageManager.isInstalled(downloadEntity.getPackageName())) {
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.DOWNLOADING_PLUGIN);
|
||||
} else {
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.DOWNLOADING_NORMAL);
|
||||
}
|
||||
break;
|
||||
case done:
|
||||
viewHolder.downloadPer.setText("安装");
|
||||
viewHolder.mDownloadPb.setText(R.string.install);
|
||||
if (downloadEntity.isPluggable()
|
||||
&& PackageManager.isInstalled(downloadEntity.getPackageName())) {
|
||||
viewHolder.downloadPb.setProgressDrawable(ContextCompat.getDrawable(viewHolder.context, R.drawable.progressbar_plugin_radius_style));
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.INSTALL_PLUGIN);
|
||||
} else {
|
||||
viewHolder.downloadPb.setProgressDrawable(ContextCompat.getDrawable(viewHolder.context, R.drawable.progressbar_normal_radius_style));
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.INSTALL_NORMAL);
|
||||
}
|
||||
break;
|
||||
case cancel:
|
||||
|
||||
136
app/src/main/java/com/gh/common/view/DownloadProgressBar.java
Normal file
136
app/src/main/java/com/gh/common/view/DownloadProgressBar.java
Normal file
@ -0,0 +1,136 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.RectF;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
public class DownloadProgressBar extends ProgressBar {
|
||||
private static final int MAX_LENGTH = 1000;
|
||||
|
||||
public enum DownloadType {
|
||||
NORMAL,
|
||||
NONE,
|
||||
PLUGIN,
|
||||
LAUNCH_OR_OPEN,
|
||||
INSTALL_NORMAL,
|
||||
INSTALL_PLUGIN,
|
||||
DOWNLOADING_NORMAL,
|
||||
DOWNLOADING_PLUGIN,
|
||||
}
|
||||
|
||||
private PorterDuffXfermode mDuffXFerMode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
|
||||
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
|
||||
private DownloadType mDownloadType;
|
||||
|
||||
private String mText;
|
||||
|
||||
private int mDefaultColor;
|
||||
|
||||
public DownloadProgressBar(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public DownloadProgressBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setMax(MAX_LENGTH);
|
||||
setProgressDrawable(getResources().getDrawable(R.drawable.game_item_btn_download_style));
|
||||
}
|
||||
|
||||
Bitmap srcBitmap;
|
||||
Canvas srcCanvas;
|
||||
RectF rectF;
|
||||
|
||||
private void create() {
|
||||
srcBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
|
||||
srcCanvas = new Canvas(srcBitmap);
|
||||
rectF = new RectF(0, 0, getProgress() * getWidth() / MAX_LENGTH, getMeasuredHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (TextUtils.isEmpty(mText)) return;
|
||||
|
||||
mPaint.setColor(mDefaultColor == 0 ? ContextCompat.getColor(getContext(), R.color.theme) : mDefaultColor); // 初始化颜色
|
||||
mPaint.setTextSize(40f);
|
||||
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||
mPaint.setXfermode(null);
|
||||
create();
|
||||
|
||||
Paint.FontMetrics fontMetrics = mPaint.getFontMetrics();
|
||||
float mTextHeight = fontMetrics.bottom - fontMetrics.descent - fontMetrics.ascent;
|
||||
float mTextWidth = mPaint.measureText(mText);
|
||||
|
||||
// todo 文字有点不居中
|
||||
srcCanvas.drawText(mText, (getWidth() - mTextWidth) / 2, (getHeight() + mTextHeight) / 2, mPaint);
|
||||
mPaint.setXfermode(mDuffXFerMode);
|
||||
mPaint.setColor(Color.WHITE); // 反向颜色
|
||||
|
||||
srcCanvas.drawRect(rectF, mPaint);
|
||||
canvas.drawBitmap(srcBitmap, 0, 0, null);
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
mText = text;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return mText;
|
||||
}
|
||||
|
||||
public void setText(@StringRes int res) {
|
||||
setText(getResources().getString(res));
|
||||
}
|
||||
|
||||
public void setDownloadType(DownloadType downloadType) {
|
||||
switch (downloadType) {
|
||||
case NORMAL:
|
||||
case INSTALL_NORMAL:
|
||||
setProgressDrawable(getResources().getDrawable(R.drawable.game_item_btn_download_style));
|
||||
mDefaultColor = Color.WHITE;
|
||||
break;
|
||||
case PLUGIN:
|
||||
case INSTALL_PLUGIN:
|
||||
setProgressDrawable(getResources().getDrawable(R.drawable.game_item_btn_plugin_style));
|
||||
mDefaultColor = Color.WHITE;
|
||||
break;
|
||||
case NONE:
|
||||
setProgressDrawable(getResources().getDrawable(R.drawable.news_detail_comment)); // todo 是否需要点击效果
|
||||
mDefaultColor = ContextCompat.getColor(getContext(), R.color.hint);
|
||||
break;
|
||||
case LAUNCH_OR_OPEN:
|
||||
setProgressDrawable(getResources().getDrawable(R.drawable.detail_downloading_normal_style)); // todo 背景是否需要与下载中区分
|
||||
mDefaultColor = ContextCompat.getColor(getContext(), R.color.theme);
|
||||
break;
|
||||
case DOWNLOADING_NORMAL:
|
||||
setProgressDrawable(getResources().getDrawable(R.drawable.detail_downloading_normal_style));
|
||||
mDefaultColor = ContextCompat.getColor(getContext(), R.color.theme);
|
||||
break;
|
||||
case DOWNLOADING_PLUGIN:
|
||||
setProgressDrawable(getResources().getDrawable(R.drawable.detail_downloading_plugin_style));
|
||||
mDefaultColor = ContextCompat.getColor(getContext(), R.color.btn_plugin);
|
||||
break;
|
||||
}
|
||||
|
||||
mDownloadType = downloadType;
|
||||
}
|
||||
|
||||
public DownloadType getDownloadType() {
|
||||
return mDownloadType;
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,6 +21,7 @@ import com.gh.common.util.DetailDownloadUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.LibaoUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.view.DownloadProgressBar;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.LibaoDetailAdapter;
|
||||
@ -73,8 +74,8 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
TextView mNoneDataTv;
|
||||
@BindView(R.id.reuse_none_data)
|
||||
LinearLayout mNoneData;
|
||||
@BindView(R.id.detail_tv_download)
|
||||
TextView mDownloadTv;
|
||||
@BindView(R.id.detail_progressbar)
|
||||
DownloadProgressBar mDownloadPb;
|
||||
|
||||
private LibaoDetailAdapter mAdapter;
|
||||
|
||||
@ -180,7 +181,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
|
||||
mIsScroll = true;
|
||||
|
||||
mAdapter = new LibaoDetailAdapter(this, this, this, mLibaoEntity, mDownloadTv, mEntrance);
|
||||
mAdapter = new LibaoDetailAdapter(this, this, this, mLibaoEntity, mDownloadPb, mEntrance);
|
||||
mLibaoDetailRv.setLayoutManager(new LinearLayoutManager(this) {
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
|
||||
@ -10,7 +10,6 @@ import android.text.TextUtils;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
@ -18,6 +17,7 @@ import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.LibaoUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.common.view.DownloadProgressBar;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SuggestionActivity;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
@ -50,7 +50,7 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
private OnRequestCallBackListener mOnRequestCallBackListener;
|
||||
private OnCodeScrollListener mOnCodeScrollListener;
|
||||
|
||||
private TextView mDownloadTv;
|
||||
private DownloadProgressBar mDownloadPb;
|
||||
|
||||
private LibaoEntity mLibaoEntity;
|
||||
private LibaoDetailEntity mLibaoDetailEntity;
|
||||
@ -60,12 +60,12 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
|
||||
public LibaoDetailAdapter(Context context, OnRequestCallBackListener onRequestCallBackListener,
|
||||
OnCodeScrollListener onCodeScrollListener, LibaoEntity libaoEntity,
|
||||
TextView tvDownload, String entrance) {
|
||||
DownloadProgressBar downloadPb, String entrance) {
|
||||
super(context);
|
||||
mOnRequestCallBackListener = onRequestCallBackListener;
|
||||
mOnCodeScrollListener = onCodeScrollListener;
|
||||
mLibaoEntity = libaoEntity;
|
||||
mDownloadTv = tvDownload;
|
||||
mDownloadPb = downloadPb;
|
||||
mEntrance = entrance;
|
||||
}
|
||||
|
||||
@ -300,7 +300,7 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
|
||||
// 点击立即安装打开下载页面,如果只有一个包 直接下载
|
||||
public void openDownload() {
|
||||
mDownloadTv.performClick();
|
||||
mDownloadPb.performClick();
|
||||
}
|
||||
|
||||
public interface OnCodeScrollListener {
|
||||
|
||||
@ -4,14 +4,13 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.common.view.DownloadProgressBar;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.DataUtils;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
@ -40,17 +39,14 @@ public class DetailViewHolder {
|
||||
public boolean isNewsDetail; // 新闻详情不显示下载的游戏名, 只显示下载状态
|
||||
|
||||
public View downloadBottom;
|
||||
public TextView downloadTv;
|
||||
public ProgressBar downloadPb;
|
||||
public TextView downloadPer;
|
||||
|
||||
public DownloadProgressBar mDownloadPb;
|
||||
|
||||
// 注意View的命名
|
||||
public DetailViewHolder(View view, GameEntity gameEntity, DownloadEntity downloadEntity, String downloadOffText,
|
||||
String downloadAddWord, boolean isNewsDetail, String entrance, String name, String title) {
|
||||
downloadBottom = view.findViewById(R.id.detail_ll_bottom);
|
||||
downloadTv = (TextView) view.findViewById(R.id.detail_tv_download);
|
||||
downloadPb = (ProgressBar) view.findViewById(R.id.detail_pb_progressbar);
|
||||
downloadPer = (TextView) view.findViewById(R.id.detail_tv_per);
|
||||
mDownloadPb = view.findViewById(R.id.detail_progressbar);
|
||||
|
||||
this.gameEntity = gameEntity;
|
||||
this.downloadOffText = downloadOffText;
|
||||
@ -60,9 +56,7 @@ public class DetailViewHolder {
|
||||
this.context = view.getContext();
|
||||
|
||||
final OnDetailDownloadClickListener listener = new OnDetailDownloadClickListener(this, entrance, name, title);
|
||||
downloadTv.setOnClickListener(listener);
|
||||
downloadPb.setOnClickListener(listener);
|
||||
downloadPer.setOnClickListener(listener);
|
||||
mDownloadPb.setOnClickListener(listener);
|
||||
}
|
||||
|
||||
static class OnDetailDownloadClickListener implements View.OnClickListener {
|
||||
@ -84,50 +78,52 @@ public class DetailViewHolder {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mViewHolder.downloadTv) {
|
||||
if (mGameEntity != null && !mGameEntity.getApk().isEmpty()) {
|
||||
switch (mViewHolder.mDownloadPb.getDownloadType()) {
|
||||
case DOWNLOADING_PLUGIN:
|
||||
case DOWNLOADING_NORMAL:
|
||||
Intent intent = DownloadManagerActivity.getDownloadMangerIntent(mViewHolder.context,
|
||||
mGameEntity.getApk().get(0).getUrl(),
|
||||
StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"));
|
||||
mViewHolder.context.startActivity(intent);
|
||||
break;
|
||||
case NONE:
|
||||
Utils.toast(mViewHolder.context, "稍等片刻~!游戏正在上传中...");
|
||||
break;
|
||||
case NORMAL:
|
||||
case PLUGIN:
|
||||
if (mGameEntity.getApk().size() == 1) {
|
||||
String str = mViewHolder.downloadTv.getText().toString();
|
||||
if (str.contains("启动")) {
|
||||
DataUtils.onGameLaunchEvent(mViewHolder.context, mGameEntity.getName(), mGameEntity.getApk().get(0).getPlatform(), mName);
|
||||
PackageUtils.launchApplicationByPackageName(mViewHolder.context, mGameEntity.getApk().get(0).getPackageName());
|
||||
} else if (NetworkUtils.isWifiConnected(mViewHolder.context)) {
|
||||
if (NetworkUtils.isWifiConnected(mViewHolder.context)) {
|
||||
download();
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(mViewHolder.context, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
download();
|
||||
}
|
||||
});
|
||||
DialogUtils.showDownloadDialog(mViewHolder.context, this::download);
|
||||
}
|
||||
} else {
|
||||
DownloadDialog.getInstance(mViewHolder.context)
|
||||
.showPopupWindow(v, mGameEntity, StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"), mName + ":" + mTitle);
|
||||
DownloadDialog.getInstance(mViewHolder.context).showPopupWindow(v, mGameEntity,
|
||||
StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"), mName + ":" + mTitle);
|
||||
}
|
||||
} else {
|
||||
Utils.toast(mViewHolder.context, "稍等片刻~!游戏正在上传中...");
|
||||
}
|
||||
} else if (v == mViewHolder.downloadPb || v == mViewHolder.downloadPer) {
|
||||
String str = mViewHolder.downloadPer.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
Intent intent = DownloadManagerActivity.getDownloadMangerIntent(mViewHolder.context,
|
||||
mGameEntity.getApk().get(0).getUrl(), StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"));
|
||||
mViewHolder.context.startActivity(intent);
|
||||
} else if ("安装".equals(str)) {
|
||||
break;
|
||||
case LAUNCH_OR_OPEN:
|
||||
if (mGameEntity.getApk().size() == 1) {
|
||||
DataUtils.onGameLaunchEvent(mViewHolder.context, mGameEntity.getName(), mGameEntity.getApk().get(0).getPlatform(), mName);
|
||||
PackageUtils.launchApplicationByPackageName(mViewHolder.context, mGameEntity.getApk().get(0).getPackageName());
|
||||
} else {
|
||||
DownloadDialog.getInstance(mViewHolder.context).showPopupWindow(v, mGameEntity,
|
||||
StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"), mName + ":" + mTitle);
|
||||
}
|
||||
break;
|
||||
case INSTALL_PLUGIN:
|
||||
case INSTALL_NORMAL:
|
||||
if (mDownloadEntity == null) {
|
||||
mDownloadEntity = DownloadManager.getInstance(mViewHolder.context).getDownloadEntityByUrl(mGameEntity.getApk().get(0).getUrl());
|
||||
}
|
||||
|
||||
if (mDownloadEntity != null) {
|
||||
PackageUtils.launchSetup(mViewHolder.context, mDownloadEntity.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void download() {
|
||||
String str = mViewHolder.downloadTv.getText().toString();
|
||||
String str = mViewHolder.mDownloadPb.getText();
|
||||
String method;
|
||||
if (str.contains("更新")) {
|
||||
method = "更新";
|
||||
@ -143,13 +139,9 @@ public class DetailViewHolder {
|
||||
|
||||
DownloadManager.createDownload(mViewHolder.context, apkEntity, mGameEntity, method, StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"), mName + ":" + mTitle);
|
||||
|
||||
mViewHolder.downloadTv.setVisibility(View.GONE);
|
||||
mViewHolder.downloadPb.setVisibility(View.VISIBLE);
|
||||
mViewHolder.downloadPer.setVisibility(View.VISIBLE);
|
||||
mViewHolder.downloadPb.setProgress(0);
|
||||
mViewHolder.downloadPer.setText("0.0%");
|
||||
|
||||
// DownloadManager.getInstance(mViewHolder.context).putStatus(apkEntity.getUrl(), "downloading");
|
||||
mViewHolder.mDownloadPb.setProgress(0);
|
||||
mViewHolder.mDownloadPb.setDownloadType("插件化".equals(method) ?
|
||||
DownloadProgressBar.DownloadType.DOWNLOADING_PLUGIN : DownloadProgressBar.DownloadType.DOWNLOADING_NORMAL);
|
||||
} else {
|
||||
Utils.toast(mViewHolder.context, msg);
|
||||
}
|
||||
|
||||
@ -497,8 +497,7 @@ public class GameDetailFragment extends NormalFragment {
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick({R.id.detail_tv_download, R.id.detail_pb_progressbar, R.id.reuse_no_connection,
|
||||
R.id.detail_tv_per, R.id.gamedetail_tabbar_xinxi_tv, R.id.gamedetail_tabbar_fuli_tv,
|
||||
@OnClick({R.id.reuse_no_connection, R.id.gamedetail_tabbar_xinxi_tv, R.id.gamedetail_tabbar_fuli_tv,
|
||||
R.id.gamedetail_kaifu_hint, R.id.gamedetail_tv_concern})
|
||||
public void onClick(View v) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user