框架MVP,greendao做数据库开发,ButterKnife.bind,Volley请求,ListView第一行都有输入框……

五仁月饼

这博客就是个“五仁月饼”分开吃都不错,合在一起就难吃了。不过这是我完成“路路鲜”农产品项目的总结,就写个博客记录一下,项目里面其它很多页面都如此。


1.activity

package com.co_insight.freshroad.business;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.co_insight.freshroad.R;
import com.co_insight.freshroad.business.adapter.CargoPriceItemAdapter;
import com.co_insight.freshroad.business.adapter.OrderVerticalAdapter;
import com.co_insight.freshroad.business.presenter.CargoPriceItemPresenter;
import com.co_insight.freshroad.business.view.CargoPriceItemView;
import com.co_insight.freshroad.utils.AppUtil;

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

import UXBL.DROID.MODEL.FR.PNameMobModel;
import UXBL.DROID.MODEL.FR.SSPriceItemMobModel;
import UXBL.DROID.MODEL.FR.SSPriceMobModel;
import UXBL.DROID.UTILS.AppConst;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ms.tool.DeviceUtil;

/**
 * 商品报价_货物
 * Created by Administrator on 2016/8/19.
 */
public class CargoPriceItemActivity extends HideInputActivity implements View.OnClickListener, CargoPriceItemView {
    @Bind(R.id.appTitle)
    TextView appTitle;
    @Bind(R.id.headRightTxt)
    TextView headRightTxt;
    @Bind(R.id.search_edit)
    EditText searchEdit;
    @Bind(R.id.purchase_type_delete_ll)
    RelativeLayout purchaseTypeDeleteLl;
    @Bind(R.id.shop_mission_item_add_bt)
    Button shopMissionItemAddBt;
    @Bind(R.id.shop_mission_item_place_bt)
    Button shopMissionItemPlaceBt;
    @Bind(R.id.shop_mission_item_lv)
    ListView listView;
    @Bind(R.id.order_vertical_lv)
    ListView verticalListView;
    @Bind(R.id.cargo_price_item_start_date)
    TextView cargoPriceItemStartDate;
    @Bind(R.id.cargo_price_item_end_date)
    TextView cargoPriceItemEndDate;

    private SSPriceMobModel bean;
    private ArrayList<SSPriceItemMobModel> list = new ArrayList<>();
    private CargoPriceItemAdapter adapter;

    private ArrayList<PNameMobModel> list_vertical = new ArrayList<>();
    private OrderVerticalAdapter adapter_vertical;

    private boolean isFilter = false;// 当前列表是否是过滤列表,true-->是
    private ArrayList<SSPriceItemMobModel> list_filter = new ArrayList<>();// 用于作为搜索输入框过滤列表的数据
    private ArrayList<SSPriceItemMobModel> list_select = new ArrayList<>();// 用于记录当前是“已选”的列表,“全部”的列表是list

