Ver Fonte

假数据

詹子聪 há 5 anos atrás
pai
commit
33d7163eb6

+ 0 - 15
app/src/main/java/com/miekir/ym/constant/FragmentType.java

@@ -1,15 +0,0 @@
-package com.miekir.ym.constant;
-
-/**
- * Copyright (C), 2019-2020, Miekir
- *
- * @author Miekir
- * @date 2020/11/24 22:49
- * Description:
- */
-public interface FragmentType {
-    /**
-     * 数码产品
-     */
-    int DIGITAL = 0;
-}

+ 43 - 0
app/src/main/java/com/miekir/ym/tool/DataTool.java

@@ -0,0 +1,43 @@
+package com.miekir.ym.tool;
+
+
+import com.miekir.ym.constant.ConstantUrl;
+import com.miekir.ym.ui.coupon.CouponBean;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Miekir
+ * @date 2020/7/8 19:36
+ * Description: 模拟数据提供者
+ */
+public class DataTool {
+    private DataTool() {
+    }
+
+    public static List<CouponBean> getTemplateList() {
+
+        List<CouponBean> couponBeanList = new ArrayList<>();
+        CouponBean meituan1 = new CouponBean();
+        //meituan1.coverUrl = ConstantUrl.URL_RANDOM_PHOTO_WALLPAPER;
+        meituan1.coverUrl = ConstantUrl.URL_RANDOM_PHOTO_ECY;
+        meituan1.couponName = "美团优惠券最多可领48元大礼包";
+        meituan1.jumpUrl = ConstantUrl.URL_MEITUAN_BONUS_1;
+        meituan1.actionEnable = true;
+
+        CouponBean meituan2 = new CouponBean();
+        //meituan2.coverUrl = ConstantUrl.URL_RANDOM_PHOTO_WALLPAPER;
+        meituan2.coverUrl = ConstantUrl.URL_RANDOM_PHOTO_ECY;
+        meituan2.couponName = "美团优惠券至少2元起(新老用户都可领)";
+        meituan2.jumpUrl = ConstantUrl.URL_MEITUAN_BONUS_2;
+        meituan2.actionEnable = true;
+
+        couponBeanList.add(meituan2);
+        couponBeanList.add(meituan1);
+
+        return couponBeanList;
+    }
+
+
+}

+ 5 - 6
app/src/main/java/com/miekir/ym/ui/MainActivity.kt

@@ -6,10 +6,9 @@ import com.flyco.tablayout.listener.OnTabSelectListener
 import com.miekir.common.adapter.TabFragmentAdapter
 import com.miekir.ym.R
 import com.miekir.ym.base.YangActivity
-import com.miekir.ym.constant.FragmentType
 import com.miekir.ym.listener.AppbarTranslateListener
 import com.miekir.ym.listener.ITopActionListener
-import com.miekir.ym.ui.about.AboutFragment
+import com.miekir.ym.ui.coupon.CouponBean
 import com.miekir.ym.ui.coupon.CouponFragment
 import kotlinx.android.synthetic.main.activity_main.*
 import java.util.*
