Skip to content
This repository was archived by the owner on Dec 28, 2022. It is now read-only.

Commit e920dcd

Browse files
committed
Dispose of disposables when service is destroyed
1 parent 41506e0 commit e920dcd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

app/src/main/java/com/simplecity/amp_library/notifications/MusicNotificationHelper.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.simplecity.amp_library.utils.PlaceholderProvider;
3232
import com.simplecity.amp_library.utils.PlaylistUtils;
3333
import io.reactivex.android.schedulers.AndroidSchedulers;
34+
import io.reactivex.disposables.CompositeDisposable;
3435
import io.reactivex.schedulers.Schedulers;
3536
import java.util.ConcurrentModificationException;
3637

@@ -48,6 +49,8 @@ public class MusicNotificationHelper extends NotificationHelper {
4849

4950
private Handler handler;
5051

52+
private CompositeDisposable compositeDisposable = new CompositeDisposable();
53+
5154
public MusicNotificationHelper(Context context) {
5255
super(context);
5356

@@ -106,7 +109,7 @@ public void notify(Context context, @NonNull Song song, boolean isPlaying, @NonN
106109
notification = getBuilder(context, song, mediaSessionToken, bitmap, isPlaying, isFavorite).build();
107110
notify(NOTIFICATION_ID, notification);
108111

109-
PlaylistUtils.isFavorite(song)
112+
compositeDisposable.add(PlaylistUtils.isFavorite(song)
110113
.first(false)
111114
.subscribeOn(Schedulers.io())
112115
.observeOn(AndroidSchedulers.mainThread())
@@ -116,7 +119,7 @@ public void notify(Context context, @NonNull Song song, boolean isPlaying, @NonN
116119
notify(notification);
117120
}, error -> {
118121
LogUtils.logException(TAG, "MusicNotificationHelper failed to present notification", error);
119-
});
122+
}));
120123

121124
handler.post(() -> Glide.with(context)
122125
.load(song)
@@ -172,4 +175,8 @@ public void notify(Notification notification) {
172175
public void cancel() {
173176
super.cancel(NOTIFICATION_ID);
174177
}
178+
179+
public void tearDown() {
180+
compositeDisposable.clear();
181+
}
175182
}

app/src/main/java/com/simplecity/amp_library/playback/MusicService.java

+1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public void onDestroy() {
281281
playbackManager.destroy();
282282

283283
dummyNotificationHelper.teardown(this);
284+
notificationHelper.tearDown();
284285

285286
disposables.clear();
286287

0 commit comments

Comments
 (0)