Automatically highlight date inside CompactCalendarView from Firebase database

Viewed 76

I am using CompactCalendarView for adding calendar to my events activity. With the code Event ev1 = new Event(Color.BLUE, 1621468800000L);compactCalendar.addEvent(ev1); i can add highlight below the date as it shown it screenshot below. It uses date in milliseconds converted to long to highlight date. I also added onDayClick class to open new activity after date is pressed.

highlighted date

Now i'm using Google Firebase. And successfully added FireBaseAdapter to display database content. So, here is my question, how can i make CompactCalendarView to pick a "dateInMilliseconds" from my database and use it to highlight date.

public class Events extends AppCompatActivity {

    private static final String TAG = "Calendar";
    private CalendarView mCalendarView;
    CompactCalendarView compactCalendar;
    private SimpleDateFormat dateFormatMonth = new SimpleDateFormat("dd.MMMM.yyyy", Locale.getDefault());
    RecyclerView eventsRecycler;
    EventsAdapter eventsAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_events);
        
        eventsRecycler = findViewById(R.id.eventsRecycler);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setReverseLayout(true);
        linearLayoutManager.setStackFromEnd(true);
        eventsRecycler.setLayoutManager(linearLayoutManager);

        FirebaseRecyclerOptions<EventsItem> options =
                new FirebaseRecyclerOptions.Builder<EventsItem>().setQuery(FirebaseDatabase.getInstance().getReference().child("events"), EventsItem.class).build();

        eventsAdapter = new EventsAdapter(options, this);
        eventsRecycler.setAdapter(eventsAdapter);

        compactCalendar = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
        compactCalendar.setUseThreeLetterAbbreviation(true);
        compactCalendar.displayOtherMonthDays(true);
        compactCalendar.shouldDrawIndicatorsBelowSelectedDays(true);

        Event ev1 = new Event(Color.BLUE, 1621468800000L);
        compactCalendar.addEvent(ev1);
        Event ev2 = new Event(Color.BLUE, 1621900800000L);
        compactCalendar.addEvent(ev2);

        compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
            @Override
            public void onDayClick(Date dateClicked) {
                Context context = getApplicationContext();

                if (dateClicked.toString().compareTo("Tue May 25 00:00:00 GMT+06:00 2021") == 0) {
                    Intent intent = new Intent(Events.this, placeholder.class);
                    startActivity(intent);
                }
                if (dateClicked.toString().compareTo("Thu May 20 00:00:00 GMT+06:00 2021") == 0) {
                    Intent intent = new Intent(Events.this, placeholder.class);
                    startActivity(intent);
                }
            }
        });
    }

If its not possible with CompactCalendarView, what else can i use to achieve my goal?

0 Answers
Related