    private CargoPriceItemPresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            setContentView(R.layout.activity_cargo_price_item);
            ButterKnife.bind(this);
            init();// 初始化
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 初始化
     */
    private void init() {
        bean = JSON.parseObject(getIntent().getStringExtra("bean"), SSPriceMobModel.class);
        presenter = new CargoPriceItemPresenter(this);

        appTitle.setText(bean.getPriceTypeDesc());
        headRightTxt.setText("已选");
        cargoPriceItemStartDate.setText(presenter.getDateStr(bean.getStartDate()));
        cargoPriceItemEndDate.setText(presenter.getDateStr(bean.getEndDate()));

        initEditText();

        setButtonColor();// 设置按钮背景颜色和是否可以点击

        list_vertical.addAll(presenter.getPNameFromDB(list));// 通过本页面的货物列表,从本地数据库中获取所有品名
        adapter_vertical = new OrderVerticalAdapter(this, list_vertical);
        verticalListView.setAdapter(adapter_vertical);
        verticalListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                presenter.dealWithVerticalListClick(list_vertical, position, list);// 处理点中与未点中之前的切换
                adapter_vertical.notifyDataSetChanged();
            }
        });

        list.addAll(presenter.dealWhitList(presenter.loadDataFromDbByScheme_id(bean.getSchema_id())));
        refreshVerticalLV(presenter.getPNameFromDB(list));// 刷新一下导航条
        presenter.setNumberText(list);// 设置选中的个数

        adapter = new CargoPriceItemAdapter(this, list, this, bean.getLocalStatus());
        listView.setAdapter(adapter);
    }

    private void initEditText() {
        purchaseTypeDeleteLl.setVisibility(View.GONE);
        searchEdit.setHint("请输入产品名称\\代码");
        searchEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean flag) {
                if (flag) {
                    if (list.size() == 0) {// 说明本地货物列表为空,直接跳转进入货物搜索页面
                        startSearchActivity(null);

                        searchEdit.clearFocus();// 清除EditText的焦点
                        searchEdit.setSelected(false);
                    }
                }
            }
        });
        searchEdit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                list_filter.clear();
                String str = searchEdit.getText().toString();

                if (TextUtils.isEmpty(str)) {
                    purchaseTypeDeleteLl.setVisibility(View.GONE);

                    adapter.changeList(list);// 清空输入框文本,复原列表数据
                    isFilter = false;
                    verticalListView.setVisibility(View.VISIBLE);// 显示导航带
                    headRightTxt.setVisibility(View.VISIBLE);// 显示“已选”“全部”
                } else {
                    purchaseTypeDeleteLl.setVisibility(View.VISIBLE);

                    // 输入框有文本,过滤列表数据
                    for (SSPriceItemMobModel bean : list) {
                        if (bean.getCargoName().contains(str)) {
                            list_filter.add(bean);
                        }
                    }

                    adapter.changeList(list_filter);// 切换数据源到搜索列表
                    isFilter = true;
                    verticalListView.setVisibility(View.INVISIBLE);// 隐藏导航带
                    headRightTxt.setVisibility(View.INVISIBLE);// 隐藏“已选”“全部”

                    if (list_filter.size() == 0) {// 说明搜索不出货物来,带上本页货物跳转进入货物搜索页面
                        if (presenter.checkIsHaveCargo(list, str))// 判断本地数据库中是否有相应字段的货物名称
                            startSearchActivity(str);
                    }
                }
            }
        });
    }

    public void dealWithNum(double num, int position) {
        if (headRightTxt.getText().toString().equals("已选")) {
            if (isFilter) {
                list_filter.get(position).setPrice(num);

                for (SSPriceItemMobModel cargo : list) {// 同步一下输入框输入的数量
                    if (cargo.getCargoID() == list_filter.get(position).getCargoID()) {
                        cargo.setPrice(num);
                    }
                }
            } else {
                list.get(position).setPrice(num);
            }
        } else {
            list_select.get(position).setPrice(num);

            for (SSPriceItemMobModel cargo : list) {// 同步一下输入框输入的数量
                if (cargo.getCargoID() == list_select.get(position).getCargoID()) {
                    cargo.setPrice(num);
                }
            }
        }

        presenter.updateFromSSPriceMobModel(bean, list);// 更新数量
        dealWithNumAndPrice();
    }

    private void dealWithNumAndPrice() {
        bean.setLocalStatus(3);// 0:未下单 1:已下单 2:已发货 3:修改中
        setButtonColor();// 设置按钮背景颜色和是否可以点击
        presenter.updateFromSSPriceMobModel(bean, list);// 更新数量

        presenter.setNumberText(list);// 设置选中的个数
    }

    @OnClick({R.id.backRLot, R.id.appTitle, R.id.headRightTxt, R.id.shop_mission_item_add_bt, R.id.shop_mission_item_place_bt,
            R.id.purchase_type_delete_ll, R.id.activity_cargo_price_item_start_ll, R.id.activity_cargo_price_item_end_ll})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.backRLot:
                finish();
                break;
            case R.id.appTitle:// 切换“正常价”和“促销价”,把修改后的类别保存到数据中去,并且修改本地状态值为“3.修改中”
                presenter.showDialog_changeTitle(this, bean);
                break;
            case R.id.purchase_type_delete_ll:// 清空输入框文本
                searchEdit.setText("");
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchEdit.getWindowToken(), 0);
                break;
            case R.id.activity_cargo_price_item_start_ll:// 开始日期,把修改后的日期保存到数据中去,并且修改本地状态值为“3.修改中”
                presenter.onDateConfigSet_start(this, bean);
                break;
            case R.id.activity_cargo_price_item_end_ll:// 截止日期,把修改后的日期保存到数据中去,并且修改本地状态值为“3.修改中”
                presenter.onDateConfigSet_end(this, bean);
                break;
            case R.id.headRightTxt:
                searchEdit.setText("");
                String str = headRightTxt.getText().toString();
                if (str.equals("已选")) {
                    headRightTxt.setText("全部");
                    list_select.clear();
                    list_select.addAll(presenter.getCargoMobModelListHaveQuantity(list));
                    adapter.changeList(list_select);
                    verticalListView.setVisibility(View.INVISIBLE);// 隐藏导航带
                } else {
                    headRightTxt.setText("已选");
                    adapter.changeList(list);
                    verticalListView.setVisibility(View.VISIBLE);// 显示导航带
                }
                break;
            case R.id.shop_mission_item_add_bt:
                startSearchActivity(null);
                break;
            case R.id.shop_mission_item_place_bt:
                if (!DeviceUtil.isOnLine(this)) {// 无网络不请求
                    AppUtil.showTostMsg(this, AppConst.NO_NETWORK_CONNECTION);
                    return;
                }

                bean.setItems(list);// 同步一下数据,选取输入框有数值的货物进行提交
                presenter.save(this, bean);// 提交下单任务
                break;
        }
    }

    /**
     * 进入货物搜索页面
     */
    private void startSearchActivity(String searchStr) {
        if (bean.getLocalStatus() == 2) {// 0:未下单 1:已下单 2:已结单 3:修改中 4.上传失败
            return;
        }

        Intent intent = new Intent(this, CargoPriceAddActivity.class);
        intent.putExtra("oldCargoList", JSON.toJSONString(presenter.ChangeToCargoMobModel(list)));
        intent.putExtra("ClassID", bean.getClassID());// 品类ID
        intent.putExtra("Type", 6);// 功能模块,6.商品报价_货物
        if (!TextUtils.isEmpty(searchStr)) {
            intent.putExtra("searchStr", searchStr);
            searchEdit.setText("");// 清空搜索框的内容
        }
        startActivityForResult(intent, 0);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (resultCode) {
            case RESULT_OK:
                try {
                    if (requestCode == 0) {// 添加货物
                        headRightTxt.setText("已选");// 回归最原始的状态
                        verticalListView.setVisibility(View.VISIBLE);// 显示导航带

                        String newCargoListStr = data.getStringExtra("newCargoList");
                        if (!TextUtils.isEmpty(newCargoListStr))
                            presenter.addCargoToList(bean, newCargoListStr, list);// 把货物搜索页面的货物加到本页面的列表中去,并且保存到本地数据库
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }

    @Override
    public void refreshLV(List<SSPriceItemMobModel> newList) {
        list.clear();
        list.addAll(presenter.dealWhitList(newList));// 对列表进行分组排序
        adapter.changeList_2(list, bean.getLocalStatus());

        refreshVerticalLV(presenter.getPNameFromDB(list));// 刷新一下导航条
        presenter.setNumberText(list);// 设置选中的个数
    }

    @Override
    public void refreshVerticalLV(List<PNameMobModel> newVerticalList) {
        list_vertical.clear();
        list_vertical.addAll(newVerticalList);
        adapter_vertical.notifyDataSetChanged();
    }

    @Override
    public void setNumberText(int number) {
    }

    @Override
    public void setButtonColor() {
        // 0:未确认 1:已确认 2:已冻结 3:修改中 4.上传失败
        switch (bean.getLocalStatus()) {
            case 0:
            case 1:
                shopMissionItemAddBt.setEnabled(true);
                shopMissionItemAddBt.setBackgroundColor(getResources().getColor(R.color.fresh_road_pink_text_color));
                shopMissionItemPlaceBt.setEnabled(false);
                shopMissionItemPlaceBt.setBackgroundColor(getResources().getColor(R.color.fresh_road_shallow_grey_text_color));
                break;
            case 3:
                shopMissionItemAddBt.setEnabled(true);
                shopMissionItemAddBt.setBackgroundColor(getResources().getColor(R.color.fresh_road_pink_text_color));
                shopMissionItemPlaceBt.setEnabled(true);
                shopMissionItemPlaceBt.setBackgroundColor(getResources().getColor(R.color.fresh_road_base_color));
                break;
            case 2:
                shopMissionItemAddBt.setEnabled(false);
                shopMissionItemAddBt.setBackgroundColor(getResources().getColor(R.color.fresh_road_shallow_grey_text_color));
                shopMissionItemPlaceBt.setEnabled(false);
                shopMissionItemPlaceBt.setBackgroundColor(getResources().getColor(R.color.fresh_road_shallow_grey_text_color));
                break;
        }
    }

    @Override
    public void setSelection(int position) {
        listView.setSelection(position);// listView 滑动到指定位置
    }

    @Override
    public void finishActivity() {
        finish();// 关闭本页面
    }

    @Override
    public void setStartDateText(String str) {
        cargoPriceItemStartDate.setText(str);
    }

    @Override
    public void setEndDateText(String str) {
        cargoPriceItemEndDate.setText(str);
    }

    @Override
    public void setTitleText(String str) {
        appTitle.setText(str);
    }
}

2.presenter

package com.co_insight.freshroad.business.presenter;

import android.app.DatePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.Log;
import android.widget.DatePicker;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.co_insight.freshroad.business.model.CargoPriceModel;
import com.co_insight.freshroad.business.model.modelImpl.CargoPriceModelImpl;
import com.co_insight.freshroad.business.utils.FreshRoadUtil;
import com.co_insight.freshroad.business.utils.InterfaceNameUtil;
import com.co_insight.freshroad.business.view.CargoPriceItemView;
import com.co_insight.freshroad.business.widget.CustomDialog;
import com.co_insight.freshroad.business.widget.NewDatePickerDialog;
import com.co_insight.freshroad.managers.DBManager;
import com.co_insight.freshroad.network.APITRequest;
import com.co_insight.freshroad.network.VolleyUtil;
import com.co_insight.freshroad.utils.AppUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import UXBL.DROID.DAO.CargoMobModelDao;
import UXBL.DROID.DAO.PNameMobModelDao;
import UXBL.DROID.MODEL.FR.CargoMobModel;
import UXBL.DROID.MODEL.FR.PNameMobModel;
import UXBL.DROID.MODEL.FR.SSPriceItemMobModel;
import UXBL.DROID.MODEL.FR.SSPriceMobModel;
import self.lucio.component.sweetdialog.SweetAlertDialog;

/**
 * 商品报价_货物
 * Created by Administrator on 2016/8/17.
 */
public class CargoPriceItemPresenter {

    private CargoPriceItemView view;
    private CargoPriceModel model;

    public CargoPriceItemPresenter(CargoPriceItemView view) {
        this.view = view;
        model = new CargoPriceModelImpl();
    }

    public void save(final Context context, final SSPriceMobModel mm) {
        if (mm.getItems().size() == 0) {
            Toast.makeText(context, "货物不能为空", Toast.LENGTH_LONG).show();
        }
        if (mm.getPriceType() == 2) {// 定价类型 1.正常价 2.促销价
            // 业务需要,促销价必须填截止日期,截止日期必须小于等于开始日期
            if (TextUtils.isEmpty(mm.getEndDate()) || mm.getEndDate().equals("0001-01-01 00:00:00")) {
                Toast.makeText(context, "促销价必须填截止日期", Toast.LENGTH_LONG).show();

                onDateConfigSet_end(context, mm);// 弹出选择截止日期的弹出框
                return;
            }

            if (mm.getStartDate().compareTo(mm.getEndDate()) > 0) {
                Toast.makeText(context, "截止日期必须大于等于开始日期", Toast.LENGTH_LONG).show();
                return;
            }
        }

        String jsonStr = JSON.toJSONString(mm);
        String url = InterfaceNameUtil.SSPriceSave();
        Log.e("url", url);
        Log.e("jsonStr", jsonStr);
        final SweetAlertDialog dialog = AppUtil.showLoading(context, "正在发送请求,请稍后...");

        APITRequest<SSPriceMobModel> request = new APITRequest<>(
                url, jsonStr, SSPriceMobModel.class, new Response.Listener<SSPriceMobModel>() {
            @Override
            public void onResponse(SSPriceMobModel response) {
                if (response == null)
                    return;

                try {
                    Toast.makeText(context, "保存成功", Toast.LENGTH_SHORT).show();

                    // 先删除后插入
                    model.deleteFromSSPriceMobModelBySchema_id(mm.getSchema_id());

                    response.setLocalStatus(response.getStatus());// 同步状态值
                    response.setLocalItems(JSON.toJSONString(response.getItems()));// 同步货物列表
                    response.setLocalPriceObjs(JSON.toJSONString(response.getPriceObjs()));// 同步报价对象
                    response.setLocalDate(FreshRoadUtil.getTodayDate_normal());// 同步拉取服务器的时间
                    model.insertFromSSPriceMobModel(response);

                    // 保存成功,关闭本页面
                    view.finishActivity();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                AppUtil.toError(dialog, error);
            }
        });
        request.setAddTokenToHeader(false);
        VolleyUtil.start(context, request);
    }

    /**
     * 通过货物列表,对pNameID进行去重和排序后
     *
     * @return 品名列表
     */
    public List<PNameMobModel> getPNameFromDB(List<SSPriceItemMobModel> old_list) {
        PNameMobModelDao dao = DBManager.instance().getDaoSession().getPNameMobModelDao();// 货物的小类

        List<PNameMobModel> list = new ArrayList<>();// 正常的“货物小类”的列表

        List<Long> newPNameIdList = new ArrayList<>();// 去重得到pNameID列表
        List<Long> oldPNameIdList = new ArrayList<>();
        for (SSPriceItemMobModel st : old_list) {
            oldPNameIdList.add(st.getPNameID());
        }
        Set<Long> sets = new HashSet<>();
        for (Long pNameID : oldPNameIdList) {
            if (sets.add(pNameID))
                newPNameIdList.add(pNameID);
        }

        for (int i = 0; i < newPNameIdList.size(); i++) {// 生成正常的“货物小类”的列表
            List<PNameMobModel> dbList = dao.queryBuilder().where(PNameMobModelDao.Properties.ID.eq(newPNameIdList.get(i))).list();
            if (dbList.size() > 0) {
                PNameMobModel pNameMobModel = dbList.get(0);
                if (i == 0)
                    pNameMobModel.setSelect_flag(true);// 默认选中第一项

                list.add(pNameMobModel);
            }
        }

        // 按照Seq进行排序
        Collections.sort(list, new Comparator<PNameMobModel>() {
            @Override
            public int compare(PNameMobModel lhs, PNameMobModel rhs) {
                return (lhs.getSeq()).compareTo(rhs.getSeq());
            }
        });

        return list;
    }

    /**
     * 处理点中与未点中之前的切换
     *
     * @param list_vertical list_vertical
     * @param position      position
     */
    public void dealWithVerticalListClick(ArrayList<PNameMobModel> list_vertical, int position, ArrayList<SSPriceItemMobModel> list) {
        for (PNameMobModel pNameMobModel : list_vertical) {
            if (pNameMobModel.getID() == list_vertical.get(position).getID()) {
                pNameMobModel.setSelect_flag(true);

                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getPNameID() == list_vertical.get(position).getID()) {
                        view.setSelection(i);// 列表滑动到相应位置,并且跳出循环
                        break;
                    }
                }
            } else {
                pNameMobModel.setSelect_flag(false);
            }
        }
    }

    /**
     * 设置选中的个数
     *
     * @param list list
     */

    public void setNumberText(ArrayList<SSPriceItemMobModel> list) {
        int number = 0;
        for (SSPriceItemMobModel st : list) {
            if (st.getPrice() != 0) {// 输入数量就当做是完成了多少项
                number++;
            }
        }

        view.setNumberText(number);
    }

    /**
     * 判断本地数据库中是否有相应字段的货物名称
     *
     * @param oldList   oldList
     * @param searchStr 搜索字段
     * @return boolean
     */
    public boolean checkIsHaveCargo(ArrayList<SSPriceItemMobModel> oldList, String searchStr) {
        List<CargoMobModel> allList = new ArrayList<>();

        CargoMobModelDao dao = DBManager.instance().getDaoSession().getCargoMobModelDao();
        for (SSPriceItemMobModel mm : oldList) {
            List<CargoMobModel> list = dao.queryBuilder()
                    .where(CargoMobModelDao.Properties.ClassID.eq(mm.getClassID()), CargoMobModelDao.Properties.Name.like("%" + searchStr + "%"))
                    .list();
            allList.addAll(list);
        }

        return allList.size() > 0;
    }

    /**
     * 更新数量
     *
     * @param entity entity
     */
    public void updateFromSSPriceMobModel(SSPriceMobModel entity, ArrayList<SSPriceItemMobModel> list) {
        entity.setLocalStatus(3);// 0:未确认 1:已确认 2:已冻结 3:修改中 4.上传失败
        entity.setLocalItems(JSON.toJSONString(list));
        model.updateFromSSPriceMobModel(entity);
    }

    /**
     * 更新其它
     *
     * @param entity entity
     */
    public void updateFromSSPriceMobModel(SSPriceMobModel entity) {
        model.updateFromSSPriceMobModel(entity);
    }

    /**
     * 获取货物列表中有数量的货物
     *
     * @param list list
     * @return list
     */
    public ArrayList<SSPriceItemMobModel> getCargoMobModelListHaveQuantity(ArrayList<SSPriceItemMobModel> list) {
        ArrayList<SSPriceItemMobModel> newList = new ArrayList<>();
        for (SSPriceItemMobModel st : list) {
            if (st.getPrice() != 0) {// 数量不为0
                newList.add(st);
            }
        }

        return newList;
    }

    /**
     * 转成货物列表
     *
     * @param list list
     * @return list
     */
    public ArrayList<CargoMobModel> ChangeToCargoMobModel(ArrayList<SSPriceItemMobModel> list) {
        ArrayList<CargoMobModel> cargoList = new ArrayList<>();
        for (SSPriceItemMobModel st : list) {
            if (st.getPrice() != 0) {// 数量或者价格不为0
                CargoMobModel cargo = new CargoMobModel();
                cargo.setID(st.getCargoID());
                cargo.setPrice(st.getPrice());

                cargoList.add(cargo);
            }
        }

        return cargoList;
    }

    /**
     * 把货物搜索页面的货物加到本页面的列表中去,并且保存到本地数据库,修改状态值:3
     *
     * @param newCargoListStr 货物搜索页面的货物列表
     * @param list            本页面的货物列表
     */
    public void addCargoToList(SSPriceMobModel bean, String newCargoListStr, ArrayList<SSPriceItemMobModel> list) {
        bean.setLocalStatus(3);// 0:未下单 1:已下单 2:已发货 3:修改中
        view.setButtonColor();// 设置按钮背景颜色和是否可以点击

        List<CargoMobModel> newCargoList = JSON.parseArray(newCargoListStr, CargoMobModel.class);

        // 更新数量和价格
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < newCargoList.size(); j++) {
                if (list.get(i).getCargoID() == newCargoList.get(j).getID()) {
                    list.get(i).setPrice(newCargoList.get(j).getPrice());
                    list.get(i).setUnitID(newCargoList.get(j).getSaleUnitID());// 新增销售单位
                    list.get(i).setUnitName(newCargoList.get(j).getSaleUnitName());
                    break;
                }
            }
        }

        // 去掉重复的,剩下就是新增的
        for (int i = 0; i < list.size(); i++) {
            for (int j = newCargoList.size() - 1; j > -1; j--) {
                if (list.get(i).getCargoID() == newCargoList.get(j).getID()) {
                    newCargoList.remove(j);
                }
            }
        }

        // 新增货物
        for (int j = 0; j < newCargoList.size(); j++) {
            SSPriceItemMobModel st = new SSPriceItemMobModel();
            st.setSSPriceID(bean.getID());
            st.setCargoID(newCargoList.get(j).getID());
            st.setCargoName(newCargoList.get(j).getName());
            st.setClassID(newCargoList.get(j).getClassID());
            st.setPNameID(newCargoList.get(j).getPNameID());
            st.setPrice(newCargoList.get(j).getPrice());
            st.setUnitID(newCargoList.get(j).getSaleUnitID());// 新增销售单位
            st.setUnitName(newCargoList.get(j).getSaleUnitName());

            list.add(st);
        }

        updateFromSSPriceMobModel(bean, list);

        // 刷新列表
        view.refreshLV((model.loadAllFromSSPriceMobModelBySchema_id(bean.getSchema_id())).getItems());
    }

    /**
     * 通过Scheme_id获取库存下的所有货物
     *
     * @param schema_id schema_id
     * @return 货物列表
     */
    public List<SSPriceItemMobModel> loadDataFromDbByScheme_id(long schema_id) {
        return model.loadAllFromSSPriceMobModelBySchema_id(schema_id).getItems();
    }

    /**
     * 对列表进行分组排序
     *
     * @param oldList 列表
     * @return 列表
     */
    public ArrayList<SSPriceItemMobModel> dealWhitList(List<SSPriceItemMobModel> oldList) {
        ArrayList<SSPriceItemMobModel> newList = new ArrayList<>();

        List<PNameMobModel> pNameList = getPNameFromDB(oldList);// 对pNameID进行去重和排序后的列表

        for (PNameMobModel pNameMobModel : pNameList)
            for (SSPriceItemMobModel stOrderItemMobModel : oldList)
                if (pNameMobModel.getID() == stOrderItemMobModel.getPNameID()) {
                    stOrderItemMobModel.setGroupName(pNameMobModel.getPName());
                    newList.add(stOrderItemMobModel);// 通过pNameID生成排序好的新列表
                }

        // 通过组ID判断是否需要显示标题
        for (int i = 0; i < newList.size(); i++) {
            if (i == 0) {
                newList.get(i).setIsShowGroupName(true);
            } else {
                if (newList.get(i).getPNameID() == newList.get(i - 1).getPNameID()) {
                    newList.get(i).setIsShowGroupName(false);
                } else {
                    newList.get(i).setIsShowGroupName(true);
                }
            }
        }

        return newList;
    }

    /**
     * 处理时间的显示
     *
     * @param billDate 旧的时间
     * @return 新的时间
     */
    public String getDateStr(String billDate) {
        if (TextUtils.isEmpty(billDate) || billDate.equals("0001-01-01 00:00:00")) {
            return "";
        } else {
            if (billDate.length() > 10)
                billDate = billDate.substring(5, 10);
            return billDate;
        }
    }

    /**
     * 选择日期
     */
    public void onDateConfigSet_start(final Context context, final SSPriceMobModel bean) {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int monthOfYear = calendar.get(Calendar.MONTH);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        if (!TextUtils.isEmpty(bean.getStartDate()) && !bean.getStartDate().equals("0001-01-01 00:00:00"))// 回单确认日期
            try {
                calendar.setTime((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(bean.getStartDate()));
                year = calendar.get(Calendar.YEAR);//获取年份
                monthOfYear = calendar.get(Calendar.MONTH);//获取月份
                dayOfMonth = calendar.get(Calendar.DATE);//获取日
            } catch (ParseException e) {
                e.printStackTrace();
            }

        NewDatePickerDialog dialog = new NewDatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                String dateStr = String.format("%02d-%02d-%02d", year, monthOfYear + 1, dayOfMonth);
                String startDate = dateStr + " 00:00:00";

                if (TextUtils.isEmpty(bean.getEndDate()) || bean.getEndDate().equals("0001-01-01 00:00:00")) {
                    // do nothing
                } else if (startDate.compareTo(FreshRoadUtil.getTodayDate_normal()) < 0) {
                    Toast.makeText(context, "开始日期必须大于等于今天", Toast.LENGTH_LONG).show();
                    return;
                } else if (startDate.compareTo(bean.getEndDate()) > 0) {
                    Toast.makeText(context, "开始日期必须小于等于截止日期", Toast.LENGTH_LONG).show();
                    return;
                }

                bean.setStartDate(startDate);// 设置“回单确认日期”并且补全时间

                // 把修改后的日期保存到数据中去,并且修改本地状态值为“3.修改中”
                bean.setLocalStatus(3);
                updateFromSSPriceMobModel(bean);

                view.setStartDateText(getDateStr(bean.getStartDate()));
                view.setButtonColor();
            }
        }, year, monthOfYear, dayOfMonth);
        dialog.setTitle("选择开始日期");
        dialog.show();
    }

    /**
     * 选择日期
     */
    public void onDateConfigSet_end(final Context context, final SSPriceMobModel bean) {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int monthOfYear = calendar.get(Calendar.MONTH);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        if (!TextUtils.isEmpty(bean.getEndDate()) && !bean.getEndDate().equals("0001-01-01 00:00:00"))// 回单确认日期
            try {
                calendar.setTime((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(bean.getEndDate()));
                year = calendar.get(Calendar.YEAR);//获取年份
                monthOfYear = calendar.get(Calendar.MONTH);//获取月份
                dayOfMonth = calendar.get(Calendar.DATE);//获取日
            } catch (ParseException e) {
                e.printStackTrace();
            }

        NewDatePickerDialog dialog = new NewDatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                String dateStr = String.format("%02d-%02d-%02d", year, monthOfYear + 1, dayOfMonth);

                String endDate = dateStr + " 00:00:00";
                if (endDate.compareTo(bean.getStartDate()) > 0 || endDate.compareTo(bean.getStartDate()) == 0) {
                    bean.setEndDate(endDate);// 设置“回单确认日期”并且补全时间

                    // 把修改后的日期保存到数据中去,并且修改本地状态值为“3.修改中”
                    bean.setLocalStatus(3);
                    updateFromSSPriceMobModel(bean);

                    view.setEndDateText(getDateStr(bean.getEndDate()));
                    view.setButtonColor();
                } else {
                    Toast.makeText(context, "截止日期必须大于等于开始日期", Toast.LENGTH_LONG).show();
                }
            }
        }, year, monthOfYear, dayOfMonth);
        dialog.setTitle("选择截止日期");
        dialog.show();
    }

    /**
     * 显示弹出框
     */
    public void showDialog_changeTitle(final Context context, final SSPriceMobModel bean) {
        CustomDialog.Builder builder = new CustomDialog.Builder(context);
        builder.setTitle("请选择价格类型");
        builder.setPositiveButton("正常价", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                bean.setPriceType(1);
                bean.setPriceTypeDesc("正常价");

                // 把修改后的日期保存到数据中去,并且修改本地状态值为“3.修改中”
                bean.setLocalStatus(3);
                updateFromSSPriceMobModel(bean);

                view.setTitleText("正常价");
                view.setButtonColor();
            }
        });
        builder.setNegativeButton("促销价", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                bean.setPriceType(2);
                bean.setPriceTypeDesc("促销价");

                // 把修改后的日期保存到数据中去,并且修改本地状态值为“3.修改中”
                bean.setLocalStatus(3);
                updateFromSSPriceMobModel(bean);

                view.setTitleText("促销价");
                view.setButtonColor();
            }
        });
        builder.create().show();
    }
}

