Переглянути джерело

home page shop goods recommends bar

billyyoyo 6 роки тому
батько
коміт
6c42b46965

+ 3 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -1965,4 +1965,7 @@ public interface ApiService {
     @GET("app/user/novice_guide")
     Observable<BaseMessage> checkNewbieGuideViewed();
 
+    @GET("app/shop/recommends")
+    Observable<BaseMessage> getShopRecommends(@Query("size") int size);
+
 }

+ 136 - 0
app/src/main/java/com/sheep/gamegroup/module/home/GoodsRecommendsBarHelper.java

@@ -0,0 +1,136 @@
+package com.sheep.gamegroup.module.home;
+
+import android.content.Context;
+import android.graphics.Paint;
+import android.support.annotation.NonNull;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.kfzs.duanduan.cardview.ScreenUtil;
+import com.kfzs.duanduan.utils.NumberFormatUtils;
+import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.entity.ShopGoodsInfo;
+import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.util.Jump2View;
+import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+import io.reactivex.Scheduler;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
+
+public class GoodsRecommendsBarHelper {
+
+    private Context mContext;
+
+    @BindView(R.id.list_view)
+    public RecyclerView listView;
+
+    private GoodsAdapter mAdapter;
+
+    private int tileWidth = 0;
+
+    public GoodsRecommendsBarHelper(Context context, View view) {
+        mContext = context;
+        ButterKnife.bind(this, view);
+        tileWidth = (int) ((ScreenUtil.getScreenWidth(context) - ScreenUtil.dip2px(context, 30)) / 3.5) - ScreenUtil.dip2px(context, 8);
+        initView();
+        initData();
+    }
+
+    private void initView() {
+        mAdapter = new GoodsAdapter();
+        listView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
+        listView.setAdapter(mAdapter);
+    }
+
+    private void initData() {
+        SheepApp.getInstance().getNetComponent().getApiService().getShopRecommends(8)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+                        ((View) listView.getParent()).setVisibility(View.GONE);
+                    }
+
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+                        mAdapter.setData(baseMessage.getDataList(ShopGoodsInfo.class));
+                    }
+                });
+    }
+
+    private class GoodsAdapter extends RecyclerView.Adapter<GoodsHoder> {
+        private List<ShopGoodsInfo> goodsList = new ArrayList<>();
+
+        private void setData(List<ShopGoodsInfo> list) {
+            goodsList = list;
+            notifyDataSetChanged();
+        }
+
+        @NonNull
+        @Override
+        public GoodsHoder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
+            View tileView = LayoutInflater.from(mContext).inflate(R.layout.goods_recommends_tile, viewGroup, false);
+            return new GoodsHoder(tileView);
+        }
+
+        @Override
+        public void onBindViewHolder(@NonNull GoodsHoder viewHolder, int i) {
+            viewHolder.bind(goodsList.get(i));
+        }
+
+        @Override
+        public int getItemCount() {
+            return goodsList.size();
+        }
+    }
+
+    public class GoodsHoder extends RecyclerView.ViewHolder {
+
+        private ShopGoodsInfo goods;
+
+        @BindView(R.id.image_view)
+        public ImageView imageView;
+        @BindView(R.id.name_view)
+        public TextView nameView;
+        @BindView(R.id.price_view)
+        public TextView priceView;
+
+        public GoodsHoder(@NonNull View itemView) {
+            super(itemView);
+            ButterKnife.bind(this, itemView);
+            imageView.getLayoutParams().width = tileWidth;
+            imageView.getLayoutParams().height = tileWidth;
+            itemView.setOnClickListener(v -> Jump2View.getInstance().gotoYYShopMerchandise(mContext, goods.getId() + ""));
+        }
+
+        public void bind(ShopGoodsInfo info) {
+            goods = info;
+            ViewUtil.setImage(imageView, info.getImage(), ScreenUtil.dip2px(mContext, 8));
+            ViewUtil.setText(nameView, info.getName());
+            ViewUtil.setText(priceView, String.format(Locale.CHINA, "¥%s起", NumberFormatUtils.retainMost2(info.getVipPrice())));
+        }
+
+    }
+
+    @OnClick({R.id.enter_shop_btn, R.id.enter_shop_ico})
+    public void enterShop() {
+        Jump2View.getInstance().gotoYYShop(mContext);
+    }
+
+}

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -2894,7 +2894,7 @@ public class Jump2View {
     }
 
     public void gotoYYShopMerchandise(Context activity, String merId) {
-        CommonUtil.getInstance().getConfigValue(Config.KEY_YY_SHOP_URL, url -> {
+        CommonUtil.getInstance().getConfigValue(Config.KEY_YY_SHOP_GOODS_URL, url -> {
             if (TextUtils.isEmpty(url)) {
                 url = "http://smallstation.9yan.io/yy_shop/#/pages/goods/goodsDetail";
             }

+ 4 - 0
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtSmallSheep.java

@@ -74,6 +74,7 @@ import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.model.util.ShowRedDot;
 import com.sheep.gamegroup.module.game.util.HpRefreshWelfareHelper;
 import com.sheep.gamegroup.module.guide.NewbieGuideHelper;
+import com.sheep.gamegroup.module.home.GoodsRecommendsBarHelper;
 import com.sheep.gamegroup.module.home.adapter.AdpHomeList;
 import com.sheep.gamegroup.module.home.fragment.FgtDailyPlayList;
 import com.sheep.gamegroup.module.home.fragment.FgtPromoteGoodsList;
@@ -187,6 +188,8 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
     LinearLayout titleCardLayout;
     @BindView(R.id.home_award_container)
     View home_award_container;
+    @BindView(R.id.goods_recommends_bar)
+    View goods_recommends_bar;
     /* 记录滑动坐标的数组 */
     int[] locate = new int[2];
 
@@ -704,6 +707,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
                 });
             }
         });
