Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use firebase with Android-week-View #580

Open
lobnaDev opened this issue Dec 30, 2021 · 2 comments
Open

use firebase with Android-week-View #580

lobnaDev opened this issue Dec 30, 2021 · 2 comments

Comments

@lobnaDev
Copy link

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; 
@anhduong1611
Copy link

do you have solution? Can yu help me?

@nlbien22
Copy link

nlbien22 commented Oct 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants