From 9ecef6f01103fc3aa0c719dd7abea4169d06c7d6 Mon Sep 17 00:00:00 2001 From: GGAutomaton <32899400+GGAutomaton@users.noreply.github.com> Date: Thu, 23 Jun 2022 19:20:16 +0800 Subject: [PATCH] Add abstract methods in PlaylistLocalItem & rename setIsModified --- .../database/playlist/PlaylistLocalItem.java | 4 ++++ .../playlist/PlaylistMetadataEntry.java | 14 +++++++++-- .../playlist/model/PlaylistEntity.java | 4 ++-- .../playlist/model/PlaylistRemoteEntity.java | 2 ++ .../local/bookmark/BookmarkFragment.java | 23 +++++++++---------- .../local/dialog/PlaylistAppendDialog.java | 4 ++-- .../local/playlist/LocalPlaylistFragment.java | 4 ++-- .../settings/SelectPlaylistFragment.java | 2 +- .../newpipe/util/debounce/DebounceSaver.java | 4 ++-- 9 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java b/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java index 352d12d6b..3d58d3f7c 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistLocalItem.java @@ -13,6 +13,10 @@ public interface PlaylistLocalItem extends LocalItem { long getDisplayIndex(); + long getUid(); + + void setDisplayIndex(long displayIndex); + /** * Merge localPlaylists and remotePlaylists by the display index. * If two items have the same display index, sort them in {@code CASE_INSENSITIVE_ORDER}. diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistMetadataEntry.java b/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistMetadataEntry.java index ff80049a3..f1ead0fa4 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistMetadataEntry.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistMetadataEntry.java @@ -11,13 +11,13 @@ public class PlaylistMetadataEntry implements PlaylistLocalItem { public static final String PLAYLIST_STREAM_COUNT = "streamCount"; @ColumnInfo(name = PLAYLIST_ID) - public final long uid; + private final long uid; @ColumnInfo(name = PLAYLIST_NAME) public final String name; @ColumnInfo(name = PLAYLIST_THUMBNAIL_URL) public final String thumbnailUrl; @ColumnInfo(name = PLAYLIST_DISPLAY_INDEX) - public long displayIndex; + private long displayIndex; @ColumnInfo(name = PLAYLIST_STREAM_COUNT) public final long streamCount; @@ -44,4 +44,14 @@ public class PlaylistMetadataEntry implements PlaylistLocalItem { public long getDisplayIndex() { return displayIndex; } + + @Override + public long getUid() { + return uid; + } + + @Override + public void setDisplayIndex(final long displayIndex) { + this.displayIndex = displayIndex; + } } diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java index 272e8a5bc..508b55508 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java @@ -41,10 +41,10 @@ public class PlaylistEntity { @Ignore public PlaylistEntity(final PlaylistMetadataEntry item) { - this.uid = item.uid; + this.uid = item.getUid(); this.name = item.name; this.thumbnailUrl = item.thumbnailUrl; - this.displayIndex = item.displayIndex; + this.displayIndex = item.getDisplayIndex(); } public long getUid() { 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 adea2738b..82baed82c 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 @@ -105,6 +105,7 @@ public class PlaylistRemoteEntity implements PlaylistLocalItem { && TextUtils.equals(getUploader(), info.getUploaderName()); } + @Override public long getUid() { return uid; } @@ -158,6 +159,7 @@ public class PlaylistRemoteEntity implements PlaylistLocalItem { return displayIndex; } + @Override public void setDisplayIndex(final long displayIndex) { this.displayIndex = displayIndex; } diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index b0833dd9c..e9cf83239 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -139,7 +139,7 @@ public final class BookmarkFragment extends BaseLocalListFragment(((PlaylistMetadataEntry) item).uid, + displayIndexInDatabase.put(new Pair<>(item.getUid(), LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM), item.getDisplayIndex()); - ((PlaylistMetadataEntry) item).displayIndex = i; + item.setDisplayIndex(i); } else if (item instanceof PlaylistRemoteEntity) { - displayIndexInDatabase.put(new Pair<>(((PlaylistRemoteEntity) item).getUid(), - LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM), - item.getDisplayIndex()); - ((PlaylistRemoteEntity) item).setDisplayIndex(i); + displayIndexInDatabase.put(new Pair<>(item.getUid(), + LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM), item.getDisplayIndex()); + item.setDisplayIndex(i); } } @@ -415,9 +414,9 @@ public final class BookmarkFragment extends BaseLocalListFragment key = new Pair<>(uid, LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM); final Long databaseIndex = displayIndexInDatabase.remove(key); @@ -463,7 +462,7 @@ public final class BookmarkFragment extends BaseLocalListFragment { if (debounceSaver != null) { - debounceSaver.setIsModified(false); + debounceSaver.setNoChangesToSave(); } }, throwable -> showError(new ErrorInfo(throwable, @@ -563,7 +562,7 @@ public final class BookmarkFragment extends BaseLocalListFragment changeLocalPlaylistName( - selectedItem.uid, + selectedItem.getUid(), dialogBinding.dialogEditText.getText().toString())) .setNegativeButton(R.string.cancel, null) .setNeutralButton(R.string.delete, (dialog, which) -> { diff --git a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java index 58a10af22..a778e6578 100644 --- a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java @@ -147,12 +147,12 @@ public final class PlaylistAppendDialog extends PlaylistDialog { if (playlist.thumbnailUrl.equals("drawable://" + R.drawable.dummy_thumbnail_playlist)) { playlistDisposables.add(manager - .changePlaylistThumbnail(playlist.uid, streams.get(0).getThumbnailUrl()) + .changePlaylistThumbnail(playlist.getUid(), streams.get(0).getThumbnailUrl()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(ignored -> successToast.show())); } - playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams) + playlistDisposables.add(manager.appendToPlaylist(playlist.getUid(), streams) .observeOn(AndroidSchedulers.mainThread()) .subscribe(ignored -> successToast.show())); diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 1b8302cac..d129e658e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -221,7 +221,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { if (debounceSaver != null) { - debounceSaver.setIsModified(false); + debounceSaver.setNoChangesToSave(); } }, throwable -> showError(new ErrorInfo(throwable, diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java index cc47c3f1c..905a44fd1 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java @@ -118,7 +118,7 @@ public class SelectPlaylistFragment extends DialogFragment { if (selectedItem instanceof PlaylistMetadataEntry) { final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem); - onSelectedListener.onLocalPlaylistSelected(entry.uid, entry.name); + onSelectedListener.onLocalPlaylistSelected(entry.getUid(), entry.name); } else if (selectedItem instanceof PlaylistRemoteEntity) { final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem); diff --git a/app/src/main/java/org/schabi/newpipe/util/debounce/DebounceSaver.java b/app/src/main/java/org/schabi/newpipe/util/debounce/DebounceSaver.java index 367174ab7..911e978ff 100644 --- a/app/src/main/java/org/schabi/newpipe/util/debounce/DebounceSaver.java +++ b/app/src/main/java/org/schabi/newpipe/util/debounce/DebounceSaver.java @@ -53,8 +53,8 @@ public class DebounceSaver { return isModified.get(); } - public void setIsModified(final boolean isModified) { - this.isModified.set(isModified); + public void setNoChangesToSave() { + isModified.set(false); } public PublishSubject getDebouncedSaveSignal() {