InventoryActivity.java 9.05 KB
package com.huaheng.tab;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huaheng.common.Constant;
import com.huaheng.common.WMSLog;
import com.huaheng.common.WMSUtils;
import com.huaheng.common.adapter.AbsCommonAdapter;
import com.huaheng.common.adapter.AbsViewHolder;
import com.huaheng.common.model.BaseBean;
import com.huaheng.common.model.Inventory;
import com.huaheng.common.model.OrderTable;
import com.huaheng.common.model.ShipmentDetail;
import com.huaheng.common.model.TableModel;
import com.huaheng.common.model.TotalInventory;
import com.huaheng.httplib.HttpInterface;
import com.huaheng.httplib.Subscribers.ProgressSubscriber;
import com.huaheng.httplib.Subscribers.SubscriberOnNextListener;
import com.huaheng.tab.util.TableActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by youjie on 2020/5/25
 */
public class InventoryActivity extends TableActivity {

    @Override
    protected void initActivityOnCreate(Bundle savedInstanceState) {
        super.initActivityOnCreate(savedInstanceState);
        setButtonView(R.layout.activity_total_inventory);
        ButterKnife.bind(this);
        setTitle(mContext.getString(R.string.inventory));
        initTableView();
        getTalbeByCondition(pageNo);
    }

    public void initTableView() {
        addTitleText("项目号", Constant.TITLE_TIME_WIDTH);
        addTitleText("物料编码", Constant.TITLE_TIME_WIDTH);
        addTitleText("物料名称", Constant.TITLE_NORMAL_WIDTH);
        addTitleText("锁线机", Constant.TITLE_NORMAL_WIDTH);
        addTitleText("内页P数", Constant.TITLE_NORMAL_WIDTH);
        addTitleText("容器号", Constant.TITLE_NORMAL_WIDTH);
        addTitleText("库位号", Constant.TITLE_NORMAL_WIDTH);
        addTitleText("数量", Constant.TITLE_NORMAL_WIDTH);
        addTitleText("创建人", Constant.TITLE_NORMAL_WIDTH);
        addTitleText("创建时间", Constant.TITLE_TIME_WIDTH);
        addTitleText("更新人", Constant.TITLE_NORMAL_WIDTH);
        addTitleText("更新时间", Constant.TITLE_TIME_WIDTH);
        mRightAdapter = new AbsCommonAdapter<TableModel>(mContext, R.layout.table_right_item) {
            @Override
            public void convert(AbsViewHolder helper, TableModel item, final int pos) {
                LinearLayout linearLayout = helper.getView(R.id.tableLineLayout);
                linearLayout.removeAllViews();
                List<String> contentList = item.getContentList();
                addMessageText(linearLayout, Constant.TITLE_TIME_WIDTH, contentList.get(0));
                addMessageText(linearLayout, Constant.TITLE_TIME_WIDTH, contentList.get(1));
                addMessageText(linearLayout, Constant.TITLE_NORMAL_WIDTH, contentList.get(2));
                addMessageText(linearLayout, Constant.TITLE_NORMAL_WIDTH, contentList.get(3));
                addMessageText(linearLayout, Constant.TITLE_NORMAL_WIDTH, contentList.get(4));
                addMessageText(linearLayout, Constant.TITLE_NORMAL_WIDTH, contentList.get(5));
                addMessageText(linearLayout, Constant.TITLE_NORMAL_WIDTH, contentList.get(6));
                addMessageText(linearLayout, Constant.TITLE_NORMAL_WIDTH, contentList.get(7));
                addMessageText(linearLayout, Constant.TITLE_NORMAL_WIDTH, contentList.get(8));
                addMessageText(linearLayout, Constant.TITLE_TIME_WIDTH, contentList.get(9));
                addMessageText(linearLayout, Constant.TITLE_NORMAL_WIDTH, contentList.get(10));
                addMessageText(linearLayout, Constant.TITLE_TIME_WIDTH, contentList.get(11));
//                setSelectBackground(helper, pos);
            }
        };
    }

