|
@@ -1,35 +1,66 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
|
+import android.os.Handler;
|
|
|
|
|
+import android.os.Message;
|
|
|
import android.support.design.widget.AppBarLayout;
|
|
import android.support.design.widget.AppBarLayout;
|
|
|
|
|
+import android.support.design.widget.TabLayout;
|
|
|
|
|
+import android.support.v4.view.ViewPager;
|
|
|
import android.support.v7.widget.AppCompatRatingBar;
|
|
import android.support.v7.widget.AppCompatRatingBar;
|
|
|
-import android.support.v7.widget.RecyclerView;
|
|
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
|
|
+import android.view.ViewGroup;
|
|
|
import android.widget.ImageButton;
|
|
import android.widget.ImageButton;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
+import com.arialyy.annotations.Download;
|
|
|
import com.arialyy.aria.core.Aria;
|
|
import com.arialyy.aria.core.Aria;
|
|
|
|
|
+import com.arialyy.aria.core.download.DownloadTask;
|
|
|
|
|
+import com.kfzs.duanduan.event.BigEvent;
|
|
|
|
|
+import com.kfzs.duanduan.mine.GiftpackListAdapter;
|
|
|
|
|
+import com.kfzs.duanduan.services.DownloadTaskService;
|
|
|
import com.kfzs.duanduan.utils.dlg.HelperUtils;
|
|
import com.kfzs.duanduan.utils.dlg.HelperUtils;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
-import com.sheep.gamegroup.helper.ImageListHelper;
|
|
|
|
|
-import com.sheep.gamegroup.util.ListUtil;
|
|
|
|
|
-import com.sheep.gamegroup.util.MyListview;
|
|
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.GameEntity;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.PlayGameEntity;
|
|
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.DataUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
|
|
+import com.sheep.gamegroup.util.TimeUtil;
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
|
|
|
+import com.sheep.gamegroup.view.fragment.FgtPlaGameGift;
|
|
|
|
|
+import com.sheep.gamegroup.view.fragment.FgtPlayGameDetail;
|
|
|
|
|
+import com.sheep.gamegroup.view.fragment.FgtPlayGameSon;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
-import com.tencent.smtt.sdk.WebView;
|
|
|
|
|
|
|
|
|
|
|
|
+import org.afinal.simplecache.ApiKey;
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Locale;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
import butterknife.ButterKnife;
|
|
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
import rx.functions.Action1;
|
|
import rx.functions.Action1;
|
|
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
|
|
+
|
|
|
|
|
+import static android.content.Intent.ACTION_PACKAGE_ADDED;
|
|
|
|
|
+import static android.content.Intent.ACTION_PACKAGE_REMOVED;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by ljy on 2018/9/4.
|
|
* Created by ljy on 2018/9/4.
|
|
@@ -38,12 +69,6 @@ import rx.functions.Action1;
|
|
|
public class ActPlayGameDetail extends BaseActivity implements Action1<Integer> {
|
|
public class ActPlayGameDetail extends BaseActivity implements Action1<Integer> {
|
|
|
@BindView(R.id.appbar_act_game_details)
|
|
@BindView(R.id.appbar_act_game_details)
|
|
|
AppBarLayout appbarActGameDetails;
|
|
AppBarLayout appbarActGameDetails;
|
|
|
- @BindView(R.id.find_game_list)
|
|
|
|
|
- RecyclerView find_game_list;
|
|
|
|
|
- @BindView(R.id.find_game_info_wv)
|
|
|
|
|
- WebView findGameInfoWv;
|
|
|
|
|
- @BindView(R.id.item_detail_listview)
|
|
|
|
|
- MyListview itemDetailListview;
|
|
|
|
|
@BindView(R.id.bottom_line_text)
|
|
@BindView(R.id.bottom_line_text)
|
|
|
TextView bottomLineText;
|
|
TextView bottomLineText;
|
|
|
@BindView(R.id.bottom_line)
|
|
@BindView(R.id.bottom_line)
|
|
@@ -70,11 +95,28 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
|
|
|
AppCompatRatingBar find_game_xin;
|
|
AppCompatRatingBar find_game_xin;
|
|
|
@BindView(R.id.find_game_down_tv)
|
|
@BindView(R.id.find_game_down_tv)
|
|
|
TextView find_game_down_tv;
|
|
TextView find_game_down_tv;
|
|
|
|
|
+ @BindView(R.id.viewpager_act_game_details)
|
|
|
|
|
+ ViewPager mViewPager;
|
|
|
|
|
+ @BindView(R.id.tabLayout)
|
|
|
|
|
+ TabLayout tabLayout;
|
|
|
|
|
+ @BindView(R.id.welfare_gift_layout)
|
|
|
|
|
+ LinearLayout welfare_gift_layout;
|
|
|
|
|
+ @BindView(R.id.welfare_tv)
|
|
|
|
|
+ TextView welfare_tv;
|
|
|
|
|
+ @BindView(R.id.gift_tv)
|
|
|
|
|
+ TextView gift_tv;
|
|
|
|
|
|
|
|
|
|
+ private Activity activity;
|
|
|
private int id;
|
|
private int id;
|
|
|
private boolean mIsExpanded = false;//是否是折叠状态
|
|
private boolean mIsExpanded = false;//是否是折叠状态
|
|
|
- private ArrayList<String> pictureList = ListUtil.emptyList();
|
|
|
|
|
- private ImageListHelper imageListHelper = new ImageListHelper();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private GameEntity gameEntity;
|
|
|
|
|
+ private PlayGameEntity playGameEntity;
|
|
|
|
|
+ private boolean isNeedReservation = false;
|
|
|
|
|
+ private Map<String, TextView> downLoadTextViewMap = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ private GiftpackListAdapter mAdapter;
|
|
|
|
|
+ private int curPosition = 0;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
protected int getLayoutId() {
|
|
@@ -84,7 +126,7 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
|
|
|
@Override
|
|
@Override
|
|
|
public void initView() {
|
|
public void initView() {
|
|
|
id = getIntent().getIntExtra("id", 0);
|
|
id = getIntent().getIntExtra("id", 0);
|
|
|
-
|
|
|
|
|
|
|
+ activity = this;
|
|
|
TitleBarUtils.getInstance()
|
|
TitleBarUtils.getInstance()
|
|
|
.setTitle(this, "详情")
|
|
.setTitle(this, "详情")
|
|
|
.setTitleFinish(this);
|
|
.setTitleFinish(this);
|
|
@@ -93,7 +135,7 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
|
|
|
|
|
|
|
|
txt_baseactivity_title.setVisibility(View.INVISIBLE);//不显示标题栏
|
|
txt_baseactivity_title.setVisibility(View.INVISIBLE);//不显示标题栏
|
|
|
|
|
|
|
|
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, HelperUtils.BAR_HEIGH);
|
|
|
|
|
|
|
+ RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 0);
|
|
|
statusHeightView.setLayoutParams(params);
|
|
statusHeightView.setLayoutParams(params);
|
|
|
|
|
|
|
|
appbarActGameDetails.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
|
|
appbarActGameDetails.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
|
|
@@ -140,13 +182,13 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
|
|
|
layoutParams3.topMargin = /*Math.max(find_game_name_tv.getHeight() + 4 * topRow, */getResources().getDimensionPixelSize(R.dimen.find_game_top3) + verticalOffset/*)*/;
|
|
layoutParams3.topMargin = /*Math.max(find_game_name_tv.getHeight() + 4 * topRow, */getResources().getDimensionPixelSize(R.dimen.find_game_top3) + verticalOffset/*)*/;
|
|
|
find_game_info_tv.setLayoutParams(layoutParams3);
|
|
find_game_info_tv.setLayoutParams(layoutParams3);
|
|
|
//下载按钮位置变化
|
|
//下载按钮位置变化
|
|
|
- RelativeLayout.LayoutParams layoutParams4 = (RelativeLayout.LayoutParams) find_game_down_tv.getLayoutParams();
|
|
|
|
|
- layoutParams4.setMarginEnd(Math.max(ibtn_baseactivity_right.getWidth(), (G.WIDTH - find_game_down_tv.getWidth()) / 2 + verticalOffset));
|
|
|
|
|
- layoutParams4.topMargin = Math.max((titleHeight - find_game_down_tv.getHeight()) / 2, getResources().getDimensionPixelSize(R.dimen.find_game_top4) + verticalOffset);// Math.max(topRow, getResources().getDimensionPixelSize(R.dimen.find_game_top4) + verticalOffset);
|
|
|
|
|
- find_game_down_tv.setLayoutParams(layoutParams4);
|
|
|
|
|
|
|
+ RelativeLayout.LayoutParams layoutParams4 = (RelativeLayout.LayoutParams) welfare_gift_layout.getLayoutParams();
|
|
|
|
|
+ layoutParams4.setMarginEnd(Math.max(ibtn_baseactivity_right.getWidth(), (G.WIDTH - welfare_gift_layout.getWidth()) / 2 + verticalOffset));
|
|
|
|
|
+ layoutParams4.topMargin = getResources().getDimensionPixelSize(R.dimen.find_game_top5) + verticalOffset;//Math.max((titleHeight - welfare_gift_layout.getHeight()) / 2, getResources().getDimensionPixelSize(R.dimen.find_game_top4) + verticalOffset);// Math.max(topRow, getResources().getDimensionPixelSize(R.dimen.find_game_top4) + verticalOffset);
|
|
|
|
|
+ welfare_gift_layout.setLayoutParams(layoutParams4);
|
|
|
//星级位置变化
|
|
//星级位置变化
|
|
|
RelativeLayout.LayoutParams layoutParams5 = (RelativeLayout.LayoutParams) find_game_xin.getLayoutParams();
|
|
RelativeLayout.LayoutParams layoutParams5 = (RelativeLayout.LayoutParams) find_game_xin.getLayoutParams();
|
|
|
- layoutParams5.topMargin = getResources().getDimensionPixelSize(R.dimen.find_game_top5) + verticalOffset;
|
|
|
|
|
|
|
+ layoutParams5.topMargin = getResources().getDimensionPixelSize(R.dimen.find_game_top210) + verticalOffset;
|
|
|
find_game_xin.setLayoutParams(layoutParams5);
|
|
find_game_xin.setLayoutParams(layoutParams5);
|
|
|
if (willTop == topRow/2) {
|
|
if (willTop == topRow/2) {
|
|
|
if (mIsExpanded) {
|
|
if (mIsExpanded) {
|
|
@@ -168,11 +210,22 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- imageListHelper.initList(this, find_game_list, pictureList);
|
|
|
|
|
|
|
+ //viewpaper
|
|
|
|
|
+ initViewPaper();
|
|
|
resetData();
|
|
resetData();
|
|
|
|
|
|
|
|
|
|
+ initData();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void initViewPaper() {
|
|
|
|
|
+ mAdapter = new GiftpackListAdapter(getSupportFragmentManager(), SheepApp.getInstance());
|
|
|
|
|
+ mAdapter.add(FgtPlayGameDetail.newInstance(gameEntity), "详情");
|
|
|
|
|
+ mAdapter.add(FgtPlaGameGift.newInstance(gameEntity), "礼包");
|
|
|
|
|
+ mViewPager.setAdapter(mAdapter);
|
|
|
|
|
+ tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
|
|
|
|
|
+ tabLayout.setupWithViewPager(mViewPager);
|
|
|
|
|
+ CommonUtil.getInstance().reflex(tabLayout, activity);
|
|
|
|
|
+ }
|
|
|
private void resetData() {
|
|
private void resetData() {
|
|
|
//游戏简介与下载
|
|
//游戏简介与下载
|
|
|
ViewUtil.setText(find_game_name_tv);
|
|
ViewUtil.setText(find_game_name_tv);
|
|
@@ -189,9 +242,81 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void initData() {
|
|
public void initData() {
|
|
|
|
|
+ GameEntity gameEntity = DataUtil.getInstance().getCacheResult(ApiKey.applications(id), GameEntity.class);
|
|
|
|
|
+ loadApp(gameEntity);
|
|
|
|
|
+
|
|
|
|
|
+ initDetailFromNet();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadApp(GameEntity gameEntity) {
|
|
|
|
|
+ if (gameEntity != null) {
|
|
|
|
|
+ loadData(gameEntity);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ resetData();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadData(GameEntity gameEntity) {
|
|
|
|
|
+ this.gameEntity = gameEntity;
|
|
|
|
|
+ playGameEntity = gameEntity.getApp();
|
|
|
|
|
+ //游戏简介与下载
|
|
|
|
|
+ GlideImageLoader.setGameImage(find_game_iv, gameEntity.getApp().getIcon());
|
|
|
|
|
+ ViewUtil.setText(find_game_name_tv, gameEntity.getApp().getName());
|
|
|
|
|
+ isNeedReservation = !gameEntity.getApp().isCanDonload();//这里认为只有两种状态:可下载与预约下载
|
|
|
|
|
+ if (isNeedReservation)
|
|
|
|
|
+ ViewUtil.setText(find_game_info_tv, String.format(Locale.CHINA, "开放时间:%s", TimeUtil.TimeStamp2Date(gameEntity.getApp().getDownload_at(), "yyyy-MM-dd\u0020HH:mm")));
|
|
|
|
|
+ else {
|
|
|
|
|
+ String format = "包体大小 (%sM)";
|
|
|
|
|
+ ViewUtil.setText(find_game_info_tv, String.format(Locale.CHINA, format, gameEntity.getApp().getPackage_size()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ find_game_xin.setRating(gameEntity.getApp().getScore() / 2);
|
|
|
|
|
+
|
|
|
|
|
+ updateView(this, gameEntity.getApp(), find_game_down_tv);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //更新按钮状态与添加点击事件
|
|
|
|
|
+ private void updateView(Activity activity, PlayGameEntity playGameEntity, TextView textView) {
|
|
|
|
|
+// if(playGameEntity.getAvailable_receive() == 0 && playGameEntity.getReceive_account() == 0){//未领取账号
|
|
|
|
|
+//
|
|
|
|
|
+// CommonUtil.getInstance()
|
|
|
|
|
+// .xiaomiRevieceAcctoun(find_game_down_tv, playGameEntity, activity);
|
|
|
|
|
+// }else
|
|
|
|
|
+ if (playGameEntity.isCanDonload()) {//可下载
|
|
|
|
|
+ downLoadTextViewMap.put(playGameEntity.getDownload_url(), textView);
|
|
|
|
|
+ downLoadTextViewMap.put(playGameEntity.getPackage_name(), textView);
|
|
|
|
|
+ playGameEntity.getFindAppHelper().updateDownloadTaskView(activity, playGameEntity, textView);
|
|
|
|
|
+ } else {//预约下载
|
|
|
|
|
+ playGameEntity.getFindAppHelper().updateReservationView(activity, playGameEntity, textView);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void initDetailFromNet() {
|
|
|
|
|
+ showProgress();
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().playGameDetail(id)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(this) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ boolean isNewData = DataUtil.getInstance().isNewData(ApiKey.playGameDetail(id));
|
|
|
|
|
+ if(isNewData) {
|
|
|
|
|
+ GameEntity gameEntity = baseMessage.getData(GameEntity.class);
|
|
|
|
|
+ loadApp(gameEntity);
|
|
|
|
|
+ }
|
|
|
|
|
+ hideProgress();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ G.showToast(baseMessage);
|
|
|
|
|
+ resetData();
|
|
|
|
|
+ hideProgress();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
@Override
|
|
@Override
|
|
|
public void call(Integer integer) {
|
|
public void call(Integer integer) {
|
|
|
|
|
|
|
@@ -203,11 +328,136 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
|
|
|
Aria.download(this).unRegister();
|
|
Aria.download(this).unRegister();
|
|
|
EventBus.getDefault().unregister(this);
|
|
EventBus.getDefault().unregister(this);
|
|
|
}
|
|
}
|
|
|
|
|
+ //获取任务对应的TextView来更新进度
|
|
|
|
|
+ private TextView getTextViewByTask(DownloadTask task) {
|
|
|
|
|
+ return getTextViewByKey(task.getKey());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
|
|
- // TODO: add setContentView(...) invocation
|
|
|
|
|
- ButterKnife.bind(this);
|
|
|
|
|
|
|
+ private TextView getTextViewByKey(String key) {
|
|
|
|
|
+ if (downLoadTextViewMap.containsKey(key))
|
|
|
|
|
+ return downLoadTextViewMap.get(key);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //下载状态监听
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onPre
|
|
|
|
|
+ void onPre(DownloadTask task) {
|
|
|
|
|
+ TextView textView = getTextViewByTask(task);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ textView.setText("准备下载中");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskStart
|
|
|
|
|
+ void taskStart(DownloadTask task) {
|
|
|
|
|
+ TextView textView = getTextViewByTask(task);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ textView.setText("开始下载中");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskResume
|
|
|
|
|
+ void taskResume(DownloadTask task) {
|
|
|
|
|
+ TextView textView = getTextViewByTask(task);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ textView.setText("恢复下载中");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //在这里处理任务执行中的状态,如进度进度条的刷新
|
|
|
|
|
+ @Download.onTaskRunning
|
|
|
|
|
+ protected void running(DownloadTask task) {
|
|
|
|
|
+ TextView textView = getTextViewByTask(task);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ textView.setText(String.format(Locale.CHINA, "%d%%", Math.abs(task.getPercent())));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskStop
|
|
|
|
|
+ void taskStop(DownloadTask task) {
|
|
|
|
|
+ TextView textView = getTextViewByTask(task);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ textView.setText(CommonUtil.CONTINUE_DOWNLOAD);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onNoSupportBreakPoint
|
|
|
|
|
+ void onNoSupportBreakPoint(DownloadTask task) {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskCancel
|
|
|
|
|
+ void taskCancel(DownloadTask task) {
|
|
|
|
|
+ TextView textView = getTextViewByTask(task);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ textView.setText("已经取消");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskFail
|
|
|
|
|
+ void taskFail(DownloadTask task) {
|
|
|
|
|
+ TextView textView = getTextViewByTask(task);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ textView.setText(CommonUtil.FAIL_DOWNLOAD);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskComplete
|
|
|
|
|
+ void taskComplete(DownloadTask task) {
|
|
|
|
|
+ TextView textView = getTextViewByTask(task);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ textView.setText(CommonUtil.START_INSTALL);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (gameEntity != null && gameEntity.getApp() != null && TextUtils.equals(task.getKey(), gameEntity.getApp().getDownload_link()))
|
|
|
|
|
+ gameEntity.getApp().updateState(DownloadTaskService.STATUS_FINISH);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Subscribe
|
|
|
|
|
+ public void onEventMainThread(Intent intent) {
|
|
|
|
|
+ if (intent != null && intent.getAction() != null && intent.getDataString() != null && intent.getDataString().contains("package:")) {
|
|
|
|
|
+ String packageName = intent.getDataString().replace("package:", "");
|
|
|
|
|
+
|
|
|
|
|
+ TextView textView = getTextViewByKey(packageName);
|
|
|
|
|
+ if (textView != null) {
|
|
|
|
|
+ switch (intent.getAction()) {
|
|
|
|
|
+ case ACTION_PACKAGE_ADDED:
|
|
|
|
|
+ textView.setText(CommonUtil.GAME_OPEN);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case ACTION_PACKAGE_REMOVED:
|
|
|
|
|
+ String path = PackageUtil.isExistsFile(packageName);
|
|
|
|
|
+ if (TextUtils.isEmpty(path)) {
|
|
|
|
|
+ textView.setText(CommonUtil.START_DOWNLOAD);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ textView.setText(CommonUtil.START_INSTALL);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (playGameEntity != null && TextUtils.equals(packageName, playGameEntity.getPackage_names())) {
|
|
|
|
|
+ switch (intent.getAction()) {
|
|
|
|
|
+ case ACTION_PACKAGE_ADDED:
|
|
|
|
|
+ playGameEntity.updateState(DownloadTaskService.STATUS_INSTALLED);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case ACTION_PACKAGE_REMOVED:
|
|
|
|
|
+ String path = PackageUtil.isExistsFile(packageName);
|
|
|
|
|
+ if (TextUtils.isEmpty(path)) {
|
|
|
|
|
+ playGameEntity.updateState(DownloadTaskService.STATUS_INIT);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ playGameEntity.updateState(DownloadTaskService.STATUS_FINISH);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Subscribe
|
|
|
|
|
+ public void onEventMainThread(BigEvent event) {
|
|
|
|
|
+ switch (event.getEventTypes()){
|
|
|
|
|
+ case REFRESH_XIAOMI_GAME_LIST:
|
|
|
|
|
+ initData();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|