package com.cygnusa.hyperm.fragments;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.gson.Gson;
import com.cygnusa.hyperm.AMAttendanceActivity;
import com.cygnusa.hyperm.ASMScheduleViewActivity;
import com.cygnusa.hyperm.AcceptTrainingActivity;
import com.cygnusa.hyperm.AttendanceScheduleActivity;
import com.cygnusa.hyperm.CreateClassRoomActivityNew;
import com.cygnusa.hyperm.R;
import com.cygnusa.hyperm.ViewScheduleActivity;
import com.cygnusa.hyperm.calendarView.EventDay;
import com.cygnusa.hyperm.calendarView.listeners.OnCalendarPageChangeListener;
import com.cygnusa.hyperm.calendarView.listeners.OnDayClickListener;
import com.cygnusa.hyperm.calendarView.utils.DrawableUtils;
import com.cygnusa.hyperm.util.ApiService;
import com.cygnusa.hyperm.util.GlobalData;
import com.cygnusa.hyperm.util.MainApplication;
import com.cygnusa.hyperm.util.TransparentProgressDialog;
import com.cygnusa.hyperm.wrappers.CalanderEventList;
import com.cygnusa.hyperm.wrappers.DateWiseDataList;
import com.cygnusa.hyperm.wrappers.ErrorResponse;
import com.cygnusa.hyperm.wrappers.SingleDataList;
import com.cygnusa.hyperm.wrappers.ViewScheduleListResponse;

import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

