package com.cpm.lorealbaautomation.dailyactivity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import androidx.cardview.widget.CardView;
import androidx.appcompat.widget.Toolbar;

import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cpm.lorealbaautomation.Database.Lorealba_Database;
import com.cpm.lorealbaautomation.R;
import com.cpm.lorealbaautomation.constant.AlertandMessages;
import com.cpm.lorealbaautomation.constant.CommonFunctions;
import com.cpm.lorealbaautomation.constant.CommonString;
import com.cpm.lorealbaautomation.delegates.PrefHelper;
import com.cpm.lorealbaautomation.download.Downloader;
import com.cpm.lorealbaautomation.gsonGetterSetter.GroomingGetterSetter;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;

import static com.cpm.lorealbaautomation.constant.CommonFunctions.getCurrentTime_only;
import static com.cpm.lorealbaautomation.constant.CommonFunctions.show_image_preview;
import static com.cpm.lorealbaautomation.dailyactivity.StoreImageActivity.convertBitmap;

public class GroomedActivity extends AppCompatActivity implements View.OnClickListener {
    ImageView grooming_img_morng, grooming_img_noon, grooming_img_evning;
    TextView time_morng_txt, time_noon_txt, time_evning_txt;
    CardView cardview_evening, card_noon, card_morning;
    FloatingActionButton btn_save;
    TextView txt_login_tym;
    Lorealba_Database db;
    Context context;
    AlertDialog alert;
    String counter_id, visit_date, username, _pathforcheck, _path, loginTym = "";
    SimpleDateFormat simpleDateFormat;
    boolean update_flag = false, clicked_flag = false;
    GroomingGetterSetter groomedObject = new GroomingGetterSetter();
    boolean click_camera = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_groomed);
        context = this;
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        if (!CommonFunctions.isTablet(context)) {
            toolbar.setTitleTextAppearance(context, R.style.changestext_sizefor_mobile);
        }
        db = new Lorealba_Database(context);
        db.open();
        validateuidata();
        validateinserted_data();
    }

    @SuppressLint("SetTextI18n")
    private void validateuidata() {
        SharedPreferences preferences = PrefHelper.getPrefs(context);
        counter_id = preferences.getString(CommonString.KEY_COUNTER_ID, "");
        visit_date = preferences.getString(CommonString.KEY_DATE, "");
        username = preferences.getString(CommonString.KEY_USERNAME, "");
        grooming_img_morng = (ImageView) findViewById(R.id.grooming_img_morng);
        grooming_img_noon = (ImageView) findViewById(R.id.grooming_img_noon);
        grooming_img_evning = (ImageView) findViewById(R.id.grooming_img_evning);
        btn_save = (FloatingActionButton) findViewById(R.id.btn_save);
        txt_login_tym = (TextView) findViewById(R.id.txt_login_tym);

        cardview_evening = (CardView) findViewById(R.id.cardview_evening);
        card_noon = (CardView) findViewById(R.id.card_noon);
        card_morning = (CardView) findViewById(R.id.card_morning);

        ///for timer
        time_morng_txt = (TextView) findViewById(R.id.time_morng_txt);
        time_noon_txt = (TextView) findViewById(R.id.time_noon_txt);
        time_evning_txt = (TextView) findViewById(R.id.time_evning_txt);
        setTitle("Grooming Image -" + username);

        grooming_img_morng.setOnClickListener(this);
        grooming_img_noon.setOnClickListener(this);
        grooming_img_evning.setOnClickListener(this);

        btn_save.setOnClickListener(this);
        db.open();
        loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
        if (loginTym != null && !loginTym.isEmpty()) {
            loginTym = CommonFunctions.setTimeFormat(loginTym);
            if (loginTym != null) {
                txt_login_tym.setText("Login Time - " + loginTym);
            } else {
                txt_login_tym.setText("Login Time - " + CommonFunctions.getCurrentTime_only());
            }
        } else {
            txt_login_tym.setText("Login Time - " + CommonFunctions.getCurrentTime_only());
        }
        add_time_for_showat_text();
    }

    @SuppressLint("SetTextI18n")
    private void add_time_for_showat_text() {
        try {
            db.open();
            loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
            if (loginTym != null && !loginTym.isEmpty()) {
                loginTym = CommonFunctions.setTimeFormat(loginTym);
                if (loginTym != null && !loginTym.isEmpty()) {
                    time_morng_txt.setText("Before " + addtime_str(loginTym, 45, 0));
                }
                db.open();
                loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
                if (loginTym != null && !loginTym.isEmpty()) {
                    loginTym = CommonFunctions.setTimeFormat(loginTym);
                    if (loginTym != null && !loginTym.isEmpty())
                        time_noon_txt.setText("Between " + addtime_str(loginTym, 0, 03) + " - " + addtime_str(loginTym, 10, 03));
                }
                db.open();
                loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
                if (loginTym != null && !loginTym.isEmpty()) {
                    loginTym = CommonFunctions.setTimeFormat(loginTym);
                    if (loginTym != null && !loginTym.isEmpty())
                        time_evning_txt.setText("Between " + addtime_str(loginTym, 0, 06) + " - " + addtime_str(loginTym, 10, 06));
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == android.R.id.home) {
            if (clicked_flag) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(CommonString.ONBACK_ALERT_MESSAGE).setCancelable(false).setPositiveButton("Ok",
                        (dialog, id1) -> {
                            overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
                            GroomedActivity.this.finish();
                        }).setNegativeButton("Cancel", (dialog, id12) -> dialog.cancel());
                AlertDialog alert = builder.create();
                alert.show();
            } else {
                overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
                GroomedActivity.this.finish();
            }
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        if (clicked_flag) {
            AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(CommonString.ONBACK_ALERT_MESSAGE).setCancelable(false).setPositiveButton("Ok",
                    (dialog, id) -> {
                        overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
                        GroomedActivity.this.finish();
                    }).setNegativeButton("Cancel", (dialog, id) -> dialog.cancel());
            AlertDialog alert = builder.create();
            alert.show();
        } else {
            overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
            GroomedActivity.this.finish();
        }
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View view) {

        if (view.getId() == R.id.grooming_img_morng) {
            try {
                SimpleDateFormat simpleDateFormat = null;
                ////for morning tym after Added 45 minutes
                db.open();
                loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
                if (loginTym != null && !loginTym.isEmpty()) {
                    loginTym = CommonFunctions.setTimeFormat(loginTym);
                    assert loginTym != null && !loginTym.isEmpty();
                    String morngTym = addtime_str(loginTym, 59, 2);
                    assert !morngTym.isEmpty();
                    simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
                    Date date1 = simpleDateFormat.parse(morngTym);
                    Date date2 = simpleDateFormat.parse(getTime());
                    assert date2 != null;
                    if (date2.before(date1)) {
                        if (groomedObject.getMorning_groom_img_str().equals("")) {
                            clicked_flag = true;
                            _pathforcheck = counter_id + "_groomed_img_mrng_" + visit_date.replace("/", "") + "_" + getCurrentTime_only().replace(":", "") + ".jpg";
                            _path = CommonString.getImagesFolder(context) + _pathforcheck;
                            if (CommonFunctions.isTablet(context)) {
                                CommonFunctions.startAnncaCameraActivity(this, _path, null, false, CommonString.CAMERA_FACE_REAR);
                            } else {
                                CommonFunctions.startAnncaCameraActivity(this, _path, null, false, CommonString.CAMERA_FACE_FRONT);
                            }
                        }
                    }
                    if (!groomedObject.getMorning_groom_img_str().isEmpty()) {
                        show_image_preview(context, groomedObject.getMorning_groom_img_str());
                    }
                }

            } catch (NumberFormatException | ParseException e) {
                e.fillInStackTrace();
            }
        } else if (view.getId() == R.id.grooming_img_noon) {
            try {
                ////for nooo tym after adding 03:10
                db.open();
                loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
                loginTym = CommonFunctions.setTimeFormat(loginTym);
                String noonTym = addtime_str(loginTym, 0, 03);
                String endNoonTym = addtime_str(loginTym, 59, 05);
                simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
                Date date1 = simpleDateFormat.parse(noonTym);
                Date date2 = simpleDateFormat.parse(getTime());
                Date date3 = simpleDateFormat.parse(endNoonTym);
                assert date2 != null;
                if (date2.after(date1) && date2.before(date3)) {
                    if (groomedObject.getNoon_groom_img_str().equals("")) {
                        clicked_flag = true;
                        _pathforcheck = counter_id + "_groomed_img_noon_" + visit_date.replace("/", "") + "_" + getCurrentTime_only().replace(":", "") + ".jpg";
                        _path = CommonString.getImagesFolder(context) + _pathforcheck;
                        if (CommonFunctions.isTablet(context)) {
                            CommonFunctions.startAnncaCameraActivity(this, _path, null, false, CommonString.CAMERA_FACE_REAR);
                        } else {
                            CommonFunctions.startAnncaCameraActivity(this, _path, null, false, CommonString.CAMERA_FACE_FRONT);
                        }
                    }
                }
                if (!groomedObject.getNoon_groom_img_str().equals("")) {
                    show_image_preview(context, groomedObject.getNoon_groom_img_str());
                }
            } catch (NumberFormatException | ParseException e) {
                e.fillInStackTrace();
            }

        } else if (view.getId() == R.id.grooming_img_evning) {
            try {
                ////for evenning tym after adding 03:10
                db.open();
                loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
                loginTym = CommonFunctions.setTimeFormat(loginTym);
                String evngTym = addtime_str(loginTym, 0, 06);
                String EndevngTym = addtime_str(loginTym, 59, 8);
                simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
                Date date1 = simpleDateFormat.parse(evngTym);
                Date date2 = simpleDateFormat.parse(getTime());
                Date date3 = simpleDateFormat.parse(EndevngTym);
                assert date2 != null;
                if (date2.after(date1) && date2.before(date3)) {
                    if (groomedObject.getEvenning_groom_img_str().equals("")) {
                        clicked_flag = true;
                        _pathforcheck = counter_id + "_groomed_img_evning_" + visit_date.replace("/", "") + "_" + getCurrentTime_only().replace(":", "") + ".jpg";
                        _path = CommonString.getImagesFolder(context) + _pathforcheck;
                        if (CommonFunctions.isTablet(context)) {
                            CommonFunctions.startAnncaCameraActivity(this, _path, null, false, CommonString.CAMERA_FACE_REAR);
                        } else {
                            CommonFunctions.startAnncaCameraActivity(this, _path, null, false, CommonString.CAMERA_FACE_FRONT);
                        }
                    }
                }
                if (!groomedObject.getEvenning_groom_img_str().equals("")) {
                    show_image_preview(context, groomedObject.getEvenning_groom_img_str());
                }
            } catch (NumberFormatException | ParseException e) {
                e.fillInStackTrace();
            }
        } else if (view.getId() == R.id.btn_save) {
            if (validategroomedimg() && click_camera) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(R.string.dialog_title).setMessage(R.string.title_activity_save_data).setCancelable(false).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
                        db.open();
                        if (update_flag) {
                            db.open();
                            db.update_Groomed_images(counter_id, username, visit_date, groomedObject, CommonFunctions.getUUID(context));
                        } else {
                            db.open();
                            db.inseetgroomingdata(counter_id, username, visit_date, groomedObject);

                        }
                        //download service
                        Intent intent = new Intent(context, Downloader.class);
                        intent.putExtra(CommonString.KEY_Groomed_Image, groomedObject);
                        Downloader.enqueueWork(context, intent);
                        overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
                        AlertandMessages.showToastMsg(context, "Data saved successfully.");
                        GroomedActivity.this.finish();
                    }
                }).setNegativeButton(android.R.string.cancel, (dialog, id1) -> dialog.cancel());

                alert = builder.create();
                alert.show();
            }
        }

    }

    @SuppressLint("UseCompatLoadingForDrawables")
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.i("MakeMachine", "resultCode: " + resultCode);
        switch (resultCode) {

            case 0:
                Log.i("MakeMachine", "User cancelled");
                break;

            case -1:
                if (_pathforcheck != null && !_pathforcheck.equals("")) {
                    if (new File(CommonString.getImagesFolder(context) + _pathforcheck).exists()) {
                        try {
                            convertBitmap(CommonString.getImagesFolder(context) + _pathforcheck);
                            if (_pathforcheck.contains("_groomed_img_mrng_")) {
                                grooming_img_morng.setImageDrawable(getResources().getDrawable(R.mipmap.camera_bsd));
                                groomedObject.setMorning_groom_img_str(_pathforcheck);
                                groomedObject.setMorning_groom_time_str(getCurrentTime_only());
                                click_camera = true;
                            } else if (_pathforcheck.contains("_groomed_img_noon_")) {
                                grooming_img_noon.setImageDrawable(getResources().getDrawable(R.mipmap.camera_bsd));
                                groomedObject.setNoon_groom_img_str(_pathforcheck);
                                groomedObject.setNoon_groom_time_str(getCurrentTime_only());
                                click_camera = true;
                            } else if (_pathforcheck.contains("_groomed_img_evning_")) {
                                grooming_img_evning.setImageDrawable(getResources().getDrawable(R.mipmap.camera_bsd));
                                groomedObject.setEvenning_groom_img_str(_pathforcheck);
                                groomedObject.setEvenning_groom_time_str(getCurrentTime_only());
                                click_camera = true;
                            }
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.fillInStackTrace();

                            AlertandMessages.showToastMsg(context, "Error");
                        }

                        _pathforcheck = "";
                    }
                }

                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }


    private boolean validategroomedimg() {
        boolean status = true;
        try {
            SimpleDateFormat simpleDateFormat = null;
            ////for morning tym after Added 45 minutes
            db.open();
            loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
            loginTym = CommonFunctions.setTimeFormat(loginTym);
            String morngTym = addtime_str(loginTym, 59, 2);
            simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
            Date date1 = simpleDateFormat.parse(morngTym);
            Date date2 = simpleDateFormat.parse(getTime());

            ////for nooo tym after adding 03:10
            String noonTym = addtime_str(loginTym, 0, 03);
            String endNoonTym = addtime_str(loginTym, 59, 05);
            simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
            Date noondate1 = simpleDateFormat.parse(noonTym);
            Date noondate2 = simpleDateFormat.parse(getTime());
            Date noondate3 = simpleDateFormat.parse(endNoonTym);

            String evngTym = addtime_str(loginTym, 0, 06);
            String EndevngTym = addtime_str(loginTym, 59, 8);
            simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
            Date evngdate1 = simpleDateFormat.parse(evngTym);
            Date evngdate2 = simpleDateFormat.parse(getTime());
            Date evngdate3 = simpleDateFormat.parse(EndevngTym);

            assert date2 != null;
            if (date2.before(date1)) {
                if (groomedObject.getMorning_groom_img_str().equals("")) {
                    AlertandMessages.showToastMsg(context, "Please Capture Full Grooming Image Before " + addtime_str(loginTym, 45, 0));
                    status = false;
                }
            } else {
                assert noondate2 != null;
                if (noondate2.after(noondate1) && noondate2.before(noondate3)) {
                    if (groomedObject.getNoon_groom_img_str().equals("")) {
                        AlertandMessages.showToastMsg(context, "Please Capture Full Grooming Image Between " + addtime_str(loginTym, 0, 3) + " - " + addtime_str(loginTym, 59, 5));
                        status = false;
                    }
                } else {
                    assert evngdate2 != null;
                    if (evngdate2.after(evngdate1) && evngdate2.before(evngdate3)) {
                        if (groomedObject.getEvenning_groom_img_str().equals("")) {
                            AlertandMessages.showToastMsg(context, "Please Capture Full Grooming Image Between " + addtime_str(loginTym, 0, 6) + " - " + addtime_str(loginTym, 59, 8));
                            status = false;
                        }
                    }
                }
            }
        } catch (ParseException e) {
            e.fillInStackTrace();
        }

        return status;
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    private void validateinserted_data() {
        db.open();
        groomedObject = db.getinserted_groomingdata(counter_id, username, visit_date);
        if (!groomedObject.getMorning_groom_img_str().equals("") || !groomedObject.getNoon_groom_img_str().equals("") || !groomedObject.getEvenning_groom_img_str().equals("")) {
            update_flag = true;
            if (!groomedObject.getMorning_groom_img_str().equals("")) {
                grooming_img_morng.setImageDrawable(getResources().getDrawable(R.mipmap.camera_bsd));
            }
            if (!groomedObject.getNoon_groom_img_str().equals("")) {
                grooming_img_noon.setImageDrawable(getResources().getDrawable(R.mipmap.camera_bsd));
            }

            if (!groomedObject.getEvenning_groom_img_str().equals("")) {
                grooming_img_evning.setImageDrawable(getResources().getDrawable(R.mipmap.camera_bsd));
            }

        }
/////for disable
        groomingimg_morng();
        groomedNoonImg();
        groomedeveningimg();
    }


    private String addtime_str(String str, int minuts, int hours) {
        SimpleDateFormat displayFormat = null;
        SimpleDateFormat parseFormat = null;
        Calendar calendar = null;
        Date date = null;
        try {
            parseFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
            displayFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
            date = parseFormat.parse(str);
            calendar = Calendar.getInstance();
            assert date != null;
            calendar.setTime(date);
            calendar.add(Calendar.HOUR, hours);
            calendar.add(Calendar.MINUTE, minuts);
            //test(displayFormat.format(calendar.getTime()));
        } catch (ParseException e) {
            e.fillInStackTrace();
        }

        assert calendar != null;
        return displayFormat.format(calendar.getTime());
    }

    private String getTime() {
        Calendar currnetDateTime = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
        return df.format(currnetDateTime.getTime());
    }

    private void groomingimg_morng() {
        try {
            SimpleDateFormat simpleDateFormat = null;
            ////for morning tym after Added 45 minutes
            db.open();
            loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
            loginTym = CommonFunctions.setTimeFormat(loginTym);
            String morngTym = addtime_str(loginTym, 59, 2);
            simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
            Date date1 = simpleDateFormat.parse(morngTym);
            Date date2 = simpleDateFormat.parse(getTime());
            assert date2 != null;
            if (date2.before(date1)) {

            } else {
                if (groomedObject.getMorning_groom_img_str().equals("")) {
                    card_morning.setCardBackgroundColor(getResources().getColor(R.color.light_red));
                    grooming_img_morng.setImageResource(R.mipmap.red_camera_icon);
                }
            }

        } catch (ParseException e) {
            e.fillInStackTrace();
        }
    }

    private void groomedNoonImg() {
        try {
            SimpleDateFormat simpleDateFormat = null;
            ////for nooo tym after adding 03:10
            db.open();
            loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
            loginTym = CommonFunctions.setTimeFormat(loginTym);
            String noonTym = addtime_str(loginTym, 0, 03);
            String endNoonTym = addtime_str(loginTym, 59, 05);
            simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
            Date date1 = simpleDateFormat.parse(noonTym);
            Date date2 = simpleDateFormat.parse(getTime());
            Date date3 = simpleDateFormat.parse(endNoonTym);
            assert date2 != null;
            if (date2.after(date1) && date2.before(date3)) {

            } else if (date2.before(date1) && date2.before(date3)) {
                if (groomedObject.getEvenning_groom_img_str().equals("")) {
                    card_noon.setCardBackgroundColor(getResources().getColor(R.color.gray));
                    grooming_img_noon.setImageResource(R.mipmap.camera);
                }
            } else {
                if (groomedObject.getNoon_groom_img_str().equals("")) {
                    card_noon.setCardBackgroundColor(getResources().getColor(R.color.light_red));
                    grooming_img_noon.setImageResource(R.mipmap.red_camera_icon);
                }
            }
        } catch (ParseException e) {
            e.fillInStackTrace();
        } catch (NumberFormatException e) {
            e.fillInStackTrace();
        } catch (Resources.NotFoundException e) {
            e.fillInStackTrace();
        }
    }

    private void groomedeveningimg() {
        try {
            SimpleDateFormat simpleDateFormat = null;
            ////for evenning tym after adding 03:10
            db.open();
            loginTym = db.get_baLoginTym(visit_date, username).getUserLoginTym();
            loginTym = CommonFunctions.setTimeFormat(loginTym);
            String evngTym = addtime_str(loginTym, 0, 06);
            String EndevngTym = addtime_str(loginTym, 59, 8);
            simpleDateFormat = new SimpleDateFormat("hh:mm:ss a", Locale.ENGLISH);
            Date date1 = simpleDateFormat.parse(evngTym);
            Date date2 = simpleDateFormat.parse(getTime());
            Date date3 = simpleDateFormat.parse(EndevngTym);

            assert date2 != null;
            if (date2.after(date1) && date2.before(date3)) {

            } else if (date2.before(date1) && date2.before(date3)) {
                if (groomedObject.getEvenning_groom_img_str().equals("")) {
                    cardview_evening.setCardBackgroundColor(getResources().getColor(R.color.gray));
                    grooming_img_evning.setImageResource(R.mipmap.camera);
                }
            } else {
                if (groomedObject.getEvenning_groom_img_str().equals("")) {
                    cardview_evening.setCardBackgroundColor(getResources().getColor(R.color.light_red));
                    grooming_img_evning.setImageResource(R.mipmap.red_camera_icon);
                }
            }

        } catch (ParseException e) {
            e.fillInStackTrace();
        }
    }
}
