diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadStatisticsListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadStatisticsListAdapter.java index 227eea6e0..c49d2f39d 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadStatisticsListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadStatisticsListAdapter.java @@ -3,10 +3,12 @@ package de.danoeh.antennapod.adapter; import android.content.Context; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.StatisticsItem; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.view.PieChartView; +import java.util.List; + /** * Adapter for the download statistics list. */ @@ -27,17 +29,17 @@ public class DownloadStatisticsListAdapter extends StatisticsListAdapter { } @Override - PieChartView.PieChartData generateChartData(DBReader.StatisticsData statisticsData) { - float[] dataValues = new float[statisticsData.feeds.size()]; - for (int i = 0; i < statisticsData.feeds.size(); i++) { - DBReader.StatisticsItem item = statisticsData.feeds.get(i); + PieChartView.PieChartData generateChartData(List statisticsData) { + float[] dataValues = new float[statisticsData.size()]; + for (int i = 0; i < statisticsData.size(); i++) { + StatisticsItem item = statisticsData.get(i); dataValues[i] = item.totalDownloadSize; } return new PieChartView.PieChartData(dataValues); } @Override - void onBindFeedViewHolder(StatisticsHolder holder, DBReader.StatisticsItem item) { + void onBindFeedViewHolder(StatisticsHolder holder, StatisticsItem item) { holder.value.setText(Converter.byteToString(item.totalDownloadSize)); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/PlaybackStatisticsListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/PlaybackStatisticsListAdapter.java index 8471569d3..c5a73c53e 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/PlaybackStatisticsListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/PlaybackStatisticsListAdapter.java @@ -4,10 +4,12 @@ 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.storage.StatisticsItem; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.view.PieChartView; +import java.util.List; + /** * Adapter for the playback statistics list. */ @@ -34,17 +36,17 @@ public class PlaybackStatisticsListAdapter extends StatisticsListAdapter { } @Override - PieChartView.PieChartData generateChartData(DBReader.StatisticsData statisticsData) { - float[] dataValues = new float[statisticsData.feeds.size()]; - for (int i = 0; i < statisticsData.feeds.size(); i++) { - DBReader.StatisticsItem item = statisticsData.feeds.get(i); + PieChartView.PieChartData generateChartData(List statisticsData) { + float[] dataValues = new float[statisticsData.size()]; + for (int i = 0; i < statisticsData.size(); i++) { + StatisticsItem item = statisticsData.get(i); dataValues[i] = countAll ? item.timePlayedCountAll : item.timePlayed; } return new PieChartView.PieChartData(dataValues); } @Override - void onBindFeedViewHolder(StatisticsHolder holder, DBReader.StatisticsItem statsItem) { + void onBindFeedViewHolder(StatisticsHolder holder, StatisticsItem statsItem) { long time = countAll ? statsItem.timePlayedCountAll : statsItem.timePlayed; holder.value.setText(Converter.shortLocalizedDuration(context, time)); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java index db65190f2..5f019d1db 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java @@ -14,9 +14,11 @@ import com.bumptech.glide.request.RequestOptions; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.glide.ApGlideSettings; -import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.StatisticsItem; import de.danoeh.antennapod.view.PieChartView; +import java.util.List; + /** * Parent Adapter for the playback and download statistics list. */ @@ -24,7 +26,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter statisticsData; PieChartView.PieChartData pieChartData; StatisticsListAdapter(Context context) { @@ -33,14 +35,14 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter statistics) { + statisticsData = statistics; pieChartData = generateChartData(statistics); notifyDataSetChanged(); } @@ -122,7 +124,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter statisticsData); - abstract void onBindFeedViewHolder(StatisticsHolder holder, DBReader.StatisticsItem item); + abstract void onBindFeedViewHolder(StatisticsHolder holder, StatisticsItem item); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadStatisticsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadStatisticsFragment.java index 34ea6d6e3..3059d7ad2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadStatisticsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/DownloadStatisticsFragment.java @@ -16,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.DownloadStatisticsListAdapter; import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.StatisticsItem; import de.danoeh.antennapod.core.util.comparator.CompareCompat; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -23,6 +24,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import java.util.Collections; +import java.util.List; /** * Displays the 'download statistics' screen @@ -71,8 +73,8 @@ public class DownloadStatisticsFragment extends Fragment { disposable = Observable.fromCallable(() -> { - DBReader.StatisticsData statisticsData = DBReader.getStatistics(); - Collections.sort(statisticsData.feeds, (item1, item2) -> + List statisticsData = DBReader.getStatistics(); + Collections.sort(statisticsData, (item1, item2) -> CompareCompat.compareLong(item1.totalDownloadSize, item2.totalDownloadSize)); return statisticsData; }) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackStatisticsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackStatisticsFragment.java index bed767e8e..d25dff743 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackStatisticsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackStatisticsFragment.java @@ -27,6 +27,7 @@ import de.danoeh.antennapod.adapter.PlaybackStatisticsListAdapter; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.core.storage.StatisticsItem; import de.danoeh.antennapod.core.util.comparator.CompareCompat; import io.reactivex.Completable; import io.reactivex.Observable; @@ -35,6 +36,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import java.util.Collections; +import java.util.List; /** * Displays the 'playback statistics' screen @@ -180,13 +182,13 @@ public class PlaybackStatisticsFragment extends Fragment { }, error -> Log.e(TAG, Log.getStackTraceString(error))); } - private DBReader.StatisticsData fetchStatistics() { - DBReader.StatisticsData statisticsData = DBReader.getStatistics(); + private List fetchStatistics() { + List statisticsData = DBReader.getStatistics(); if (countAll) { - Collections.sort(statisticsData.feeds, (item1, item2) -> + Collections.sort(statisticsData, (item1, item2) -> CompareCompat.compareLong(item1.timePlayedCountAll, item2.timePlayedCountAll)); } else { - Collections.sort(statisticsData.feeds, (item1, item2) -> + Collections.sort(statisticsData, (item1, item2) -> CompareCompat.compareLong(item1.timePlayed, item2.timePlayed)); } return statisticsData; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index e6d21794c..e2da40ec3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -866,17 +866,15 @@ public final class DBReader { } /** - * Searches the DB for statistics + * Searches the DB for statistics. * - * @return The StatisticsInfo object + * @return The list of statistics objects */ @NonNull - public static StatisticsData getStatistics() { + public static List getStatistics() { PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); - long totalTimeCountAll = 0; - long totalTime = 0; List feedTime = new ArrayList<>(); List feeds = getFeedList(); @@ -922,72 +920,10 @@ public final class DBReader { feedTime.add(new StatisticsItem( feed, feedTotalTime, feedPlayedTime, feedPlayedTimeCountAll, episodes, episodesStarted, episodesStartedIncludingMarked, totalDownloadSize)); - totalTime += feedPlayedTime; - totalTimeCountAll += feedPlayedTimeCountAll; } adapter.close(); - return new StatisticsData(totalTime, totalTimeCountAll, feedTime); - } - - public static class StatisticsData { - /** - * Simply sums up time of podcasts that are marked as played - */ - public final long totalTimeCountAll; - - /** - * Respects speed, listening twice, ... - */ - public final long totalTime; - - public final List feeds; - - public StatisticsData(long totalTime, long totalTimeCountAll, List feeds) { - this.totalTime = totalTime; - this.totalTimeCountAll = totalTimeCountAll; - this.feeds = feeds; - } - } - - public static class StatisticsItem { - public final Feed feed; - public final long time; - - /** - * Respects speed, listening twice, ... - */ - public final long timePlayed; - /** - * Simply sums up time of podcasts that are marked as played - */ - public final long timePlayedCountAll; - public final long episodes; - /** - * Episodes that are actually played - */ - public final long episodesStarted; - /** - * All episodes that are marked as played (or have position != 0) - */ - public final long episodesStartedIncludingMarked; - /** - * Simply sums up the size of download podcasts - */ - public final long totalDownloadSize; - - public StatisticsItem(Feed feed, long time, long timePlayed, long timePlayedCountAll, - long episodes, long episodesStarted, long episodesStartedIncludingMarked, - long totalDownloadSize) { - this.feed = feed; - this.time = time; - this.timePlayed = timePlayed; - this.timePlayedCountAll = timePlayedCountAll; - this.episodes = episodes; - this.episodesStarted = episodesStarted; - this.episodesStartedIncludingMarked = episodesStartedIncludingMarked; - this.totalDownloadSize = totalDownloadSize; - } + return feedTime; } /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/StatisticsItem.java b/core/src/main/java/de/danoeh/antennapod/core/storage/StatisticsItem.java new file mode 100644 index 000000000..f96af185b --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/StatisticsItem.java @@ -0,0 +1,51 @@ +package de.danoeh.antennapod.core.storage; + +import de.danoeh.antennapod.core.feed.Feed; + +public class StatisticsItem { + public final Feed feed; + public final long time; + + /** + * Respects speed, listening twice, ... + */ + public final long timePlayed; + + /** + * Simply sums up time of podcasts that are marked as played. + */ + public final long timePlayedCountAll; + + /** + * Number of episodes. + */ + public final long episodes; + + /** + * Episodes that are actually played. + */ + public final long episodesStarted; + + /** + * All episodes that are marked as played (or have position != 0). + */ + public final long episodesStartedIncludingMarked; + + /** + * Simply sums up the size of download podcasts. + */ + public final long totalDownloadSize; + + public StatisticsItem(Feed feed, long time, long timePlayed, long timePlayedCountAll, + long episodes, long episodesStarted, long episodesStartedIncludingMarked, + long totalDownloadSize) { + this.feed = feed; + this.time = time; + this.timePlayed = timePlayed; + this.timePlayedCountAll = timePlayedCountAll; + this.episodes = episodes; + this.episodesStarted = episodesStarted; + this.episodesStartedIncludingMarked = episodesStartedIncludingMarked; + this.totalDownloadSize = totalDownloadSize; + } +}