3.view

package com.co_insight.freshroad.business.view;

import java.util.List;

import UXBL.DROID.MODEL.FR.PNameMobModel;
import UXBL.DROID.MODEL.FR.SSPriceItemMobModel;

/**
 * 商品报价_货物
 * Created by Administrator on 2016/8/19.
 */
public interface CargoPriceItemView {
    void refreshLV(List<SSPriceItemMobModel> newList);

    void refreshVerticalLV(List<PNameMobModel> newVerticalList);

    void setNumberText(int number);

    void setButtonColor();

    void setSelection(int position);

    void finishActivity();

    void setStartDateText(String str);

    void setEndDateText(String str);

    void setTitleText(String str);
}

4.1.model

package com.co_insight.freshroad.business.model;

import java.util.List;

import UXBL.DROID.MODEL.FR.SSPriceMobModel;

/**
 * 商品报价
 * Created by Administrator on 2016/8/18.
 */
public interface CargoPriceModel {
    List<SSPriceMobModel> loadAllFromSSPriceMobModel_simple();

    List<SSPriceMobModel> loadAllFromSSPriceMobModel();

    SSPriceMobModel loadAllFromSSPriceMobModelBySchema_id(long schema_id);

    SSPriceMobModel loadAllFromSSPriceMobModelByID(long ID);

