Parcourir la source

游戏主页添加限时抢购入口

zengjiebin il y a 7 ans
Parent
commit
a68b4fbe6e

+ 9 - 2
app/src/main/java/com/sheep/gamegroup/module/game/fragment/FgtPlayGame.java

@@ -24,6 +24,7 @@ import com.sheep.gamegroup.module.game.adapter.AdpGameCenterType;
 import com.sheep.gamegroup.module.game.model.GameCenterType;
 import com.sheep.gamegroup.module.game.model.GamePortTypes;
 import com.sheep.gamegroup.module.game.util.HpRefreshWelfareHelper;
+import com.sheep.gamegroup.module.game.util.PromoteGoodsHelper;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.Jump2View;
@@ -87,6 +88,10 @@ public class FgtPlayGame extends BaseFragment {
     @BindView(R.id.hp_refresh_welfare_box)
     View hp_refresh_welfare_box;
     private HpRefreshWelfareHelper mHpRefreshWelfareHelper;//刷新福利的帮助类
+    //商品限时抢购入口与刷新商品
+    @BindView(R.id.play_game_promote_goods)
+    View play_game_promote_goods;
+    private PromoteGoodsHelper mPromoteGoodsHelper;//的帮助类
     @Override
     public void onViewCreated() {
         //banner
@@ -95,8 +100,9 @@ public class FgtPlayGame extends BaseFragment {
         banner.setLayoutParams(bannerLayoutParams);
 
         //玩转游戏  游戏福利专区入口
-
         mHpRefreshWelfareHelper = new HpRefreshWelfareHelper(hp_refresh_welfare_box);
+        //玩转游戏  商城限时抢购入口
+        mPromoteGoodsHelper = new PromoteGoodsHelper(play_game_promote_goods);
 
 
         //绵羊新游、免费道具、绵羊推荐、排行榜
@@ -133,9 +139,10 @@ public class FgtPlayGame extends BaseFragment {
         initGameTagList();
         if(mHpRefreshWelfareHelper != null)
             mHpRefreshWelfareHelper.refreshData();
+        if(mPromoteGoodsHelper != null)
+            mPromoteGoodsHelper.refreshData();
     }
 
-
     //获取出包类型列表 的tagList
     private void initGameTagList() {
         gameEntityListx.clear();

+ 140 - 0
app/src/main/java/com/sheep/gamegroup/module/game/util/PromoteGoodsHelper.java

@@ -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()));
+        });
+
+    }
+}

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/module/home/fragment/FgtPromoteGoodsList.java

@@ -154,7 +154,7 @@ public class FgtPromoteGoodsList extends BaseFragment implements ILoadMore, IRef
         try {
             GetPromoteGoodsUrl getPromoteGoodsUrl = DataUtil.getInstance().getCacheResult(getKey(), GetPromoteGoodsUrl.class);
             if(getPromoteGoodsUrl != null){
-                adapter.setBaseUrl(getPromoteGoodsUrl.getUrl());
+                adapter.setBaseUrl(getPromoteGoodsUrl.getGoods_url());
                 ListUtil.addAllItem(list, getPromoteGoodsUrl.getList());
             }
             notifyDataSetChanged();
@@ -179,7 +179,7 @@ public class FgtPromoteGoodsList extends BaseFragment implements ILoadMore, IRef
                                 if (isNewData) {
                                     GetPromoteGoodsUrl getPromoteGoodsUrl = baseMessage.getData(GetPromoteGoodsUrl.class);
                                     if(getPromoteGoodsUrl != null){
-                                        adapter.setBaseUrl(getPromoteGoodsUrl.getUrl());
+                                        adapter.setBaseUrl(getPromoteGoodsUrl.getGoods_url());
                                         ListUtil.addAllItem(list, getPromoteGoodsUrl.getList());
                                     }
                                 }

+ 16 - 4
app/src/main/java/com/sheep/gamegroup/module/yf_shop/model/GetPromoteGoodsUrl.java

@@ -8,7 +8,8 @@ import java.util.List;
  */
 public class GetPromoteGoodsUrl {
     private List<PromoteGoods> list;
-    private String url;
+    private String goods_url;
+    private String list_url;
 
     public List<PromoteGoods> getList() {
         return list;
@@ -19,10 +20,21 @@ public class GetPromoteGoodsUrl {
     }
 
     public String getUrl() {
-        return url;
+        return goods_url;
+    }
+    public String getGoods_url() {
+        return goods_url;
+    }
+
+    public void setGoods_url(String goods_url) {
+        this.goods_url = goods_url;
+    }
+
+    public String getList_url() {
+        return list_url;
     }
 
-    public void setUrl(String url) {
-        this.url = url;
+    public void setList_url(String list_url) {
+        this.list_url = list_url;
     }
 }

+ 4 - 0
app/src/main/res/layout/fgt_play_game.xml

@@ -54,6 +54,10 @@
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content" />
 
+            <include
+                android:id="@+id/play_game_promote_goods"
+                layout="@layout/item_game_promote_goods"/>
+
         </LinearLayout>
 
     </android.support.v4.widget.NestedScrollView>

+ 47 - 0
app/src/main/res/layout/include_look_more_and_change.xml

@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <ImageView
+        android:id="@+id/item_change_one_iv"
+        android:layout_width="22dp"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="12dp"
+        android:adjustViewBounds="true"
+        android:padding="5dp"
+        android:scaleType="fitXY"
+        android:src="@mipmap/ic_change_one"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <TextView
+        android:id="@+id/item_change_one_tv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:paddingTop="14dp"
+        android:paddingBottom="14dp"
+        android:paddingStart="14dp"
+        android:paddingEnd="39dp"
+        android:text="换一个"
+        android:textColor="#ff333333"
+        android:textSize="12sp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <TextView
+        android:id="@+id/item_look_more"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="114dp"
+        android:padding="15dp"
+        android:text="查看更多"
+        android:textColor="#ff8e8e8e"
+        android:textSize="10sp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+</android.support.constraint.ConstraintLayout>

+ 22 - 0
app/src/main/res/layout/item_game_promote_goods.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="10dp"
+        android:background="@color/bg_home_color"/>
+    <include layout="@layout/hp_game_welfare_entrance"/>
+    <include
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="-7dp"
+        layout="@layout/item_hp_promote_goods"/>
+    <include
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="-11dp"
+        android:layout_marginBottom="7dp"
+        layout="@layout/include_look_more_and_change"/>
+</LinearLayout>