|
|
@@ -0,0 +1,140 @@
|
|
|
+package com.sheep.gamegroup.module.game.util;
|
|
|
+
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.sheep.gamegroup.absBase.AbsObserver;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.WebParams;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.module.yf_shop.model.GetPromoteGoodsUrl;
|
|
|
+import com.sheep.gamegroup.module.yf_shop.model.PromoteGoods;
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
+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.Locale;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+import butterknife.OnClick;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by realicing on 2019/3/27.
|
|
|
+ * realicing@sina.com
|
|
|
+ * 小绵羊3.5.3新增 -- 商品限时抢购
|
|
|
+ */
|
|
|
+public class PromoteGoodsHelper {
|
|
|
+
|
|
|
+ private View play_game_promote_goods;
|
|
|
+
|
|
|
+ public PromoteGoodsHelper(View play_game_promote_goods) {
|
|
|
+ this.play_game_promote_goods = play_game_promote_goods;
|
|
|
+ ButterKnife.bind(this, play_game_promote_goods);
|
|
|
+ initView();
|
|
|
+ }
|
|
|
+
|
|
|
+ @BindView(R.id.item_icon_iv)
|
|
|
+ ImageView item_icon_iv;
|
|
|
+ @BindView(R.id.item_remainder_time)
|
|
|
+ TextView item_remainder_time;
|
|
|
+ @BindView(R.id.item_name_tv)
|
|
|
+ TextView item_name_tv;
|
|
|
+ @BindView(R.id.item_yuan_jia_tv)
|
|
|
+ TextView item_yuan_jia_tv;
|
|
|
+ @BindView(R.id.item_xian_jia_tv)
|
|
|
+ TextView item_xian_jia_tv;
|
|
|
+ @BindView(R.id.item_discount_box)
|
|
|
+ LinearLayout item_discount_box;
|
|
|
+ @BindView(R.id.item_discount_tv)
|
|
|
+ TextView item_discount_tv;
|
|
|
+
|
|
|
+ @OnClick(R.id.hp_gwe_tv2)
|
|
|
+ public void toPromoteGoodsList() {//跳转到商城列表
|
|
|
+ if(TextUtils.isEmpty(baseUrl)){
|
|
|
+ G.showToast(R.string.please_contact_customer_service);
|
|
|
+ } else {
|
|
|
+ Jump2View.getInstance().goWeb(SheepApp.getInstance().getCurrentActivity(), baseUrl, "商品限时抢购");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @OnClick(R.id.item_look_more)
|
|
|
+ public void toLookMore() {//跳转到商城列表
|
|
|
+ toPromoteGoodsList();
|
|
|
+ }
|
|
|
+ @OnClick(R.id.item_change_one_tv)
|
|
|
+ public void toChangeOne() {//切换到下一个
|
|
|
+ ViewUtil.setVisibility(play_game_promote_goods, false);
|
|
|
+ ViewUtil.delay2(new AbsObserver<Integer>(){
|
|
|
+ @Override
|
|
|
+ public void onNext(Integer o) {
|
|
|
+ loadMore();
|
|
|
+ }
|
|
|
+ }, 100L);
|
|
|
+ }
|
|
|
+
|
|
|
+ //初始化刷新福利
|
|
|
+ private void initView() {
|
|
|
+ refreshData();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void refreshData() {
|
|
|
+ page = 1;
|
|
|
+ per_page = 1;
|
|
|
+ initData();
|
|
|
+ }
|
|
|
+ public void loadMore() {
|
|
|
+ page++;
|
|
|
+ initData();
|
|
|
+ }
|
|
|
+ private int page = 1;
|
|
|
+ private int per_page = 1;
|
|
|
+ public void initData() {
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getYfShopPromoteGoods(page, per_page)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ loadData(baseMessage.getData(GetPromoteGoodsUrl.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ if(baseMessage.getCode() != null && baseMessage.getCode() == 400){
|
|
|
+ //已经翻到最后一个,需要重新获取第一个数据
|
|
|
+ refreshData();
|
|
|
+ } else {
|
|
|
+ ViewUtil.setVisibility(play_game_promote_goods, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ private String baseUrl;
|
|
|
+ private void loadData(GetPromoteGoodsUrl getPromoteGoodsUrl){
|
|
|
+ baseUrl = getPromoteGoodsUrl.getList_url();
|
|
|
+ PromoteGoods item = ListUtil.getItem(getPromoteGoodsUrl.getList(), 0);
|
|
|
+ ViewUtil.setVisibility(play_game_promote_goods, item != null);
|
|
|
+ if(item == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ViewUtil.setImage(item_icon_iv, item.getGoods_thumb());
|
|
|
+ ViewUtil.setText(item_name_tv, item.getGoods_name());
|
|
|
+ ViewUtil.setText(item_remainder_time, item.getRemainderTime());
|
|
|
+ ViewUtil.setText(item_yuan_jia_tv, item.getPromotePriceText());
|
|
|
+ ViewUtil.setText(item_xian_jia_tv, item.getMarketPriceText());
|
|
|
+ ViewUtil.setText(item_discount_tv, item.getDiscountText());
|
|
|
+ item_discount_box.setOnClickListener(view -> {
|
|
|
+ String url = String.format(Locale.CHINA, "%s?id=%s", getPromoteGoodsUrl.getGoods_url(), item.getGoods_id());
|
|
|
+ Jump2View.getInstance().goWeb(SheepApp.getInstance().getCurrentActivity(), new WebParams(url).setTitle(item.getGoods_name()));
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+}
|