diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2017-04-16 20:10:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-16 20:10:16 +0200 |
commit | 4a37d16e433843ac18c53b5bc27676f2073d7b4c (patch) | |
tree | 0004e1a1dec3aaff70b427daeae27ab3e8aa99eb /app | |
parent | 9542ef156989cefe9534f414f034195f8b717b8f (diff) | |
parent | 8f226803cbfeaee628ca5b745bab03a7293c84d1 (diff) | |
download | AntennaPod-4a37d16e433843ac18c53b5bc27676f2073d7b4c.zip |
Merge pull request #2294 from ByteHamster/stats-duration
Allow choosing between getDuration and getPlayedDuration
Diffstat (limited to 'app')
4 files changed, 103 insertions, 11 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/StatisticsActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/StatisticsActivity.java index 9bb8f8856..b2ff43c43 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/StatisticsActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/StatisticsActivity.java @@ -1,14 +1,18 @@ package de.danoeh.antennapod.activity; +import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.ProgressBar; +import android.widget.RadioButton; import android.widget.TextView; import de.danoeh.antennapod.R; @@ -28,12 +32,16 @@ public class StatisticsActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private static final String TAG = StatisticsActivity.class.getSimpleName(); + private static final String PREF_NAME = "StatisticsActivityPrefs"; + private static final String PREF_COUNT_ALL = "countAll"; private Subscription subscription; private TextView totalTimeTextView; private ListView feedStatisticsList; private ProgressBar progressBar; private StatisticsListAdapter listAdapter; + private boolean countAll = false; + private SharedPreferences prefs; @Override protected void onCreate(Bundle savedInstanceState) { @@ -42,10 +50,14 @@ public class StatisticsActivity extends AppCompatActivity getSupportActionBar().setDisplayShowHomeEnabled(true); setContentView(R.layout.statistics_activity); + prefs = getSharedPreferences(PREF_NAME, MODE_PRIVATE); + countAll = prefs.getBoolean(PREF_COUNT_ALL, false); + totalTimeTextView = (TextView) findViewById(R.id.total_time); feedStatisticsList = (ListView) findViewById(R.id.statistics_list); progressBar = (ProgressBar) findViewById(R.id.progressBar); listAdapter = new StatisticsListAdapter(this); + listAdapter.setCountAll(countAll); feedStatisticsList.setAdapter(listAdapter); feedStatisticsList.setOnItemClickListener(this); } @@ -53,10 +65,15 @@ public class StatisticsActivity extends AppCompatActivity @Override public void onResume() { super.onResume(); - progressBar.setVisibility(View.VISIBLE); - totalTimeTextView.setVisibility(View.GONE); - feedStatisticsList.setVisibility(View.GONE); - loadStats(); + refreshStatistics(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.statistics, menu); + return true; } @Override @@ -64,22 +81,54 @@ public class StatisticsActivity extends AppCompatActivity if (item.getItemId() == android.R.id.home) { finish(); return true; + } else if (item.getItemId() == R.id.statistics_mode) { + selectStatisticsMode(); + return true; } else { return super.onOptionsItemSelected(item); } } - private void loadStats() { - if(subscription != null) { + private void selectStatisticsMode() { + View contentView = View.inflate(this, R.layout.statistics_mode_select_dialog, null); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setView(contentView); + builder.setTitle(R.string.statistics_mode); + + if (countAll) { + ((RadioButton) contentView.findViewById(R.id.statistics_mode_count_all)).setChecked(true); + } else { + ((RadioButton) contentView.findViewById(R.id.statistics_mode_normal)).setChecked(true); + } + + builder.setPositiveButton(android.R.string.ok, (dialog, which) -> { + countAll = ((RadioButton) contentView.findViewById(R.id.statistics_mode_count_all)).isChecked(); + listAdapter.setCountAll(countAll); + prefs.edit().putBoolean(PREF_COUNT_ALL, countAll).apply(); + refreshStatistics(); + }); + + builder.show(); + } + + private void refreshStatistics() { + progressBar.setVisibility(View.VISIBLE); + totalTimeTextView.setVisibility(View.GONE); + feedStatisticsList.setVisibility(View.GONE); + loadStatistics(); + } + + private void loadStatistics() { + if (subscription != null) { subscription.unsubscribe(); } - subscription = Observable.fromCallable(() -> DBReader.getStatistics()) + subscription = Observable.fromCallable(() -> DBReader.getStatistics(countAll)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { if (result != null) { totalTimeTextView.setText(Converter - .shortLocalizedDuration(this, result.totalTime)); + .shortLocalizedDuration(this, countAll ? result.totalTimeCountAll : result.totalTime)); listAdapter.update(result.feedTime); progressBar.setVisibility(View.GONE); totalTimeTextView.setVisibility(View.VISIBLE); @@ -95,9 +144,10 @@ public class StatisticsActivity extends AppCompatActivity AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(stats.feed.getTitle()); dialog.setMessage(getString(R.string.statistics_details_dialog, - stats.episodesStarted, + countAll ? stats.episodesStartedIncludingMarked : stats.episodesStarted, stats.episodes, - Converter.shortLocalizedDuration(this, stats.timePlayed), + Converter.shortLocalizedDuration(this, countAll ? + stats.timePlayedCountAll : stats.timePlayed), Converter.shortLocalizedDuration(this, stats.time))); dialog.setPositiveButton(android.R.string.ok, null); dialog.show(); 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 fe891281b..c060083a6 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java @@ -25,11 +25,15 @@ import de.danoeh.antennapod.core.util.Converter; public class StatisticsListAdapter extends BaseAdapter { private Context context; List<DBReader.StatisticsItem> feedTime = new ArrayList<>(); + private boolean countAll = true; public StatisticsListAdapter(Context context) { this.context = context; } + public void setCountAll(boolean countAll) { + this.countAll = countAll; + } @Override public int getCount() { @@ -77,7 +81,8 @@ public class StatisticsListAdapter extends BaseAdapter { holder.title.setText(feed.getTitle()); holder.time.setText(Converter.shortLocalizedDuration(context, - feedTime.get(position).timePlayed)); + countAll ? feedTime.get(position).timePlayedCountAll + : feedTime.get(position).timePlayed)); return convertView; } diff --git a/app/src/main/res/layout/statistics_mode_select_dialog.xml b/app/src/main/res/layout/statistics_mode_select_dialog.xml new file mode 100644 index 000000000..8f8e1e657 --- /dev/null +++ b/app/src/main/res/layout/statistics_mode_select_dialog.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:padding="16dp"> + + <TextView + android:text="@string/statistics_speed_not_counted" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="16dp"/> + + <RadioButton + android:id="@+id/statistics_mode_normal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/statistics_mode_normal"/> + + <RadioButton + android:id="@+id/statistics_mode_count_all" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/statistics_mode_count_all"/> +</RadioGroup> diff --git a/app/src/main/res/menu/statistics.xml b/app/src/main/res/menu/statistics.xml new file mode 100644 index 000000000..6ecc70707 --- /dev/null +++ b/app/src/main/res/menu/statistics.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:custom="http://schemas.android.com/apk/res-auto"> + + <item + android:id="@+id/statistics_mode" + android:icon="?attr/ic_filter" + android:title="@string/statistics_mode" + custom:showAsAction="never"> + </item> + +</menu> |