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