diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2018-08-06 23:38:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-06 23:38:37 +0200 |
commit | 1d265a9c3a6f72c0e1455dd4381505b8bee02b3f (patch) | |
tree | 9bae77cdba6dd133fc49796b23e9852b1a938d1a /core | |
parent | 3d61002d88c880dfe02c95836f21f8fccbabec90 (diff) | |
download | AntennaPod-1d265a9c3a6f72c0e1455dd4381505b8bee02b3f.zip |
Database access threading (#2781)
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java | 6 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java | 33 |
2 files changed, 24 insertions, 15 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 574e43faa..a7c01e43a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -263,6 +263,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { Log.d(TAG, "Service created."); isRunning = true; + NotificationCompat.Builder notificationBuilder = createBasicNotification(); + startForeground(NOTIFICATION_ID, notificationBuilder.build()); + registerReceiver(autoStateUpdated, new IntentFilter("com.google.android.gms.car.media.STATUS")); registerReceiver(headsetDisconnected, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); registerReceiver(shutdownReceiver, new IntentFilter(ACTION_SHUTDOWN_PLAYBACK_SERVICE)); @@ -311,11 +314,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { } flavorHelper.initializeMediaPlayer(PlaybackService.this); - mediaSession.setActive(true); - NotificationCompat.Builder notificationBuilder = createBasicNotification(); - startForeground(NOTIFICATION_ID, notificationBuilder.build()); EventBus.getDefault().post(new ServiceEvent(ServiceEvent.Action.SERVICE_STARTED)); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index a3f02d5cc..31067839a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -42,9 +42,12 @@ import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.playback.Playable.PlayableUtils; +import rx.Completable; import rx.Observable; +import rx.Single; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; +import rx.observers.Subscribers; import rx.schedulers.Schedulers; /** @@ -780,18 +783,24 @@ public abstract class PlaybackController { } private void initServiceNotRunning() { - if (getMedia() == null) { - return; - } - if (getMedia().getMediaType() == MediaType.AUDIO) { - TypedArray res = activity.obtainStyledAttributes(new int[]{ - de.danoeh.antennapod.core.R.attr.av_play_big}); - getPlayButton().setImageResource( - res.getResourceId(0, de.danoeh.antennapod.core.R.drawable.ic_play_arrow_grey600_36dp)); - res.recycle(); - } else { - getPlayButton().setImageResource(R.drawable.ic_av_play_circle_outline_80dp); - } + Single.create(subscriber -> subscriber.onSuccess(getMedia())) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe((Object media) -> { + if (media == null) { + return; + } + + if (((Playable) media).getMediaType() == MediaType.AUDIO) { + TypedArray res = activity.obtainStyledAttributes(new int[]{ + de.danoeh.antennapod.core.R.attr.av_play_big}); + getPlayButton().setImageResource( + res.getResourceId(0, de.danoeh.antennapod.core.R.drawable.ic_play_arrow_grey600_36dp)); + res.recycle(); + } else { + getPlayButton().setImageResource(R.drawable.ic_av_play_circle_outline_80dp); + } + }); } /** |