|
|
@@ -2,54 +2,35 @@ package com.sheep.gamegroup.view.adapter;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
-import android.text.Html;
|
|
|
+import android.graphics.Color;
|
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.jcodecraeer.xrecyclerview.XRecyclerView;
|
|
|
-import com.kfzs.duanduan.services.DownloadTaskService;
|
|
|
-import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
-import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
-import com.sheep.gamegroup.model.entity.TaskReleaseEty;
|
|
|
-import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
-import com.sheep.gamegroup.util.CommonUtil;
|
|
|
-import com.sheep.gamegroup.util.DeviceUtil;
|
|
|
+import com.sheep.gamegroup.model.entity.DownloadWelfare;
|
|
|
import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.ViewHolder;
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
-import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
-import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
|
import java.util.List;
|
|
|
-import java.util.Locale;
|
|
|
-
|
|
|
-import rx.android.schedulers.AndroidSchedulers;
|
|
|
-import rx.functions.Action1;
|
|
|
-import rx.schedulers.Schedulers;
|
|
|
-
|
|
|
-import static com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST;
|
|
|
|
|
|
/**
|
|
|
* Created by realicing on 2018/8/28.
|
|
|
* realicing@sina.com
|
|
|
*/
|
|
|
-public class DownloadWelfareAdapter extends AdbCommonRecycler<TaskReleaseEty>{
|
|
|
- private Action1<Integer> action1;
|
|
|
- public DownloadWelfareAdapter(Context context, List<TaskReleaseEty> list, Action1<Integer> action1) {
|
|
|
+public class DownloadWelfareAdapter extends AdbCommonRecycler<DownloadWelfare>{
|
|
|
+ public DownloadWelfareAdapter(Context context, List<DownloadWelfare> list) {
|
|
|
super(context, list);
|
|
|
- this.action1 = action1;
|
|
|
}
|
|
|
- public static final int TO_REFRESH = 1;
|
|
|
@Override
|
|
|
public int getViewIdByType(int type) {
|
|
|
return R.layout.item_download_welfare;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void convert(ViewHolder holder, final TaskReleaseEty item) {
|
|
|
+ public void convert(ViewHolder holder, final DownloadWelfare item) {
|
|
|
ImageView item_download_welfare_iv = (ImageView)holder.getView(R.id.item_download_welfare_iv);
|
|
|
ImageView item_download_welfare_iv2 = (ImageView)holder.getView(R.id.item_download_welfare_iv2);
|
|
|
TextView item_download_welfare_name_tv = (TextView)holder.getView(R.id.item_download_welfare_name_tv);
|
|
|
@@ -58,147 +39,41 @@ public class DownloadWelfareAdapter extends AdbCommonRecycler<TaskReleaseEty>{
|
|
|
TextView item_download_welfare_num_tv1 = (TextView)holder.getView(R.id.item_download_welfare_num_tv1);
|
|
|
TextView item_download_welfare_date_tv = (TextView)holder.getView(R.id.item_download_welfare_date_tv);
|
|
|
TextView item_download_welfare_btn_bottom = (TextView)holder.getView(R.id.item_download_welfare_btn_bottom);
|
|
|
- TextView item_download_welfare_btn_top = (TextView)holder.getView(R.id.item_download_welfare_btn_top);
|
|
|
View item_download_welfare_line = holder.getView(R.id.item_download_welfare_line);
|
|
|
+
|
|
|
+ item_download_welfare_iv2.setVisibility(View.GONE);
|
|
|
+ item_download_welfare_money.setTextColor(Color.parseColor("#ff999999"));
|
|
|
item_download_welfare_line.setVisibility(holder.getAdapterPosition() + 1 == getItemCount() ? View.GONE : View.VISIBLE);
|
|
|
+ item_download_welfare_btn_bottom.setText("去使用");
|
|
|
+ item_download_welfare_btn_bottom.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ if (item.getGame_id() != null) {
|
|
|
+ ViewUtil.showGamePayAccount((Activity) context, item.getGame_id(), item.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
if(item == null){
|
|
|
ViewUtil.setDefaultText(item_download_welfare_name_tv);
|
|
|
ViewUtil.setDefaultText(item_download_welfare_num_tv);
|
|
|
ViewUtil.setDefaultText(item_download_welfare_num_tv1);
|
|
|
ViewUtil.setDefaultText(item_download_welfare_date_tv);
|
|
|
ViewUtil.setDefaultText(item_download_welfare_money);
|
|
|
- item_download_welfare_iv2.setVisibility(View.GONE);
|
|
|
} else if(context instanceof Activity){
|
|
|
- final TaskEty itemTask = item.getTask();
|
|
|
- if(itemTask == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- GlideImageLoader.setGameImage(item_download_welfare_iv, itemTask.getIcon());
|
|
|
+ GlideImageLoader.setGameImage(item_download_welfare_iv, item.getIcon());
|
|
|
ViewUtil.setText(item_download_welfare_name_tv, item.getName());
|
|
|
- item_download_welfare_money.setText(Html.fromHtml(String.format(Locale.CHINA, "<font size='1'>¥</font>%s", item.getBonusText())));
|
|
|
+ ViewUtil.setText(item_download_welfare_money, item.getUseBalanceText());
|
|
|
ViewUtil.setText(item_download_welfare_num_tv, item.getGiftRatioText());
|
|
|
- ViewUtil.setText(item_download_welfare_num_tv1, item.getLastNumText());
|
|
|
+ ViewUtil.setH5Text(item_download_welfare_num_tv1, item.getBalanceH5());
|
|
|
ViewUtil.setText(item_download_welfare_date_tv, item.getDateText());
|
|
|
- item_download_welfare_iv2.setVisibility(item.isTaskFinished()? View.VISIBLE : View.INVISIBLE);
|
|
|
-
|
|
|
- item_download_welfare_btn_bottom.setTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + itemTask.getDownload_link());
|
|
|
- switch (item.getUser_task_status()){//1,已接受任务 2,正在进行中,3完成任务,4放弃任务,5任务失败,6审核失败,7提交审核,8任务已下线,9至少完成了一个任务了
|
|
|
- case 0:
|
|
|
- item_download_welfare_money.setVisibility(View.VISIBLE);
|
|
|
- item_download_welfare_btn_top.setVisibility(View.INVISIBLE);
|
|
|
- item_download_welfare_btn_bottom.setEnabled(true);
|
|
|
- item_download_welfare_btn_bottom.setText("下载领取");
|
|
|
- item_download_welfare_btn_bottom.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- acceptedTask(item.getId());
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- case 2:
|
|
|
- item_download_welfare_money.setVisibility(View.VISIBLE);
|
|
|
- item_download_welfare_btn_top.setVisibility(View.INVISIBLE);
|
|
|
- item_download_welfare_btn_bottom.setEnabled(true);
|
|
|
- item.getDownloadHelper().updateDownloadTaskView((Activity) context, itemTask, item_download_welfare_btn_bottom);
|
|
|
- if(item.getDownloadHelper().getDownLoadType() == DownloadTaskService.STATUS_INSTALLED){//已经安装的话
|
|
|
- item_download_welfare_btn_bottom.setText("领取奖励");
|
|
|
- item_download_welfare_btn_bottom.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- if (itemTask.isGameReservationCantDownload()) {
|
|
|
- CommonUtil.getInstance().reservationGameTask(context, item, new Action1<Integer>() {
|
|
|
- @Override
|
|
|
- public void call(Integer integer) {
|
|
|
- if(action1 != null)
|
|
|
- action1.call(TO_REFRESH);
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- acceptedReceiveAward(item);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- item_download_welfare_money.setVisibility(View.INVISIBLE);
|
|
|
- item_download_welfare_btn_top.setVisibility(View.VISIBLE);
|
|
|
- item.getDownloadHelper().updateDownloadTaskView((Activity) context, itemTask, item_download_welfare_btn_bottom);
|
|
|
- if(item.getDownloadHelper().getDownLoadType() == DownloadTaskService.STATUS_INSTALLED) {//已经安装的话
|
|
|
- item_download_welfare_btn_bottom.setText("启动");
|
|
|
- }
|
|
|
- item_download_welfare_btn_top.setText("充值");
|
|
|
- item_download_welfare_btn_top.setEnabled(true);
|
|
|
- item_download_welfare_btn_top.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- if (itemTask.getThird_task_id() != null) {
|
|
|
- ViewUtil.showGamePayAccount((Activity) context, itemTask.getThird_task_id(), item.getName());
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
- default:
|
|
|
- item_download_welfare_money.setVisibility(View.VISIBLE);
|
|
|
- item_download_welfare_btn_top.setVisibility(View.INVISIBLE);
|
|
|
- item_download_welfare_btn_bottom.setText("已经下线");
|
|
|
- item_download_welfare_btn_bottom.setEnabled(false);
|
|
|
- break;
|
|
|
- }
|
|
|
+ holder.itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ Jump2View.getInstance().goGameTaskDetailView(context, item.getRelease_id(), item.getGame_id(),1);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 领取任务
|
|
|
- */
|
|
|
- private void acceptedTask(int release_task_id) {
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.put("device_id", DeviceUtil.getDeviceId(SheepApp.getInstance()));
|
|
|
- object.put("release_task_id", release_task_id);
|
|
|
- SheepApp.getInstance()
|
|
|
- .getNetComponent()
|
|
|
- .getApiService()
|
|
|
- .acceptedTask(object)
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
- G.showToast(baseMessage);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {//领取任务成功
|
|
|
- G.showToast(baseMessage);
|
|
|
- if(action1 != null)
|
|
|
- action1.call(TO_REFRESH);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- /**
|
|
|
- * 领取奖励
|
|
|
- */
|
|
|
- private void acceptedReceiveAward(TaskReleaseEty item) {
|
|
|
- SheepApp.getInstance()
|
|
|
- .getNetComponent()
|
|
|
- .getApiService()
|
|
|
- .receive_award(item.getAccepted_task_id())
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
- G.showToast(baseMessage);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
- //这里领取了奖励,要刷新用户信息
|
|
|
- CommonUtil.getInstance().updateUserInfo(null);
|
|
|
- if(action1 != null)
|
|
|
- action1.call(TO_REFRESH);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
}
|