com.cjc.activity.carManagement.CarDisassemblyTypeActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.cjc.activity.carManagement.CarDisassemblyTypeActivity.java

Source

package com.cjc.activity.carManagement;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.app.Config;
import com.base.ui.BaseActivity;
import com.base.utils.GsonUtils;
import com.base.utils.LogUtil;
import com.base.utils.StringUtils;
import com.base.utils.Tools;
import com.cjc.activity.carDisassembly.PhotoViewActivity;
import com.cjc.adapter.CarDisassemblyTypeAdapter;
import com.cjc.model.CarListItem;
import com.cjc.model.DisassemblyDetail;
import com.cjc.model.UploadPicture;
import com.hxky.car.R;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 *   ?
 */
public class CarDisassemblyTypeActivity extends BaseActivity {

    @BindView(R.id.tvLicensePlate)
    TextView tvLicensePlate;
    @BindView(R.id.tvCarStyle)
    TextView tvCarStyle;
    @BindView(R.id.tvApproachTime)
    TextView tvApproachTime;
    @BindView(R.id.tvCarCode)
    TextView tvCarCode;
    @BindView(R.id.tvOldNewGree)
    TextView tvOldNewGree;
    @BindView(R.id.tvPumpCount)
    TextView tvPumpCount;
    @BindView(R.id.tvBatteryCount)
    TextView tvBatteryCount;
    @BindView(R.id.tvMotorCount)
    TextView tvMotorCount;
    @BindView(R.id.tvCarDoorCount)
    TextView tvCarDoorCount;
    @BindView(R.id.tvAluminumCount)
    TextView tvAluminumCount;
    @BindView(R.id.tvElectricalCount)
    TextView tvElectricalCount;
    @BindView(R.id.tvIsAluminum)
    TextView tvIsAluminum;
    @BindView(R.id.tvCisternCount)
    TextView tvCisternCount;
    @BindView(R.id.tvTireCount)
    TextView tvTireCount;
    @BindView(R.id.tvSeatCount)
    TextView tvSeatCount;
    @BindView(R.id.tvAirConditionerCount)
    TextView tvAirConditionerCount;
    @BindView(R.id.tvThreeWayCount)
    TextView tvThreeWayCount;
    @BindView(R.id.tvRemark)
    TextView tvRemark;
    @BindView(R.id.btnDismantleWay1)
    Button btnDismantleWay1;
    @BindView(R.id.btnDismantleWay2)
    Button btnDismantleWay2;
    @BindView(R.id.btnDismantleWay3)
    Button btnDismantleWay3;
    @BindView(R.id.btnDismantleWay4)
    Button btnDismantleWay4;
    @BindView(R.id.btnCarOut)
    Button btnCarOut;
    @BindView(R.id.ll1)
    LinearLayout ll1;
    @BindView(R.id.ll2)
    LinearLayout ll2;
    @BindView(R.id.gvImage)
    GridView gvImage;
    @BindView(R.id.tvVin)
    TextView tvVin;
    @BindView(R.id.tvEngineNumber)
    TextView tvEngineNumber;
    @BindView(R.id.tvLocation)
    TextView tvLocation;
    @BindView(R.id.tvCreateTime)
    TextView tvCreateTime;
    @BindView(R.id.tvDisplacement)
    TextView tvDisplacement;
    @BindView(R.id.llMore)
    LinearLayout llMore;
    @BindView(R.id.tvMore)
    TextView tvMore;
    @BindView(R.id.tvUseType)
    TextView tvUseType;
    @BindView(R.id.tvSelfWeight)
    TextView tvSelfWeight;
    @BindView(R.id.tvNatureType)
    TextView tvNatureType;
    @BindView(R.id.tvCheckType)
    TextView tvCheckType;
    private CarListItem carListItem;
    private boolean isCarOut;
    private List<UploadPicture> dismantlePhotoBeanList = new ArrayList<>();
    private CarDisassemblyTypeAdapter carDisassemblyTypeAdapter;

    @Override
    protected void handleMessageImpl(Message msg) {
        super.handleMessageImpl(msg);
        switch (msg.what) {
        case Config.Task.HaveDismantleInfo:
            handleResult();
            break;
        case Config.Task.SaveDismantleInfo:
            handleCheckTypeResult();
            break;
        case Config.Task.SaveCarOutput:
            handleCheckTypeResult();
            break;
        case Config.Task.MSG_ERROR:
            closeLoadingDialog();
            Tools.showToast(R.string.networkError);
            break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.act_car_disassembly_type;
    }

    @Override
    protected void setData() {
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            if (bundle.containsKey(Config.Extras.CarItem)) {
                carListItem = (CarListItem) bundle.getSerializable(Config.Extras.CarItem);
                if (carListItem != null) {
                    setDataView();
                    loadData();
                }
            }
            if (bundle.containsKey(Config.Extras.IsCarOUt)) {
                isCarOut = bundle.getBoolean(Config.Extras.IsCarOUt);
            }
            if (isCarOut) {
                btnCarOut.setVisibility(View.VISIBLE);
                ll1.setVisibility(View.GONE);
                ll2.setVisibility(View.GONE);
                mCommonTitle.setTitle("");
            } else {
                btnCarOut.setVisibility(View.GONE);
                ll1.setVisibility(View.VISIBLE);
                ll2.setVisibility(View.VISIBLE);
                mCommonTitle.setTitle("?");
            }
        }
        carDisassemblyTypeAdapter = new CarDisassemblyTypeAdapter(context, dismantlePhotoBeanList);
        gvImage.setAdapter(carDisassemblyTypeAdapter);
    }