    void deleteAllFromSSPriceMobModel();

    void deleteFromSSPriceMobModelBySchema_id(long schema_id);

    long insertFromSSPriceMobModel(SSPriceMobModel entity);

    void updateFromSSPriceMobModel(SSPriceMobModel entity);

    boolean checkIsChange();

    boolean checkIsToday();
}

4.2.ModelImpl

package com.co_insight.freshroad.business.model.modelImpl;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.co_insight.freshroad.business.model.CargoPriceModel;
import com.co_insight.freshroad.managers.DBManager;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import UXBL.DROID.DAO.SSPriceMobModelDao;
import UXBL.DROID.MODEL.FR.SSPriceItemMobModel;
import UXBL.DROID.MODEL.FR.SSPriceMobModel;
import UXBL.DROID.MODEL.FR.SSPriceObjMobModel;

/**
 * 商品报价
 * Created by Administrator on 2016/8/18.
 */
public class CargoPriceModelImpl implements CargoPriceModel {
    private SSPriceMobModelDao dao = DBManager.instance().getDaoSession().getSSPriceMobModelDao();

    @Override
    public List<SSPriceMobModel> loadAllFromSSPriceMobModel_simple() {
        return dao.loadAll();
    }

    @Override
    public List<SSPriceMobModel> loadAllFromSSPriceMobModel() {
        List<SSPriceMobModel> list = dao.loadAll();
        for (SSPriceMobModel ss : list) {
            if (!TextUtils.isEmpty(ss.getLocalItems()))
                ss.getItems().addAll(JSON.parseArray(ss.getLocalItems(), SSPriceItemMobModel.class));
            if (!TextUtils.isEmpty(ss.getLocalPriceObjs()))
                ss.getPriceObjs().addAll(JSON.parseArray(ss.getLocalPriceObjs(), SSPriceObjMobModel.class));
        }

        return list;
    }