import jp.wasabeef.recyclerview.animators.SlideInLeftAnimator;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ClassRoomTainingActivity extends Fragment {

    Button newClassRoomSchedule;
    com.cygnusa.hyperm.calendarView.CalendarView calendarView;
    private BottomSheetBehavior mBottomSheetBehavior1;
    private RecyclerView rclEvents;
    private ApiService apiService;
    DateWiseDataList dateWiseDataList = new DateWiseDataList();
    DateWiseEventAdapter dateAdapter;
    List<EventDay> events = new ArrayList<>();
    String calendarClickedDate;
    private TransparentProgressDialog progressDialog;
    String selectdMonth = "";
    int selectedYear = 0;
    SimpleDateFormat df;
    String dateString = "", selectedDateString = "", currentDateString = "";
    Date selectedDate = new Date();
    private LinearLayout cyonColorCode;
    Date currentDate = new Date();
    public static Handler.Callback callback;
    Activity activity;
    String startDateString = "", endDateString = "";

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_classroom_training, container, false);
        activity = getActivity();
        initView(view);
        // getEventDays();
        return view;
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        callback = new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {

                return false;
            }
        };
    }

    private void initView(View view) {


        cyonColorCode = view.findViewById(R.id.cyonColorCode);
        calendarView = view.findViewById(R.id.calendarView);
        newClassRoomSchedule = view.findViewById(R.id.newSchedule);
        apiService = ((MainApplication) activity.getApplication()).getClient();
        cyonColorCode.setVisibility(View.GONE);
        if (GlobalData.user.getData().getRole().equalsIgnoreCase("5")) {
            newClassRoomSchedule.setVisibility(View.VISIBLE);
            cyonColorCode.setVisibility(View.VISIBLE);
        } else {
            newClassRoomSchedule.setVisibility(View.GONE);
            cyonColorCode.setVisibility(View.GONE);
        }


        View bottomSheet = view.findViewById(R.id.bottom_sheet1);
        rclEvents = bottomSheet.findViewById(R.id.rclEvents);

        rclEvents.setHasFixedSize(true);
        rclEvents.setItemAnimator(new SlideInLeftAnimator());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        rclEvents.setLayoutManager(linearLayoutManager);

        mBottomSheetBehavior1 = BottomSheetBehavior.from(bottomSheet);
        mBottomSheetBehavior1.setHideable(true);
        mBottomSheetBehavior1.setPeekHeight(300);
        mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_HIDDEN);


        //"2020Wed Jul 01 00:00:00 GMT+05:30 2020"

        int month = calendarView.getCurrentPageDate().get(Calendar.MONTH) + 1;
        if (month < 10) {
            dateString = "0" + month;
        } else {
            dateString = String.valueOf(month);
        }
        int year = calendarView.getCurrentPageDate().get(Calendar.YEAR);
        dateString = year + "-" + dateString;


        Date c = Calendar.getInstance().getTime();
        System.out.println("Current time => " + c);

        df = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
        currentDateString = df.format(c);

        Log.e("ActualDate", currentDateString);

        calendarView.setOnForwardPageChangeListener(new OnCalendarPageChangeListener() {
            @Override
            public void onChange() {
                if (mBottomSheetBehavior1.getState() == BottomSheetBehavior.STATE_EXPANDED) {
                    mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_HIDDEN);
                }
                int month = calendarView.getCurrentPageDate().get(Calendar.MONTH) + 1;
                if (month < 10) {
                    dateString = "0" + month;
                } else {
                    dateString = String.valueOf(month);
                }
                int year = calendarView.getCurrentPageDate().get(Calendar.YEAR);
                calendarView.getCurrentPageDate().get(Calendar.DATE);
                dateString = year + "-" + dateString;

                Log.e("SelectedDate", dateString);
                events = new ArrayList<>();
                getEventDays();

            }
        });

        calendarView.setOnPreviousPageChangeListener(new OnCalendarPageChangeListener() {
            @Override
            public void onChange() {
                if (mBottomSheetBehavior1.getState() == BottomSheetBehavior.STATE_EXPANDED) {
                    mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_HIDDEN);
                }
                int month = calendarView.getCurrentPageDate().get(Calendar.MONTH) + 1;
                if (month < 10) {
                    dateString = "0" + month;
                } else {
                    dateString = String.valueOf(month);
                }
                int year = calendarView.getCurrentPageDate().get(Calendar.YEAR);
                dateString = year + "-" + dateString;
                Log.e("SelectedPreDate", dateString);
                events = new ArrayList<>();
                getEventDays();
            }
        });


        newClassRoomSchedule.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GlobalData.fullSingleDataLists = null;
                startActivity(new Intent(getActivity(), CreateClassRoomActivityNew.class));
            }
        });

        calendarView.setOnDayClickListener(new OnDayClickListener() {
            @Override
            public void onDayClick(EventDay eventDay) {
                if (mBottomSheetBehavior1.getState() == BottomSheetBehavior.STATE_EXPANDED) {
                    mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_HIDDEN);
                }
                calendarClickedDate = String.valueOf(eventDay.getCalendar().get(Calendar.DAY_OF_MONTH));
                GlobalData.CURRENTDATE = Integer.parseInt(calendarClickedDate);
                int month = calendarView.getCurrentPageDate().get(Calendar.MONTH) + 1;

                if (month < 10) {
                    selectdMonth = "0" + month;
                } else {
                    selectdMonth = String.valueOf(month);
                }

                if (GlobalData.CURRENTDATE < 10) {
                    calendarClickedDate = "0" + calendarClickedDate;
                } else {
                    calendarClickedDate = String.valueOf(calendarClickedDate);
                }
                selectedYear = eventDay.getCalendar().get(Calendar.YEAR);
                GlobalData.CURRENTMONTH = Integer.parseInt(selectdMonth);
                GlobalData.CURRENTYEAR = selectedYear;
                selectedDateString = calendarClickedDate + "-" + selectdMonth + "-" + year;

                selectedDate = calendarView.getCurrentPageDate().getTime();
                Log.e("currentDateString", selectedDateString);
                if (eventDay.getmSingleDataList() != null && eventDay.getmSingleDataList().size() > 0) {
                    dateAdapter = new DateWiseEventAdapter(eventDay.getmSingleDataList());
                    rclEvents.setAdapter(dateAdapter);
                    if (mBottomSheetBehavior1.getState() != BottomSheetBehavior.STATE_EXPANDED) {
                        mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_EXPANDED);
                    } else {
                        mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_HIDDEN);
                    }
                }
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        getEventDays();
    }

    private void getScheduledList(String scheduleId) {
        apiService.getScheduledList(scheduleId).enqueue(new Callback<ViewScheduleListResponse>() {
            @Override
            public void onResponse(@NotNull Call<ViewScheduleListResponse> call, @NotNull Response<ViewScheduleListResponse> response) {
                if (response.body() != null) {
                    if (response.body().getData() != null) {
                        GlobalData.scheduledDataList = new ArrayList<>();
                        GlobalData.scheduledDataList = response.body().getData();
                        if (GlobalData.scheduledDataList.get(0).getIsDeleted().equalsIgnoreCase("1")) {
                            Intent i = new Intent(getActivity(), ViewScheduleActivity.class);
                            i.putExtra("SCHEDULE_ID", scheduleId);
                            startActivity(i);
                            getActivity().finish();
                        } else if (GlobalData.user.getData().getRole().equalsIgnoreCase("14") || GlobalData.user.getData().getRole().equalsIgnoreCase("4") || GlobalData.user.getData().getRole().equalsIgnoreCase("6")) {
                            startActivity(new Intent(getActivity(), AMAttendanceActivity.class));
                        } else if (GlobalData.user.getData().getRole().equalsIgnoreCase("10")) {
                            startActivity(new Intent(getActivity(), AcceptTrainingActivity.class));
                        } else if (GlobalData.user.getData().getRole().equalsIgnoreCase("5")) {
                            if (currentDateString.equalsIgnoreCase(selectedDateString)) {
                                if (GlobalData.scheduledDataList.get(0).getStatus().equalsIgnoreCase("1")) {
                                    if (GlobalData.scheduledDataList.get(0).getAttendanceUpdateStatus().equalsIgnoreCase("1")) {
                                        startActivity(new Intent(getActivity(), AttendanceScheduleActivity.class));
                                        getActivity().finish();
                                    } else {
                                        Intent i = new Intent(getActivity(), ViewScheduleActivity.class);
                                        i.putExtra("SCHEDULE_ID", scheduleId);
                                        startActivity(i);
                                        getActivity().finish();
                                    }
                                } else {
                                    Intent i = new Intent(getActivity(), ViewScheduleActivity.class);
                                    i.putExtra("SCHEDULE_ID", scheduleId);
                                    startActivity(i);
                                    getActivity().finish();
                                }

                            } else {
                                Intent i = new Intent(getActivity(), ViewScheduleActivity.class);
                                i.putExtra("SCHEDULE_ID", scheduleId);
                                startActivity(i);
                                getActivity().finish();
                            }
                        } else if (GlobalData.user.getData().getRole().equalsIgnoreCase("7")) {
                            if (currentDateString.equalsIgnoreCase(selectedDateString)) {
                                if (GlobalData.scheduledDataList.get(0).getStatus().equalsIgnoreCase("1")) {
                                    if (GlobalData.scheduledDataList.get(0).getAttendanceUpdateStatus().equalsIgnoreCase("1")) {
                                        startActivity(new Intent(getActivity(), AMAttendanceActivity.class));
                                    } else {
                                        Intent i = new Intent(getActivity(), ASMScheduleViewActivity.class);
                                        i.putExtra("SCHEDULE_ID", scheduleId);
                                        startActivity(i);
                                    }
                                } else {
                                    Intent i = new Intent(getActivity(), ASMScheduleViewActivity.class);
                                    i.putExtra("SCHEDULE_ID", scheduleId);
                                    startActivity(i);
                                }
                            } else {
                                Intent i = new Intent(getActivity(), ASMScheduleViewActivity.class);
                                i.putExtra("SCHEDULE_ID", scheduleId);
                                startActivity(i);
                            }
                        }
                    } else if (response.body() != null) {
                        GlobalData.showToast(getActivity(), response.body().getMessage(), Toast.LENGTH_SHORT).show();
                    }
                } else if (response.body() != null && response.body().getStatus() == 401) {
                    GlobalData.canLogout = true;
                    Objects.requireNonNull(getActivity()).finish();
                } else if (response.errorBody() != null) {
                    Gson gson = new Gson();
                    ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
                    GlobalData.showToast(getActivity(), message.getMessage(), Toast.LENGTH_SHORT).show();
                    if (message.getStatus() == 401) {
                        GlobalData.canLogout = true;
                        Objects.requireNonNull(getActivity()).finish();
                    }
                }
            }

            @Override
            public void onFailure
                    (@NotNull Call<ViewScheduleListResponse> call, @NotNull Throwable t) {
                Log.e("rr", Objects.requireNonNull(t.getMessage()));
            }
        });
    }


    private void getEventDays() {
        progressDialog = new TransparentProgressDialog(getActivity());
        progressDialog.show();
        HashMap<String, String> map = new HashMap<>();
        map.put("month", dateString);

        apiService.getEventCalanderList(map).enqueue(new Callback<CalanderEventList>() {
            @Override
            public void onResponse(@NotNull Call<CalanderEventList> call, @NotNull Response<CalanderEventList> response) {
                if (progressDialog != null && progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                if (response.body() != null) {
                    if (response.body().getDateWiseDataList() != null) {
                        dateWiseDataList = new DateWiseDataList();
                        dateWiseDataList = response.body().getDateWiseDataList();
                        GlobalData.fullSingleDataLists = response.body();
                        setDateWiseDataList(dateWiseDataList);
                    }
                } else if (response.body() != null && response.body().getStatus() == 401) {
                    GlobalData.canLogout = true;
                    Objects.requireNonNull(getActivity()).finish();
                } else if (response.errorBody() != null) {
                    Gson gson = new Gson();
                    ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
                    GlobalData.showToast(getActivity(), message.getMessage(), Toast.LENGTH_SHORT).show();
                    if (message.getStatus() == 401) {
                        GlobalData.canLogout = true;
                        Objects.requireNonNull(getActivity()).finish();
                    }
                }

            }

            @Override
            public void onFailure(@NotNull Call<CalanderEventList> call, Throwable t) {
                if (progressDialog != null && progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
            }
        });
    }

    private void setDateWiseDataList(DateWiseDataList dateWiseDataList) {

        setDateWiseEvent(dateWiseDataList.getSingleDateOneList(), "-1");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwoList(), "-2");
        setDateWiseEvent(dateWiseDataList.getSingleDateThreeList(), "-3");
        setDateWiseEvent(dateWiseDataList.getSingleDateFourList(), "-4");
        setDateWiseEvent(dateWiseDataList.getSingleDateFiveList(), "-5");
        setDateWiseEvent(dateWiseDataList.getSingleDateSixList(), "-6");
        setDateWiseEvent(dateWiseDataList.getSingleDateSevenList(), "-7");
        setDateWiseEvent(dateWiseDataList.getSingleDateEightList(), "-8");
        setDateWiseEvent(dateWiseDataList.getSingleDateNineList(), "-9");
        setDateWiseEvent(dateWiseDataList.getSingleDateTenList(), "-10");

        setDateWiseEvent(dateWiseDataList.getSingleDateElevenList(), "-11");
        setDateWiseEvent(dateWiseDataList.getSingleDateTweleList(), "-12");
        setDateWiseEvent(dateWiseDataList.getSingleDateThirteenList(), "-13");
        setDateWiseEvent(dateWiseDataList.getSingleDateFourteenList(), "-14");
        setDateWiseEvent(dateWiseDataList.getSingleDateFifteenList(), "-15");
        setDateWiseEvent(dateWiseDataList.getSingleDateSixteenList(), "-16");
        setDateWiseEvent(dateWiseDataList.getSingleDateSeventeenList(), "-17");
        setDateWiseEvent(dateWiseDataList.getSingleDateEighteenList(), "-18");
        setDateWiseEvent(dateWiseDataList.getSingleDateNineteenList(), "-19");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentyList(), "-20");

        setDateWiseEvent(dateWiseDataList.getSingleDateTwentyOneList(), "-21");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentyTwoList(), "-22");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentyThreeList(), "-23");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentyFourList(), "-24");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentyFiveList(), "-25");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentySixList(), "-26");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentySevenList(), "-27");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentyEightList(), "-28");
        setDateWiseEvent(dateWiseDataList.getSingleDateTwentyNineList(), "-29");
        setDateWiseEvent(dateWiseDataList.getSingleDateThirtyList(), "-30");
        setDateWiseEvent(dateWiseDataList.getSingleDateThirtyOneList(), "-31");

