From cb41afb11fd5fb5d7de9b5c5f581da150b4a672a Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Sat, 10 Feb 2018 17:20:56 -0800 Subject: [PATCH] -Fixed Soundcloud playlist bookmark button not working when entered from search page. -Fixed NPE when playlist fragment is destroyed while renaming. -Fixed remote playlist thumbnail to use uploader avatar when thumbnail url is unavailable. -Added dispose on exit to all database requests in local playlist fragment. --- .../playlist/model/PlaylistRemoteEntity.java | 3 +- .../list/playlist/PlaylistFragment.java | 10 ++--- .../local/RemotePlaylistManager.java | 5 ++- .../local/bookmark/LocalPlaylistFragment.java | 41 ++++++++++++++----- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java index 5e3db62a9..486350fc9 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistRemoteEntity.java @@ -66,7 +66,8 @@ public class PlaylistRemoteEntity implements PlaylistLocalItem { @Ignore public PlaylistRemoteEntity(final PlaylistInfo info) { - this(info.getServiceId(), info.getName(), info.getUrl(), info.getThumbnailUrl(), + this(info.getServiceId(), info.getName(), info.getUrl(), + info.getThumbnailUrl() == null ? info.getUploaderAvatarUrl() : info.getThumbnailUrl(), info.getUploaderName(), info.getStreamCount()); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 2c0b94c69..db382ef5d 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -125,11 +125,6 @@ public class PlaylistFragment extends BaseListInfoFragment { super.initViews(rootView, savedInstanceState); infoListAdapter.useMiniItemVariants(true); - - remotePlaylistManager.getPlaylist(serviceId, url) - .onBackpressureLatest() - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(getPlaylistBookmarkSubscriber()); } @Override @@ -280,6 +275,11 @@ public class PlaylistFragment extends BaseListInfoFragment { showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, NewPipe.getNameOfService(result.getServiceId()), result.getUrl(), 0); } + remotePlaylistManager.getPlaylist(result) + .onBackpressureLatest() + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(getPlaylistBookmarkSubscriber()); + remotePlaylistManager.onUpdate(result) .subscribeOn(AndroidSchedulers.mainThread()) .subscribe(integer -> {/* Do nothing*/}, this::onError); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/local/RemotePlaylistManager.java b/app/src/main/java/org/schabi/newpipe/fragments/local/RemotePlaylistManager.java index 3012f3d73..1e9be5638 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/local/RemotePlaylistManager.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/local/RemotePlaylistManager.java @@ -25,8 +25,9 @@ public class RemotePlaylistManager { return playlistRemoteTable.getAll().subscribeOn(Schedulers.io()); } - public Flowable> getPlaylist(final int serviceId, final String url) { - return playlistRemoteTable.getPlaylist(serviceId, url).subscribeOn(Schedulers.io()); + public Flowable> getPlaylist(final PlaylistInfo info) { + return playlistRemoteTable.getPlaylist(info.getServiceId(), info.getUrl()) + .subscribeOn(Schedulers.io()); } public Single deletePlaylist(final long playlistId) { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/local/bookmark/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/local/bookmark/LocalPlaylistFragment.java index a3a78e46e..20eee38fc 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/local/bookmark/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/local/bookmark/LocalPlaylistFragment.java @@ -43,7 +43,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import icepick.State; import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; +import io.reactivex.disposables.Disposables; import io.reactivex.subjects.PublishSubject; import static org.schabi.newpipe.util.AnimationUtils.animateView; @@ -76,7 +78,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment debouncedSaveSignal; - private Disposable debouncedSaver; + private CompositeDisposable disposables; /* Has the playlist been fully loaded from db */ private AtomicBoolean isLoadingComplete; @@ -99,6 +101,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment - changePlaylistName(nameEdit.getText().toString()) - ); + .setPositiveButton(R.string.rename, (dialogInterface, i) -> { + changePlaylistName(nameEdit.getText().toString()); + }); dialogBuilder.show(); } private void changePlaylistName(final String name) { + if (playlistManager == null) return; + this.name = name; setTitle(name); Log.d(TAG, "Updating playlist id=[" + playlistId + "] with new name=[" + name + "] items"); - playlistManager.renamePlaylist(playlistId, name) + final Disposable disposable = playlistManager.renamePlaylist(playlistId, name) .observeOn(AndroidSchedulers.mainThread()) .subscribe(longs -> {/*Do nothing on success*/}, this::onError); + disposables.add(disposable); } private void changeThumbnailUrl(final String thumbnailUrl) { + if (playlistManager == null) return; + final Toast successToast = Toast.makeText(getActivity(), R.string.playlist_thumbnail_change_success, Toast.LENGTH_SHORT); @@ -385,9 +395,11 @@ public class LocalPlaylistFragment extends BaseLocalListFragment successToast.show(), this::onError); + disposables.add(disposable); } private void deleteItem(final PlaylistStreamEntry item) { @@ -399,11 +411,15 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { if (isModified != null) isModified.set(false); }, this::onError ); + disposables.add(disposable); }