Making sure that ExternalPlayerFragment is updated when starting first media

This commit is contained in:
ByteHamster 2019-04-11 20:41:39 +02:00
parent 5745da75a6
commit 1d0e22135e
2 changed files with 27 additions and 20 deletions

View File

@ -776,15 +776,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
loadData(); loadData();
} }
public void onEventMainThread(ServiceEvent event) {
Log.d(TAG, "onEvent(" + event + ")");
switch(event.action) {
case SERVICE_STARTED:
externalPlayerFragment.connectToPlaybackService();
break;
}
}
public void onEventMainThread(ProgressEvent event) { public void onEventMainThread(ProgressEvent event) {
Log.d(TAG, "onEvent(" + event + ")"); Log.d(TAG, "onEvent(" + event + ")");
switch(event.action) { switch(event.action) {

View File

@ -18,11 +18,13 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.event.ServiceEvent;
import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.feed.MediaType;
import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.ApGlideSettings;
import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.greenrobot.event.EventBus;
import io.reactivex.Maybe; import io.reactivex.Maybe;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
@ -90,9 +92,12 @@ public class ExternalPlayerFragment extends Fragment {
loadMediaInfo(); loadMediaInfo();
} }
public void connectToPlaybackService() { public void onEventMainThread(ServiceEvent event) {
Log.d(TAG, "onEvent(" + event + ")");
if (event.action == ServiceEvent.Action.SERVICE_STARTED) {
controller.init(); controller.init();
} }
}
private PlaybackController setupPlaybackController() { private PlaybackController setupPlaybackController() {
return new PlaybackController(getActivity(), true) { return new PlaybackController(getActivity(), true) {
@ -109,12 +114,12 @@ public class ExternalPlayerFragment extends Fragment {
@Override @Override
public boolean loadMediaInfo() { public boolean loadMediaInfo() {
ExternalPlayerFragment fragment = ExternalPlayerFragment.this; return ExternalPlayerFragment.this.loadMediaInfo();
if (fragment != null) {
return fragment.loadMediaInfo();
} else {
return false;
} }
@Override
public void setupGUI() {
ExternalPlayerFragment.this.loadMediaInfo();
} }
@Override @Override
@ -133,17 +138,28 @@ public class ExternalPlayerFragment extends Fragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
onPositionObserverUpdate(); onPositionObserverUpdate();
}
@Override
public void onStart() {
super.onStart();
controller.init(); controller.init();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
if (controller != null) {
controller.release();
}
EventBus.getDefault().unregister(this);
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
Log.d(TAG, "Fragment is about to be destroyed"); Log.d(TAG, "Fragment is about to be destroyed");
if (controller != null) {
controller.release();
}
if (disposable != null) { if (disposable != null) {
disposable.dispose(); disposable.dispose();
} }