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

Commit

Permalink
Dispose of disposables when service is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
timusus committed Oct 30, 2019
1 parent 41506e0 commit e920dcd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.simplecity.amp_library.utils.PlaceholderProvider;
import com.simplecity.amp_library.utils.PlaylistUtils;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import java.util.ConcurrentModificationException;

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

private Handler handler;

private CompositeDisposable compositeDisposable = new CompositeDisposable();

public MusicNotificationHelper(Context context) {
super(context);

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

PlaylistUtils.isFavorite(song)
compositeDisposable.add(PlaylistUtils.isFavorite(song)
.first(false)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand All @@ -116,7 +119,7 @@ public void notify(Context context, @NonNull Song song, boolean isPlaying, @NonN
notify(notification);
}, error -> {
LogUtils.logException(TAG, "MusicNotificationHelper failed to present notification", error);
});
}));

handler.post(() -> Glide.with(context)
.load(song)
Expand Down Expand Up @@ -172,4 +175,8 @@ public void notify(Notification notification) {
public void cancel() {
super.cancel(NOTIFICATION_ID);
}

public void tearDown() {
compositeDisposable.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ public void onDestroy() {
playbackManager.destroy();

dummyNotificationHelper.teardown(this);
notificationHelper.tearDown();

disposables.clear();

Expand Down

0 comments on commit e920dcd

Please sign in to comment.