Untitled

mail@pastecode.io avatar
unknown
java
3 years ago
3.3 kB
2
Indexable
findViewById(R.id.buttonBarChart).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //startActivity(new Intent(getApplicationContext(), BarChartActivity.class));

                String curUserID = FirebaseAuth.getInstance().getUid();

                new DaysHelper(curUserID).calculateAvgScores(new DaysHelper.GetAvgScores() {
                    @Override
                    public void avgScoresLoaded(int avgSleepScore, int avgFoodScore, int avgMoodScore, List<Days> allDays, List<Days> daysRelatedToUser) {
                        Bundle bundle = new Bundle();

                        ArrayList<Integer> sleepScores = new ArrayList<Integer>();
                        ArrayList<Integer> foodScores = new ArrayList<Integer>();
                        ArrayList<Integer> moodScores = new ArrayList<Integer>();

                        for(Days d : daysRelatedToUser)
                        {

                            int counter = 0;
                            int dailyAvg = 0;
                            for(int i = 1; i < d.getSleepScores().size(); i++)
                            {
                                dailyAvg += d.getSleepScores().get(i);
                                counter++;
                            }

                            int avgScoreForDay = 0;
                            if(counter != 0) {
                                avgScoreForDay = dailyAvg / counter;
                            }

                            sleepScores.add(avgScoreForDay);

                            counter = 0;
                            dailyAvg = 0;
                            for(int i = 1; i < d.getFoodScores().size(); i++)
                            {
                                dailyAvg += d.getFoodScores().get(i);
                                counter++;
                            }

                            avgScoreForDay = 0;
                            if(counter != 0) {
                                avgScoreForDay = dailyAvg / counter;
                            }

                            foodScores.add(avgScoreForDay);

                            for(int i = 1; i < d.getMoodScores().size(); i++)
                            {
                                dailyAvg += d.getMoodScores().get(i);
                                counter++;
                            }

                            avgScoreForDay = 0;
                            if(counter != 0) {
                                avgScoreForDay = dailyAvg / counter;
                            }

                            moodScores.add(avgScoreForDay);
                        }

                        bundle.putIntegerArrayList("SleepScores", sleepScores);
                        bundle.putIntegerArrayList("FoodScores", foodScores);
                        bundle.putIntegerArrayList("MoodScores", moodScores);

                        Intent newIntent = new Intent(getApplicationContext(), BarChartActivity.class);
                        newIntent.putExtras(bundle);
                        startActivity(newIntent);
                    }
                });

            }
        });