    @Override
    public SSPriceMobModel loadAllFromSSPriceMobModelBySchema_id(long schema_id) {
        List<SSPriceMobModel> list = dao.queryBuilder().where(SSPriceMobModelDao.Properties.Schema_id.eq(schema_id)).list();
        if (list.size() > 0) {
            if (!TextUtils.isEmpty(list.get(0).getLocalItems()))
                list.get(0).getItems().addAll(JSON.parseArray(list.get(0).getLocalItems(), SSPriceItemMobModel.class));
            return list.get(0);
        }
        return null;
    }

    @Override
    public SSPriceMobModel loadAllFromSSPriceMobModelByID(long ID) {
        List<SSPriceMobModel> list = dao.queryBuilder().where(SSPriceMobModelDao.Properties.ID.eq(ID)).list();
        if (list.size() > 0)
            return list.get(0);
        return null;
    }

    @Override
    public void deleteAllFromSSPriceMobModel() {
        dao.deleteAll();
    }

    @Override
    public void deleteFromSSPriceMobModelBySchema_id(long schema_id) {
        dao.queryBuilder().where(SSPriceMobModelDao.Properties.Schema_id.eq(schema_id)).buildDelete().executeDeleteWithoutDetachingEntities();
    }

    @Override
    public long insertFromSSPriceMobModel(SSPriceMobModel entity) {
        return dao.insert(entity);
    }

    @Override
    public void updateFromSSPriceMobModel(SSPriceMobModel entity) {
        dao.update(entity);
    }

    @Override
    public boolean checkIsChange() {
        long count = dao.queryBuilder().where(SSPriceMobModelDao.Properties.LocalStatus.eq("3")).count();
        return count > 0;
    }

    @Override
    public boolean checkIsToday() {
        String str = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
        long count_like = dao.queryBuilder().where(SSPriceMobModelDao.Properties.LocalDate.like("%" + str + "%")).count();
        long count_all = dao.queryBuilder().count();

        return count_all != 0 && count_like == count_all;
    }
}

5.1.adapter

package com.co_insight.freshroad.business.adapter;

import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.co_insight.freshroad.R;
import com.co_insight.freshroad.business.CargoPriceItemActivity;

import java.util.ArrayList;

import UXBL.DROID.MODEL.FR.SSPriceItemMobModel;

/**
 * 商品报价_货物
 * Created by Administrator on 2016/8/17.
 */
public class CargoPriceItemAdapter extends BaseAdapter {

    // 设置组视图的数据源
    private ArrayList<SSPriceItemMobModel> list = new ArrayList<>();

    // 加载布局
    private LayoutInflater mInflater;
    private View.OnClickListener listener;
    private Context context;
    private int LocalStatus;

    // 构造器:加载布局,设置数据源
    public CargoPriceItemAdapter(Context context, ArrayList<SSPriceItemMobModel> list, View.OnClickListener listener, int LocalStatus) {
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.listener = listener;
        this.context = context;
        this.list = list;
        this.LocalStatus = LocalStatus;
    }

    /**
     * google 2011年开发者大会上提出的方法——ListView单条更新
     *
     * @param listView
     * @param id
     */
    public void updateSingleRow(ListView listView, long id) {
        if (listView != null) {
            int start = listView.getFirstVisiblePosition();
            for (int i = start, j = listView.getLastVisiblePosition(); i <= j; i++)
                if (id == ((SSPriceItemMobModel) listView.getItemAtPosition(i)).getID()) {
                    View view = listView.getChildAt(i - start);
                    getView(i, view, listView);
                    break;
                }
        }
    }