@@ -22,10 +21,10 @@ class MainActivity : YangActivity() {
     override fun initViews(savedInstanceState: Bundle?) {
         val titles = arrayOf("数码", "美食", "工具", "关于")
         val fragments: ArrayList<Fragment> = ArrayList()
-        fragments.add(CouponFragment(FragmentType.DIGITAL))
-        fragments.add(CouponFragment(FragmentType.DIGITAL))
-        fragments.add(CouponFragment(FragmentType.DIGITAL))
-        fragments.add(CouponFragment(FragmentType.DIGITAL))
+        fragments.add(CouponFragment(CouponBean.TYPE_ALL))
+        fragments.add(CouponFragment(CouponBean.TYPE_ALL))
+        fragments.add(CouponFragment(CouponBean.TYPE_ALL))
+        fragments.add(CouponFragment(CouponBean.TYPE_ALL))
 
         val adapter = TabFragmentAdapter(supportFragmentManager, fragments)
         vp_main.adapter = adapter

+ 29 - 36
app/src/main/java/com/miekir/ym/ui/coupon/CouponAdapter.java

@@ -34,49 +34,43 @@ public class CouponAdapter extends BaseQuickAdapter<CouponBean, BaseViewHolder>
     private Context mContext;
 
     public CouponAdapter(Context context, @Nullable List<CouponBean> data) {
-        super(R.layout.item_template, data);
+        super(R.layout.item_coupon, data);
         mRadius = (int) context.getResources().getDimension(R.dimen.margin_s);
         mContext = context;
     }
 
     @Override
     protected void convert(@NonNull BaseViewHolder holder, CouponBean couponBean) {
-        ImageView iv_template = holder.getView(R.id.iv_template);
+        ImageView iv_coupon = holder.getView(R.id.iv_coupon);
         // 解决图片错乱
-        iv_template.setTag(R.id.iv_template, couponBean.coverUrl);
-        if (couponBean.isCoverUrlLocal) {
-            int resourceId = Integer.parseInt(couponBean.coverUrl);
-            iv_template.setScaleType(ImageView.ScaleType.CENTER_CROP);
-            iv_template.setImageResource(resourceId);
-        } else {
-            // 圆角
-            Glide.with(mContext).load(couponBean.coverUrl)
-                    //先加载原图大小的十分之一
-                    .thumbnail(0.1f)
-                    .into(new SimpleTarget<Drawable>() {
-                        @Override
-                        public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
-                            if (resource == null) {
-                                iv_template.setImageResource(R.mipmap.logo_gray);
-                                return;
-                            }
+        iv_coupon.setTag(R.id.iv_coupon, couponBean.coverUrl);
 
-                            String coverUrl = null;
-                            try {
-                                coverUrl = (String) iv_template.getTag(R.id.iv_template);
-                            } catch (Exception e) {
-                                e.printStackTrace();
-                            }
-                            if (TextUtils.isEmpty(coverUrl) || !TextUtils.equals(coverUrl, couponBean.coverUrl)) {
-                                iv_template.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
-                                iv_template.setImageResource(R.mipmap.logo_gray);
-                            } else {
-                                iv_template.setScaleType(ImageView.ScaleType.CENTER_CROP);
-                                iv_template.setImageDrawable(resource);
-                            }
-                        }
-                    });
-        }
+        Glide.with(mContext).load(couponBean.coverUrl)
+            //先加载原图大小的十分之一
+            .thumbnail(0.1f)
+            .into(new SimpleTarget<Drawable>() {
+                @Override
+                public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
+                    if (resource == null) {
+                        iv_coupon.setImageResource(R.mipmap.logo_gray);
+                        return;
+                    }
+
+                    String coverUrl = null;
+                    try {
+                        coverUrl = (String) iv_coupon.getTag(R.id.iv_coupon);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                    if (TextUtils.isEmpty(coverUrl) || !TextUtils.equals(coverUrl, couponBean.coverUrl)) {
+                        iv_coupon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
+                        iv_coupon.setImageResource(R.mipmap.logo_gray);
+                    } else {
+                        iv_coupon.setScaleType(ImageView.ScaleType.CENTER_CROP);
+                        iv_coupon.setImageDrawable(resource);
+                    }
+                }
+            });
 
 
         holder.setText(R.id.tv_template, couponBean.couponName);
@@ -87,7 +81,6 @@ public class CouponAdapter extends BaseQuickAdapter<CouponBean, BaseViewHolder>
                     ToastTool.showShort("敬请期待");
                     return;
                 }
-
                 ActivityTool.openUrl((Activity) mContext, couponBean.jumpUrl);
             }
         });

+ 13 - 11
app/src/main/java/com/miekir/ym/ui/coupon/CouponBean.java

@@ -12,6 +12,19 @@ import java.io.Serializable;
  * Description: 优惠券实体
  */
 public class CouponBean implements Serializable {
+    /**
+     * 全部
+     */
+    public static final int TYPE_ALL = 0;
+    /**
+     * 生活
+     */
+    public static final int TYPE_LIVE = 1;
+    /**
+     * 数字
+     */
+    public static final int TYPE_DIGITAL = 2;
+
     /**
      * 模板Id
      */
@@ -20,7 +33,6 @@ public class CouponBean implements Serializable {
      * 模板类型
      */
     public int couponType;
-
     /**
      * 模板名称
      */
@@ -33,35 +45,25 @@ public class CouponBean implements Serializable {
      * 封面图片URL
      */
     public String coverUrl = ConstantUrl.URL_RANDOM_PHOTO_WALLPAPER;
-
-
     /**
      * 是否可以响应点击
      */
     public boolean actionEnable;
-
-    /**是否是本地写死的数据*/
-    public boolean isLocal;
-
     /**
      * 创建时间
      */
     public long createTimeMillis;
-
     /**
      * 更新时间
      */
     public long updateTimeMillis;
 
-    public boolean isCoverUrlLocal;
-
     public void updateData(CouponBean couponBean) {
         this.couponType = couponBean.couponType;
         this.couponName = couponBean.couponName;
         this.coverUrl = couponBean.coverUrl;
         this.jumpUrl = couponBean.jumpUrl;
         this.actionEnable = couponBean.actionEnable;
-        this.isLocal = couponBean.isLocal;
         this.createTimeMillis = couponBean.createTimeMillis;
         this.updateTimeMillis = couponBean.updateTimeMillis;
     }

+ 4 - 10
app/src/main/java/com/miekir/ym/ui/coupon/CouponFragment.java

@@ -1,7 +1,6 @@
 package com.miekir.ym.ui.coupon;
 
 import android.content.DialogInterface;
-import android.content.Intent;
 
 import androidx.appcompat.app.AlertDialog;
 import androidx.recyclerview.widget.LinearLayoutManager;
@@ -13,7 +12,6 @@ import com.miekir.common.utils.ToastTool;
 import com.miekir.mvp.presenter.InjectPresenter;
 import com.miekir.mvp.view.BaseMvpFragment;
 import com.miekir.ym.R;
-import com.miekir.ym.constant.FragmentType;
 import com.miekir.ym.listener.ITopActionListener;
 import com.miekir.ym.listener.OnRcvScrollListener;
 import com.miekir.ym.widget.NormalDividerItemDecoration;
@@ -28,7 +26,7 @@ public class CouponFragment extends BaseMvpFragment implements ICouponView<Coupo
     private static final int PAGE_START = 0;
     private static final int PAGE_SIZE = 20;
 
-    private int mTemplateType = FragmentType.DIGITAL;
+    private int mTemplateType = CouponBean.TYPE_ALL;
 
     @InjectPresenter
     CouponPresenter mPresenter;
@@ -77,7 +75,7 @@ public class CouponFragment extends BaseMvpFragment implements ICouponView<Coupo
         srl_template.setOnRefreshListener(() -> {
             mIsRefresh = true;
             mCurrentPage = PAGE_START;
-            mPresenter.getTemplateData(mCurrentPage, PAGE_SIZE);
+            mPresenter.getCouponData(mCurrentPage, PAGE_SIZE);
         });
 
         // 加载更多
@@ -89,7 +87,7 @@ public class CouponFragment extends BaseMvpFragment implements ICouponView<Coupo
                 if (!srl_template.isRefreshing()) {
                     mIsRefresh = false;
                     srl_template.setRefreshing(true);
-                    mPresenter.getTemplateData(mCurrentPage, PAGE_SIZE);
+                    mPresenter.getCouponData(mCurrentPage, PAGE_SIZE);
                 }
             }
         });
