Commit 2d520f03 by 张建升

菜品 boom 代码同步

parent f0a91a2d
package com.gingersoft.supply_chain.di.component;
import dagger.BindsInstance;
import dagger.Component;
import com.jess.arms.di.component.AppComponent;
import com.gingersoft.supply_chain.di.module.OtherFunctionModule;
import com.gingersoft.supply_chain.mvp.contract.OtherFunctionContract;
import com.jess.arms.di.scope.FragmentScope;
import com.gingersoft.supply_chain.mvp.ui.fragment.food.OtherFunctionFragment;
/**
* ================================================
* Created by zjs on 07/07/2021 21:11
* Description
* ================================================
*/
@FragmentScope
@Component(modules = OtherFunctionModule.class, dependencies = AppComponent.class)
public interface OtherFunctionComponent {
void inject(OtherFunctionFragment fragment);
@Component.Builder
interface Builder {
@BindsInstance
OtherFunctionComponent.Builder view(OtherFunctionContract.View view);
OtherFunctionComponent.Builder appComponent(AppComponent appComponent);
OtherFunctionComponent build();
}
}
\ No newline at end of file
package com.gingersoft.supply_chain.di.module;
import com.gingersoft.supply_chain.mvp.contract.OtherFunctionContract;
import com.gingersoft.supply_chain.mvp.model.OtherFunctionModel;
import dagger.Binds;
import dagger.Module;
/**
* ================================================
* Created by zjs on 07/07/2021 21:11
* Description
* ================================================
*/
@Module
public abstract class OtherFunctionModule {
@Binds
abstract OtherFunctionContract.Model bindOtherFunctionModel(OtherFunctionModel model);
}
\ No newline at end of file
package com.gingersoft.supply_chain.mvp.contract;
import com.gingersoft.gsa.cloud.common.bean.BaseResult;
import com.gingersoft.supply_chain.mvp.bean.BuyIngredientsBean;
import com.gingersoft.supply_chain.mvp.bean.FoodByCategoryResultBean;
import com.gingersoft.supply_chain.mvp.bean.FoodListInfoBean;
import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean;
import com.jess.arms.mvp.IView;
import com.jess.arms.mvp.IModel;
import java.util.List;
import java.util.Map;
import io.reactivex.Observable;
/**
* ================================================
* Created by zjs on 07/07/2021 21:11
* Description
* ================================================
*/
public interface OtherFunctionContract {
interface View extends IView {
/**
* 加載分類
*
* @param foodCategoryTrees 所有分類層級信息
*/
void initCategoryInfo(List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees);
/**
* 加載失敗
*/
void loadFail();
/**
* 結束加載並且沒有更多數據了
*/
void finishLoad(boolean noData);
/**
* 加載食品
*
* @param buyIngredientsBeans 顯示的食材
* @param addToHead 是否添加到頭部
* @param isReset 是否重新設置數據
*/
void loadFood(List<BuyIngredientsBean> buyIngredientsBeans, boolean addToHead, boolean isReset);
void selectFirstCategoryByIndex(int position);
/**
* 食材列表滾動到指定位置
*
* @param index 指定位置
*/
void scrollToPosition(int index);
}
//Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
interface Model extends IModel {
Observable<FoodListInfoBean> getFoodIngredientsData(Map<String, Object> map);
Observable<BaseResult> getFoodBySupplierId(Map<String, Object> map);
Observable<BaseResult> deleteFood(int foodId);
Observable<OrderCategoryBean> getCategoryTrees(Map<String, Object> map);
Observable<FoodByCategoryResultBean> getFoodByCategory(Map<String, Object> map);
}
}
package com.gingersoft.supply_chain.mvp.model;
import android.app.Application;
import com.gingersoft.gsa.cloud.common.bean.BaseResult;
import com.gingersoft.supply_chain.mvp.bean.FoodByCategoryResultBean;
import com.gingersoft.supply_chain.mvp.bean.FoodListInfoBean;
import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean;
import com.gingersoft.supply_chain.mvp.server.SupplierServer;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.jess.arms.di.scope.FragmentScope;
import javax.inject.Inject;
import com.gingersoft.supply_chain.mvp.contract.OtherFunctionContract;
import java.util.Map;
import io.reactivex.Observable;
/**
* ================================================
* Created by zjs on 07/07/2021 21:11
* Description
* ================================================
*/
@FragmentScope
public class OtherFunctionModel extends BaseModel implements OtherFunctionContract.Model {
@Inject
Gson mGson;
@Inject
Application mApplication;
@Inject
public OtherFunctionModel(IRepositoryManager repositoryManager) {
super(repositoryManager);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mGson = null;
this.mApplication = null;
}
@Override
public Observable<FoodListInfoBean> getFoodIngredientsData(Map<String, Object> map) {
return mRepositoryManager.obtainRetrofitService(SupplierServer.class).getFoodIngredientsData(map);
}
@Override
public Observable<BaseResult> getFoodBySupplierId(Map<String, Object> map) {
return mRepositoryManager.obtainRetrofitService(SupplierServer.class).getFoodBySupplierId(map);
}
@Override
public Observable<BaseResult> deleteFood(int foodId) {
return mRepositoryManager.obtainRetrofitService(SupplierServer.class).deleteFood(foodId);
}
@Override
public Observable<OrderCategoryBean> getCategoryTrees(Map<String, Object> map) {
return mRepositoryManager.obtainRetrofitService(SupplierServer.class).getCategoryTrees(map);
}
@Override
public Observable<FoodByCategoryResultBean> getFoodByCategory(Map<String, Object> map) {
return mRepositoryManager.obtainRetrofitService(SupplierServer.class).getFoodByCategory(map);
}
}
\ No newline at end of file
package com.gingersoft.supply_chain.mvp.presenter;
import android.app.Application;
import android.text.TextUtils;
import android.util.Log;
import com.gingersoft.gsa.cloud.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.common.constans.AppConstant;
import com.gingersoft.gsa.cloud.common.utils.CollectionUtils;
import com.gingersoft.gsa.cloud.common.utils.JsonUtils;
import com.gingersoft.gsa.cloud.common.utils.log.LogUtil;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.supply_chain.mvp.bean.BuyIngredientsBean;
import com.gingersoft.supply_chain.mvp.bean.FoodByCategoryResultBean;
import com.gingersoft.supply_chain.mvp.bean.FoodListInfoBean;
import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean;
import com.gingersoft.supply_chain.mvp.content.SupplyShoppingCart;
import com.gingersoft.supply_chain.mvp.contract.BuyIngredientsContract;
import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.FragmentScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
import javax.inject.Inject;
import com.gingersoft.supply_chain.mvp.contract.OtherFunctionContract;
import com.jess.arms.utils.RxLifecycleUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* ================================================
* Created by zjs on 07/07/2021 21:11
* Description
* ================================================
*/
@FragmentScope
public class OtherFunctionPresenter extends BasePresenter<OtherFunctionContract.Model, OtherFunctionContract.View> {
@Inject
public OtherFunctionPresenter(OtherFunctionContract.Model model, OtherFunctionContract.View rootView) {
super(model, rootView);
}
@Inject
RxErrorHandler mErrorHandler;
@Inject
Application mApplication;
@Inject
ImageLoader mImageLoader;
@Inject
AppManager mAppManager;
/**
* 分類數據的緩存,之後加載就讀取這裡面的
*/
private List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees;
/**
* 供應商信息轉為分類之後的緩存,之後加載就讀取這裡面的
*/
private List<OrderCategoryBean.FoodCategoryTrees> supplierTranCategoryCache;
// /**
// * 用戶選購的食材列表
// */
// private Map<Integer, PurchaseFoodBean> purchaseFoodBeanMap = new HashMap<>();
/**
* 分類商品緩存,用於根據一級分類下標獲取下面的分類和食材
*/
private List<List<BuyIngredientsBean>> categoryFoods = new ArrayList<>();
/**
* 供應商商品緩存,根據下標獲取食材和供應商信息
*/
private List<BuyIngredientsBean> supplierFoods = new ArrayList<>();
/**
* 列表顯示的食品,不管是分類還是供應商的商品,都轉換到這個集合中用於顯示到列表中,這個集合就代表列表中所有商品
*/
private List<BuyIngredientsBean> showFoods = new ArrayList<>();
@Override
public void onDestroy() {
super.onDestroy();
this.mErrorHandler = null;
this.mAppManager = null;
this.mImageLoader = null;
this.mApplication = null;
}
/**
* 統計食品數量
*/
public int statisticsFoodQuantity() {
List<PurchaseFoodBean> cartFoods = SupplyShoppingCart.getInstance().getCartFoods();
int foodSize = 0;
for (PurchaseFoodBean cartFood : cartFoods) {
foodSize += cartFood.getFoodQuantity();
}
return foodSize;
}
/**
* 跟據供應商id統計食品數量
*/
public int statisticsFoodQuantityBySupplierId(int supplierId) {
List<PurchaseFoodBean> cartFoods = SupplyShoppingCart.getInstance().getCartFoods();
int foodSize = 0;
for (PurchaseFoodBean cartFood : cartFoods) {
if (cartFood.getSupplierId() == supplierId) {
foodSize += cartFood.getFoodQuantity();
}
}
return foodSize;
}
/**
* 獲取分類的結構:所有分類和分類的子分類都有
*/
public void getCategoryTrees() {
if (foodCategoryTrees != null) {
initCategoryGoodsSize(foodCategoryTrees);
mRootView.initCategoryInfo(foodCategoryTrees);
return;
}
Map<String, Object> map = new HashMap<>(2);
AppConstant.addBrandId(map);
AppConstant.addRestaurantId(map);
mModel.getCategoryTrees(map)//發送請求
.subscribeOn(Schedulers.io())//切換到io異步線程
.doOnSubscribe(disposable -> mRootView.showLoading(AppConstant.GET_INFO_LOADING))//顯示加載提示框
.subscribeOn(AndroidSchedulers.mainThread())//切換到主線程,上面的提示框就在主線程
.observeOn(AndroidSchedulers.mainThread())//切換到主線程,隱藏提示框在主線程
.doAfterTerminate(() -> mRootView.hideLoading())//任務執行完成後,隱藏提示框
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))//綁定生命週期,頁面隱藏時斷開請求
.observeOn(AndroidSchedulers.mainThread())//切換到主線程
.subscribe(new ErrorHandleSubscriber<OrderCategoryBean>(mErrorHandler) {//mErrorHandler是統一的錯誤處理
@Override
public void onNext(OrderCategoryBean orderCategoryBean) {//數據處理
if (orderCategoryBean.isSuccess()) {
List<OrderCategoryBean.FoodCategoryTrees> data = orderCategoryBean.getData();
if (data != null) {
//將分類食品的list容量設置為一級分類的數量,這樣就不用擔心之後加載不同position的分類數據時,計算位置了
categoryFoods = new ArrayList<>(data.size());
for (OrderCategoryBean.FoodCategoryTrees ignored : data) {
categoryFoods.add(null);
}
foodCategoryTrees = new ArrayList<>();
foodCategoryTrees.addAll(data);
}
//第一次加載初始化數量
initCategoryGoodsSize(data);
mRootView.initCategoryInfo(data);
} else if (TextUtil.isNotEmptyOrNullOrUndefined(orderCategoryBean.getErrMsg())) {
mRootView.showMessage(orderCategoryBean.getErrMsg());
} else {
mRootView.showMessage(AppConstant.GET_INFO_ERROR);
}
}
});
}
/**
* 根據一級分類獲取下面所有包括子分類的食品
*
* @param position 一級分類下標
* @param categoryTrees 一級分類信息
* @param addToHead 是否添加到頭部
*/
public void getFoodByCategory(int position, OrderCategoryBean.FoodCategoryTrees categoryTrees, boolean addToHead, boolean isReset) {
//先看看這個分類的食材有沒有緩存,沒有緩衝再加載
Map<String, Object> map = new HashMap<>(5);
map.put("pageSize", 1000);
map.put("pageIndex", 0);
AppConstant.addBrandId(map);
AppConstant.addRestaurantId(map);
map.put("parentId", categoryTrees.getId());
mModel.getFoodByCategory(map)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> {
// mRootView.showLoading(Constant.GET_INFO_LOADING)
})
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterNext(dis -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<FoodByCategoryResultBean>(mErrorHandler) {
@Override
public void onNext(@NonNull FoodByCategoryResultBean info) {
if (info.isSuccess()) {
//拿到所有食品
List<PurchaseFoodBean> foodBeans = info.getData();
//初始化分類和食品的顯示集合
List<BuyIngredientsBean> buyIngredientsBeans = new ArrayList<>();
conversionShowInfo(foodBeans, categoryTrees, buyIngredientsBeans, 0);
//將數據插入緩衝中
categoryFoods.set(position, buyIngredientsBeans);
if (addToHead) {
showFoods.addAll(0, buyIngredientsBeans);
} else {
showFoods.addAll(buyIngredientsBeans);
}
mRootView.loadFood(buyIngredientsBeans, addToHead, isReset);
} else if (TextUtil.isNotEmptyOrNullOrUndefined(info.getErrMsg())) {
mRootView.showMessage(info.getErrMsg());
mRootView.loadFail();
} else {
mRootView.loadFail();
}
}
@Override
public void onError(Throwable t) {
super.onError(t);
}
/**
* 將食品數據,分類信息進行合併轉換處理
*
* @param foodBeans 食品信息
* @param foodCategoryTree 分類
* @param buyIngredientsBeans 遞歸用到,這個分類轉換後的
* @param foodSize 遞歸用到的數量,用於記錄遍歷了多少個食品
*/
private void conversionShowInfo(List<PurchaseFoodBean> foodBeans, OrderCategoryBean.FoodCategoryTrees foodCategoryTree, List<BuyIngredientsBean> buyIngredientsBeans, int foodSize) {
BuyIngredientsBean buyIngredientsBean = new BuyIngredientsBean();
buyIngredientsBean.id = foodCategoryTree.getId();
buyIngredientsBean.parentId = foodCategoryTree.getParentId();
buyIngredientsBean.categoryName = foodCategoryTree.getName();
buyIngredientsBean.purchaseFoodList = new ArrayList<>();
if (foodBeans != null && foodSize != foodBeans.size()) {
boolean haveThisCategoryBean = true;
int categoryFoodSize = 0;
for (PurchaseFoodBean foodBean : foodBeans) {
//將食品按分類隔開
PurchaseFoodBean cachePurchaseFoodBean = SupplyShoppingCart.getInstance().getFoodByFoodId(foodBean.getId());
if (cachePurchaseFoodBean != null) {
foodBean.setFoodQuantity(cachePurchaseFoodBean.getFoodQuantity());
categoryFoodSize++;
}
if (foodBean.getFoodCategoryId() == foodCategoryTree.getId()) {
buyIngredientsBean.purchaseFoodList.add(foodBean);
haveThisCategoryBean = false;
foodSize++;
} else if (!haveThisCategoryBean) {
//因為食品是按順序排列,如果之前已經有這個分類的食品,後來沒了,之後的數據就不用遍歷了
break;
}
}
foodCategoryTree.setSize(categoryFoodSize);
}
buyIngredientsBeans.add(buyIngredientsBean);
List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees = foodCategoryTree.getFoodCategoryTrees();
//遍歷子分類
if (foodCategoryTrees != null) {
for (OrderCategoryBean.FoodCategoryTrees categoryTree : foodCategoryTrees) {
conversionShowInfo(foodBeans, categoryTree, buyIngredientsBeans, foodSize);
}
}
}
});
}
/**
* 初始化分類商品數量
*
* @param foodCategoryTrees 所有分類
*/
public void initCategoryGoodsSize(List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees) {
//先將食品數量置0
for (OrderCategoryBean.FoodCategoryTrees foodCategoryTree : foodCategoryTrees) {
foodCategoryTree.setSize(0);
}
for (PurchaseFoodBean cartFood : SupplyShoppingCart.getInstance().getCartFoods()) {
int size = foodCategoryTrees.size();
for (int i = 0; i < size; i++) {
OrderCategoryBean.FoodCategoryTrees categoryTrees = foodCategoryTrees.get(i);
if (cartFood.getFoodCategoryId() == categoryTrees.getId()) {
categoryTrees.setSize(categoryTrees.getSize() + 1);
break;
} else {
initCategorySize(categoryTrees, categoryTrees.getFoodCategoryTrees(), cartFood);
}
}
}
}
/**
* 遞歸多級分類,統計食品在分類下的數量,最後都計在父分類下
*
* @param parentFoodCategory 父分類
* @param foodCategoryTrees 子分類
* @param value 商品
*/
public void initCategorySize(OrderCategoryBean.FoodCategoryTrees parentFoodCategory, List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees, PurchaseFoodBean value) {
if (CollectionUtils.isNotNullOrEmpty(foodCategoryTrees)) {
//遍歷二級,找到這個食品
int size = foodCategoryTrees.size();
for (int i = 0; i < size; i++) {
OrderCategoryBean.FoodCategoryTrees categoryTrees = foodCategoryTrees.get(i);
if (value.getFoodCategoryId() == categoryTrees.getId()) {
parentFoodCategory.setSize(parentFoodCategory.getSize() + 1);
categoryTrees.setSize(categoryTrees.getSize() + 1);
break;
} else {
initCategorySize(parentFoodCategory, categoryTrees.getFoodCategoryTrees(), value);
}
}
}
}
/**
* 獲取數據,供應商
*
* @param supplierId 供應商id, -1就是加載所有供應商
*/
public void loadFoodIngredientsData(int supplierId, boolean isReset) {
if (supplierTranCategoryCache != null) {
//如果有緩存,直接加載緩存的,需要和用戶已採購食材合併數量
initSupplierGoodsSize(supplierTranCategoryCache);
mRootView.initCategoryInfo(supplierTranCategoryCache);
return;
}
Map<String, Object> map = new HashMap<>(5);
map.put("pageSize", 1000);
map.put("pageIndex", 0);
AppConstant.addBrandId(map);
AppConstant.addRestaurantId(map);
if (supplierId != -1) {
map.put("supplierId", supplierId);
}
mModel.getFoodIngredientsData(map)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(AppConstant.GET_INFO_LOADING))
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<FoodListInfoBean>(mErrorHandler) {
@Override
public void onNext(@NonNull FoodListInfoBean info) {
if (info.isSuccess() && info.getData() != null) {
List<FoodListInfoBean.DataBean> data = info.getData();
if (data != null) {
initSupplierFoods(data.size());
supplierTranCategoryCache = new ArrayList<>(data.size());
//將顯示的商品列表清空
clearShowFoods();
//遍歷供應商,這裡接口返回了第一個供應商的食品信息,添加進去、
// 其他供應商先佔位,設為空
int size = data.size();
for (int i = 0; i < size; i++) {
FoodListInfoBean.DataBean dataBean = data.get(i);
OrderCategoryBean.FoodCategoryTrees supplierToCategory = new OrderCategoryBean.FoodCategoryTrees(dataBean.getId(), dataBean.getSupplierName(), 0);
if (i == 0) {
BuyIngredientsBean buyIngredientsBean = conversionSupplierToShowInfo(supplierToCategory, dataBean.getPurchaseFoodListVOS());
showFoods.add(buyIngredientsBean);
supplierFoods.set(i, buyIngredientsBean);
} else {
supplierFoods.set(i, null);
}
supplierTranCategoryCache.add(supplierToCategory);
}
//第一次需要初始化每個供應商下已採購的食品數量
initSupplierGoodsSize(supplierTranCategoryCache);
mRootView.initCategoryInfo(supplierTranCategoryCache);
loadFood(showFoods.get(0), false, true);
}
}
}
});
}
/**
* 初始化供應商的分類的商品數量
*
* @param foodCategoryTrees 分類,供應商也是分類
*/
private void initSupplierGoodsSize(List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees) {
//先將食品數量置0
for (OrderCategoryBean.FoodCategoryTrees foodCategoryTree : foodCategoryTrees) {
foodCategoryTree.setSize(0);
}
for (PurchaseFoodBean cartFood : SupplyShoppingCart.getInstance().getCartFoods()) {
int size = foodCategoryTrees.size();
for (int i = 0; i < size; i++) {
OrderCategoryBean.FoodCategoryTrees categoryTrees = foodCategoryTrees.get(i);
if (cartFood.getSupplierId() == categoryTrees.getId()) {
categoryTrees.setSize(categoryTrees.getSize() + 1);
}
}
}
}
/**
* 將供應商食材和用戶已點的食材數量合併
*
* @param supplierToCategory 供應商信息
* @param purchaseFoodListVOS 供應商食材信息
* @return 用於顯示的信息
*/
private BuyIngredientsBean conversionSupplierToShowInfo(OrderCategoryBean.FoodCategoryTrees supplierToCategory, List<PurchaseFoodBean> purchaseFoodListVOS) {
//這裡已經返回了第一個供應商的商品
BuyIngredientsBean buyIngredientsBean = new BuyIngredientsBean();
buyIngredientsBean.id = supplierToCategory.getId();
buyIngredientsBean.categoryName = supplierToCategory.getName();
if (CollectionUtils.isNotNullOrEmpty(purchaseFoodListVOS)) {
int foodSize = 0;
for (PurchaseFoodBean foodBean : purchaseFoodListVOS) {
//將食品按分類隔開
PurchaseFoodBean cachePurchaseFoodBean = SupplyShoppingCart.getInstance().getFoodByFoodId(foodBean.getId());
if (cachePurchaseFoodBean != null) {
foodBean.setFoodQuantity(cachePurchaseFoodBean.getFoodQuantity());
foodSize++;
}
}
supplierToCategory.setSize(foodSize);
}
buyIngredientsBean.purchaseFoodList = purchaseFoodListVOS;
return buyIngredientsBean;
}
/**
* 獲取數據,供應商
*
* @param position 供應商下標
* @param foodCategoryTrees 供應商轉換為分類後的信息
*/
public void getFoodsBySupplier(String name , int position, OrderCategoryBean.FoodCategoryTrees foodCategoryTrees, boolean addToHead, boolean isReset) {
Map<String, Object> map = new HashMap<>(5);
map.put("pageSize", 1000);
map.put("pageIndex", 0);
LogUtil.e(" zjs getFoodsBySupplier foodCategoryTrees.getId()= "+foodCategoryTrees.getId() +
" name="+name +" position="+position);
final boolean hasName=!TextUtils.isEmpty(name);
if (hasName) {
map.put("name", name);
}else {
if (foodCategoryTrees != null) {
map.put("supplierId", foodCategoryTrees.getId());
}
}
AppConstant.addBrandId(map);
AppConstant.addRestaurantId(map);
mModel.getFoodBySupplierId(map)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> {
//mRootView.showLoading(Constant.GET_INFO_LOADING)
})
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> {
//mRootView.hideLoading()
})
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<BaseResult>(mErrorHandler) {
@Override
public void onNext(@NonNull BaseResult info) {
if (info.isSuccess() && info.getData() != null) {
List<PurchaseFoodBean> purchaseFoodListVOS = JsonUtils.parseArray(info.getData(), PurchaseFoodBean.class);
BuyIngredientsBean buyIngredientsBean = conversionSupplierToShowInfo(foodCategoryTrees, purchaseFoodListVOS);
if (hasName) {
loadFood(buyIngredientsBean, addToHead, isReset);
}else {
supplierFoods.set(position, buyIngredientsBean);
showFoods.add(addToHead ? 0 : showFoods.size(), buyIngredientsBean);
loadFood(buyIngredientsBean, addToHead, isReset);
}
}
}
});
}
private void loadFood(BuyIngredientsBean buyIngredientsBean, boolean addToHead, boolean isReset) {
ArrayList<BuyIngredientsBean> buyIngredientsBeans = new ArrayList<>();
buyIngredientsBeans.add(buyIngredientsBean);
mRootView.loadFood(buyIngredientsBeans, addToHead, isReset);
}
/**
* 刪除食品
*
* @param categoryPosition 分類在一級分類的位置,用戶如果現在顯示的是供應商,則值為-1
* @param groupPosition 組下標
* @param position 在組中的下標
*/
public void deleteFood(int foodId, int categoryPosition, int groupPosition, int position) {
mModel.deleteFood(foodId)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(AppConstant.DELETE_LOADING))
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterNext(dis -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<BaseResult>(mErrorHandler) {
@Override
public void onNext(BaseResult baseResult) {
if (baseResult.isSuccess()) {
//需要在供應商和分類的緩存中這個食品移除
// categoryFoods
// supplierFoods
//列表中刪除掉這個食品
showFoods.get(groupPosition).purchaseFoodList.remove(position);
//移除在購物車中的緩存
SupplyShoppingCart.getInstance().removeFoodsByFoodId(foodId);
//刷新頁面
mRootView.loadFood(new ArrayList<>(showFoods), true, true);
} else if (TextUtil.isNotEmptyOrNullOrUndefined(baseResult.getErrMsg())) {
mRootView.showMessage(baseResult.getErrMsg());
} else {
mRootView.showMessage(AppConstant.DELETE_FAIL);
}
}
});
}
/**
* 如果頁面單是顯示一個供應商食材,那麼外部就要調用到這個,長度設置為一
*/
public void initSupplierFoods(int length) {
supplierFoods = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
supplierFoods.add(null);
}
}
/**
* @return 用戶採購的食材
*/
public List<PurchaseFoodBean> getPurchaseFood() {
return SupplyShoppingCart.getInstance().getCartFoods();
}
/**
* 添加食品到採購map中
*
* @param purchaseFoodBean 採購的食品
*/
public void addFood(PurchaseFoodBean purchaseFoodBean) {
if (purchaseFoodBean.getFoodQuantity() == 0) {
SupplyShoppingCart.getInstance().removeFoodsByFoodId(purchaseFoodBean.getId());
} else {
SupplyShoppingCart.getInstance().addFood(purchaseFoodBean);
}
}
/**
* 清除顯示的食材
*/
public void clearShowFoods() {
showFoods.clear();
}
/**
* 清除分類食材緩存
*/
public void clearCategoryFoods() {
int size = categoryFoods.size();
for (int i = 0; i < size; i++) {
categoryFoods.set(i, null);
}
}
public void clearCategoryTreesCache() {
foodCategoryTrees = null;
}
/**
* 清除供應商食材緩存
*/
public void clearSupplierFoods() {
int size = supplierFoods.size();
for (int i = 0; i < size; i++) {
supplierFoods.set(i, null);
}
}
public void clearSupplierCache() {
supplierTranCategoryCache = null;
}
/**
* 判斷是否有本地緩存
*
* @param isSupplier 是否查供應商
* @param position 分類下標
* @return true 有緩存
*/
public boolean isHasLocationInfo(boolean isSupplier, int position) {
if (isSupplier) {
if (position >= supplierFoods.size()) {
return false;
}
return supplierFoods.get(position) != null;
} else {
if (position >= categoryFoods.size()) {
return false;
}
return categoryFoods.get(position) != null;
}
}
/**
* 判斷這個分類的數據是否已經加載到顯示列表中了
*
* @param foodCategoryTrees 分類
* @return 這個分類在列表中的下標
*/
public int isShowGoods(OrderCategoryBean.FoodCategoryTrees foodCategoryTrees) {
return showFoods.indexOf(new BuyIngredientsBean(foodCategoryTrees.getId(), foodCategoryTrees.getName(), foodCategoryTrees.getParentId()));
}
/**
* 根據分類的下標獲取在食品列表中的下標
*
* @param categoryIndex 分類下標
* @return 食品列表中的下標
*/
public int getFoodIndexByCategoryIndex(int categoryIndex) {
int progress = 0;
for (int i = 0; i < showFoods.size(); i++) {
if (i >= categoryIndex) {
return progress;
} else {
progress += showFoods.get(i).purchaseFoodList.size() + 1;
}
}
return progress;
}
/**
* 加載下一個分類的數據。如果已加載,則是後面的未加載的分類下標,如果未加載,就是這個未加載的分類下標
*
* @param position 分類下標
* @param foodCategoryTrees 分類
*/
public void loadNextCategoryFood(String name, boolean isSupplier, int position, List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees) {
List<BuyIngredientsBean> buyIngredientsBeans = null;
if (isSupplier) {
if (supplierFoods.get(position) != null) {
buyIngredientsBeans = new ArrayList<>();
buyIngredientsBeans.add(supplierFoods.get(position));
}
} else {
buyIngredientsBeans = categoryFoods.get(position);
}
if (CollectionUtils.isNotNullOrEmpty(buyIngredientsBeans)) {
Log.e("eee", "loadNextCategoryFood不為空");
//判斷是否已經加載到列表中了,如果已經加載到列表中,那麼就加載下一個
if (showFoods.contains(buyIngredientsBeans.get(0))) {
Log.e("eee", "loadNextCategoryFood已加載");
position++;
int size;
if (isSupplier) {
size = supplierFoods.size();
} else {
size = categoryFoods.size();
}
if (position < size) {
Log.e("eee", "下一個");
loadNextCategoryFood(name,isSupplier, position, foodCategoryTrees);
} else {
mRootView.finishLoad(true);
}
} else {
Log.e("eee", "loadNextCategoryFood未加載");
//加載
// mRootView.selectFirstCategoryByIndex(position);
if (isHasLocationInfo(isSupplier, position)) {
loadCacheFood(isSupplier, position, false, false);
} else {
if (isSupplier) {
getFoodsBySupplier(name,position, foodCategoryTrees.get(position), false, false);
} else {
getFoodByCategory(position, foodCategoryTrees.get(position), false, false);
}
}
}
} else {
if (isSupplier) {
getFoodsBySupplier(name,position, foodCategoryTrees.get(position), false, false);
} else {
Log.e("eee", "loadNextCategoryFood為空");
getFoodByCategory(position, foodCategoryTrees.get(position), false, false);
}
}
}
/**
* 根據分類的下標獲得他的一級分類
*
* @param index 分類下標
*/
public BuyIngredientsBean getFirstCategoryByIndex(int index) {
if (index >= showFoods.size()) {
return null;
}
BuyIngredientsBean buyIngredientsBean = showFoods.get(index);
boolean isParent = buyIngredientsBean.parentId == 0;
for (int i = index; i > -1; i--) {
BuyIngredientsBean data = showFoods.get(i);
if (isParent && data.id == buyIngredientsBean.id) {
//是父分類
return data;
} else if (data.id == buyIngredientsBean.parentId) {
//子分類
if (data.parentId == 0) {
return data;
} else {
return getFirstCategoryByIndex(i);
}
}
}
return null;
}
/**
* 加載緩存中的商品
*
* @param position 分類下標
* @param addToHead 是否添加到頭部
*/
public void loadCacheFood(boolean isSupplier, int position, boolean addToHead, boolean isReset) {
if (isSupplier) {
BuyIngredientsBean buyIngredientsBean = supplierFoods.get(position);
if (buyIngredientsBean != null) {
if (showFoods.contains(buyIngredientsBean)) {
//如果列表中已经有这个分类的数据,则加载上一个分类
position -= 1;
if (position >= 0 && position < categoryFoods.size()) {
loadCacheFood(isSupplier, position, addToHead, isReset);
} else {
mRootView.finishLoad(false);
}
} else {
Log.e("eee", "加载供應商缓存");
List<BuyIngredientsBean> food = new ArrayList<>();
food.add(supplierFoods.get(position));
if (addToHead) {
showFoods.addAll(0, food);
} else {
showFoods.addAll(food);
}
mRootView.loadFood(food, addToHead, isReset);
}
} else {
Log.e("eee", "没有供應商缓存" + position);
//需要通过接口
getFoodsBySupplier("", position, supplierTranCategoryCache.get(position), addToHead, isReset);
}
} else {
List<BuyIngredientsBean> buyIngredientsBeans = categoryFoods.get(position);
if (CollectionUtils.isNotNullOrEmpty(buyIngredientsBeans)) {
if (showFoods.contains(buyIngredientsBeans.get(0))) {
//如果列表中已经有这个分类的数据,则加载上一个分类
position -= 1;
if (position >= 0 && position < categoryFoods.size()) {
loadCacheFood(isSupplier, position, addToHead, isReset);
} else {
mRootView.finishLoad(false);
}
} else {
Log.e("eee", "加载分类缓存");
if (addToHead) {
showFoods.addAll(0, categoryFoods.get(position));
} else {
showFoods.addAll(categoryFoods.get(position));
}
mRootView.loadFood(categoryFoods.get(position), addToHead, isReset);
}
} else {
Log.e("eee", "没有分类缓存" + position);
//需要通过接口
getFoodByCategory(position, foodCategoryTrees.get(position), addToHead, isReset);
}
}
}
/**
* 在所有食材中獲取分類下標
*
* @param allShowFood 所以顯示的食材
* @param categoryTrees 分類
* @return 下標
*/
public int getIndexInAllFood(List<BuyIngredientsBean> allShowFood, OrderCategoryBean.FoodCategoryTrees categoryTrees) {
//從一層中找到當前分類的位置
int index = allShowFood.indexOf(new BuyIngredientsBean(categoryTrees.getId(), categoryTrees.getName(), categoryTrees.getParentId()));
int position = index;
for (int i = 0; i < index; i++) {
position += allShowFood.get(i).purchaseFoodList.size();
}
return position;
}
}
......@@ -23,6 +23,7 @@ import com.gingersoft.supply_chain.mvp.ui.adapter.PurchaseFunctionAdapter;
import com.gingersoft.supply_chain.mvp.ui.fragment.category.CategoryFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.food.FoodManagementFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.food.MeasurementUnitFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.food.OtherFunctionFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.order.PurchaseListFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.supplier.SupplierListFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.warehouse.SnInOutboundRecordsFragment;
......@@ -104,6 +105,11 @@ public class FunctionListFragment extends BaseSupplyChainFragment<FunctionListPr
}
purchaseFunctionBeans.add(new PurchaseFunctionBean("庫存管理", storage));
List<Function> otherFunction = new ArrayList<>();
otherFunction.add(new Function("菜品Boom", R.drawable.ic_inventory_inquiry));
purchaseFunctionBeans.add(new PurchaseFunctionBean("其他功能", otherFunction));
PurchaseFunctionAdapter purchaseFunctionAdapter = new PurchaseFunctionAdapter(mContext, purchaseFunctionBeans);
purchaseFunctionAdapter.setFunctionClickListener((adapter, view, position) -> {
FunctionChildAdapter functionChildAdapter = (FunctionChildAdapter) adapter;
......@@ -150,6 +156,9 @@ public class FunctionListFragment extends BaseSupplyChainFragment<FunctionListPr
case "設置":
new XPopup.Builder(requireContext()).asCustom(new UpdateRestaurantInfoPop(requireContext())).show();
break;
case "菜品Boom":
start(OtherFunctionFragment.newInstance());
break;
default:
break;
......
package com.gingersoft.supply_chain.mvp.ui.fragment.food;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.gingersoft.gsa.cloud.common.loadsir.purchase.NotGoodsCallback;
import com.gingersoft.gsa.cloud.common.utils.CollectionUtils;
import com.gingersoft.gsa.cloud.common.utils.log.LogUtil;
import com.gingersoft.gsa.cloud.ui.utils.AppDialog;
import com.gingersoft.supply_chain.R;
import com.gingersoft.supply_chain.R2;
import com.gingersoft.supply_chain.di.component.DaggerOtherFunctionComponent;
import com.gingersoft.supply_chain.mvp.bean.BuyIngredientsBean;
import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean;
import com.gingersoft.supply_chain.mvp.contract.OtherFunctionContract;
import com.gingersoft.supply_chain.mvp.presenter.OtherFunctionPresenter;
import com.gingersoft.supply_chain.mvp.ui.adapter.BuyIngredientsAdapter;
import com.gingersoft.supply_chain.mvp.ui.adapter.FirstLevelCategoryAdapter;
import com.gingersoft.supply_chain.mvp.ui.adapter.SecondCategoryAdapter;
import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.order.ShoppingCatFragment;
import com.gingersoft.supply_chain.mvp.ui.widget.CenterLayoutManager;
import com.gingersoft.supply_chain.mvp.ui.widget.GoodsDetailsPopup;
import com.gingersoft.supply_chain.mvp.ui.widget.GroupedGridLayoutManager;
import com.gingersoft.supply_chain.mvp.ui.widget.ShowSecondCategoryPopup;
import com.gingersoft.supply_chain.mvp.ui.widget.StickyHeaderLayout;
import com.gingersoft.supply_chain.mvp.utils.ViewUtils;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.jess.arms.di.component.AppComponent;
import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;
import com.kingja.loadsir.core.LoadSir;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupPosition;
import com.qmuiteam.qmui.alpha.QMUIAlphaButton;
import com.qmuiteam.qmui.alpha.QMUIAlphaImageButton;
import com.qmuiteam.qmui.alpha.QMUIAlphaTextView;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
import lombok.val;
import static com.gingersoft.supply_chain.mvp.ui.fragment.food.NewFoodIngredientsFragment.EDIT_FOOD_RESULT_CODE;
/**
* ================================================
* Created by zjs on 07/07/2021 21:11
* Description 其他功能菜品消耗
* ================================================
*/
public class OtherFunctionFragment extends BaseSupplyChainFragment<OtherFunctionPresenter> implements OtherFunctionContract.View,View.OnClickListener {
@BindView(R2.id.topbar_food_ingredients)
QMUITopBar topbarFoodIngredients;
@BindView(R2.id.layout_purchase_food_content)
RelativeLayout layoutContent;
@BindView(R2.id.ed_food_ingredients_search)
EditText edFoodIngredientsSearch;
@BindView(R2.id.layout_food_ingredients_search)
LinearLayout layoutFoodIngredientsSearch;
@BindView(R2.id.tv_switch_food_ingredients_show_type)
QMUIAlphaTextView tvSwitchFoodIngredientsShowType;
@BindView(R2.id.rv_food_ingredients_category)
RecyclerView rvFirstCategory;
protected FirstLevelCategoryAdapter firstLevelCategoryAdapter;
@BindView(R2.id.layout_ingredients_left)
LinearLayout layoutIngredientsLeft;
@BindView(R2.id.rv_food_ingredients_second_category)
RecyclerView rvSecondCategory;
private SecondCategoryAdapter secondCategoryAdapter;
protected BuyIngredientsAdapter adapter;
@BindView(R2.id.rv_food_ingredients)
RecyclerView rvFoodIngredients;
@BindView(R2.id.srl_supplier)
LinearLayout srlSupplier;
@BindView(R2.id.btn_new_food_ingredient)
QMUIAlphaButton btnNewFoodIngredient;
@BindView(R2.id.btn_food_ingredients_confirm)
QMUIAlphaButton btnFoodIngredientsConfirm;
@BindView(R2.id.tv_ingredients_food_num)
TextView tvIngredientsFoodNum;
@BindView(R2.id.layout_choose_size)
LinearLayout layoutChooseSize;
@BindView(R2.id.btn_food_ingredients_cancel)
QMUIAlphaButton btnFoodIngredientsCancel;
@BindView(R2.id.layout_food_ingredients_btn)
LinearLayout layoutFoodIngredientsBtn;
@BindView(R2.id.btn_switch_row)
QMUIAlphaImageButton btnSwitchRow;
@BindView(R2.id.layout_category)
CollapsingToolbarLayout layoutCategory;
@BindView(R2.id.card_show_more_category)
CardView cardMoreCategory;
@BindView(R2.id.iv_unfold_arrow)
ImageView ivUnfoldArrow;
@BindView(R2.id.refreshLayout)
SmartRefreshLayout refreshLayout;
@BindView(R2.id.view_stick_head)
StickyHeaderLayout stickyHeaderLayout;
@BindView(R2.id.fresh_header)
ClassicsHeader classicsHeader;
@BindView(R2.id.tv_select_food_size)
TextView tvSelectFoodSize;
@BindView(R2.id.layout_food_ingredients_top)
LinearLayout mLayoutFoodSearch;
/**
* 購物車數量textview
*/
TextView tvShoppingCart;
/**
* 購物車中商品數量
*/
int shoppingCartNum = 0;
/**
* 0單列
* 1雙列
*/
protected boolean isSinger = true;
/**
* 是否顯示供應商食材
* true 是 false 否,顯示分類食材
*/
protected boolean isShowSupplier = false;
protected LoadService fullRegister;
/**
* 購物車requestCode
*/
protected final static int TO_SHOPPING_CART_REQUEST_CODE = 1001;
/**
* 新增/編輯食材 request_code
*/
protected final int EDIT_FOOD_REQUEST_CODE = 1050;
public static OtherFunctionFragment newInstance() {
OtherFunctionFragment fragment = new OtherFunctionFragment();
return fragment;
}
@Override
public void setupFragmentComponent(@NonNull AppComponent appComponent) {
DaggerOtherFunctionComponent //如找不到该类,请编译一下项目
.builder()
.appComponent(appComponent)
.view(this)
.build()
.inject(this);
}
@Override
public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_other_function, container, false);
}
@Override
public void initData(@Nullable Bundle savedInstanceState) {
initTopBar();
initPage();
initLoadSir();
initRefresh();
//將購物車中的食品數據導出
//初始化購物車數量
setTvShoppingCartNum(mPresenter.statisticsFoodQuantity());
loadDataByType();
}
/**
* 初始化下拉刷新上拉加載
*/
private void initRefresh() {
refreshLayout.setOnRefreshListener(refreshLayout -> {
//在這裡不是刷新,而是獲取上一個分類的數據
int i = firstLevelCategoryAdapter.getSelectedIndex() - 1;
if (i >= 0) {
loadFirstCategoryInfo(i, true, false);
} else {
setRefreshState(false);
}
}).setOnLoadMoreListener(refreshLayout -> {
//加載下一個分類
int i = firstLevelCategoryAdapter.getSelectedIndex() + 1;
if (i < firstLevelCategoryAdapter.getItemCount()) {
//判斷是否有緩存,把緩存拿出來,看看有沒有加載到列表中,如果已經加載了,繼續獲取下一個分類,一直到沒有加載的那個
mPresenter.loadNextCategoryFood(edFoodIngredientsSearch.getText().toString(), isShowSupplier, i, firstLevelCategoryAdapter.getData());
} else {
finishLoad(true);
}
}).setEnableOverScrollBounce(false).setEnableAutoLoadMore(true);
}
private void initLoadSir() {
fullRegister = LoadSir.getDefault().register(layoutContent, (Callback.OnReloadListener) v -> {
if (v.getId() == R.id.layout_not_commodity) {
//新增食材
toCreateFood();
}
});
}
/**
* 根據類型加載數據
*/
protected void loadDataByType() {
setSecondCategoryShowState(View.VISIBLE);
//獲取一級分類
mPresenter.getCategoryTrees();
}
protected void initTopBar() {
initTopBar(topbarFoodIngredients, getString(R.string.str_title_purchase_order));
View view = View.inflate(requireContext(), R.layout.view_shopping_car, null);
tvShoppingCart = view.findViewById(R.id.tv_purchase_cart_number);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
view.setLayoutParams(layoutParams);
view.setOnClickListener(this);
topbarFoodIngredients.addRightView(view, R.id.qmui_shopping_cart);
}
protected void initPage() {
layoutChooseSize.setVisibility(View.GONE);
layoutFoodIngredientsBtn.setVisibility(View.VISIBLE);
}
/**
* 新建食品
*/
protected void toCreateFood() {
String defaultName = getCurrentCategoryName();
if (isShowSupplier) {
startForResult(NewFoodIngredientsFragment.newInstance(defaultName, ""), EDIT_FOOD_REQUEST_CODE);
} else {
startForResult(NewFoodIngredientsFragment.newInstance("", defaultName), EDIT_FOOD_REQUEST_CODE);
}
}
@OnClick({R2.id.layout_food_ingredients_search, R2.id.tv_switch_food_ingredients_show_type, R2.id.btn_food_ingredients_confirm,
R2.id.btn_food_ingredients_cancel, R2.id.btn_switch_row, R2.id.card_show_more_category,R2.id.iv_food_search})
@Override
public void onClick(View v) {
int viewId = v.getId();
if (viewId == R.id.layout_food_ingredients_search || viewId == R.id.iv_food_search ) {
//跳轉搜索頁面
jumpToSearch();
} else if (viewId == R.id.btn_switch_row) {
//切換顯示單雙列
switchShowSingerOrDouble();
} else if (viewId == R.id.tv_switch_food_ingredients_show_type) {
//切換顯示分類或是顯示供應商
switchShowCategoryOrSupplier();
} else if (viewId == R.id.card_show_more_category) {
//展開分類
unfoldCategory();
} else if (viewId == R.id.btn_food_ingredients_confirm || viewId == R.id.qmui_shopping_cart) {
//確認
confirm();
} else if (viewId == R.id.btn_food_ingredients_cancel) {
//取消
killMyself();
}
}
/**
* 跳轉到搜索頁面
*/
private void jumpToSearch() {
int position = firstLevelCategoryAdapter.getSelectedIndex() ;
LogUtil.e("zjs jumpToSearch 跳轉到搜索頁面 position"+position);
mPresenter.getFoodsBySupplier(edFoodIngredientsSearch.getText().toString(),position, firstLevelCategoryAdapter.getItem(position), false, true);
}
/**
* 切換顯示單列或雙列
*/
private void switchShowSingerOrDouble() {
//切換單雙列
isSinger = !isSinger;
setLayoutManager();
adapter.setShowSingerRow(isSinger);
btnSwitchRow.setImageResource(isSinger ? R.drawable.ic_single_row : R.drawable.ic_double_row);
rvFoodIngredients.setAdapter(adapter);
}
private int lastIndex = 0;
/**
* 是不是用戶滑動
*/
private boolean isUser = true;
private void setLayoutManager() {
LinearLayoutManager linearLayoutManager = isSinger ? new LinearLayoutManager(requireContext()) : getDoubleRowManager();
rvFoodIngredients.setLayoutManager(linearLayoutManager);
}
/**
* 食材recyclerview滑動監聽
*/
private RecyclerView.OnScrollListener mFoodScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (!isUser) {
//不是用戶手動滑動的,不執行下面的
isUser = true;
return;
}
int currentStickyGroup = stickyHeaderLayout.getCurrentStickyGroup();
//手指往上滑動,獲取下一個分類數據
//記錄當前滑動到哪個header,如果和上次不一致,頂部的分類就切換選中
if (currentStickyGroup != lastIndex) {
if (currentStickyGroup == -1) {
return;
}
lastIndex = currentStickyGroup;
//拿到當前顯示的分類信息
BuyIngredientsBean headerDataByPosition = adapter.getHeaderDataByPosition(currentStickyGroup);
if (headerDataByPosition == null) {
return;
}
//頂部懸浮顯示的是一級分類
if (headerDataByPosition.parentId == 0) {
//找到這個一級分類,左側一級分類切換到選中,頂部二級分類切換顯示
int firstLevelCategoryIndex = firstLevelCategoryAdapter.getItemPosition(new OrderCategoryBean.FoodCategoryTrees(headerDataByPosition.id, headerDataByPosition.categoryName, headerDataByPosition.parentId));
if (firstLevelCategoryIndex > -1) {
//判斷這個分類是否已經被加載了,如果已經加載過了,就需要往下找,一直找到沒有被加載那個
selectFirstCategoryByIndex(firstLevelCategoryIndex);
}
} else {
//二級或三級分類,同時也要判斷是否要切換一級分類
OrderCategoryBean.FoodCategoryTrees currentStickyCategory = new OrderCategoryBean.FoodCategoryTrees(headerDataByPosition.id, headerDataByPosition.categoryName, headerDataByPosition.parentId);
int secondLevelCategoryIndex = secondCategoryAdapter.getItemPosition(currentStickyCategory);
if (secondLevelCategoryIndex >= 0) {
secondCategorySelect(secondLevelCategoryIndex, true);
} else {
//沒有這個二級或三級分類,判斷是否切換了一級分類
BuyIngredientsBean firstCategory = mPresenter.getFirstCategoryByIndex(currentStickyGroup);
if (firstCategory != null) {
OrderCategoryBean.FoodCategoryTrees foodCategoryTrees = new OrderCategoryBean.FoodCategoryTrees(firstCategory.id, firstCategory.categoryName, firstCategory.parentId);
int firstCategoryIndex = firstLevelCategoryAdapter.getItemPosition(foodCategoryTrees);
if (firstCategoryIndex != firstLevelCategoryAdapter.getSelectedIndex()) {
if (firstCategoryIndex >= 0 && firstCategoryIndex != firstLevelCategoryAdapter.getSelectedIndex() && firstCategoryIndex < firstLevelCategoryAdapter.getItemCount()) {
//切換一級分類
selectFirstCategoryByIndex(firstCategoryIndex);
}
}
}
}
}
}
}
};
private void secondCategorySelect(int secondLevelCategoryIndex2, boolean select) {
if (select) {
secondCategoryAdapter.setSelectedIndex(secondLevelCategoryIndex2);
rvSecondCategory.post(() -> ViewUtils.moveToCenterByHorizontal(rvSecondCategory, secondLevelCategoryIndex2));
}
}
/**
* 切換顯示分類或供應商
*/
private void switchShowCategoryOrSupplier() {
isShowSupplier = !isShowSupplier;
if (isShowSupplier) {
//獲取供應商
setSecondCategoryShowState(View.GONE);
mPresenter.loadFoodIngredientsData(-1, true);
} else {
//獲取分類
setSecondCategoryShowState(View.VISIBLE);
mPresenter.getCategoryTrees();
}
setShowTypeBtn();
}
private void setShowTypeBtn() {
if (isShowSupplier) {
tvSwitchFoodIngredientsShowType.setText(getString(R.string.str_supplier));
} else {
tvSwitchFoodIngredientsShowType.setText(getString(R.string.str_species));
}
}
/**
* 展開二級分類
*/
private void unfoldCategory() {
if (secondCategoryAdapter == null) {
return;
}
new XPopup.Builder(requireContext())
.atView(layoutCategory)
.popupPosition(PopupPosition.Bottom)
.hasShadowBg(false)
.borderRadius(0)
.asCustom(new ShowSecondCategoryPopup(requireContext(), layoutCategory.getMeasuredWidth(), secondCategoryAdapter.getSelectIndex(), secondCategoryAdapter.getData()).setOnCategoryClickListener(new ShowSecondCategoryPopup.OnCategoryClickListener() {
@Override
public void onClick(OrderCategoryBean.FoodCategoryTrees foodCategoryTrees, int position, int categoryLevel) {
//如果是二級分類,選中這個二級分類
secondCategorySelect(position, categoryLevel == 2);
//加載當前分類下的食品
//二級分類點擊
//列表要定位到指定位置
//找到這個分類的下標
int categoryIndex = mPresenter.getIndexInAllFood(adapter.getData(), foodCategoryTrees);
if (categoryIndex != -1) {
scrollToPosition(categoryIndex, (LinearLayoutManager) rvFoodIngredients.getLayoutManager());
isUser = false;
}
}
}))
.show();
}
/**
* 確認,進入購物車頁面
*/
protected void confirm() {
List<PurchaseFoodBean> purchaseFood = mPresenter.getPurchaseFood();
if (CollectionUtils.isNotNullOrEmpty(purchaseFood)) {
startForResult(ShoppingCatFragment.newInstance(), TO_SHOPPING_CART_REQUEST_CODE);
setFragmentResult(RESULT_OK, null);
} else {
showMessage("請選擇食材");
}
}
/**
* 一级分类
*
* @param foodCategoryTrees 所有分類層級信息
*/
@Override
public void initCategoryInfo(List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees) {
if (CollectionUtils.isNotNullOrEmpty(foodCategoryTrees)) {
fullRegister.showSuccess();
if (firstLevelCategoryAdapter == null) {
firstLevelCategoryAdapter = new FirstLevelCategoryAdapter(foodCategoryTrees, requireContext());
rvFirstCategory.setAdapter(firstLevelCategoryAdapter);
firstLevelCategoryAdapter.setOnItemClickListener((adapter, view, position) -> {
LogUtil.e("zjs initCategoryInfo ItemClick position "+position);
firstCategoryClick(position);
});
} else {
scrollToPosition(0, (LinearLayoutManager) rvFirstCategory.getLayoutManager());
firstLevelCategoryAdapter.setNewInstance(foodCategoryTrees);
}
//默認選中第0個分類
firstCategoryClick(0);
} else {
fullRegister.showCallback(NotGoodsCallback.class);
}
}
/**
* 加載一級分類數據
*
* @param position 一級分類下標
*/
private void loadFirstCategoryInfo(int position, boolean addToHead, boolean isReset) {
//切換右側顯示的二級分類和食材
// 现在改为在滑動事件中切換
if (!mPresenter.isHasLocationInfo(isShowSupplier, position)) {
//本地沒有緩衝才去查找
//獲取點擊的分類的所有食材
if (isShowSupplier) {
mPresenter.getFoodsBySupplier(edFoodIngredientsSearch.getText().toString(),position, firstLevelCategoryAdapter.getItem(position), addToHead, isReset);
} else {
mPresenter.getFoodByCategory(position, firstLevelCategoryAdapter.getItem(position), addToHead, isReset);
}
} else {
//本地有緩存,拿緩存中的數據
mPresenter.loadCacheFood(isShowSupplier, position, addToHead, isReset);
}
}
@Override
public void selectFirstCategoryByIndex(int position) {
firstLevelCategoryAdapter.setSelectedIndex(position);
loadSecondCategory(firstLevelCategoryAdapter.getItem(position).getFoodCategoryTrees());
ViewUtils.moveToCenterByVertical(rvFirstCategory, position);
}
/**
* 一級分類點擊,判斷列表中有沒有這個分類的數據,有的話就滾動
*
* @param position 分類下標
*/
private void firstCategoryClick(int position) {
if (position > firstLevelCategoryAdapter.getItemCount()) {
return;
}
//這個分類的數據是否已經在顯示列表中
int categoryIndex = mPresenter.isShowGoods(firstLevelCategoryAdapter.getItem(position));
if (categoryIndex == -1) {
//未顯示
//清空食材列表,重新加載當前下標分類的食品數據
mPresenter.clearShowFoods();
selectFirstCategoryByIndex(position);
loadFirstCategoryInfo(position, false, true);
} else {
//已經在列表中了,只需要滾動到指定位置
//通過分類下標,拿到列表食物下標
selectFirstCategoryByIndex(position);
scrollToPosition(mPresenter.getFoodIndexByCategoryIndex(categoryIndex));
}
}
@Override
public void loadFail() {
}
@Override
public void finishLoad(boolean noData) {
refreshLayout.finishLoadMore();
refreshLayout.finishRefresh();
if (noData) {
refreshLayout.finishRefreshWithNoMoreData();
}
}
/**
* 加載二級分類
*
* @param foodCategoryTrees
*/
private void loadSecondCategory(List<OrderCategoryBean.FoodCategoryTrees> foodCategoryTrees) {
if (secondCategoryAdapter != null && CollectionUtils.isNullOrEmpty(foodCategoryTrees)) {
secondCategoryAdapter.setNewInstance(null);
return;
}
if (secondCategoryAdapter == null) {
secondCategoryAdapter = new SecondCategoryAdapter(requireContext(), foodCategoryTrees);
rvSecondCategory.setLayoutManager(new CenterLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
rvSecondCategory.setAdapter(secondCategoryAdapter);
OnItemClickListener onItemClickListener = (a, view, position2) -> {
secondCategorySelect(position2, true);
//加載當前分類下的食品
//二級分類點擊
//列表要定位到指定位置
//找到這個分類的下標
int categoryIndex = mPresenter.getIndexInAllFood(adapter.getData(), secondCategoryAdapter.getItem(position2));
scrollToPosition(categoryIndex, (LinearLayoutManager) rvFoodIngredients.getLayoutManager());
isUser = false;
};
secondCategoryAdapter.setOnItemClickListener(onItemClickListener);
} else {
secondCategoryAdapter.setNewInstance(foodCategoryTrees);
}
setSecondCategoryShowState(View.VISIBLE);
}
/**
* 加載食品,找到這些食品最近的上一個分類,將數據添加到這個分類下面,如果沒有,就添加到最頂部
*/
@Override
public void loadFood(List<BuyIngredientsBean> buyIngredientsBeans, boolean addToHead, boolean isReset) {
setRefreshState(false);
fullRegister.showSuccess();
if (adapter == null) {
adapter = new BuyIngredientsAdapter(requireContext(), buyIngredientsBeans);
rvFoodIngredients.setAdapter(adapter);
adapter.setOnItemClickListener((a, holder, groupPosition, childPosition) -> {
BuyIngredientsBean buyIngredientsBean = adapter.getData().get(groupPosition);
PurchaseFoodBean purchaseFoodBean = buyIngredientsBean.purchaseFoodList.get(childPosition);
//显示弹窗
GoodsDetailsPopup foodDetailsPopup = getFoodDetailsPopup(purchaseFoodBean)
.setOnFoodNumberChangeListener((purchaseFoodBean1, p, c, beforeNum, currentNum) -> {
foodNumberChanger(purchaseFoodBean, groupPosition, beforeNum, currentNum);
//需要刷新列表
adapter.notifyChildChanged(groupPosition, childPosition);
});
new XPopup.Builder(requireContext())
.autoOpenSoftInput(false)
.autoFocusEditText(false)
.asCustom(foodDetailsPopup)
.show();
});
adapter.setOnItemChildClickListener((a, view, groupPosition, position) -> {
if (groupPosition < adapter.getData().size()) {
if (position < adapter.getData().get(groupPosition).purchaseFoodList.size()) {
PurchaseFoodBean purchaseFoodBean = adapter.getData().get(groupPosition).purchaseFoodList.get(position);
if (view.getId() == R.id.iv_commodity_edit) {
//編輯
startForResult(NewFoodIngredientsFragment.newInstance(purchaseFoodBean), EDIT_FOOD_REQUEST_CODE);
} else if (view.getId() == R.id.iv_commodity_delete) {
//刪除食材
AppDialog.getInstance().showWaringDialog(mContext, "是否確認刪除" + purchaseFoodBean.getName(), () -> {
mPresenter.deleteFood(purchaseFoodBean.getId(), isShowSupplier ? -1 : firstLevelCategoryAdapter.getSelectedIndex(), groupPosition, position);
});
}
return;
}
}
showMessage(getString(R.string.str_data_info));
});
adapter.setAnimationWithDefault(BaseQuickAdapter.AnimationType.AlphaIn);
adapter.setOnFoodNumberChangeListener((purchaseFoodBean, parentCategoryIndex, categoryIndex, beforeNum, currentNum) -> foodNumberChanger(purchaseFoodBean, parentCategoryIndex, beforeNum, currentNum));
rvFoodIngredients.removeOnScrollListener(mFoodScrollListener);
rvFoodIngredients.addOnScrollListener(mFoodScrollListener);
setLayoutManager();
} else {
if (isReset) {
adapter.setNewInstance(buyIngredientsBeans);
} else {
int startIndex = 0;
int endIndex = 0;
if (!addToHead) {
//添加到尾部
startIndex = adapter.getItemCount() + 1;
}
for (BuyIngredientsBean buyIngredientsBean : buyIngredientsBeans) {
endIndex += buyIngredientsBean.purchaseFoodList.size() + 1;
}
endIndex += startIndex;
adapter.addData(addToHead ? 0 : adapter.getData().size(), buyIngredientsBeans, startIndex, endIndex);
}
}
}
protected GoodsDetailsPopup getFoodDetailsPopup(PurchaseFoodBean purchaseFoodBean) {
return new GoodsDetailsPopup(requireContext(), purchaseFoodBean);
}
/**
* 食品数量改变时调用
*
* @param purchaseFoodBean 食品信息
* @param parentCategoryIndex 食品分类下标:食品所属分类在列表中的下标
* @param beforeNum 改变之前的数量
* @param currentNum 改变之后的数量
*/
private void foodNumberChanger(PurchaseFoodBean purchaseFoodBean, int parentCategoryIndex, int beforeNum, int currentNum) {
BuyIngredientsBean firstCategory = mPresenter.getFirstCategoryByIndex(parentCategoryIndex);
if (firstCategory != null) {
int firstCategoryByIndex = firstLevelCategoryAdapter.getItemPosition(new OrderCategoryBean.FoodCategoryTrees(firstCategory.id, firstCategory.categoryName, firstCategory.parentId));
//找到一級分類下標
if (beforeNum == 0 || currentNum == 0) {
OrderCategoryBean.FoodCategoryTrees item = firstLevelCategoryAdapter.getItem(firstCategoryByIndex);
//正
if (item.getSize() < 0) {
item.setSize(0);
}
if (beforeNum == 0) {
item.setSize(item.getSize() + 1);
} else {
item.setSize(item.getSize() - 1);
}
firstLevelCategoryAdapter.notifyItemChanged(firstCategoryByIndex);
}
}
//修改
mPresenter.addFood(purchaseFoodBean);
shoppingCartNum += currentNum - beforeNum;
setTvShoppingCartNum(shoppingCartNum);
}
protected void setSecondCategoryShowState(int visibility) {
layoutCategory.setVisibility(visibility);
}
private void setTvShoppingCartNum(int num) {
tvSelectFoodSize.setText(String.valueOf(num));
//食材管理頁面,這個tvShoppingCart為空
if (tvShoppingCart != null) {
tvShoppingCart.setText(String.valueOf(num));
if (num > 0) {
tvShoppingCart.setVisibility(View.VISIBLE);
} else {
tvShoppingCart.setVisibility(View.GONE);
}
}
shoppingCartNum = num;
}
public void setRefreshState(boolean noMoreData) {
refreshLayout.finishRefresh();
refreshLayout.finishLoadMore();
refreshLayout.setEnableRefresh(true);
refreshLayout.setNoMoreData(noMoreData);
}
@Override
public void scrollToPosition(int index) {
refreshLayout.finishRefresh();
refreshLayout.finishLoadMore();
scrollToPosition(index, (LinearLayoutManager) rvFoodIngredients.getLayoutManager());
}
/**
* 獲取雙列的recyclerview的layoutManager
*/
@NotNull
private GroupedGridLayoutManager getDoubleRowManager() {
val gridLayoutManager = new GroupedGridLayoutManager(requireContext(), 2, adapter);
return gridLayoutManager;
}
/**
* 滾動到指定位置
*
* @param n 下標
* @param linearLayoutManager recyclerview的layoutManager
*/
public void scrollToPosition(int n, LinearLayoutManager linearLayoutManager) {
isUser = false;
linearLayoutManager.scrollToPositionWithOffset(n, 0);
}
/**
* 獲取當前分類名稱
*
* @return 當前分類名稱
*/
private String getCurrentCategoryName() {
String defaultName = "";
if (firstLevelCategoryAdapter != null) {
if (firstLevelCategoryAdapter.getItemCount() > firstLevelCategoryAdapter.getSelectedIndex()) {
defaultName = firstLevelCategoryAdapter.getItem(firstLevelCategoryAdapter.getSelectedIndex()).getName();
}
}
return defaultName;
}
@Override
public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
super.onFragmentResult(requestCode, resultCode, data);
if (requestCode == TO_SHOPPING_CART_REQUEST_CODE && resultCode == RESULT_OK) {
resetData();
} else if (requestCode == EDIT_FOOD_REQUEST_CODE && resultCode == EDIT_FOOD_RESULT_CODE) {
resetData();
}
}
private void resetData() {
//之前去到購物車頁面,現在回到這個頁面
//如果修改了供應商和分類信息,可以清除掉緩存再獲取,就能刷新頁面
//購物車食材數量發生了變化,需要刷新當前頁面的食材數量
setTvShoppingCartNum(mPresenter.statisticsFoodQuantity());
mPresenter.clearShowFoods();
mPresenter.clearCategoryFoods();
mPresenter.clearSupplierFoods();
mPresenter.clearSupplierCache();
mPresenter.clearCategoryTreesCache();
refreshData();
}
protected void refreshData() {
if (isShowSupplier) {
// if (pageType == GET_FOOD_BY_SUPPLIER) {
// mPresenter.getFoodsBySupplier(0, firstLevelCategoryAdapter.getItem(0), false, true);
// } else {
mPresenter.loadFoodIngredientsData(-1, true);
// }
} else {
mPresenter.getCategoryTrees();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@color/supply_chain_bg_color"
android:orientation="vertical">
<com.qmuiteam.qmui.widget.QMUITopBar
android:id="@+id/topbar_food_ingredients"
android:layout_width="match_parent"
android:layout_height="@dimen/head_height"
android:background="@color/theme_color"
app:qmui_topbar_title_color="@color/theme_white_color" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/layout_purchase_food_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layout_food_ingredients_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_8"
android:layout_marginTop="@dimen/dp_4"
android:layout_marginRight="@dimen/dp_10"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible">
<LinearLayout
android:id="@+id/layout_food_ingredients_search"
android:layout_width="0dp"
android:layout_height="@dimen/dp_40"
android:layout_marginBottom="@dimen/dp_4"
android:layout_marginTop="@dimen/dp_4"
android:layout_weight="1"
android:background="@drawable/shape_white_eight_corners_bg"
android:orientation="horizontal">
<EditText
android:id="@+id/ed_food_ingredients_search"
style="@style/supplier_search_style"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/dp_8"
android:layout_marginRight="@dimen/dp_5"
android:layout_weight="1"
android:background="@null"
android:hint="搜索食材名稱" />
<ImageView
android:id="@+id/iv_food_search"
android:paddingLeft="@dimen/dp_12"
android:paddingRight="@dimen/dp_10"
android:paddingTop="@dimen/dp_6"
android:paddingBottom="@dimen/dp_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/dp_10"
android:src="@drawable/ic_search" />
</LinearLayout>
<com.qmuiteam.qmui.alpha.QMUIAlphaImageButton
android:id="@+id/btn_switch_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/dp_6"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:src="@drawable/ic_single_row" />
</LinearLayout>
<LinearLayout
android:id="@+id/srl_supplier"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/layout_food_ingredients_btn"
android:layout_below="@id/layout_food_ingredients_top"
android:layout_marginTop="@dimen/dp_5"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/layout_ingredients_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<com.qmuiteam.qmui.alpha.QMUIAlphaTextView
android:id="@+id/tv_switch_food_ingredients_show_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_7"
android:background="@drawable/shape_light_small_app_btn"
android:gravity="center"
android:paddingLeft="@dimen/dp_4"
android:paddingTop="@dimen/dp_5"
android:paddingRight="@dimen/dp_4"
android:paddingBottom="@dimen/dp_5"
android:text="@string/str_species"
android:textColor="@color/white"
android:textSize="@dimen/dp_14" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_food_ingredients_category"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="vertical">
<!-- 二級分類 -->
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/layout_category"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_40"
android:background="@color/white"
android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_food_ingredients_second_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/dp_40" />
<androidx.cardview.widget.CardView
android:id="@+id/card_show_more_category"
android:layout_width="@dimen/dp_40"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@color/white"
app:cardElevation="@dimen/dp_10">
<ImageView
android:id="@+id/iv_unfold_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_inverted_triangle_66" />
</androidx.cardview.widget.CardView>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<!-- 食材 -->
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:id="@+id/fresh_header"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
app:srlAccentColor="#aaa"
app:srlDrawableArrow="@drawable/ic_pulling"
app:srlDrawableMarginRight="@dimen/dp_5"
app:srlDrawableSize="@dimen/dp_12"
app:srlEnableLastTime="false"
app:srlFinishDuration="300"
app:srlPrimaryColor="@color/trans"
app:srlTextFinish="加載完成"
app:srlTextPulling="下滑查看上一分類"
app:srlTextRefreshing="正在飛速加載..."
app:srlTextRelease="釋放查看上一分類"
app:srlTextSizeTitle="@dimen/dp_12" />
<com.gingersoft.supply_chain.mvp.ui.widget.StickyHeaderLayout
android:id="@+id/view_stick_head"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_food_ingredients"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</com.gingersoft.supply_chain.mvp.ui.widget.StickyHeaderLayout>
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
app:srlDrawableArrow="@drawable/ic_push"
app:srlDrawableMarginRight="@dimen/dp_5"
app:srlDrawableSize="@dimen/dp_12"
app:srlTextFailed="加載完成"
app:srlTextLoading="正在飛速加載中..."
app:srlTextPulling="上拉加載更多"
app:srlTextRelease="釋放查看下一分類"
app:srlTextSizeTitle="@dimen/dp_12" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_food_ingredients_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_20"
android:layout_marginBottom="@dimen/dp_10"
android:visibility="gone"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.qmuiteam.qmui.alpha.QMUIAlphaButton
android:id="@+id/btn_new_food_ingredient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_app_btn"
android:gravity="center"
android:text="+新增食材"
android:textColor="@color/white"
android:textSize="@dimen/dp_16"
android:visibility="gone" />
<LinearLayout
android:id="@+id/layout_choose_size"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/dp_20"
android:layout_weight="1"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_chosen"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_16" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/left_parenthesis"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_16" />
<TextView
android:id="@+id/tv_select_food_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="@color/required_color"
android:textSize="@dimen/dp_16" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/right_parenthesis"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_16" />
</LinearLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.qmuiteam.qmui.alpha.QMUIAlphaButton
android:id="@+id/btn_food_ingredients_confirm"
style="@style/Save_Btn_Style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="確定"
android:visibility="visible" />
<TextView
android:id="@+id/tv_ingredients_food_num"
android:layout_width="@dimen/dp_20"
android:layout_height="@dimen/dp_20"
android:layout_gravity="right"
android:autoSizeMaxTextSize="@dimen/dp_8"
android:autoSizeMinTextSize="@dimen/dp_4"
android:background="@drawable/ui_shape_red_oval"
android:gravity="center"
android:text="3"
android:textColor="@color/white"
android:textSize="@dimen/dp_12"
android:visibility="gone"
app:layout_constraintRight_toRightOf="@id/iv_shopping_cart"
app:layout_constraintTop_toTopOf="@id/iv_shopping_cart" />
</FrameLayout>
<com.qmuiteam.qmui.alpha.QMUIAlphaButton
android:id="@+id/btn_food_ingredients_cancel"
style="@style/Cancel_Btn_Style"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginTop="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:layout_weight="1"
android:text="取消" />
</LinearLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment