package com.dbs.mplus.fatima.fragment;

import android.app.DatePickerDialog;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.dbs.mplus.fatima.R;
import com.dbs.mplus.fatima.activity.ConsentActivity;
import com.dbs.mplus.fatima.activity.activityEvent.CenterMenu;
import com.dbs.mplus.fatima.adapter.ConsentHistoryAdapter;
import com.dbs.mplus.fatima.adapter.ConsentWriteAdapter;
import com.dbs.mplus.fatima.customView.CustomAlertDialog;
import com.dbs.mplus.fatima.httpTask.DataParser;
import com.dbs.mplus.fatima.httpTask.HttpCallBack;
import com.dbs.mplus.fatima.model.ConsentListVO;
import com.dbs.mplus.fatima.model.ConsentWriteListVO;
import com.dbs.mplus.fatima.util.ConsentConfig;
import com.dbs.mplus.fatima.util.Util;

import java.util.ArrayList;
import java.util.HashMap;


public class HistoryFragment extends Fragment {

  private static final String TAG = "HistoryFragment";
  private AppCompatActivity mActivity;
  private Context mContext;
  private ConsentActivity instance;
  private CenterMenu centerMenu;
  private LinearLayoutManager linearLayoutManager;

  private DatePickerDialog leftDateDialog;
  private DatePickerDialog rightDateDialog;
  private CustomAlertDialog csAlert;

  private LinearLayout typePatient;
  private LinearLayout patientLeftRound;
  private ImageView ivPatient;
  private LinearLayout patientRightRound;
  private TextView tvPatient;

  private LinearLayout typeWriter;
  private LinearLayout writerLeftRound;
  private ImageView ivWriter;
  private LinearLayout writerRightRound;
  private TextView tvWriter;

  private Button btnHistorySearch;

  private LinearLayout leftDateLayout;
  private LinearLayout rightDateLayout;
  private TextView tvLeftDate;
  private TextView tvRightDate;

  private CheckBox checkAll;
  private CheckBox checkNowrite;
  private CheckBox checkTemp;
  private CheckBox checkGudu;
  private CheckBox checkPateintSign;
  private CheckBox checkCert;
  private CheckBox checkPrint;
  private TextView tvEmptyMsg;
  public RecyclerView historyPatientRecyclerView;
  public RecyclerView historyWriteRecyclerView;

  private HashMap<View, String> consentStateData;
  public String searchType = "patient";

  public HistoryFragment(AppCompatActivity mActivity, Context mContext, CenterMenu centerMenu) {
    this.mContext   = mContext;
    this.mActivity  = mActivity;
    this.instance   = (ConsentActivity) mContext;
    this.centerMenu = centerMenu;
    this.consentStateData = new HashMap<View, String>();
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

  }

  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View view = (View) inflater.inflate(R.layout.activity_history_fragment, container, false);

    csAlert = new CustomAlertDialog(mContext);

    typePatient         = (LinearLayout) view.findViewById(R.id.typePatient);
    patientLeftRound    = (LinearLayout) view.findViewById(R.id.patientLeftRound);
    ivPatient           = (ImageView) view.findViewById(R.id.ivPatient);
    patientRightRound   = (LinearLayout) view.findViewById(R.id.patientRightRound);
    tvPatient           = (TextView) view.findViewById(R.id.tvPatient);
    typeWriter          = (LinearLayout) view.findViewById(R.id.typeWriter);
    writerLeftRound     = (LinearLayout) view.findViewById(R.id.writerLeftRound);
    ivWriter            = (ImageView) view.findViewById(R.id.ivWriter);
    writerRightRound    = (LinearLayout) view.findViewById(R.id.writerRightRound);
    tvWriter            = (TextView) view.findViewById(R.id.tvWriter);
    btnHistorySearch    = (Button) view.findViewById(R.id.btnHistorySearch);

    leftDateLayout      = (LinearLayout) view.findViewById(R.id.leftDateLayout);
    rightDateLayout     = (LinearLayout) view.findViewById(R.id.rightDateLayout);
    tvLeftDate          = (TextView) view.findViewById(R.id.tvLeftDate);
    tvRightDate         = (TextView) view.findViewById(R.id.tvRightDate);

