Merge pull request #2096 from domingos86/fix-cover-fragment

fix cover fragment onMediaChanged
This commit is contained in:
Martin Fietz 2016-10-02 23:33:48 +02:00 committed by GitHub
commit 8da8bf6af6
3 changed files with 24 additions and 23 deletions

View File

@ -69,10 +69,11 @@ public class ChaptersFragment extends ListFragment implements MediaplayerInfoCon
@Override @Override
public void onMediaChanged(Playable media) { public void onMediaChanged(Playable media) {
if(this.media == media || adapter == null) { if(this.media == media) {
return; return;
} }
this.media = media; this.media = media;
if (adapter != null) {
adapter.setMedia(media); adapter.setMedia(media);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
if(media == null || media.getChapters() == null || media.getChapters().size() == 0) { if(media == null || media.getChapters() == null || media.getChapters().size() == 0) {
@ -81,6 +82,7 @@ public class ChaptersFragment extends ListFragment implements MediaplayerInfoCon
setEmptyText(null); setEmptyText(null);
} }
} }
}
public void setController(PlaybackController controller) { public void setController(PlaybackController controller) {
this.controller = controller; this.controller = controller;

View File

@ -33,22 +33,15 @@ public class CoverFragment extends Fragment implements MediaplayerInfoContentFra
public static CoverFragment newInstance(Playable item) { public static CoverFragment newInstance(Playable item) {
CoverFragment f = new CoverFragment(); CoverFragment f = new CoverFragment();
if (item != null) { f.media = item;
Bundle args = new Bundle();
args.putParcelable(ARG_PLAYABLE, item);
f.setArguments(args);
}
return f; return f;
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Bundle args = getArguments(); if (media == null) {
if (args != null) { Log.e(TAG, TAG + " was called without media");
media = args.getParcelable(ARG_PLAYABLE);
} else {
Log.e(TAG, TAG + " was called with invalid arguments");
} }
} }
@ -98,11 +91,13 @@ public class CoverFragment extends Fragment implements MediaplayerInfoContentFra
@Override @Override
public void onMediaChanged(Playable media) { public void onMediaChanged(Playable media) {
if(!isAdded() || this.media == media) { if(this.media == media) {
return; return;
} }
this.media = media; this.media = media;
if (isAdded()) {
loadMediaInfo(); loadMediaInfo();
} }
}
} }

View File

@ -185,8 +185,10 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
Bundle args = getArguments(); Bundle args = getArguments();
if (args.containsKey(ARG_PLAYABLE)) { if (args.containsKey(ARG_PLAYABLE)) {
if (media == null) {
media = args.getParcelable(ARG_PLAYABLE); media = args.getParcelable(ARG_PLAYABLE);
shownotesProvider = media; shownotesProvider = media;
}
load(); load();
} else if (args.containsKey(ARG_FEEDITEM_ID)) { } else if (args.containsKey(ARG_FEEDITEM_ID)) {
long id = getArguments().getLong(ARG_FEEDITEM_ID); long id = getArguments().getLong(ARG_FEEDITEM_ID);
@ -377,12 +379,14 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
@Override @Override
public void onMediaChanged(Playable media) { public void onMediaChanged(Playable media) {
if(this.media == media || webvDescription == null) { if(this.media == media) {
return; return;
} }
this.media = media; this.media = media;
this.shownotesProvider = media; this.shownotesProvider = media;
if (webvDescription != null) {
load(); load();
} }
}
} }