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

Commit

Permalink
Another attempt to fix playlist related crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
timusus committed Apr 8, 2020
1 parent 4965d46 commit 505206a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ public Observable<List<Playlist>> getPlaylistsRelay() {
playlistsSubscription = SqlBriteUtils.createObservableList(ShuttleApplication.getInstance(), Playlist::new, Playlist.getQuery())
.subscribe(playlistsRelay, error -> LogUtils.logException(TAG, "getPlaylistRelay threw error", error));
}
return playlistsRelay.subscribeOn(Schedulers.io()).map(ArrayList::new);
return playlistsRelay
.distinctUntilChanged()
.subscribeOn(Schedulers.io()).map(ArrayList::new);
}

public Observable<List<Song>> getFavoriteSongsRelay() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ private static Completable createPlaylistMenu(SubMenu subMenu, boolean autoUpdat
return DataManager.getInstance()
.getPlaylistsRelay()
.take(autoUpdate ? Long.MAX_VALUE : 1)
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(playlists -> {
if (subMenu != null) {
subMenu.clear();
Expand All @@ -249,8 +250,7 @@ private static Completable createPlaylistMenu(SubMenu subMenu, boolean autoUpdat
})
.ignoreElements()
.doOnError(throwable -> LogUtils.logException(TAG, "createUpdatingPlaylistMenu failed", throwable))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
.subscribeOn(Schedulers.io());
}

/**
Expand Down Expand Up @@ -402,10 +402,14 @@ private static void insertPlaylistItems(@NonNull Context context,

Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlist.id);
if (uri != null) {
ShuttleApplication.getInstance().getContentResolver().bulkInsert(uri, contentValues);
PlaylistUtils.showPlaylistToast(context, songs.size());
if (insertCallback != null) {
insertCallback.run();
try {
ShuttleApplication.getInstance().getContentResolver().bulkInsert(uri, contentValues);
PlaylistUtils.showPlaylistToast(context, songs.size());
if (insertCallback != null) {
insertCallback.run();
}
} catch (SecurityException e) {
LogUtils.logException(TAG, "Failed to insert playlist items", e);
}
}
}
Expand Down

0 comments on commit 505206a

Please sign in to comment.