From 5989d6daf67a295ccd8e80ce6e40c570b743f779 Mon Sep 17 00:00:00 2001 From: Xavier Gouchet Date: Tue, 8 Oct 2019 19:48:26 +0200 Subject: [PATCH] Remove the unnecessary StatisticsEvent --- .../preferences/StatisticsFragment.java | 33 ++++++++----------- .../core/event/StatisticsEvent.java | 14 -------- .../antennapod/core/storage/DBWriter.java | 2 -- 3 files changed, 14 insertions(+), 35 deletions(-) delete mode 100644 core/src/main/java/de/danoeh/antennapod/core/event/StatisticsEvent.java diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/StatisticsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/StatisticsFragment.java index 2e6a3b5d5..265fd6e5e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/StatisticsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/StatisticsFragment.java @@ -20,15 +20,12 @@ import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; - import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.adapter.StatisticsListAdapter; -import de.danoeh.antennapod.core.event.StatisticsEvent; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; +import io.reactivex.Completable; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -72,11 +69,6 @@ public class StatisticsFragment extends Fragment { return root; } - @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - EventBus.getDefault().register(this); - } - @Override public void onStart() { super.onStart(); @@ -86,7 +78,6 @@ public class StatisticsFragment extends Fragment { @Override public void onDestroyView() { super.onDestroyView(); - EventBus.getDefault().unregister(this); if (disposable != null) { disposable.dispose(); } @@ -110,12 +101,6 @@ public class StatisticsFragment extends Fragment { return super.onOptionsItemSelected(item); } - @Subscribe - public void onEvent(StatisticsEvent event) { - Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); - refreshStatistics(); - } - private void selectStatisticsMode() { View contentView = View.inflate(getContext(), R.layout.statistics_mode_select_dialog, null); AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); @@ -133,15 +118,25 @@ public class StatisticsFragment extends Fragment { listAdapter.setCountAll(countAll); prefs.edit().putBoolean(PREF_COUNT_ALL, countAll).apply(); refreshStatistics(); + getActivity().invalidateOptionsMenu(); }); builder.show(); } private void resetStatistics() { - progressBar.setVisibility(View.VISIBLE); - feedStatisticsList.setVisibility(View.GONE); - DBWriter.resetStatistics(); + if (!countAll) { + progressBar.setVisibility(View.VISIBLE); + feedStatisticsList.setVisibility(View.GONE); + if (disposable != null) { + disposable.dispose(); + } + + disposable = Completable.fromFuture(DBWriter.resetStatistics()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(this::refreshStatistics, error -> Log.e(TAG, Log.getStackTraceString(error))); + } } private void refreshStatistics() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/event/StatisticsEvent.java b/core/src/main/java/de/danoeh/antennapod/core/event/StatisticsEvent.java deleted file mode 100644 index 15b44c2af..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/event/StatisticsEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.danoeh.antennapod.core.event; - -public class StatisticsEvent { - - public enum Action { - STATISTICS_UPDATED - } - - public final Action action; - - public StatisticsEvent(Action action) { - this.action = action; - } -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index 815eeeb50..2113679b9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -24,7 +24,6 @@ import de.danoeh.antennapod.core.event.FavoritesEvent; import de.danoeh.antennapod.core.event.FeedItemEvent; import de.danoeh.antennapod.core.event.MessageEvent; import de.danoeh.antennapod.core.event.QueueEvent; -import de.danoeh.antennapod.core.event.StatisticsEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedEvent; @@ -969,7 +968,6 @@ public class DBWriter { } } adapter.close(); - EventBus.getDefault().post(new StatisticsEvent(StatisticsEvent.Action.STATISTICS_UPDATED)); }); } }