|
|
@@ -14,6 +14,8 @@ import com.sheep.gamegroup.model.entity.Applications;
|
|
|
import com.sheep.gamegroup.model.entity.GiftBag;
|
|
|
import com.sheep.gamegroup.model.entity.GiftBagApp;
|
|
|
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.Jump2View;
|
|
|
import com.sheep.gamegroup.util.StringUtils;
|
|
|
@@ -44,6 +46,7 @@ import static com.sheep.gamegroup.view.adapter.WelfareAdapter.TO_REFRESH;
|
|
|
public class GiftCenterAdapter extends AdbCommonRecycler<GiftBagApp> {
|
|
|
|
|
|
private Action1<Integer> action1;
|
|
|
+
|
|
|
public GiftCenterAdapter(Context context, List<GiftBagApp> list, Action1<Integer> action1) {
|
|
|
super(context, list);
|
|
|
this.action1 = action1;
|
|
|
@@ -56,17 +59,18 @@ public class GiftCenterAdapter extends AdbCommonRecycler<GiftBagApp> {
|
|
|
|
|
|
@Override
|
|
|
public void convert(ViewHolder holder, final GiftBagApp item) {
|
|
|
- ImageView item_download_welfare_iv = (ImageView)holder.getView(R.id.item_download_welfare_iv);
|
|
|
- ImageView item_download_welfare_tip_iv = (ImageView)holder.getView(R.id.item_download_welfare_tip_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);
|
|
|
- TextView item_download_welfare_money = (TextView)holder.getView(R.id.item_download_welfare_money);
|
|
|
- TextView item_download_welfare_num_tv = (TextView)holder.getView(R.id.item_download_welfare_num_tv);
|
|
|
- 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);
|
|
|
- TextView item_download_welfare_btn_center = (TextView)holder.getView(R.id.item_download_welfare_btn_center);
|
|
|
+ ImageView item_download_welfare_vip_flag = (ImageView) holder.getView(R.id.item_download_welfare_vip_flag);
|
|
|
+ ImageView item_download_welfare_iv = (ImageView) holder.getView(R.id.item_download_welfare_iv);
|
|
|
+ ImageView item_download_welfare_tip_iv = (ImageView) holder.getView(R.id.item_download_welfare_tip_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);
|
|
|
+ TextView item_download_welfare_money = (TextView) holder.getView(R.id.item_download_welfare_money);
|
|
|
+ TextView item_download_welfare_num_tv = (TextView) holder.getView(R.id.item_download_welfare_num_tv);
|
|
|
+ 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);
|
|
|
+ TextView item_download_welfare_btn_center = (TextView) holder.getView(R.id.item_download_welfare_btn_center);
|
|
|
View item_download_welfare_line = holder.getView(R.id.item_download_welfare_line);
|
|
|
item_download_welfare_line.setVisibility(holder.getAdapterPosition() + 1 == getItemCount() ? View.GONE : View.VISIBLE);
|
|
|
item_download_welfare_money.setVisibility(View.GONE);
|
|
|
@@ -75,22 +79,23 @@ public class GiftCenterAdapter extends AdbCommonRecycler<GiftBagApp> {
|
|
|
item_download_welfare_num_tv1.setVisibility(View.GONE);
|
|
|
item_download_welfare_iv2.setVisibility(View.GONE);
|
|
|
item_download_welfare_btn_center.setVisibility(View.VISIBLE);
|
|
|
- if(item == null){
|
|
|
+ if (item == null) {
|
|
|
ViewUtil.setDefaultText(item_download_welfare_name_tv);
|
|
|
ViewUtil.setDefaultText(item_download_welfare_num_tv);
|
|
|
ViewUtil.setDefaultText(item_download_welfare_date_tv);
|
|
|
item_download_welfare_iv2.setVisibility(View.GONE);
|
|
|
item_download_welfare_tip_iv.setVisibility(View.GONE);
|
|
|
- } else if(context instanceof Activity){
|
|
|
+ } else if (context instanceof Activity) {
|
|
|
final Applications itemApp = item.getApp();
|
|
|
final GiftBag itemGiftBag = item.getGift_bag();
|
|
|
- if(itemApp == null || itemGiftBag == null){
|
|
|
+ if (itemApp == null || itemGiftBag == null) {
|
|
|
return;
|
|
|
}
|
|
|
GlideImageLoader.setGameImage(item_download_welfare_iv, itemApp.getIcon());
|
|
|
ViewUtil.setText(item_download_welfare_name_tv, itemGiftBag.getGiftName());
|
|
|
ViewUtil.setText(item_download_welfare_date_tv, itemGiftBag.getDateText());
|
|
|
- if(TextUtils.isEmpty(item.getCode())){//没有code,就视为没有领取礼包
|
|
|
+ ViewUtil.setVisibility(item_download_welfare_vip_flag, item.getGift_bag().getIsVip() == 1);
|
|
|
+ if (TextUtils.isEmpty(item.getCode())) {//没有code,就视为没有领取礼包
|
|
|
item_download_welfare_tip_iv.setVisibility(View.GONE);
|
|
|
ViewUtil.setText(item_download_welfare_num_tv, itemGiftBag.getLastNumText());
|
|
|
item_download_welfare_btn_center.setText("领取");
|
|
|
@@ -135,34 +140,53 @@ public class GiftCenterAdapter extends AdbCommonRecycler<GiftBagApp> {
|
|
|
|
|
|
/**
|
|
|
* 领取礼包
|
|
|
+ *
|
|
|
* @param activity 为空时,不显示领取成功对话框
|
|
|
* @param item
|
|
|
* @param action1
|
|
|
*/
|
|
|
public static void receiveGiftBag(final Activity activity, final GiftBagApp item, final Action1<Integer> action1) {
|
|
|
+ if (item.getGift_bag().getIsVip() == 1) {
|
|
|
+ CommonUtil.getInstance().getUserInfo(true, user -> {
|
|
|
+ if(!user.isVIP()){
|
|
|
+ ViewUtil.showConfirmDialog(activity, "温馨提示", "该礼包为VIP特权礼包,推荐您成为VIP用户,领取礼包~!",
|
|
|
+ "放弃", "成为VIP", diag -> {
|
|
|
+ },
|
|
|
+ dialog -> Jump2View.getInstance().gotoVip(activity)).show();
|
|
|
+ } else {
|
|
|
+ obtainGiftBag(activity, item, action1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ obtainGiftBag(activity, item, action1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void obtainGiftBag(final Activity activity, final GiftBagApp item, final Action1<Integer> action1) {
|
|
|
int gift_bag_id = item.getGift_bag().getId();
|
|
|
GIFT_BAG_RECEIVE.onEvent("gift_bag_id", gift_bag_id);
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().receiveGiftBag(gift_bag_id)
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
- String code = baseMessage.getData(String.class);
|
|
|
- item.setReceived(true);
|
|
|
- item.setCode(code);
|
|
|
- if(action1 != null)
|
|
|
- action1.call(TO_REFRESH);
|
|
|
- if(activity != null)
|
|
|
- ViewUtil.showGetWelfareDialog(activity, item);
|
|
|
- }
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ String code = baseMessage.getData(String.class);
|
|
|
+ item.setReceived(true);
|
|
|
+ item.setCode(code);
|
|
|
+ if (action1 != null)
|
|
|
+ action1.call(TO_REFRESH);
|
|
|
+ if (activity != null)
|
|
|
+ ViewUtil.showGetWelfareDialog(activity, item);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
- if(action1 != null)
|
|
|
- action1.call(RECEIVE_FAILED);
|
|
|
- G.showToast(baseMessage);
|
|
|
- }
|
|
|
- });
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ if (action1 != null)
|
|
|
+ action1.call(RECEIVE_FAILED);
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|