+        new GoodsRecommendsBarHelper(getContext(), goods_recommends_bar);
     }
 
     private int curPosition = 0;

+ 1 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/Config.java

@@ -56,6 +56,7 @@ public class Config {
     //有范商城地址的 key
     public static final String KEY_YF_SHOP_URL = "yf_shop_url";
     public static final String KEY_YY_SHOP_URL = "yy_shop_url";
+    public static final String KEY_YY_SHOP_GOODS_URL = "yy_shop_item_url";
     //龙猫竞猜分享地址 key
     public static final String KEY_LMJC_URL = "lmjc_url";
     //充值VIP地址的 key

+ 43 - 0
app/src/main/res/layout/goods_recommends_bar.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:padding="15dp"
+    android:background="@color/white">
+
+    <TextView
+        android:text="每日推荐"
+        android:textColor="@color/black_6_3"
+        android:textSize="16sp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+    <TextView
+        android:id="@+id/enter_shop_btn"
+        android:text="进入商城"
+        android:textColor="@color/gray_999"
+        android:textSize="11sp"
+        android:layout_alignParentRight="true"
+        android:layout_marginTop="3dp"
+        android:layout_marginRight="10dp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+    
+    <ImageView
+        android:id="@+id/enter_shop_ico"
+        android:src="@mipmap/x_ic_next"
+        android:layout_alignParentRight="true"
+        android:tint="@color/gray_999"
+        android:layout_marginTop="5dp"
+        android:padding="1dp"
+        android:layout_width="10dp"
+        android:layout_height="10dp" />
+
+    <android.support.v7.widget.RecyclerView
+        android:id="@+id/list_view"
+        android:layout_marginTop="30dp"
+        android:minHeight="50dp"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
+
+</RelativeLayout>

+ 41 - 0
app/src/main/res/layout/goods_recommends_tile.xml

@@ -0,0 +1,41 @@
+<?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="wrap_content"
+    android:layout_height="wrap_content"
+    android:layout_marginRight="8dp">
+
+    <ImageView
+        android:id="@+id/image_view"
+        android:layout_width="80dp"
+        android:layout_height="80dp"
+        android:src="@mipmap/ic_launcher"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <TextView
+        android:id="@+id/name_view"
+        android:text="提绳保温杯"
+        android:textSize="12sp"
+        android:textColor="@color/black_6_3"
+        app:layout_constraintTop_toBottomOf="@+id/image_view"
+        android:layout_marginTop="10dp"
+        android:lines="1"
+        android:ellipsize="end"
+        app:layout_constraintLeft_toLeftOf="@+id/image_view"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+    <TextView
+        android:id="@+id/price_view"
+        android:text="¥21.00"
+        android:textSize="12sp"
+        android:textColor="#F21245"
+        app:layout_constraintTop_toBottomOf="@+id/name_view"
+        app:layout_constraintLeft_toLeftOf="@+id/name_view"
+        android:lines="1"
+        android:layout_marginTop="7dp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+</android.support.constraint.ConstraintLayout>

+ 8 - 1
app/src/main/res/layout/homepage_act_layout.xml

@@ -115,12 +115,19 @@
                 </LinearLayout>
 
                 <include
+                    android:id="@+id/goods_recommends_bar"
+                    layout="@layout/goods_recommends_bar"
+                    android:layout_below="@+id/home_award_container"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"/>
+
+                <include
                     android:id="@+id/hp_refresh_welfare_box"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:visibility="gone"
                     layout="@layout/inclue_hp_refresh_welfare_box"
-                    android:layout_below="@id/home_award_container" />
+                    android:layout_below="@id/goods_recommends_bar" />
 
                 <LinearLayout
                     android:id="@+id/home_vp_ll"