diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index b4e8d4d71..e90681931 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -103,6 +103,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe protected void onStop() { super.onStop(); Log.d(TAG, "onStop()"); + pagerAdapter.setController(null); if(subscription != null) { subscription.unsubscribe(); } @@ -112,9 +113,13 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe @Override public void onDestroy() { + Log.d(TAG, "onDestroy()"); super.onDestroy(); // don't risk creating memory leaks + drawerLayout = null; navAdapter = null; + navList = null; + navDrawer = null; drawerToggle = null; pager = null; pagerAdapter = null; @@ -171,6 +176,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe if(pagerAdapter != null && controller != null && controller.getMedia() != media) { media = controller.getMedia(); pagerAdapter.onMediaChanged(media); + pagerAdapter.setController(controller); } EventDistributor.getInstance().register(contentUpdate); @@ -258,7 +264,8 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe }); pager = (ViewPager) findViewById(R.id.pager); - pagerAdapter = new AudioplayerPagerAdapter(getSupportFragmentManager()); + pagerAdapter = new AudioplayerPagerAdapter(getSupportFragmentManager(), media); + pagerAdapter.setController(controller); pager.setAdapter(pagerAdapter); CirclePageIndicator pageIndicator = (CirclePageIndicator) findViewById(R.id.page_indicator); pageIndicator.setViewPager(pager); @@ -537,10 +544,16 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe void onMediaChanged(Playable media); } - private class AudioplayerPagerAdapter extends FragmentStatePagerAdapter { + private static class AudioplayerPagerAdapter extends FragmentStatePagerAdapter { - public AudioplayerPagerAdapter(FragmentManager fm) { + private static final String TAG = "AudioplayerPagerAdapter"; + + private Playable media; + private PlaybackController controller; + + public AudioplayerPagerAdapter(FragmentManager fm, Playable media) { super(fm); + this.media = media; } private CoverFragment coverFragment; @@ -548,6 +561,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe private ChaptersFragment chaptersFragment; public void onMediaChanged(Playable media) { + this.media = media; if(coverFragment != null) { coverFragment.onMediaChanged(media); } @@ -559,6 +573,13 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe } } + public void setController(PlaybackController controller) { + this.controller = controller; + if(chaptersFragment != null) { + chaptersFragment.setController(controller); + } + } + @Nullable public ChaptersFragment getChaptersFragment() { return chaptersFragment; @@ -580,7 +601,8 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe return itemDescriptionFragment; case POS_CHAPTERS: if(chaptersFragment == null) { - chaptersFragment = ChaptersFragment.newInstance(media, controller); + chaptersFragment = ChaptersFragment.newInstance(media); + chaptersFragment.setController(controller); } return chaptersFragment; default: diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 48ed270cb..090085414 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -260,6 +260,7 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O Log.d(TAG, "onStop()"); if (controller != null) { controller.release(); + controller = null; // prevent leak } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java index 96abdd835..aea911f79 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.fragment; import android.os.Bundle; import android.support.v4.app.ListFragment; +import android.util.Log; import android.view.View; import android.widget.ListView; @@ -15,15 +16,16 @@ import de.danoeh.antennapod.core.util.playback.PlaybackController; public class ChaptersFragment extends ListFragment implements AudioplayerContentFragment { + private static final String TAG = "ChaptersFragment"; + private Playable media; private PlaybackController controller; private ChaptersListAdapter adapter; - public static ChaptersFragment newInstance(Playable media, PlaybackController controller) { + public static ChaptersFragment newInstance(Playable media) { ChaptersFragment f = new ChaptersFragment(); f.media = media; - f.controller = controller; return f; } @@ -37,6 +39,10 @@ public class ChaptersFragment extends ListFragment implements AudioplayerContent lv.setPadding(0, vertPadding, 0, vertPadding); adapter = new ChaptersListAdapter(getActivity(), 0, pos -> { + if(controller == null) { + Log.d(TAG, "controller is null"); + return; + } Chapter chapter = (Chapter) getListAdapter().getItem(pos); controller.seekToChapter(chapter); }); @@ -58,6 +64,7 @@ public class ChaptersFragment extends ListFragment implements AudioplayerContent public void onDestroy() { super.onDestroy(); adapter = null; + controller = null; } @Override @@ -74,4 +81,9 @@ public class ChaptersFragment extends ListFragment implements AudioplayerContent setEmptyText(null); } } + + public void setController(PlaybackController controller) { + this.controller = controller; + } + } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index c1c1aab6c..4a93bac7e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -111,7 +111,7 @@ public class ItemDescriptionFragment extends Fragment implements AudioplayerCont public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "Creating view"); - webvDescription = new WebView(getActivity()); + webvDescription = new WebView(getActivity().getApplicationContext()); if (Build.VERSION.SDK_INT >= 11) { webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null); }