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 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<StatisticsItem> 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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<StatisticsItem> 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));
|
||||
|
||||
|
|
|
@ -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<Recycle
|
|||
private static final int TYPE_HEADER = 0;
|
||||
private static final int TYPE_FEED = 1;
|
||||
final Context context;
|
||||
private DBReader.StatisticsData statisticsData;
|
||||
private List<StatisticsItem> statisticsData;
|
||||
PieChartView.PieChartData pieChartData;
|
||||
|
||||
StatisticsListAdapter(Context context) {
|
||||
|
@ -33,14 +35,14 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
|||
|
||||
@Override
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
return statisticsData.feeds.get(position - 1);
|
||||
return statisticsData.get(position - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +71,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
|||
holder.totalTime.setText(getHeaderValue());
|
||||
} else {
|
||||
StatisticsHolder holder = (StatisticsHolder) h;
|
||||
DBReader.StatisticsItem statsItem = statisticsData.feeds.get(position - 1);
|
||||
StatisticsItem statsItem = statisticsData.get(position - 1);
|
||||
Glide.with(context)
|
||||
.load(statsItem.feed.getImageLocation())
|
||||
.apply(new RequestOptions()
|
||||
|
@ -86,8 +88,8 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
|||
}
|
||||
}
|
||||
|
||||
public void update(DBReader.StatisticsData statistics) {
|
||||
this.statisticsData = statistics;
|
||||
public void update(List<StatisticsItem> statistics) {
|
||||
statisticsData = statistics;
|
||||
pieChartData = generateChartData(statistics);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
@ -122,7 +124,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
|
|||
|
||||
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.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<StatisticsItem> statisticsData = DBReader.getStatistics();
|
||||
Collections.sort(statisticsData, (item1, item2) ->
|
||||
CompareCompat.compareLong(item1.totalDownloadSize, item2.totalDownloadSize));
|
||||
return statisticsData;
|
||||
})
|
||||
|
|
|
@ -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<StatisticsItem> fetchStatistics() {
|
||||
List<StatisticsItem> 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;
|
||||
|
|
|
@ -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<StatisticsItem> getStatistics() {
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
|
||||
long totalTimeCountAll = 0;
|
||||
long totalTime = 0;
|
||||
List<StatisticsItem> feedTime = new ArrayList<>();
|
||||
|
||||
List<Feed> 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<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;
|
||||
}
|
||||
return feedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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