    public void changeList(ArrayList<SSPriceItemMobModel> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public void changeList_2(ArrayList<SSPriceItemMobModel> list, int LocalStatus) {
        this.list = list;
        this.LocalStatus = LocalStatus;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertVie, ViewGroup parent) {
        TextView lv_shop_mission_group_name;
        TextView lv_shop_mission_item_name;
        EditText lv_shop_mission_item_number_et;

        View convertView = mInflater.inflate(R.layout.listview_cargo_price_item, null);
        lv_shop_mission_group_name = (TextView) convertView.findViewById(R.id.lv_shop_mission_group_name);
        lv_shop_mission_item_name = (TextView) convertView.findViewById(R.id.lv_shop_mission_item_name);
        lv_shop_mission_item_number_et = (EditText) convertView.findViewById(R.id.lv_shop_mission_item_number_et);

        if (list.get(position).isShowGroupName()) {
            lv_shop_mission_group_name.setVisibility(View.VISIBLE);
            lv_shop_mission_group_name.setText(list.get(position).getGroupName());
        } else {
            lv_shop_mission_group_name.setVisibility(View.GONE);
        }

        try {
            // 设置文本
            String newName = list.get(position).getCargoName();
            if (!TextUtils.isEmpty(list.get(position).getUnitName()))
                newName = newName + "(" + list.get(position).getUnitName() + ")";
            lv_shop_mission_item_name.setText(newName);

            if (list.get(position).getPrice() != 0)
                lv_shop_mission_item_number_et.setText(String.valueOf(list.get(position).getPrice()));

            if (LocalStatus == 2) {// 0:未下单 1:已下单 2:已结单 3:修改中 4.上传失败
                lv_shop_mission_item_number_et.setFocusable(false);
                lv_shop_mission_item_number_et.setFocusableInTouchMode(false);

                lv_shop_mission_item_name.setEnabled(false);
            } else {
                final EditText editText = lv_shop_mission_item_number_et;
                lv_shop_mission_item_number_et.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        try {
                            String str = editText.getText().toString().trim();
                            if (!TextUtils.isEmpty(str)) {
                                ((CargoPriceItemActivity) context).dealWithNum(Double.parseDouble(str), position);
                            } else {
                                ((CargoPriceItemActivity) context).dealWithNum(0, position);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

                lv_shop_mission_item_name.setTag(position);
                lv_shop_mission_item_name.setOnClickListener(listener);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }
}

5.2.

package com.co_insight.freshroad.business.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.co_insight.freshroad.R;

import java.util.ArrayList;

import UXBL.DROID.MODEL.FR.PNameMobModel;

/**
 * 商品搜索
 */
public class OrderVerticalAdapter extends BaseAdapter {

    // 设置组视图的数据源
    private ArrayList<PNameMobModel> list = new ArrayList<>();

    // 加载布局
    private LayoutInflater mInflater;

    // 构造器:加载布局,设置数据源
    public OrderVerticalAdapter(Context context, ArrayList<PNameMobModel> list) {
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.list = list;
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        GroupViewHolder holder;
        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.listview_purchase_search, null);
            holder = new GroupViewHolder();
            holder.lv_purchase_search_tv = (TextView) convertView.findViewById(R.id.lv_purchase_search_tv);
            holder.lv_purchase_search_iv = (ImageView) convertView.findViewById(R.id.lv_purchase_search_iv);

            convertView.setTag(holder);
        } else {
            holder = (GroupViewHolder) convertView.getTag();
        }

        // 设置文本
        if (!TextUtils.isEmpty(list.get(position).getPName())) {
            if (list.get(position).getPName().length() > 0) {
                holder.lv_purchase_search_tv.setText(list.get(position).getPName().substring(0, 1));// 只取第一个名称
            } else {
                holder.lv_purchase_search_tv.setText("");
            }
        } else {
            holder.lv_purchase_search_tv.setText("");
        }

        // 设置是否选中的状态
        if (list.get(position).isSelect_flag()) {
            holder.lv_purchase_search_iv.setVisibility(View.VISIBLE);
            holder.lv_purchase_search_tv.setTextColor(Color.parseColor("#FFFFFF"));
        } else {
            holder.lv_purchase_search_iv.setVisibility(View.INVISIBLE);
            holder.lv_purchase_search_tv.setTextColor(Color.parseColor("#5D5D5D"));
        }

        return convertView;
    }

    class GroupViewHolder {
        TextView lv_purchase_search_tv;
        ImageView lv_purchase_search_iv;
    }
}

6.bean

package UXBL.DROID.MODEL.FR;

import UXBL.DROID.DAO.DaoSession;
import de.greenrobot.dao.DaoException;

import UXBL.DROID.DAO.SSPriceMobModelDao;

// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS

// KEEP INCLUDES - put your custom includes here
import java.util.ArrayList;
// KEEP INCLUDES END
/**
 * Entity mapped to table SSPRICE_MOB_MODEL.
 */
public class SSPriceMobModel {

    private Long schema_id;
    private long ID;
    private String Guid;
    private int Status;
    private int LocalStatus;
    private String StatusDesc;
    private long CustomerID;
    private String CustomerName;
    private int NatureType;
    private String NatureTypeDesc;
    private long ClassID;
    private String ClassName;
    private String StartDate;
    private String EndDate;
    private int PriceType;
    private String PriceTypeDesc;
    private String LocalItems;
    private String LocalPriceObjs;
    private String CreateDate;
    private String UpdateDate;
    private String LocalDate;

    /** Used to resolve relations */
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    private transient SSPriceMobModelDao myDao;


    // KEEP FIELDS - put your custom fields here
//    model.addLongProperty("schema_id").primaryKey().autoincrement();// 自增主键
//    model.addLongProperty("ID").notNull();// ID
//    model.addStringProperty("Guid");// Guid
//    model.addIntProperty("Status").notNull();// 状态值【0:未确认 1:已确认 2:已冻结】
//    model.addIntProperty("LocalStatus").notNull();// 0:未确认 1:已确认 2:已冻结 3:修改中 4.上传失败
//    model.addStringProperty("StatusDesc");// 状态显示
//    model.addLongProperty("CustomerID").notNull();// 门店ID
//    model.addStringProperty("CustomerName");// 门店名称
//    model.addIntProperty("NatureType").notNull();// 业务类型 1.买断2.专柜
//    model.addStringProperty("NatureTypeDesc");// 业务类型
//    model.addLongProperty("ClassID").notNull();// 品类
//    model.addStringProperty("ClassName");// 品类
//    model.addStringProperty("StartDate");// 生效日期
//    model.addStringProperty("EndDate");// 结束日期(促销价时,必填)
//    model.addIntProperty("PriceType").notNull();// 定价类型 1.正常价 2.促销价
//    model.addStringProperty("PriceTypeDesc");// 定价类型
//    model.addStringProperty("LocalItems");// 本地新增一个字段用于存储“货物”表
//    model.addStringProperty("LocalPriceObjs");// 本地新增一个字段用于存储“报价对象”表
//    model.addStringProperty("CreateDate");// 创建时间
//    model.addStringProperty("UpdateDate");// 修改时间
//    model.addStringProperty("LocalDate");// 当前从服务器拉取数据时记录的时间

    private ArrayList<SSPriceItemMobModel> Items = new ArrayList<>();// 货物
    private ArrayList<SSPriceObjMobModel> PriceObjs = new ArrayList<>();// 报价对象
    // KEEP FIELDS END

    public SSPriceMobModel() {
    }

    public SSPriceMobModel(Long schema_id) {
        this.schema_id = schema_id;
    }

    public SSPriceMobModel(Long schema_id, long ID, String Guid, int Status, int LocalStatus, String StatusDesc, long CustomerID, String CustomerName, int NatureType, String NatureTypeDesc, long ClassID, String ClassName, String StartDate, String EndDate, int PriceType, String PriceTypeDesc, String LocalItems, String LocalPriceObjs, String CreateDate, String UpdateDate, String LocalDate) {
        this.schema_id = schema_id;
        this.ID = ID;
        this.Guid = Guid;
        this.Status = Status;
        this.LocalStatus = LocalStatus;
        this.StatusDesc = StatusDesc;
        this.CustomerID = CustomerID;
        this.CustomerName = CustomerName;
        this.NatureType = NatureType;
        this.NatureTypeDesc = NatureTypeDesc;
        this.ClassID = ClassID;
        this.ClassName = ClassName;
        this.StartDate = StartDate;
        this.EndDate = EndDate;
        this.PriceType = PriceType;
        this.PriceTypeDesc = PriceTypeDesc;
        this.LocalItems = LocalItems;
        this.LocalPriceObjs = LocalPriceObjs;
        this.CreateDate = CreateDate;
        this.UpdateDate = UpdateDate;
        this.LocalDate = LocalDate;
    }

    /** called by internal mechanisms, do not call yourself. */
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getSSPriceMobModelDao() : null;
    }

    public Long getSchema_id() {
        return schema_id;
    }

    public void setSchema_id(Long schema_id) {
        this.schema_id = schema_id;
    }

    public long getID() {
        return ID;
    }

    public void setID(long ID) {
        this.ID = ID;
    }

    public String getGuid() {
        return Guid;
    }

    public void setGuid(String Guid) {
        this.Guid = Guid;
    }

    public int getStatus() {
        return Status;
    }

    public void setStatus(int Status) {
        this.Status = Status;
    }

    public int getLocalStatus() {
        return LocalStatus;
    }

    public void setLocalStatus(int LocalStatus) {
        this.LocalStatus = LocalStatus;
    }

    public String getStatusDesc() {
        return StatusDesc;
    }

    public void setStatusDesc(String StatusDesc) {
        this.StatusDesc = StatusDesc;
    }

    public long getCustomerID() {
        return CustomerID;
    }

    public void setCustomerID(long CustomerID) {
        this.CustomerID = CustomerID;
    }

    public String getCustomerName() {
        return CustomerName;
    }

    public void setCustomerName(String CustomerName) {
        this.CustomerName = CustomerName;
    }

    public int getNatureType() {
        return NatureType;
    }

    public void setNatureType(int NatureType) {
        this.NatureType = NatureType;
    }

    public String getNatureTypeDesc() {
        return NatureTypeDesc;
    }

    public void setNatureTypeDesc(String NatureTypeDesc) {
        this.NatureTypeDesc = NatureTypeDesc;
    }

    public long getClassID() {
        return ClassID;
    }

    public void setClassID(long ClassID) {
        this.ClassID = ClassID;
    }

    public String getClassName() {
        return ClassName;
    }

    public void setClassName(String ClassName) {
        this.ClassName = ClassName;
    }

    public String getStartDate() {
        return StartDate;
    }

    public void setStartDate(String StartDate) {
        this.StartDate = StartDate;
    }

    public String getEndDate() {
        return EndDate;
    }

    public void setEndDate(String EndDate) {
        this.EndDate = EndDate;
    }

    public int getPriceType() {
        return PriceType;
    }

    public void setPriceType(int PriceType) {
        this.PriceType = PriceType;
    }

    public String getPriceTypeDesc() {
        return PriceTypeDesc;
    }

    public void setPriceTypeDesc(String PriceTypeDesc) {
        this.PriceTypeDesc = PriceTypeDesc;
    }

    public String getLocalItems() {
        return LocalItems;
    }

    public void setLocalItems(String LocalItems) {
        this.LocalItems = LocalItems;
    }

    public String getLocalPriceObjs() {
        return LocalPriceObjs;
    }

    public void setLocalPriceObjs(String LocalPriceObjs) {
        this.LocalPriceObjs = LocalPriceObjs;
    }

    public String getCreateDate() {
        return CreateDate;
    }

    public void setCreateDate(String CreateDate) {
        this.CreateDate = CreateDate;
    }

    public String getUpdateDate() {
        return UpdateDate;
    }

    public void setUpdateDate(String UpdateDate) {
        this.UpdateDate = UpdateDate;
    }

    public String getLocalDate() {
        return LocalDate;
    }

    public void setLocalDate(String LocalDate) {
        this.LocalDate = LocalDate;
    }

    /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    // KEEP METHODS - put your custom methods here

    public ArrayList<SSPriceItemMobModel> getItems() {
        return Items;
    }

    public void setItems(ArrayList<SSPriceItemMobModel> items) {
        Items = items;
    }

    public ArrayList<SSPriceObjMobModel> getPriceObjs() {
        return PriceObjs;
    }

    public void setPriceObjs(ArrayList<SSPriceObjMobModel> priceObjs) {
        PriceObjs = priceObjs;
    }

    // KEEP METHODS END

}

package UXBL.DROID.MODEL.FR;

/**
 * 商品报价_货物
 * Created by Administrator on 2016/8/18.
 */
public class SSPriceItemMobModel {

    private long ID;
    private long SSPriceID;// 外键 APP:(获取)存储、上传
    private long CargoID;// 货物ID APP:存储、上传
    private String CargoName;// 货物名称 APP:存储
    private long ClassID;// 品类
    private long PNameID;// 小类 APP:存储
    private long UnitID;// 单位ID APP:存储、上传
    private String UnitName;// 单位 APP:存储
    private double Price;// 单价 APP:存储、上传
    private String CreateDate;// 创建时间
    private String UpdateDate;// 修改时间

    private String groupName;// 组名
    private boolean isShowGroupName;// 是否显示组名

    public SSPriceItemMobModel() {
    }

    public SSPriceItemMobModel(long ID, long SSPriceID, long cargoID, String cargoName, long classID, long PNameID, long unitID, String unitName, double price, String createDate, String updateDate) {
        this.ID = ID;
        this.SSPriceID = SSPriceID;
        CargoID = cargoID;
        CargoName = cargoName;
        ClassID = classID;
        this.PNameID = PNameID;
        UnitID = unitID;
        UnitName = unitName;
        Price = price;
        CreateDate = createDate;
        UpdateDate = updateDate;
    }

    public long getID() {
        return ID;
    }

    public void setID(long ID) {
        this.ID = ID;
    }

    public long getSSPriceID() {
        return SSPriceID;
    }

    public void setSSPriceID(long SSPriceID) {
        this.SSPriceID = SSPriceID;
    }

    public long getCargoID() {
        return CargoID;
    }

    public void setCargoID(long cargoID) {
        CargoID = cargoID;
    }

    public String getCargoName() {
        return CargoName;
    }

    public void setCargoName(String cargoName) {
        CargoName = cargoName;
    }

    public long getClassID() {
        return ClassID;
    }

    public void setClassID(long classID) {
        ClassID = classID;
    }

    public long getPNameID() {
        return PNameID;
    }

    public void setPNameID(long PNameID) {
        this.PNameID = PNameID;
    }

    public long getUnitID() {
        return UnitID;
    }

    public void setUnitID(long unitID) {
        UnitID = unitID;
    }

    public String getUnitName() {
        return UnitName;
    }

    public void setUnitName(String unitName) {
        UnitName = unitName;
    }

    public double getPrice() {
        return Price;
    }

    public void setPrice(double price) {
        Price = price;
    }

    public String getCreateDate() {
        return CreateDate;
    }

    public void setCreateDate(String createDate) {
        CreateDate = createDate;
    }

    public String getUpdateDate() {
        return UpdateDate;
    }

    public void setUpdateDate(String updateDate) {
        UpdateDate = updateDate;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public boolean isShowGroupName() {
        return isShowGroupName;
    }

    public void setIsShowGroupName(boolean isShowGroupName) {
        this.isShowGroupName = isShowGroupName;
    }
}

package UXBL.DROID.MODEL.FR;

import java.util.ArrayList;

import UXBL.DROID.DAO.DaoSession;
import de.greenrobot.dao.DaoException;

import UXBL.DROID.DAO.PNameMobModelDao;

// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS

// KEEP INCLUDES - put your custom includes here
// KEEP INCLUDES END
/**
 * Entity mapped to table PNAME_MOB_MODEL.
 */
public class PNameMobModel {

    private Long schema_id;
    private long ID;
    private String PName;
    private Long Seq;
    private String CreateDate;
    private String UpdateDate;

    /** Used to resolve relations */
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    private transient PNameMobModelDao myDao;


    // KEEP FIELDS - put your custom fields here
//    model.addLongProperty("schema_id").primaryKey().autoincrement();// 自增主键
//    model.addLongProperty("ID").notNull();// ID
//    model.addStringProperty("PName");// 品名
//    model.addLongProperty("Seq");// 序号
//    model.addStringProperty("CreateDate");// 创建时间
//    model.addStringProperty("UpdateDate");// 修改时间

    private boolean select_flag;// 品名是否选中

    private ArrayList<CategoryNameBean> categoryNameBeanList = new ArrayList<>();// 属性名称列表
    // KEEP FIELDS END

    public PNameMobModel() {
    }

    public PNameMobModel(Long schema_id) {
        this.schema_id = schema_id;
    }

    public PNameMobModel(Long schema_id, long ID, String PName, Long Seq, String CreateDate, String UpdateDate) {
        this.schema_id = schema_id;
        this.ID = ID;
        this.PName = PName;
        this.Seq = Seq;
        this.CreateDate = CreateDate;
        this.UpdateDate = UpdateDate;
    }

    /** called by internal mechanisms, do not call yourself. */
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getPNameMobModelDao() : null;
    }

    public Long getSchema_id() {
        return schema_id;
    }

    public void setSchema_id(Long schema_id) {
        this.schema_id = schema_id;
    }

    public long getID() {
        return ID;
    }

    public void setID(long ID) {
        this.ID = ID;
    }

    public String getPName() {
        return PName;
    }

    public void setPName(String PName) {
        this.PName = PName;
    }

    public Long getSeq() {
        return Seq;
    }

    public void setSeq(Long Seq) {
        this.Seq = Seq;
    }

    public String getCreateDate() {
        return CreateDate;
    }

    public void setCreateDate(String CreateDate) {
        this.CreateDate = CreateDate;
    }

    public String getUpdateDate() {
        return UpdateDate;
    }

    public void setUpdateDate(String UpdateDate) {
        this.UpdateDate = UpdateDate;
    }

    /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.delete(this);
    }

    /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.update(this);
    }

