alamkanak/Android-Week-View

use firebase with Android-week-View

lobnaDev opened this issue · 2 comments

I am trying to add events dynamically from Firebase , but I'm not able to display any events, , I stuck with problem and try many ways because onMonthChange called before executing firebase, please help guys.

private void RetriveAllAppointment(ArrayList<String> id_list) {
            mrefDatabase = FirebaseDatabase.getInstance().getReference("Appointments").child("Active");
            mrefDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    if (dataSnapshot.exists()) {
                        for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                         times_list = new ArrayList<>();
                                    for (DataSnapshot snapshot1 : snapshot.getChildren()) {
                       appointmantdate = snapshot.child("Date").getValue().toString();
                      selectedVenueName = snapshot.child("venueName").getValue().toString();
                                        if (snapshot.hasChild("times")) {
                                            for (DataSnapshot timesnapshot :snapshot.child("times").getChildren()) {
                                         String time = timesnapshot.getValue().toString();
                                         times_list.add(time);}
                                            CreateEvent(year, month);}

create event from data that come from firebase

 public void CreateEvent(int year, int month) {
            String[] separated = appointmantdate.split("-");
            int year_ = Integer.parseInt(separated[0]);
            int month_ = Integer.parseInt(separated[1]);
            int day = Integer.parseInt(separated[2]);
            for (int a = 0; a < times_list.size(); a++) {

                String[] timeSplit = times_list.get(a).split(":");
                int time_hour = Integer.parseInt(timeSplit[0]);
                int time_minute = Integer.parseInt(timeSplit[1]);

                Calendar startTime = Calendar.getInstance();
                startTime.set(Calendar.HOUR_OF_DAY, time_hour);
                startTime.set(Calendar.MINUTE, time_minute);
                startTime.set(Calendar.DAY_OF_MONTH, day);
                startTime.set(Calendar.MONTH, month_ - 1);
                startTime.set(Calendar.YEAR, year_);
                Calendar endTime = (Calendar) startTime.clone();

                String[] endtimeSplit = times_list.get(times_list.size() - 1).split(":");
                int endtime_hour = Integer.parseInt(endtimeSplit[0]);
                int endtime_minute = Integer.parseInt(endtimeSplit[1]);
                endTime.add(Calendar.HOUR, endtime_hour);
                startTime.set(Calendar.MINUTE, endtime_minute);
                endTime.set(Calendar.MONTH, month - 1);
                event = new WeekViewEvent(1, selectedVenueName, startTime, endTime);
                event.setColor(getActivity(). getResources().getColor(R.color.event_color_03));
                events.add(event);}
  onMonthChange method
@Override
  public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
      List<WeekViewEvent> lastone = new ArrayList<WeekViewEvent>();
      
      if (appointmantdate != null && times_list != null) {
        lastone = CreateEvent(newYear, newMonth);
          events.addAll(lastone);
      }
      ArrayList<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();
      for (WeekViewEvent event : events) {
          if (eventMatches(event, newYear, newMonth)) {
              matchedEvents.add(event);
          }
       return matchedEvents; 

do you have solution? Can yu help me?

do you have solution? Can yu help me?
Tui cũng bí yu