    checkAll            = (CheckBox) view.findViewById(R.id.checkAll);
    checkNowrite        = (CheckBox) view.findViewById(R.id.checkNowrite);
    checkTemp           = (CheckBox) view.findViewById(R.id.checkTemp);
    checkGudu           = (CheckBox) view.findViewById(R.id.checkGudu);
    checkPateintSign    = (CheckBox) view.findViewById(R.id.checkPateintSign);
    checkCert           = (CheckBox) view.findViewById(R.id.checkCert);
    checkPrint          = (CheckBox) view.findViewById(R.id.checkPrint);

    tvEmptyMsg          = (TextView) view.findViewById(R.id.tvEmptyMsg);
    historyPatientRecyclerView = (RecyclerView) view.findViewById(R.id.historyPatientRecyclerView);
    historyWriteRecyclerView = (RecyclerView) view.findViewById(R.id.historyWriteRecyclerView);

    if (!instance.mobile.equals("O")) {
      typePatient.setVisibility(View.GONE);
      typeWriter.setVisibility(View.GONE);
    }

    GradientDrawable btnSearchBg = (GradientDrawable) btnHistorySearch.getBackground();
    btnSearchBg.setColorFilter(ContextCompat.getColor(mContext, R.color.typeLeftColor), PorterDuff.Mode.SRC_ATOP);

    setDate();
    setEvent();
    setDrawableHistoryType("patient");

    return view;
  }

  private void setDrawableHistoryType(String type) {
    GradientDrawable patientLeftBg = (GradientDrawable) patientLeftRound.getBackground();
    GradientDrawable patientRightBg = (GradientDrawable) patientRightRound.getBackground();
    GradientDrawable writerLeftBg = (GradientDrawable) writerLeftRound.getBackground();
    GradientDrawable writerRightBg = (GradientDrawable) writerRightRound.getBackground();

    if (type.equals("patient")) {
      patientLeftBg.setColorFilter(ContextCompat.getColor(mContext, R.color.typeLeftColor), PorterDuff.Mode.SRC_ATOP);
      patientRightBg.setColorFilter(ContextCompat.getColor(mContext, R.color.typeRightColor), PorterDuff.Mode.SRC_ATOP);
      ivPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
      tvPatient.setTextColor(ContextCompat.getColor(mContext, R.color.white));

      writerLeftBg.setColorFilter(ContextCompat.getColor(mContext, R.color.historyTypeColor), PorterDuff.Mode.SRC_ATOP);
      writerRightBg.setColorFilter(ContextCompat.getColor(mContext, R.color.departmentBtnColor), PorterDuff.Mode.SRC_ATOP);
      ivWriter.setColorFilter(ContextCompat.getColor(mContext, R.color.black), PorterDuff.Mode.SRC_ATOP);
      tvWriter.setTextColor(ContextCompat.getColor(mContext, R.color.black));

      checkAll.setChecked(true);
      checkNowrite.setChecked(false);
      checkTemp.setChecked(false);
      checkGudu.setChecked(false);
      checkPateintSign.setChecked(false);
      checkCert.setChecked(false);
      checkPrint.setChecked(false);
    } else {
      patientLeftBg.setColorFilter(ContextCompat.getColor(mContext, R.color.historyTypeColor), PorterDuff.Mode.SRC_ATOP);
      patientRightBg.setColorFilter(ContextCompat.getColor(mContext, R.color.departmentBtnColor), PorterDuff.Mode.SRC_ATOP);
      ivPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.black), PorterDuff.Mode.SRC_ATOP);
      tvPatient.setTextColor(ContextCompat.getColor(mContext, R.color.black));

      writerLeftBg.setColorFilter(ContextCompat.getColor(mContext, R.color.typeLeftColor), PorterDuff.Mode.SRC_ATOP);
      writerRightBg.setColorFilter(ContextCompat.getColor(mContext, R.color.typeRightColor), PorterDuff.Mode.SRC_ATOP);
      ivWriter.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
      tvWriter.setTextColor(ContextCompat.getColor(mContext, R.color.white));

      checkAll.setChecked(false);
      checkNowrite.setChecked(false);
      checkTemp.setChecked(false);
      checkGudu.setChecked(false);
      checkPateintSign.setChecked(true);
      checkCert.setChecked(false);
      checkPrint.setChecked(false);
    }

