|
@@ -0,0 +1,149 @@
|
|
|
|
|
+package com.miekir.ym.ui.home.more.favorite;
|
|
|
|
|
+
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+
|
|
|
|
|
+import androidx.annotation.Nullable;
|
|
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
+
|
|
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
|
|
+import com.miekir.common.utils.ToastTool;
|
|
|
|
|
+import com.miekir.mvp.presenter.InjectPresenter;
|
|
|
|
|
+import com.miekir.ym.R;
|
|
|
|
|
+import com.miekir.ym.base.YangActivity;
|
|
|
|
|
+import com.miekir.ym.listener.OnRcvScrollListener;
|
|
|
|
|
+import com.miekir.ym.ui.home.coupon.CouponAdapter;
|
|
|
|
|
+import com.miekir.ym.ui.home.coupon.CouponBean;
|
|
|
|
|
+import com.miekir.ym.ui.home.coupon.ICouponView;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Copyright (C), 2019-2020, Miekir
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author Miekir
|
|
|
|
|
+ * @date 2020/8/12 19:40
|
|
|
|
|
+ * Description: 输入文字搜索
|
|
|
|
|
+ */
|
|
|
|
|
+public class MyFavActivity extends YangActivity implements IMyFavView, ICouponView<CouponBean> {
|
|
|
|
|
+ private static final int PAGE_START = 0;
|
|
|
|
|
+ private static final int PAGE_SIZE = 20;
|
|
|
|
|
+ private int mCurrentPage = PAGE_START;
|
|
|
|
|
+
|
|
|
|
|
+ private RecyclerView rv_search_result;
|
|
|
|
|
+ private List<CouponBean> mGoodsList = new ArrayList<>();
|
|
|
|
|
+ private CouponAdapter mAdapter;
|
|
|
|
|
+ private boolean mIsLoading = false;
|
|
|
|
|
+
|
|
|
|
|
+ @InjectPresenter
|
|
|
|
|
+ MyFavPresenter myFavPresenter;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getLayoutId() {
|
|
|
|
|
+ return R.layout.activity_my_fav;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initViews(Bundle savedInstanceState) {
|
|
|
|
|
+ setTitle("我的收藏");
|
|
|
|
|
+ rv_search_result = findViewById(R.id.rv_search_result);
|
|
|
|
|
+ // 必须要设置LayoutManager,否则RecyclerView不知道要使用什么布局,从而在界面上不显示
|
|
|
|
|
+ LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
|
|
|
|
|
+ rv_search_result.setLayoutManager(layoutManager);
|
|
|
|
|
+ mAdapter = new CouponAdapter(this, mGoodsList);
|
|
|
|
|
+ rv_search_result.setAdapter(mAdapter);
|
|
|
|
|
+ mAdapter.setEmptyView(R.layout.view_empty, rv_search_result);
|
|
|
|
|
+
|
|
|
|
|
+ // 加载更多
|
|
|
|
|
+ rv_search_result.addOnScrollListener(new OnRcvScrollListener() {
|
|
|
|
|
+ // 滑动时不要去加载图片
|
|
|
|
|
+ //RecyclerView.SCROLL_STATE_IDLE //空闲状态
|
|
|
|
|
+ //RecyclerView.SCROLL_STATE_FLING //滚动状态
|
|
|
|
|
+ //RecyclerView.SCROLL_STATE_TOUCH_SCROLL //触摸后状态
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
|
+ super.onScrollStateChanged(recyclerView, newState);
|
|
|
|
|
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
|
|
|
|
+ //恢复Glide加载图片
|
|
|
|
|
+ Glide.with(getApplicationContext()).resumeRequests();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //禁止Glide加载图片
|
|
|
|
|
+ Glide.with(getApplicationContext()).pauseRequests();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onBottom() {
|
|
|
|
|
+ super.onBottom();
|
|
|
|
|
+ if (mIsLoading) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果到底部了,而且不是正在加载状态,就变为正在加载状态,并及时去加载数据
|
|
|
|
|
+ showLoading();
|
|
|
|
|
+ mIsLoading = true;
|
|
|
|
|
+ myFavPresenter.getMyFavGoods(mCurrentPage, PAGE_SIZE);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+ showLoading();
|
|
|
|
|
+ mIsLoading = true;
|
|
|
|
|
+ myFavPresenter.getMyFavGoods(mCurrentPage, PAGE_SIZE);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取商品结果
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param success
|
|
|
|
|
+ * @param goodsList
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onCouponDataCome(boolean success, String message, List<CouponBean> goodsList) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDeleteCoupon(boolean success, String message, int position) {
|
|
|
|
|
+ if (success) {
|
|
|
|
|
+ mGoodsList.remove(position);
|
|
|
|
|
+ mAdapter.notifyItemRemoved(position);
|
|
|
|
|
+ ToastTool.showShort("删除成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ToastTool.showShort("删除失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFavCouponDataCome(boolean success, String message, List<CouponBean> goodsList) {
|
|
|
|
|
+ mIsLoading = false;
|
|
|
|
|
+
|
|
|
|
|
+ if (!success) {
|
|
|
|
|
+ ToastTool.showShort(message);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (goodsList != null) {
|
|
|
|
|
+ int start = mGoodsList.size();
|
|
|
|
|
+ mGoodsList.addAll(goodsList);
|
|
|
|
|
+ if (mCurrentPage > PAGE_START) {
|
|
|
|
|
+ // 刚开始数据为0时不能使用notifyItemRangeInserted
|
|
|
|
|
+ mAdapter.notifyItemRangeInserted(start, goodsList.size());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 请求到数据了,页数自增
|
|
|
|
|
+ if (goodsList != null && goodsList.size() > 0) {
|
|
|
|
|
+ mCurrentPage++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ToastTool.showShort("没有更多数据了");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|