|
|
@@ -1,11 +1,14 @@
|
|
|
package com.itant.shibei.ui.home.search;
|
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.EditText;
|
|
|
|
|
|
+import androidx.appcompat.app.AlertDialog;
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
@@ -13,6 +16,9 @@ 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.ui.home.goods.GoodsPresenter;
|
|
|
+import com.itant.shibei.ui.home.goods.IGoodsView;
|
|
|
+import com.itant.shibei.ui.mine.goods.AddGoodsActivity;
|
|
|
import com.itant.shibei.widget.DividerItemDecoration;
|
|
|
import com.itant.shibei.widget.bottomlistener.OnRcvScrollListener;
|
|
|
import com.miekir.common.utils.ToastTool;
|
|
|
@@ -22,6 +28,8 @@ import com.miekir.mvp.presenter.InjectPresenter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import rx_activity_result2.RxActivityResult;
|
|
|
+
|
|
|
/**
|
|
|
* Copyright (C), 2019-2020, Miekir
|
|
|
*
|
|
|
@@ -29,7 +37,7 @@ import java.util.List;
|
|
|
* @date 2020/8/12 19:40
|
|
|
* Description: 输入文字搜索
|
|
|
*/
|
|
|
-public class SearchActivity extends BaseBeiActivity implements View.OnClickListener, ISearchView, View.OnFocusChangeListener {
|
|
|
+public class SearchActivity extends BaseBeiActivity implements View.OnClickListener, ISearchView, View.OnFocusChangeListener, IGoodsView {
|
|
|
private static final int PAGE_START = 0;
|
|
|
private static final int PAGE_SIZE = 20;
|
|
|
private int mCurrentPage = PAGE_START;
|
|
|
@@ -47,6 +55,9 @@ public class SearchActivity extends BaseBeiActivity implements View.OnClickListe
|
|
|
@InjectPresenter
|
|
|
SearchPresenter searchPresenter;
|
|
|
|
|
|
+ @InjectPresenter
|
|
|
+ GoodsPresenter goodsPresenter;
|
|
|
+
|
|
|
@Override
|
|
|
public int getLayoutID() {
|
|
|
return R.layout.activity_search;
|
|
|
@@ -67,6 +78,8 @@ public class SearchActivity extends BaseBeiActivity implements View.OnClickListe
|
|
|
DividerItemDecoration decoration = new DividerItemDecoration(dividerWidth);
|
|
|
rv_search_result.addItemDecoration(decoration);
|
|
|
mAdapter = new GoodsAdapter(this, mGoodsList);
|
|
|
+ mAdapter.setGoodsLongClickListener(this::showAdminDialog);
|
|
|
+ rv_search_result.setAdapter(mAdapter);
|
|
|
mAdapter.setEmptyView(R.layout.view_empty, rv_search_result);
|
|
|
// 加载更多
|
|
|
rv_search_result.addOnScrollListener(new OnRcvScrollListener(){
|
|
|
@@ -116,6 +129,58 @@ public class SearchActivity extends BaseBeiActivity implements View.OnClickListe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改商品或者删除商品
|
|
|
+ */
|
|
|
+ private void showAdminDialog(int position) {
|
|
|
+ GoodsBean goodsBean = mGoodsList.get(position);
|
|
|
+ if (goodsBean.isLocal) {
|
|
|
+ // 本地写死的不能删除
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ AlertDialog alertDialog = new AlertDialog.Builder(this)
|
|
|
+ .setMessage("选择操作")
|
|
|
+ .setPositiveButton("修改", (dialog, which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ Intent modifyIntent = new Intent(this, AddGoodsActivity.class);
|
|
|
+ modifyIntent.putExtra(AddGoodsActivity.KEY_MODIFY_GOODS, goodsBean);
|
|
|
+ RxActivityResult.on(this).startIntent(modifyIntent)
|
|
|
+ .filter(result -> result.resultCode() == RESULT_OK)
|
|
|
+ .subscribe(result -> {
|
|
|
+ // 修改商品成功之后刷新item
|
|
|
+ GoodsBean modifiedBean = (GoodsBean) result.data().getSerializableExtra(AddGoodsActivity.KEY_MODIFY_GOODS);
|
|
|
+ goodsBean.updateData(modifiedBean);
|
|
|
+ mAdapter.notifyItemChanged(position);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .setNeutralButton("取消", (dialog, which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ })
|
|
|
+ .setNegativeButton("删除", (DialogInterface dialog, int which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ showDeleteDialog(position);
|
|
|
+ }).create();
|
|
|
+ alertDialog.setCanceledOnTouchOutside(false);
|
|
|
+ alertDialog.setCancelable(false);
|
|
|
+ alertDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否删除商品
|
|
|
+ */
|
|
|
+ private void showDeleteDialog(int position) {
|
|
|
+ GoodsBean goodsBean = mGoodsList.get(position);
|
|
|
+ AlertDialog alertDialog = new AlertDialog.Builder(this)
|
|
|
+ .setMessage("确定删除商品:" + goodsBean.title)
|
|
|
+ .setNegativeButton("取消", (dialog, which) -> dialog.dismiss())
|
|
|
+ .setPositiveButton("确定", (DialogInterface dialog, int which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ // 删除商品
|
|
|
+ goodsPresenter.deleteGoodsById(position, goodsBean.id);
|
|
|
+ }).create();
|
|
|
+ alertDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onSearchKeywordResult(boolean success, String message, List<GoodsBean> goodsList) {
|
|
|
dismissLoading();
|
|
|
@@ -143,6 +208,35 @@ public class SearchActivity extends BaseBeiActivity implements View.OnClickListe
|
|
|
// 请求到数据了,页数自增
|
|
|
if (goodsList != null && goodsList.size() > 0) {
|
|
|
mCurrentPage++;
|
|
|
+ } else {
|
|
|
+ ToastTool.showShort("没有更多数据了");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取商品结果
|
|
|
+ * @param success
|
|
|
+ * @param message
|
|
|
+ * @param goodsList
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onGoodsDataCome(boolean success, String message, List<GoodsBean> goodsList) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除商品结果
|
|
|
+ * @param success
|
|
|
+ * @param message
|
|
|
+ * @param position
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onDeleteGoodsResult(boolean success, String message, int position) {
|
|
|
+ if (success) {
|
|
|
+ mAdapter.notifyItemRemoved(position);
|
|
|
+ ToastTool.showShort("删除成功");
|
|
|
+ } else {
|
|
|
+ ToastTool.showShort(message);
|
|
|
}
|
|
|
}
|
|
|
|