    /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.refresh(this);
    }

    // KEEP METHODS - put your custom methods here

    public boolean isSelect_flag() {
        return select_flag;
    }

    public void setSelect_flag(boolean select_flag) {
        this.select_flag = select_flag;
    }

    public ArrayList<CategoryNameBean> getCategoryNameBeanList() {
        return categoryNameBeanList;
    }

    public void setCategoryNameBeanList(ArrayList<CategoryNameBean> categoryNameBeanList) {
        this.categoryNameBeanList = categoryNameBeanList;
    }
// KEEP METHODS END

}


7.layout

activity_cargo_price_item.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:segmentedgroup="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fresh_road_white_text_color">

    <RelativeLayout
        android:id="@+id/shop_mission_item_rl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include layout="@layout/default_app_head3" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/shop_mission_item_rll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/shop_mission_item_rl"
        android:focusable="true"
        android:focusableInTouchMode="true">

        <include layout="@layout/layout_search_header" />

        <RelativeLayout
            android:id="@+id/purchase_type_delete_ll"
            android:layout_width="45dp"
            android:layout_height="35dp"
            android:layout_alignParentRight="true">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginRight="15dp"
                android:contentDescription="@string/app_name"
                android:src="@drawable/x_clear_icon" />
        </RelativeLayout>
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/shop_mission_item_lll"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:layout_below="@id/shop_mission_item_rll"
        android:background="#E0F5D6"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="5"
            android:paddingLeft="10dp"
            android:text="品名规格"
            android:textColor="#74D148" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:text="价格"
            android:textColor="#74D148" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/shop_mission_item_ll"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/activity_cargo_price_item_start_ll"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/cargo_price_item_start_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="08-07"
                android:textColor="@color/fresh_road_pink_text_color"
                android:textSize="20sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="开始日期"
                android:textColor="@color/fresh_road_black_text_color"
                android:textSize="15sp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/activity_cargo_price_item_end_ll"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/cargo_price_item_end_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="08-08"
                android:textColor="@color/fresh_road_pink_text_color"
                android:textSize="20sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="截止日期"
                android:textColor="@color/fresh_road_black_text_color"
                android:textSize="15sp" />
        </LinearLayout>

        <Button
            android:id="@+id/shop_mission_item_add_bt"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/fresh_road_new_bt_bg_color"
            android:text="@string/shop_order_add_bt_str"
            android:textColor="@color/fresh_road_white_text_color"
            android:textSize="20sp" />

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <Button
                android:id="@+id/shop_mission_item_place_bt"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/fresh_road_base_color"
                android:text="@string/ok"
                android:textColor="@color/fresh_road_white_text_color"
                android:textSize="20sp" />

            <ImageView
                android:id="@+id/shop_mission_item_warning_iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:contentDescription="@string/app_name"
                android:src="@drawable/warning_icon"
                android:visibility="invisible" />
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/shop_mission_item_ll"
        android:layout_below="@id/shop_mission_item_lll"
        android:baselineAligned="false"
        android:orientation="horizontal">

        <ListView
            android:id="@+id/shop_mission_item_lv"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="10"
            android:descendantFocusability="beforeDescendants" />

        <ListView
            android:id="@+id/order_vertical_lv"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:divider="@null"
            android:scrollbars="none" />
    </LinearLayout>