//    if (instance.consentHistoryAdapter != null) {
//      if (type.equals("patient")) {
//        historyPatientRecyclerView.setVisibility(View.VISIBLE);
//        historyWriteRecyclerView.setVisibility(View.GONE);
//      } else {
//        historyPatientRecyclerView.setVisibility(View.GONE);
//        historyWriteRecyclerView.setVisibility(View.VISIBLE);
//      }
//    }

//    if (instance.consentHistoryAdapter != null) {
//      instance.consentHistoryAdapter.arrayList.clear();
//      instance.consentHistoryAdapter.apiType = type;
//      instance.consentHistoryAdapter.notifyDataSetChanged();
//    }

  }

  private void setEvent() {

    // 환자별/작성자별 색상 변경 리스너
    typePatient.setOnClickListener(onClickListener);
    typeWriter.setOnClickListener(onClickListener);

    leftDateLayout.setOnClickListener(onClickListener);
    rightDateLayout.setOnClickListener(onClickListener);

    // 조회 버튼 이벤트
    btnHistorySearch.setOnClickListener(onClickListener);

    // 체크박스 체크 리스너
    checkAll.setOnCheckedChangeListener(onCheckedChangeListener);
    checkNowrite.setOnCheckedChangeListener(onCheckedChangeListener);
    checkTemp.setOnCheckedChangeListener(onCheckedChangeListener);
    checkGudu.setOnCheckedChangeListener(onCheckedChangeListener);
    checkPateintSign.setOnCheckedChangeListener(onCheckedChangeListener);
    checkCert.setOnCheckedChangeListener(onCheckedChangeListener);
    checkPrint.setOnCheckedChangeListener(onCheckedChangeListener);
  }


  private void setDate() {
    int year  = Util.toDayDate()[0];
    int month = Integer.parseInt(Util.plusZero(Util.toDayDate()[1] - 1));
    int day   = Integer.parseInt(Util.plusZero(Util.toDayDate()[2]));


    String rightDate = Util.toDayDate()[0] + "/" + Util.plusZero(Util.toDayDate()[1]) + "/" + Util.plusZero(Util.toDayDate()[2]);
    String leftDate  = Util.addDate(rightDate, "yyyy/MM/dd", 0, 0, -7, 0, 0);
    tvRightDate.setText(rightDate);
    tvLeftDate.setText(leftDate);

    leftDateDialog  = new DatePickerDialog(mContext, R.style.DatePickerDialogTheme , leftDateListener, year, month, day - 7);
    rightDateDialog = new DatePickerDialog(mContext, R.style.DatePickerDialogTheme , rightDateListener, year, month, day);
  }

  private DatePickerDialog.OnDateSetListener rightDateListener = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
      String m            = Util.plusZero(month + 1);
      String d            = Util.plusZero(dayOfMonth);
      String selectedDate = year + "/" + m + "/" + d;
      String ymd          = year + m + d; // 선택한 날짜
      String leftDate     = getLeftDate(); // 왼쪽 날짜
      leftDate            = Util.removeSlashStr(leftDate);

      int ymdInt      = Integer.parseInt(ymd);
      int leftDateInt = Integer.parseInt(leftDate);

      if (leftDateInt <= ymdInt) {
        setRightDate(selectedDate);
      } else {
        csAlert.show();
        csAlert.setContent("조회 마지막일 보다 지난 날짜로 지정될 수 없습니다.", ConsentConfig.ALERT_BTN_TYPE);
        csAlert.btnConfirm2.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            csAlert.dismiss();
          }
        });
      }
    }
  };

  private DatePickerDialog.OnDateSetListener leftDateListener = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
      String m            = Util.plusZero(month + 1);
      String d            = Util.plusZero(dayOfMonth);
      String selectedDate = year + "/" + m + "/" + d;
      String ymd          = year + m + d;
      String rightDate    = getRightDate();
      rightDate           = Util.removeSlashStr(rightDate);

      int ymdInt        = Integer.parseInt(ymd);
      int rightDateInt  = Integer.parseInt(rightDate);

      if (rightDateInt >= ymdInt) {
        setLeftDate(selectedDate);
      } else {
        csAlert.show();
        csAlert.setContent("조회 시작일 보다 이전 날짜로 지정될 수 없습니다.", ConsentConfig.ALERT_BTN_TYPE);
        csAlert.btnConfirm2.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            csAlert.dismiss();
          }
        });
      }
    }
  };



  private View.OnClickListener onClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      if (v == typePatient) {
        searchType = "patient";
        setDrawableHistoryType("patient");
      } else if (v == typeWriter) {
        searchType = "write";
        setDrawableHistoryType("write");
      } else if (v == leftDateLayout) {
        leftDateDialog.show();
      } else if (v == rightDateLayout) {
        rightDateDialog.show();
      } else if (btnHistorySearch == v) {
        getHistoryConsentList(searchType);
      }

    }
  };

  private CheckBox.OnCheckedChangeListener onCheckedChangeListener = new CheckBox.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton v, boolean isChecked) {

      if (v == checkAll) {
        if (isChecked == true) {
          checkAll.setChecked(true);
          checkNowrite.setChecked(false);
          checkTemp.setChecked(false);
          checkGudu.setChecked(false);
          checkPateintSign.setChecked(false);
          checkCert.setChecked(false);
          checkPrint.setChecked(false);
          consentStateData.put(checkAll, ConsentConfig.ALL);
        } else {
//          consentStateData.remove(checkAll);
          consentStateData.clear();
        }

      } else if (v == checkNowrite) {
        if (isChecked == true) {
          checkAll.setChecked(false);
          consentStateData.put(checkNowrite, "'" + ConsentConfig.UNFINISHED + "'");
        } else {
          consentStateData.remove(checkNowrite);
        }

      } else if (v == checkTemp) {
        if (isChecked == true) {
          checkAll.setChecked(false);
          consentStateData.put(checkTemp, "'" + ConsentConfig.TEMP + "'");
        } else {
          consentStateData.remove(checkTemp);
        }

      } else if (v == checkGudu) {
        if (isChecked == true) {
          checkAll.setChecked(false);
          consentStateData.put(checkGudu, "'" + ConsentConfig.VERBAL + "'");
        } else {
          consentStateData.remove(checkGudu);
        }

      } else if (v == checkPateintSign) {
        if (isChecked == true) {
          checkAll.setChecked(false);
          consentStateData.put(checkPateintSign, "'" + ConsentConfig.ELECTR_CMP + "'");
        } else {
          consentStateData.remove(checkPateintSign);
        }

      } else if (v == checkCert) {
        if (isChecked == true) {
          checkAll.setChecked(false);
          consentStateData.put(checkCert, "'" + ConsentConfig.CERTIFY_CMP + "'");
        } else {
          consentStateData.remove(checkCert);
        }
      } else if (v == checkPrint) {
        if (isChecked == true) {
          checkAll.setChecked(false);
          consentStateData.put(checkPrint, "'" + ConsentConfig.PAPER_OUT + "'");
        } else {
          consentStateData.remove(checkPrint);
        }
      }


//      if (checkNowrite.isChecked() && checkTemp.isChecked() && checkGudu.isChecked() && checkPateintSign.isChecked() && checkCert.isChecked() && checkPrint.isChecked()) {
//        checkAll.setChecked(true);
//        checkNowrite.setChecked(false);
//        checkTemp.setChecked(false);
//        checkGudu.setChecked(false);
//        checkPateintSign.setChecked(false);
//        checkCert.setChecked(false);
//        checkPrint.setChecked(false);
//        consentStateData.put(checkAll, ConsentConfig.ALL);
//
//        consentStateData.remove(checkNowrite);
//        consentStateData.remove(checkTemp);
//        consentStateData.remove(checkGudu);
//        consentStateData.remove(checkPateintSign);
//        consentStateData.remove(checkCert);
//        consentStateData.remove(checkPrint);
//      }
//
//      if (!checkAll.isChecked() && !checkNowrite.isChecked() && !checkTemp.isChecked() && !checkGudu.isChecked() && !checkPateintSign.isChecked() && !checkCert.isChecked() && !checkPrint.isChecked()) {
//        checkAll.setChecked(true);
//        consentStateData.put(checkAll, ConsentConfig.ALL);
//        consentStateData.remove(checkNowrite);
//        consentStateData.remove(checkTemp);
//        consentStateData.remove(checkGudu);
//        consentStateData.remove(checkPateintSign);
//        consentStateData.remove(checkCert);
//        consentStateData.remove(checkPrint);
//      }
    }
  };

  public void getHistoryConsentList(final String type) {
    Log.e(TAG, "type -- > " + type);

    HttpCallBack callBack = new HttpCallBack() {
      @Override
      public void result(String result) {
        Log.e(TAG, "getHistoryConsentList -- > " + result);
        if (result.equals("")) {
        } else {
          if (type.equals("patient")) {
            ArrayList<ConsentListVO> arrayList = DataParser.getConsentList(mContext, result);
            setHistoryConsentList(arrayList);
          } else {
            ArrayList<ConsentWriteListVO> arrayList = DataParser.getUnfinishedListPerDoctor(mContext, result);
            setWirteConsentList(arrayList);
          }
        }

      }

      @Override
      public void stop() {

      }

      @Override
      public void error() {

      }
    };

    if (centerMenu.patientInfoVO == null) {
      instance.showSingButtonDialog(mContext.getString(R.string.emptyPatientInfo));
    } else {

      instance.showProgress();

      if (consentStateData == null || consentStateData.size() == 0) {
        csAlert.show();
        csAlert.setContent(mContext.getString(R.string.emptyCheckConsentState), ConsentConfig.ALERT_BTN_TYPE);
        csAlert.btnConfirm2.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            instance.dismissProgress();
            csAlert.dismiss();
          }
        });

        return;
      }

      String consentState = "";
      int count = 0;
      for (View key : consentStateData.keySet()) {

        String state = consentStateData.get(key);

        if (state.equals("ALL")) {
//          consentState = "'" + ConsentConfig.UNFINISHED + "', " + "'" + ConsentConfig.TEMP + "'," + "'" + ConsentConfig.VERBAL + "', " + "'" + ConsentConfig.ELECTR_CMP + "', " + "'" + ConsentConfig.CERTIFY_CMP + "', " + "'" + ConsentConfig.PAPER_OUT + "'";
          consentState = "ALL";
        } else {
          consentState += state;
          if (consentStateData.size() - 1 > count) {
            consentState = consentState + ", ";
          }
        }

        count = count + 1;
      }

      String action = "";
      String method = "";
      HashMap<String, String> mData = new HashMap<>();
      if (type.equals("write")) {
        action = ConsentConfig.HOST_HOSPITAL;
        method = ConsentConfig.GET_UNFINISHED_LIST_PER_DOCTOR;
        mData.put("userid", Util.getStringPreference(mContext, "userInfo", "emplNo"));
        mData.put("status", consentState);
        mData.put("fromdd", getLeftDate());
        mData.put("todd", getRightDate());
      } else {
        action = ConsentConfig.HOST_CONSENT;
        method = ConsentConfig.GET_CONSENT_LIST;
        mData.put("patientCode", centerMenu.patientInfoVO.getPid());
        mData.put("startDt", getLeftDate());
        mData.put("endDt", getRightDate());
        mData.put("consentState", consentState);
        mData.put("jobkindcd", instance.mobile.equals("O") && (instance.jobKindCd.equals("1140") || instance.jobKindCd.equals("1113")) ? "ALL" : instance.jobKindCd);
      }

      Log.e(TAG, "mData -- > " + mData);

      if (Util.checkNetwork(mContext) == true) {
        Util.callHttp(mContext, action, method, mData, callBack);
      } else {
        instance.dismissProgress();
        Util.networkErrorAlert(mActivity);
      }
    }

  }

  private void setHistoryConsentList(final ArrayList<ConsentListVO> arrayList) {

    mActivity.runOnUiThread(new Runnable() {
      @Override
      public void run() {

        instance.dismissProgress();
        if (arrayList.size() > 0) {
//          tvEmptyMsg.setVisibility(View.GONE);
        } else {
//          tvEmptyMsg.setVisibility(View.VISIBLE);
          emptyList();
        }

        if (instance.consentHistoryAdapter == null) {
          instance.consentHistoryAdapter = new ConsentHistoryAdapter(mActivity, mContext, arrayList, "patient");
          linearLayoutManager = new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false);
          historyPatientRecyclerView.setLayoutManager(linearLayoutManager);
          historyPatientRecyclerView.setAdapter(instance.consentHistoryAdapter);
        } else {
          if (instance.consentHistoryAdapter.checkMap != null) {
            instance.consentHistoryAdapter.checkMap.clear();
          }

          instance.consentHistoryAdapter.arrayList.clear();
          instance.consentHistoryAdapter.arrayList = arrayList;
          instance.consentHistoryAdapter.notifyDataSetChanged();
        }

        historyPatientRecyclerView.setVisibility(View.VISIBLE);
        historyWriteRecyclerView.setVisibility(View.GONE);

      }
    });
  }

  private void setWirteConsentList(final ArrayList<ConsentWriteListVO> arrayList) {
    mActivity.runOnUiThread(new Runnable() {
      @Override
      public void run() {

        instance.dismissProgress();
        if (arrayList.size() > 0) {
//          tvEmptyMsg.setVisibility(View.GONE);
        } else {
//          tvEmptyMsg.setVisibility(View.VISIBLE);
          emptyList();
        }

        if (instance.consentWriteAdapter == null) {
          instance.consentWriteAdapter = new ConsentWriteAdapter(mActivity, mContext, arrayList, "write");
          LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false);
          historyWriteRecyclerView.setLayoutManager(linearLayoutManager);
          historyWriteRecyclerView.setAdapter(instance.consentWriteAdapter);
        } else {
          if (instance.consentWriteAdapter.checkMap != null) {
            instance.consentWriteAdapter.checkMap.clear();
          }
          instance.consentWriteAdapter.arrayList.clear();
          instance.consentWriteAdapter.arrayList = arrayList;
          instance.consentWriteAdapter.notifyDataSetChanged();
        }

        historyPatientRecyclerView.setVisibility(View.GONE);
        historyWriteRecyclerView.setVisibility(View.VISIBLE);
      }
    });
  }

  private void emptyList() {
    csAlert.show();
    csAlert.setContent(mContext.getString(R.string.emptyHistory), ConsentConfig.ALERT_BTN_TYPE);
    csAlert.btnConfirm2.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        csAlert.dismiss();
      }
    });
  }

  public void changeLeftDate(String date) {
    int year = Integer.parseInt(date.split("/")[0]);
    int month = Integer.parseInt(date.split("/")[1]);
    int day = Integer.parseInt(date.split("/")[2]);
    leftDateDialog  = new DatePickerDialog(mContext, R.style.DatePickerDialogTheme , leftDateListener, year, month -1, day);
    tvLeftDate.setText(date);
  }

  private String getLeftDate() {
    return Util.removeSlashStr(tvLeftDate.getText().toString());
  }

  public void setLeftDate(String date) {
    tvLeftDate.setText(date);
  }

  private String getRightDate() {
    return Util.removeSlashStr(tvRightDate.getText().toString());
  }

  private void setRightDate(String date) {
    tvRightDate.setText(date);
  }


}