    @Override
    public void setDatas(List<BaseBean> baseBeans, int type) {
        List<TableModel> mDatas = new ArrayList<>();
        for (BaseBean baseBean : baseBeans) {
            TableModel tableMode = new TableModel();
            Inventory inventory = (Inventory) baseBean;
            ArrayList<String> contentList = new ArrayList<>();
            contentList.add(String.valueOf(inventory.getProject()));
            contentList.add(inventory.getMaterialCode());
            contentList.add(inventory.getMaterialName());
            contentList.add(inventory.getLinecode());
            contentList.add(inventory.getPqty());
            contentList.add(inventory.getContainerCode());
            contentList.add(inventory.getLocationCode());
            contentList.add(String.valueOf(inventory.getQty().intValue()));
            contentList.add(String.valueOf(inventory.getCreatedBy()));
            contentList.add(String.valueOf(inventory.getCreated()));
            contentList.add(String.valueOf(inventory.getLastUpdatedBy()));
            contentList.add(String.valueOf(inventory.getLastUpdated()));
            tableMode.setContentList(contentList);
            mDatas.add(tableMode);
        }
        mRightAdapter.addData(mDatas, false);
        //加载数据成功,增加页数
        mDatas.clear();
    }

    private void showSearchDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_search_inventory, null);
        TextView cancel = view.findViewById(R.id.modify_qty_cancel);
        TextView sure = view.findViewById(R.id.modify_qty_sure);
        final EditText projectEdit = view.findViewById(R.id.projectEdit);
        final EditText materialEdit = view.findViewById(R.id.materialEdit);
        final Dialog dialog = builder.create();
        dialog.show();
        dialog.getWindow().setContentView(view);
        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String project = projectEdit.getText().toString();
                String materialCode = materialEdit.getText().toString();
                mobileTotalInventory(pageNo, pageSize, project, materialCode);
                dialog.dismiss();
            }
        });
    }

    @Override
    public void select(BaseBean baseBean) {
        Inventory inventory = (Inventory) baseBean;
        mobileTotalInventoryDetail(inventory.getProject(), inventory.getMaterialCode());
    }

    @OnClick({R.id.refreshBtn, R.id.searchBtn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.refreshBtn:
                getTalbeByCondition(pageNo);
                break;
            case R.id.searchBtn:
                showSearchDialog();
                break;
        }
    }

    @Override
    protected void getTalbeByCondition(int page) {
        totalInventory(page);
    }

    private void totalInventory(int page) {
        mobileTotalInventory(page, 10, null, null);
    }

    private void mobileTotalInventory(int pageNumber, int pageSize, String project, String materialCode) {
        HttpInterface.getInsstance(mContext).mobileTotalInventory(new ProgressSubscriber<TotalInventory>(mContext, mobileTotalInventoryListener), pageNumber, pageSize, project, materialCode);
    }

    SubscriberOnNextListener mobileTotalInventoryListener = new SubscriberOnNextListener<TotalInventory>() {
        @Override
        public void onNext(TotalInventory totalInventory) {
            clearSelectBean();
            List<Inventory> inventories = totalInventory.getList();
            for(Inventory inventory : inventories) {
                inventory.setContainerCode("");
                inventory.setLocationCode("");
            }
            tableBeans = (List) inventories;
            pageNo = upPageNo;
            setData(tableBeans);
            freshMenuText(totalInventory.getTotal());
        }

        @Override
        public void onError(String str) {
            upPageNo = pageNo;
            mRightAdapter.clearData(true);
        }
    };

    private void mobileTotalInventoryDetail(String project, String materialCode) {
        HttpInterface.getInsstance(mContext).mobileTotalInventoryDetail(new ProgressSubscriber<List<Inventory>>(mContext, mobileTotalInventoryDetailListener), project, materialCode);
    }

    SubscriberOnNextListener mobileTotalInventoryDetailListener = new SubscriberOnNextListener<List<Inventory>>() {
        @Override
        public void onNext(List<Inventory> inventorys) {
            clearSelectBean();
            tableBeans = (List)inventorys;
            pageNo = upPageNo;
            setData(tableBeans);
//            freshMenuText(totalInventory.getTotal());
        }

        @Override
        public void onError(String str) {
            upPageNo = pageNo;
            mRightAdapter.clearData(true);
        }
    };
}