@@ -99,7 +97,7 @@ public class CouponFragment extends BaseMvpFragment implements ICouponView<Coupo
     protected void onLazyLoad() {
         // 获取数据
         srl_template.setRefreshing(true);
-        mPresenter.getTemplateData(mCurrentPage, PAGE_SIZE);
+        mPresenter.getCouponData(mCurrentPage, PAGE_SIZE);
     }
 
     /**
@@ -107,10 +105,6 @@ public class CouponFragment extends BaseMvpFragment implements ICouponView<Coupo
      */
     private void showAdminDialog(int position) {
         CouponBean couponBean = mCouponBeanList.get(position);
-        if (couponBean.isLocal) {
-            // 本地写死的不能删除
-            return;
-        }
         AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
                 .setMessage("选择操作")
                 .setPositiveButton("修改", (dialog, which) -> {

+ 7 - 4
app/src/main/java/com/miekir/ym/ui/coupon/CouponPresenter.java

@@ -6,6 +6,7 @@ import com.miekir.mvp.presenter.BasePresenter;
 import com.miekir.network.RetrofitHelper;
 import com.miekir.network.widget.observe.NetMvpObserver;
 import com.miekir.ym.base.ApiService;
+import com.miekir.ym.tool.DataTool;
 
 import java.util.List;
 
@@ -21,7 +22,7 @@ import io.reactivex.schedulers.Schedulers;
  */
 public class CouponPresenter extends BasePresenter<ICouponView<CouponBean>> {
 
-    public void getTemplateData(int pageNum, int pageSize) {
+    public void getCouponData(int pageNum, int pageSize) {
         NetMvpObserver<List<CouponBean>> disposable = new NetMvpObserver<List<CouponBean>>() {
             @Override
             public void onSuccess(int code, List<CouponBean> result) {
@@ -30,9 +31,11 @@ public class CouponPresenter extends BasePresenter<ICouponView<CouponBean>> {
 
             @Override
             public void onFailure(int code, Throwable e, String errMsg) {
-                post(view -> view.onCouponDataCome(false,
-                        TextUtils.isEmpty(errMsg) ? "获取失败:"+e.getMessage() : errMsg,
-                        null));
+//                post(view -> view.onCouponDataCome(false,
+//                        TextUtils.isEmpty(errMsg) ? "获取失败:"+e.getMessage() : errMsg,
+//                        null));
+                // todo 删除假数据
+                post(view -> view.onCouponDataCome(true, "", DataTool.getTemplateList()));
             }
         };
 

+ 1 - 1
app/src/main/res/layout/activity_main.xml

@@ -34,7 +34,7 @@
                 android:id="@+id/title"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="羊毛党 · 精选"
+                android:text="羊毛党 · 精选好券"
                 android:textStyle="bold"
                 android:textColor="@color/black_theme"
                 android:textSize="@dimen/size_hello" />

+ 1 - 1
app/src/main/res/layout/item_template.xml

@@ -24,7 +24,7 @@
             android:background="@color/white"
             android:foreground="@drawable/selectable_item_background">
             <ImageView
-                android:id="@+id/iv_template"
+                android:id="@+id/iv_coupon"
                 android:layout_width="match_parent"
                 android:layout_height="@dimen/height_cover"
                 android:src="@mipmap/logo_gray" />