Doubt when fetching data in Firebase and insert in MaterialCalendarView Android

0

Friends made an App for my wife that is nothing more than a calendar that stores the eyelash Extensions calls she makes, I use the Firebase RealTime Database, however over time the stored and returned data has been increasing, causing I am trying to get the data in an AsyncTask and even though it is heavy, I also tried to perform a local DB insertion with SQLite, so nothing, could friends help me?

Taking advantage, I search the bank every month selected in the calendar, so to fill all events, is it necessary to do this search every change or am I wrong? Maybe that's what slows down the process ..

Here are my search and insertion methods in the calendar:

    private void buscaAtendimentosParaCalendario(String mesAnoSelecionado) {
    System.out.println("Buscou eventos do calendario!!!");
    String idUsuario = retornaIdUsuario();
    usuarioRef = databaseRef.child("atendimento")
            .child(idUsuario)
            .child(mesAnoSelecionado);
    valueEventListenerUsuarioRef = usuarioRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot dados : dataSnapshot.getChildren()) {
                Atendimento atendimento = dados.getValue(Atendimento.class);
                saldoMensal = saldoMensal + atendimento.getValor();
                System.out.println("Busquei atendimento para o calendário");
                System.out.println("dia da semana ===== >>>" + atendimento.getDiaDaSemana() + " Dia do mes == " + atendimento.getDia());
                String textoData = atendimento.getData();
                String dataArray[] = textoData.split("/");
                diaInseridoNoCalendario = CalendarDay.from(Integer.valueOf(dataArray[2]),
                        Integer.valueOf(dataArray[1]) - 1,
                        Integer.valueOf(dataArray[0]));
                System.out.println(atendimento.getValor());
                insereEventoNoCalendario(diaInseridoNoCalendario);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });}

private void selecionaMesAtendimento() {
    calendarView.setOnMonthChangedListener(new OnMonthChangedListener() {
        @Override
        public void onMonthChanged(MaterialCalendarView materialCalendarView, CalendarDay calendarDay) {
            String mesSelecionado = String.format("%d", (calendarDay.getMonth() + 1));
            mesAnoSelecionado = String.valueOf(mesSelecionado + "" + calendarDay.getYear());
            buscaAtendimentosParaCalendario(mesAnoSelecionado);

        }
    });
}

public void insereEventoNoCalendario(CalendarDay calendarDay) {
    data.add(calendarDay);
    calendarView.addDecorators(new EventDecorator(getResources().getColor(R.color.colorPrimary), data));
}
    
asked by anonymous 14.12.2018 / 18:38

0 answers