    /**
     * ??
     */
    public void loadData() {
        showLoadingDialog(true);
        Map<String, Object> params = new HashMap<>();
        params.put("SessionKey", biz.getSessionKey());
        params.put("UserID", biz.getUserId());
        params.put("CarID", carListItem.getCarID());
        okHttp.postJson(Config.Url.HaveDismantleInfo, params, handler, Config.Task.HaveDismantleInfo);
    }

    /**
     * ??
     *
     * @param type 1: 2: 3: 4:
     */
    public void loadCheckTypeData(int type) {
        showLoadingDialog(true);
        Map<String, Object> params = new HashMap<>();
        params.put("SessionKey", biz.getSessionKey());
        params.put("UserID", biz.getUserId());
        params.put("CarID", carListItem.getCarID());
        params.put("DismantleWay", type);
        okHttp.postJson(Config.Url.SaveDismantleInfo, params, handler, Config.Task.SaveDismantleInfo);
    }

    /**
     * 
     */
    public void loadCarOtData() {
        showLoadingDialog(true);
        Map<String, Object> params = new HashMap<>();
        params.put("SessionKey", biz.getSessionKey());
        params.put("UserID", biz.getUserId());
        params.put("CarID", carListItem.getCarID());
        okHttp.postJson(Config.Url.SaveCarOutput, params, handler, Config.Task.SaveCarOutput);
    }