//        Calendar calendar5 = Calendar.getInstance();
//        calendar5.add(Calendar.DAY_OF_MONTH, 2);
//        events.add(new EventDay(calendar5, DrawableUtils.getRedDots(getApplicationContext()), "This is a second sample event to show"));
//        Calendar calendar6 = Calendar.getInstance();
//        calendar6.add(Calendar.DAY_OF_MONTH, 3);
//        events.add(new EventDay(calendar6, DrawableUtils.getBlueDots(getApplicationContext()), "This is a third sample event to show"));

        calendarView.setEvents(events);
    }

    private void setDateWiseEvent(List<SingleDataList> dateList, String date) {

        if (dateList != null && dateList.size() > 0) {
            for (int i = 0; i < dateList.size(); i++) {
                String mdate = dateString + date;
                Calendar calendar = Calendar.getInstance();
                try {
                    calendar.setTime(Objects.requireNonNull(new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(mdate)));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if (dateList.get(i).getTrainingStatus() != null && !dateList.get(i).getTrainingStatus().equalsIgnoreCase("")) {
                    events.add(new EventDay(calendar, DrawableUtils.getPeachDots(getActivity(), dateList.get(i).getTrainingStatus()), dateList));
                } else {
                    events.add(new EventDay(calendar, DrawableUtils.getPeachDots(getActivity(), "#000000"), dateList));

                }
            }
        }
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            Objects.requireNonNull(getActivity()).finish();
            getActivity().onBackPressed();
        }
        return super.onOptionsItemSelected(item);
    }

    private class DateWiseEventAdapter extends RecyclerView.Adapter<ViewHolder> {
        List<SingleDataList> mSingleDataLists;

        public DateWiseEventAdapter(List<SingleDataList> singleDataLists) {
            mSingleDataLists = singleDataLists;

        }

        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.events_view_holder, parent, false);
            return new ViewHolder(v);
        }

        @SuppressLint("SetTextI18n")
        @Override
        public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
            holder.txtName.setText(mSingleDataLists.get(position).getTitle());
            if (mSingleDataLists.get(position).getTrainingStatus() != null && !
                    mSingleDataLists.get(position).getTrainingStatus().equalsIgnoreCase(""))
                holder.ciricle.setBackgroundColor(Color.parseColor(mSingleDataLists.get(position).getTrainingStatus()));

            String startDate = mSingleDataLists.get(position).getStarttime();
            String endDate = mSingleDataLists.get(position).getEndtime();
            String startTime = "", endTime = "";

            try {
                JSONArray arrayFromTime = new JSONArray(startDate);
                for (int i = 0; i < arrayFromTime.length(); i++) {
                    startTime = (String) arrayFromTime.get(i);
                    Log.e("ID", startTime);
                }
                JSONArray arrayToTime = new JSONArray(endDate);
                for (int i = 0; i < arrayToTime.length(); i++) {
                    endTime = (String) arrayToTime.get(i);
                    Log.e("ID", endTime);
                }
            } catch (JSONException e) {
                e.printStackTrace();
                holder.txt_startDate.setText("Start Time : " + startDate);
                holder.endDate.setText("End Time      : " + endDate);
            }