</RelativeLayout>


listview_purchase_search.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/fresh_road_white_text_color">

    <ImageView
        android:id="@+id/lv_purchase_search_iv"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerInParent="true"
        android:contentDescription="@string/app_name"
        android:src="@drawable/filled_red_circle"
        android:visibility="gone" />

    <TextView
        android:id="@+id/lv_purchase_search_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingBottom="15dp"
        android:paddingTop="15dp"
        android:singleLine="true"
        android:text="最"
        android:textColor="#5D5D5D" />

</RelativeLayout>


listview_cargo_price_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
    android:orientation="vertical">

    <TextView
        android:id="@+id/lv_shop_mission_group_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#F3F1F2"
        android:padding="5dp"
        android:text="经营"
        android:textColor="@color/fresh_road_black_text_color" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="5dp">

        <TextView
            android:id="@+id/lv_shop_mission_item_name"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:gravity="center_vertical"
            android:maxLines="2"
            android:text="商品名称"
            android:textColor="@color/fresh_road_black_text_color"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/lv_shop_mission_item_number_et"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:background="@drawable/bg_conner_stroke_solid_gray"
            android:digits="1234567890."
            android:gravity="center"
            android:inputType="numberDecimal"
            android:selectAllOnFocus="true"
            android:singleLine="true"
            android:textColor="@color/fresh_road_base_color" />
    </LinearLayout>
</LinearLayout>


manifest.xml

        <activity
            android:name=".business.CargoPriceItemActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan" />



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值