From fcb35a403f5b8904b22427f6b6ee2ae8bc81dc50 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Tue, 22 Mar 2016 13:24:09 -0400 Subject: [PATCH] remove reference to MainActivity instance --- .../fragment/AllEpisodesFragment.java | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index c562d5559..335cf5414 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.fragment; -import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; @@ -24,7 +23,6 @@ import android.widget.Toast; import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; import java.util.List; -import java.util.concurrent.atomic.AtomicReference; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; @@ -81,8 +79,6 @@ public class AllEpisodesFragment extends Fragment { private boolean itemsLoaded = false; private boolean viewsCreated = false; - private AtomicReference activity = new AtomicReference<>(); - private boolean isUpdatingFeeds; protected Subscription subscription; @@ -101,7 +97,6 @@ public class AllEpisodesFragment extends Fragment { public void onStart() { super.onStart(); EventDistributor.getInstance().register(contentUpdate); - this.activity.set((MainActivity) getActivity()); if (viewsCreated && itemsLoaded) { onFragmentLoaded(); } @@ -132,12 +127,6 @@ public class AllEpisodesFragment extends Fragment { } } - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - this.activity.set((MainActivity) getActivity()); - } - @Override public void onDestroyView() { super.onDestroyView(); @@ -176,18 +165,13 @@ public class AllEpisodesFragment extends Fragment { } protected void resetViewState() { - listAdapter = null; - activity.set(null); viewsCreated = false; + listAdapter = null; } - private final MenuItemUtils.UpdateRefreshMenuItemChecker updateRefreshMenuItemChecker = new MenuItemUtils.UpdateRefreshMenuItemChecker() { - @Override - public boolean isRefreshing() { - return DownloadService.isRunning && DownloadRequester.getInstance().isDownloadingFeeds(); - } - }; + private final MenuItemUtils.UpdateRefreshMenuItemChecker updateRefreshMenuItemChecker = + () -> DownloadService.isRunning && DownloadRequester.getInstance().isDownloadingFeeds(); @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { @@ -325,7 +309,7 @@ public class AllEpisodesFragment extends Fragment { viewsCreated = true; - if (itemsLoaded && activity.get() != null) { + if (itemsLoaded) { onFragmentLoaded(); } @@ -334,7 +318,7 @@ public class AllEpisodesFragment extends Fragment { private void onFragmentLoaded() { if (listAdapter == null) { - MainActivity mainActivity = activity.get(); + MainActivity mainActivity = (MainActivity) getActivity(); listAdapter = new AllEpisodesRecycleAdapter(mainActivity, itemAccess, new DefaultActionButtonCallback(mainActivity), showOnlyNewEpisodes()); listAdapter.setHasStableIds(true); @@ -477,7 +461,7 @@ public class AllEpisodesFragment extends Fragment { if (data != null) { episodes = data; itemsLoaded = true; - if (viewsCreated && activity.get() != null) { + if (viewsCreated) { onFragmentLoaded(); } }