//            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
//
//            try {
//                startDateString = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(Objects.requireNonNull(format.parse(startDate)));
//                endDateString = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(Objects.requireNonNull(format.parse(endDate)));
//            } catch (ParseException e) {
//                e.printStackTrace();
//            }

            holder.txt_startDate.setText("Start Time : " + startTime);
            holder.endDate.setText("End Time      : " + endTime);


            holder.btnOk.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GlobalData.CALPOS = position;

                    String endDate = mSingleDataLists.get(position).getEndDate();
                    String startDate = mSingleDataLists.get(position).getStartDate();

                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
                    String startDateString = "", endDateString = "", startDateFullString = "";
                    try {
                        startDateString = new SimpleDateFormat("dd", Locale.getDefault()).format(Objects.requireNonNull(format.parse(startDate)));
                        endDateString = new SimpleDateFormat("dd", Locale.getDefault()).format(Objects.requireNonNull(format.parse(endDate)));

                        startDateFullString = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(Objects.requireNonNull(format.parse(startDate)));

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

                    GlobalData.STARTDATESTRING = startDateFullString;

                    GlobalData.STARTDATE = Integer.parseInt(startDateString);
                    GlobalData.ENDDATE = Integer.parseInt(endDateString);

                    GlobalData.SCHEDULE_ID = mSingleDataLists.get(position).getScheduleId();

                    getScheduledList(mSingleDataLists.get(position).getScheduleId());

                    if (mBottomSheetBehavior1.getState() != BottomSheetBehavior.STATE_EXPANDED) {
                        mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_EXPANDED);
                    } else {
                        mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_HIDDEN);
                    }
                }
            });
        }

        @Override
        public int getItemCount() {
            return mSingleDataLists.size();
        }
    }

    private static class ViewHolder extends RecyclerView.ViewHolder {

        TextView txtName, txt_startDate, endDate;
        TextView ciricle;
        Button btnOk;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            ciricle = itemView.findViewById(R.id.ciricle);
            txtName = itemView.findViewById(R.id.txt_eventName);
            txt_startDate = itemView.findViewById(R.id.txt_startDate);
            endDate = itemView.findViewById(R.id.txt_endDate);
            btnOk = itemView.findViewById(R.id.btnOk);
        }
    }
}
