fix issue: thumbnail update when element deleted + thumbnail update when element added and no thumbnail

This commit is contained in:
decarvalhobo 2019-12-02 22:20:43 +01:00 committed by TobiGr
parent dad88b83fb
commit 8de367e03f
3 changed files with 31 additions and 3 deletions

View File

@ -152,9 +152,19 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
final Toast successToast = Toast.makeText(getContext(),
R.string.playlist_add_stream_success, Toast.LENGTH_SHORT);
playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show()));
if(playlist.thumbnailUrl.equals("https://i.ytimg.com/")){ //empty playlist
playlistDisposables.add(manager.createPlaylist(playlist.name, streams)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show()));
playlistDisposables.add(manager.deletePlaylist(playlist.uid)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show()));
}
else {
playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show()));
}
getDialog().dismiss();
}

View File

@ -413,10 +413,24 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
disposables.add(disposable);
}
private void updateThumbnailUrl() {
String newThumbnailUrl;
if(!itemListAdapter.getItemsList().isEmpty()){
newThumbnailUrl = ((PlaylistStreamEntry)itemListAdapter.getItemsList().get(0)).thumbnailUrl;
}
else newThumbnailUrl = "https://i.ytimg.com/";
changeThumbnailUrl(newThumbnailUrl);
}
private void deleteItem(final PlaylistStreamEntry item) {
if (itemListAdapter == null) return;
itemListAdapter.removeItem(item);
if(playlistManager.getPlaylistThumbnail(playlistId).equals(item.thumbnailUrl)) // If yes change for the first thumbnail of the list
updateThumbnailUrl();
setVideoCount(itemListAdapter.getItemsList().size());
saveChanges();
}

View File

@ -103,6 +103,10 @@ public class LocalPlaylistManager {
return modifyPlaylist(playlistId, null, thumbnailUrl);
}
public String getPlaylistThumbnail(final long playlistId) {
return playlistTable.getPlaylist(playlistId).blockingFirst().get(0).getThumbnailUrl();
}
private Maybe<Integer> modifyPlaylist(final long playlistId,
@Nullable final String name,
@Nullable final String thumbnailUrl) {