summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod/adapter/PlaybackStatisticsListAdapter.java
blob: ce6ad2f835536eab56182761ac8eee2c5730cd24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package de.danoeh.antennapod.adapter;

import android.content.Context;
import androidx.appcompat.app.AlertDialog;

import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.util.Converter;

/**
 * Adapter for the playback statistics list
 */
public class PlaybackStatisticsListAdapter extends StatisticsListAdapter {

    boolean countAll = true;

    public PlaybackStatisticsListAdapter(Context context) {
        super(context);
    }

    public void setCountAll(boolean countAll) {
        this.countAll = countAll;
    }

    @Override
    int getHeaderCaptionResourceId() {
        return R.string.total_time_listened_to_podcasts;
    }

    @Override
    void onBindHeaderViewHolder(HeaderHolder holder) {
        long time = countAll ? statisticsData.totalTimeCountAll : statisticsData.totalTime;
        holder.totalTime.setText(Converter.shortLocalizedDuration(context, time));
        float[] dataValues = new float[statisticsData.feeds.size()];
        for (int i = 0; i < statisticsData.feeds.size(); i++) {
            DBReader.StatisticsItem item = statisticsData.feeds.get(i);
            dataValues[i] = countAll ? item.timePlayedCountAll : item.timePlayed;
        }
        holder.pieChart.setData(dataValues);
    }

    @Override
    void onBindFeedViewHolder(StatisticsHolder holder, int position) {
        DBReader.StatisticsItem statsItem = statisticsData.feeds.get(position - 1);
        long time = countAll ? statsItem.timePlayedCountAll : statsItem.timePlayed;
        holder.value.setText(Converter.shortLocalizedDuration(context, time));

        holder.itemView.setOnClickListener(v -> {
            AlertDialog.Builder dialog = new AlertDialog.Builder(context);
            dialog.setTitle(statsItem.feed.getTitle());
            dialog.setMessage(context.getString(R.string.statistics_details_dialog,
                    countAll ? statsItem.episodesStartedIncludingMarked : statsItem.episodesStarted,
                    statsItem.episodes, Converter.shortLocalizedDuration(context,
                            countAll ? statsItem.timePlayedCountAll : statsItem.timePlayed),
                    Converter.shortLocalizedDuration(context, statsItem.time)));
            dialog.setPositiveButton(android.R.string.ok, null);
            dialog.show();
        });
    }

}