|
|
@@ -0,0 +1,106 @@
|
|
|
+package com.itant.shibei.ui.mine.fav;
|
|
|
+
|
|
|
+import android.os.Bundle;
|
|
|
+
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+
|
|
|
+import com.itant.shibei.R;
|
|
|
+import com.itant.shibei.base.BaseBeiActivity;
|
|
|
+import com.itant.shibei.ui.home.goods.GoodsAdapter;
|
|
|
+import com.itant.shibei.ui.home.goods.GoodsBean;
|
|
|
+import com.itant.shibei.widget.bottomlistener.OnRcvScrollListener;
|
|
|
+import com.itant.shibei.widget.decoration.CardViewDividerItemDecoration;
|
|
|
+import com.miekir.common.utils.ToastTool;
|
|
|
+import com.miekir.mvp.presenter.InjectPresenter;
|
|
|
+
|
|
|
+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 BaseBeiActivity implements IMyFavView {
|
|
|
+ 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<GoodsBean> mGoodsList = new ArrayList<>();
|
|
|
+ private GoodsAdapter mAdapter;
|
|
|
+ private boolean mIsLoading = false;
|
|
|
+
|
|
|
+ @InjectPresenter
|
|
|
+ MyFavPresenter myFavPresenter;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getLayoutID() {
|
|
|
+ return R.layout.activity_search;
|
|
|
+ }
|
|
|
+
|
|
|
+ @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);
|
|
|
+ int dividerWidth = (int) getResources().getDimension(R.dimen.margin_s);
|
|
|
+ CardViewDividerItemDecoration decoration = new CardViewDividerItemDecoration(dividerWidth);
|
|
|
+ rv_search_result.addItemDecoration(decoration);
|
|
|
+ mAdapter = new GoodsAdapter(this, mGoodsList);
|
|
|
+ rv_search_result.setAdapter(mAdapter);
|
|
|
+ mAdapter.setEmptyView(R.layout.view_empty, rv_search_result);
|
|
|
+
|
|
|
+ // 加载更多
|
|
|
+ rv_search_result.addOnScrollListener(new OnRcvScrollListener(){
|
|
|
+ @Override
|
|
|
+ public void onBottom() {
|
|
|
+ super.onBottom();
|
|
|
+ if (mIsLoading) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果到底部了,而且不是正在加载状态,就变为正在加载状态,并及时去加载数据
|
|
|
+ showLoading();
|
|
|
+ mIsLoading = true;
|
|
|
+ myFavPresenter.getMyFavGoods(mCurrentPage, PAGE_SIZE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取商品结果
|
|
|
+ * @param success
|
|
|
+ * @param message
|
|
|
+ * @param goodsList
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onGoodsDataCome(boolean success, String message, List<GoodsBean> goodsList) {
|
|
|
+ dismissLoading();
|
|
|
+ mIsLoading = false;
|
|
|
+
|
|
|
+ if (!success) {
|
|
|
+ ToastTool.showShort(message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (goodsList != null) {
|
|
|
+ mGoodsList.addAll(goodsList);
|
|
|
+ }
|
|
|
+
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ // 请求到数据了,页数自增
|
|
|
+ if (goodsList != null && goodsList.size() > 0) {
|
|
|
+ mCurrentPage++;
|
|
|
+ } else {
|
|
|
+ ToastTool.showShort("没有更多数据了");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|