    @Override
    protected void addListeners() {
        tvMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (llMore.getVisibility() == View.VISIBLE) {
                    tvMore.setText("");
                    llMore.setVisibility(View.GONE);
                } else {
                    tvMore.setText("");
                    llMore.setVisibility(View.VISIBLE);
                }
            }
        });
        btnCarOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadCarOtData();

                //                AlertDialog.Builder builder = new AlertDialog.Builder(context);  //
                //                builder.setTitle("??"); //
                //                builder.setMessage("?"); //
                //                builder.setPositiveButton("", new DialogInterface.OnClickListener() { //
                //                    @Override
                //                    public void onClick(DialogInterface dialog, int which) {
                //                        dialog.dismiss(); //dialog
                //
                //                    }
                //                });
                //                builder.setNegativeButton("?", new DialogInterface.OnClickListener() { //?
                //                    @Override
                //                    public void onClick(DialogInterface dialog, int which) {
                //                        dialog.dismiss();
                //                    }
                //                });
                //                builder.show();
            }
        });
        gvImage.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (!StringUtils.isEmpty(carDisassemblyTypeAdapter.getItem(position).getOriginalUrl())) {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable(Config.Extras.PictureList, (Serializable) dismantlePhotoBeanList);
                    bundle.putInt(Config.Extras.Position, position);
                    enterPage(PhotoViewActivity.class, bundle);
                }
            }
        });

    }

    private void handleResult() {
        closeLoadingDialog();
        if (mCommonData == null)
            return;
        if (mCommonData.getSuccess() == 0) {
            DisassemblyDetail disassemblyDetail = GsonUtils.toObject(mCommonData.getData(),
                    DisassemblyDetail.class);
            if (disassemblyDetail == null)
                return;
            LogUtil.e("-->" + disassemblyDetail.getDismantleWay());

            /**
             * 1: 2: 3: 4:
             */
            if ("1".equals(disassemblyDetail.getDismantleWay())) {
                tvCheckType.setText("");
            } else if ("2".equals(disassemblyDetail.getDismantleWay())) {
                tvCheckType.setText("");
            } else if ("3".equals(disassemblyDetail.getDismantleWay())) {
                tvCheckType.setText("");
            } else if ("4".equals(disassemblyDetail.getDismantleWay())) {
                tvCheckType.setText("");
            }
            if ("".equals(disassemblyDetail.getNatureType())) {
                tvNatureType.setTextColor(ContextCompat.getColor(context, R.color.red));
            } else {
                tvNatureType.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));

            }
            tvNatureType.setText(disassemblyDetail.getNatureType());
            tvVin.setText(disassemblyDetail.getVIN());
            tvEngineNumber.setText(disassemblyDetail.getEngineNumber());
            tvDisplacement.setText(disassemblyDetail.getDisplacement());
            tvUseType.setText(disassemblyDetail.getUseType());
            DisassemblyDetail.CarSurveyBean carSurvey = disassemblyDetail.getCarSurvey();
            if (!StringUtils.isEmpty(carSurvey.getCreateTime())) {
                String[] split = carSurvey.getCreateTime().split(" ");
                tvCreateTime.setText(split[0]);
            }

            if (StringUtils.isEmpty(disassemblyDetail.getLocation())) {
                tvLocation.setText("");
            } else {
                tvLocation.setText(disassemblyDetail.getLocation());
            }
            tvOldNewGree.setText(carSurvey.getOldNewGree());
            tvCarCode.setText(carListItem.getCarCode());
            tvPumpCount.setText(StringUtils.toString(carSurvey.getPumpCount()));
            tvBatteryCount.setText(StringUtils.toString(carSurvey.getBatteryCount()));
            tvMotorCount.setText(StringUtils.toString(carSurvey.getMotorCount()));
            tvCarDoorCount.setText(StringUtils.toString(carSurvey.getCarDoorCount()));
            tvAluminumCount.setText(StringUtils.toString(carSurvey.getAluminumCount()));
            tvElectricalCount.setText(StringUtils.toString(carSurvey.getElectricalCount()));
            tvCisternCount.setText(StringUtils.toString(carSurvey.getCisternCount()));
            tvTireCount.setText(StringUtils.toString(carSurvey.getTireCount()));
            tvSeatCount.setText(StringUtils.toString(carSurvey.getSeatCount()));
            tvAirConditionerCount.setText(StringUtils.toString(carSurvey.getAirConditionerCount()));
            tvThreeWayCount.setText(StringUtils.toString(carSurvey.getThreeWayCount()));
            tvSelfWeight.setText(carSurvey.getSelfWeight());
            tvRemark.setText(carSurvey.getRemark());
            String[] stringArray = getResources().getStringArray(R.array.carIsAluminum);
            tvIsAluminum.setText(stringArray[carSurvey.getIsAluminum()]);

            List<DisassemblyDetail.DismantlePhotoBean> dismantlePhoto = disassemblyDetail.getDismantlePhoto();
            if (dismantlePhoto != null) {
                dismantlePhotoBeanList.clear();
                for (DisassemblyDetail.DismantlePhotoBean bean : dismantlePhoto) {
                    UploadPicture uploadPicture = new UploadPicture();
                    uploadPicture.setOriginalUrl(bean.getOriginalUrl());
                    uploadPicture.setPhotoName(bean.getPhotoName());
                    dismantlePhotoBeanList.add(uploadPicture);
                }
                carDisassemblyTypeAdapter.updateData(dismantlePhotoBeanList);
            }
        } else {
            Tools.showToast(mCommonData.getMessage());
        }
    }

    private void handleCheckTypeResult() {
        closeLoadingDialog();
        if (mCommonData == null)
            return;
        if (mCommonData.getSuccess() == 0) {
            finish();
        }
        Tools.showToast(mCommonData.getMessage());
    }

    private void setDataView() {
        //        tvCarCode.setText("?:" + carListItem.getCarCode());
        tvLicensePlate.setText(carListItem.getLicencePlate());
        tvCarStyle.setText(carListItem.getCarStyle());
        if (!StringUtils.isEmpty(carListItem.getApproachTime())) {
            String[] split = carListItem.getApproachTime().split(" ");
            tvApproachTime.setText(split[0]);
        }

    }

    @OnClick({ R.id.btnDismantleWay1, R.id.btnDismantleWay2, R.id.btnDismantleWay3, R.id.btnDismantleWay4 })
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.btnDismantleWay1:
            createDialog(1);
            break;
        case R.id.btnDismantleWay2:
            createDialog(2);
            break;
        case R.id.btnDismantleWay3:
            createDialog(3);
            break;
        case R.id.btnDismantleWay4:
            createDialog(4);
            break;
        }
    }

    private void createDialog(final int way) {
        // 2: 3: 4:
        String message = "";
        if (way == 1) {
            message = "";
        } else if (way == 2) {
            message = "";
        } else if (way == 3) {
            message = "";
        } else if (way == 4) {
            message = "";
        }
        final Dialog dialog = new Dialog(context, R.style.DialogNoTitle);
        View view = View.inflate(context, R.layout.dlg_dismantling, null);
        dialog.setContentView(view);
        TextView mTvUpdateMsg = (TextView) view.findViewById(R.id.tvTypeContent);
        mTvUpdateMsg.setText(message);
        Button btnOk = (Button) view.findViewById(R.id.btnOk);
        Button btnCancel = (Button) view.findViewById(R.id.btnCancel);
        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadCheckTypeData(way);
                dialog.dismiss();
            }
        });
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dialog.dismiss();
            }
        });
        dialog.show();
    }
}