Merge pull request #3814 from ByteHamster/clean-up-statistics
Clean up statistics
This commit is contained in:
commit
c16385743c
|
@ -3,10 +3,12 @@ package de.danoeh.antennapod.adapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
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.core.util.Converter;
|
||||||
import de.danoeh.antennapod.view.PieChartView;
|
import de.danoeh.antennapod.view.PieChartView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter for the download statistics list.
|
* Adapter for the download statistics list.
|
||||||
*/
|
*/
|
||||||
|
@ -27,17 +29,17 @@ public class DownloadStatisticsListAdapter extends StatisticsListAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
PieChartView.PieChartData generateChartData(DBReader.StatisticsData statisticsData) {
|
PieChartView.PieChartData generateChartData(List<StatisticsItem> statisticsData) {
|
||||||
float[] dataValues = new float[statisticsData.feeds.size()];
|
float[] dataValues = new float[statisticsData.size()];
|
||||||
for (int i = 0; i < statisticsData.feeds.size(); i++) {
|
for (int i = 0; i < statisticsData.size(); i++) {
|
||||||
DBReader.StatisticsItem item = statisticsData.feeds.get(i);
|
StatisticsItem item = statisticsData.get(i);
|
||||||
dataValues[i] = item.totalDownloadSize;
|
dataValues[i] = item.totalDownloadSize;
|
||||||
}
|
}
|
||||||
return new PieChartView.PieChartData(dataValues);
|
return new PieChartView.PieChartData(dataValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBindFeedViewHolder(StatisticsHolder holder, DBReader.StatisticsItem item) {
|
void onBindFeedViewHolder(StatisticsHolder holder, StatisticsItem item) {
|
||||||
holder.value.setText(Converter.byteToString(item.totalDownloadSize));
|
holder.value.setText(Converter.byteToString(item.totalDownloadSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,12 @@ import android.content.Context;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
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.core.util.Converter;
|
||||||
import de.danoeh.antennapod.view.PieChartView;
|
import de.danoeh.antennapod.view.PieChartView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter for the playback statistics list.
|
* Adapter for the playback statistics list.
|
||||||
*/
|
*/
|
||||||
|
@ -34,17 +36,17 @@ public class PlaybackStatisticsListAdapter extends StatisticsListAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
PieChartView.PieChartData generateChartData(DBReader.StatisticsData statisticsData) {
|
PieChartView.PieChartData generateChartData(List<StatisticsItem> statisticsData) {
|
||||||
float[] dataValues = new float[statisticsData.feeds.size()];
|
float[] dataValues = new float[statisticsData.size()];
|
||||||
for (int i = 0; i < statisticsData.feeds.size(); i++) {
|
for (int i = 0; i < statisticsData.size(); i++) {
|
||||||
DBReader.StatisticsItem item = statisticsData.feeds.get(i);
|
StatisticsItem item = statisticsData.get(i);
|
||||||
dataValues[i] = countAll ? item.timePlayedCountAll : item.timePlayed;
|
dataValues[i] = countAll ? item.timePlayedCountAll : item.timePlayed;
|
||||||
}
|
}
|
||||||
return new PieChartView.PieChartData(dataValues);
|
return new PieChartView.PieChartData(dataValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBindFeedViewHolder(StatisticsHolder holder, DBReader.StatisticsItem statsItem) {
|
void onBindFeedViewHolder(StatisticsHolder holder, StatisticsItem statsItem) {
|
||||||
long time = countAll ? statsItem.timePlayedCountAll : statsItem.timePlayed;
|
long time = countAll ? statsItem.timePlayedCountAll : statsItem.timePlayed;
|
||||||
holder.value.setText(Converter.shortLocalizedDuration(context, time));
|
holder.value.setText(Converter.shortLocalizedDuration(context, time));
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,11 @@ import com.bumptech.glide.request.RequestOptions;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
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 de.danoeh.antennapod.view.PieChartView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent Adapter for the playback and download statistics list.
|
* Parent Adapter for the playback and download statistics list.
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +26,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
||||||
private static final int TYPE_HEADER = 0;
|
private static final int TYPE_HEADER = 0;
|
||||||
private static final int TYPE_FEED = 1;
|
private static final int TYPE_FEED = 1;
|
||||||
final Context context;
|
final Context context;
|
||||||
private DBReader.StatisticsData statisticsData;
|
private List<StatisticsItem> statisticsData;
|
||||||
PieChartView.PieChartData pieChartData;
|
PieChartView.PieChartData pieChartData;
|
||||||
|
|
||||||
StatisticsListAdapter(Context context) {
|
StatisticsListAdapter(Context context) {
|
||||||
|
@ -33,14 +35,14 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return statisticsData.feeds.size() + 1;
|
return statisticsData.size() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DBReader.StatisticsItem getItem(int position) {
|
public StatisticsItem getItem(int position) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return statisticsData.feeds.get(position - 1);
|
return statisticsData.get(position - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +71,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
||||||
holder.totalTime.setText(getHeaderValue());
|
holder.totalTime.setText(getHeaderValue());
|
||||||
} else {
|
} else {
|
||||||
StatisticsHolder holder = (StatisticsHolder) h;
|
StatisticsHolder holder = (StatisticsHolder) h;
|
||||||
DBReader.StatisticsItem statsItem = statisticsData.feeds.get(position - 1);
|
StatisticsItem statsItem = statisticsData.get(position - 1);
|
||||||
Glide.with(context)
|
Glide.with(context)
|
||||||
.load(statsItem.feed.getImageLocation())
|
.load(statsItem.feed.getImageLocation())
|
||||||
.apply(new RequestOptions()
|
.apply(new RequestOptions()
|
||||||
|
@ -86,8 +88,8 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(DBReader.StatisticsData statistics) {
|
public void update(List<StatisticsItem> statistics) {
|
||||||
this.statisticsData = statistics;
|
statisticsData = statistics;
|
||||||
pieChartData = generateChartData(statistics);
|
pieChartData = generateChartData(statistics);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
@ -122,7 +124,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
||||||
|
|
||||||
abstract String getHeaderValue();
|
abstract String getHeaderValue();
|
||||||
|
|
||||||
abstract PieChartView.PieChartData generateChartData(DBReader.StatisticsData statisticsData);
|
abstract PieChartView.PieChartData generateChartData(List<StatisticsItem> statisticsData);
|
||||||
|
|
||||||
abstract void onBindFeedViewHolder(StatisticsHolder holder, DBReader.StatisticsItem item);
|
abstract void onBindFeedViewHolder(StatisticsHolder holder, StatisticsItem item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.adapter.DownloadStatisticsListAdapter;
|
import de.danoeh.antennapod.adapter.DownloadStatisticsListAdapter;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
|
import de.danoeh.antennapod.core.storage.StatisticsItem;
|
||||||
import de.danoeh.antennapod.core.util.comparator.CompareCompat;
|
import de.danoeh.antennapod.core.util.comparator.CompareCompat;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
@ -23,6 +24,7 @@ import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the 'download statistics' screen
|
* Displays the 'download statistics' screen
|
||||||
|
@ -71,8 +73,8 @@ public class DownloadStatisticsFragment extends Fragment {
|
||||||
|
|
||||||
disposable =
|
disposable =
|
||||||
Observable.fromCallable(() -> {
|
Observable.fromCallable(() -> {
|
||||||
DBReader.StatisticsData statisticsData = DBReader.getStatistics();
|
List<StatisticsItem> statisticsData = DBReader.getStatistics();
|
||||||
Collections.sort(statisticsData.feeds, (item1, item2) ->
|
Collections.sort(statisticsData, (item1, item2) ->
|
||||||
CompareCompat.compareLong(item1.totalDownloadSize, item2.totalDownloadSize));
|
CompareCompat.compareLong(item1.totalDownloadSize, item2.totalDownloadSize));
|
||||||
return statisticsData;
|
return statisticsData;
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,6 +27,7 @@ import de.danoeh.antennapod.adapter.PlaybackStatisticsListAdapter;
|
||||||
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
|
import de.danoeh.antennapod.core.storage.StatisticsItem;
|
||||||
import de.danoeh.antennapod.core.util.comparator.CompareCompat;
|
import de.danoeh.antennapod.core.util.comparator.CompareCompat;
|
||||||
import io.reactivex.Completable;
|
import io.reactivex.Completable;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
@ -35,6 +36,7 @@ import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the 'playback statistics' screen
|
* Displays the 'playback statistics' screen
|
||||||
|
@ -180,13 +182,13 @@ public class PlaybackStatisticsFragment extends Fragment {
|
||||||
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DBReader.StatisticsData fetchStatistics() {
|
private List<StatisticsItem> fetchStatistics() {
|
||||||
DBReader.StatisticsData statisticsData = DBReader.getStatistics();
|
List<StatisticsItem> statisticsData = DBReader.getStatistics();
|
||||||
if (countAll) {
|
if (countAll) {
|
||||||
Collections.sort(statisticsData.feeds, (item1, item2) ->
|
Collections.sort(statisticsData, (item1, item2) ->
|
||||||
CompareCompat.compareLong(item1.timePlayedCountAll, item2.timePlayedCountAll));
|
CompareCompat.compareLong(item1.timePlayedCountAll, item2.timePlayedCountAll));
|
||||||
} else {
|
} else {
|
||||||
Collections.sort(statisticsData.feeds, (item1, item2) ->
|
Collections.sort(statisticsData, (item1, item2) ->
|
||||||
CompareCompat.compareLong(item1.timePlayed, item2.timePlayed));
|
CompareCompat.compareLong(item1.timePlayed, item2.timePlayed));
|
||||||
}
|
}
|
||||||
return statisticsData;
|
return statisticsData;
|
||||||
|
|
|
@ -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
|
@NonNull
|
||||||
public static StatisticsData getStatistics() {
|
public static List<StatisticsItem> getStatistics() {
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
|
|
||||||
long totalTimeCountAll = 0;
|
|
||||||
long totalTime = 0;
|
|
||||||
List<StatisticsItem> feedTime = new ArrayList<>();
|
List<StatisticsItem> feedTime = new ArrayList<>();
|
||||||
|
|
||||||
List<Feed> feeds = getFeedList();
|
List<Feed> feeds = getFeedList();
|
||||||
|
@ -922,72 +920,10 @@ public final class DBReader {
|
||||||
feedTime.add(new StatisticsItem(
|
feedTime.add(new StatisticsItem(
|
||||||
feed, feedTotalTime, feedPlayedTime, feedPlayedTimeCountAll, episodes,
|
feed, feedTotalTime, feedPlayedTime, feedPlayedTimeCountAll, episodes,
|
||||||
episodesStarted, episodesStartedIncludingMarked, totalDownloadSize));
|
episodesStarted, episodesStartedIncludingMarked, totalDownloadSize));
|
||||||
totalTime += feedPlayedTime;
|
|
||||||
totalTimeCountAll += feedPlayedTimeCountAll;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter.close();
|
adapter.close();
|
||||||
return new StatisticsData(totalTime, totalTimeCountAll, feedTime);
|
return 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<StatisticsItem> feeds;
|
|
||||||
|
|
||||||
public StatisticsData(long totalTime, long totalTimeCountAll, List<StatisticsItem> 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue