Add abstract methods in PlaylistLocalItem & rename setIsModified

This commit is contained in:
GGAutomaton 2022-06-23 19:20:16 +08:00
parent ba394a7ab4
commit 9ecef6f011
9 changed files with 38 additions and 23 deletions

View File

@ -13,6 +13,10 @@ public interface PlaylistLocalItem extends LocalItem {
long getDisplayIndex(); long getDisplayIndex();
long getUid();
void setDisplayIndex(long displayIndex);
/** /**
* Merge localPlaylists and remotePlaylists by the display index. * Merge localPlaylists and remotePlaylists by the display index.
* If two items have the same display index, sort them in {@code CASE_INSENSITIVE_ORDER}. * If two items have the same display index, sort them in {@code CASE_INSENSITIVE_ORDER}.

View File

@ -11,13 +11,13 @@ public class PlaylistMetadataEntry implements PlaylistLocalItem {
public static final String PLAYLIST_STREAM_COUNT = "streamCount"; public static final String PLAYLIST_STREAM_COUNT = "streamCount";
@ColumnInfo(name = PLAYLIST_ID) @ColumnInfo(name = PLAYLIST_ID)
public final long uid; private final long uid;
@ColumnInfo(name = PLAYLIST_NAME) @ColumnInfo(name = PLAYLIST_NAME)
public final String name; public final String name;
@ColumnInfo(name = PLAYLIST_THUMBNAIL_URL) @ColumnInfo(name = PLAYLIST_THUMBNAIL_URL)
public final String thumbnailUrl; public final String thumbnailUrl;
@ColumnInfo(name = PLAYLIST_DISPLAY_INDEX) @ColumnInfo(name = PLAYLIST_DISPLAY_INDEX)
public long displayIndex; private long displayIndex;
@ColumnInfo(name = PLAYLIST_STREAM_COUNT) @ColumnInfo(name = PLAYLIST_STREAM_COUNT)
public final long streamCount; public final long streamCount;
@ -44,4 +44,14 @@ public class PlaylistMetadataEntry implements PlaylistLocalItem {
public long getDisplayIndex() { public long getDisplayIndex() {
return displayIndex; return displayIndex;
} }
@Override
public long getUid() {
return uid;
}
@Override
public void setDisplayIndex(final long displayIndex) {
this.displayIndex = displayIndex;
}
} }

View File

@ -41,10 +41,10 @@ public class PlaylistEntity {
@Ignore @Ignore
public PlaylistEntity(final PlaylistMetadataEntry item) { public PlaylistEntity(final PlaylistMetadataEntry item) {
this.uid = item.uid; this.uid = item.getUid();
this.name = item.name; this.name = item.name;
this.thumbnailUrl = item.thumbnailUrl; this.thumbnailUrl = item.thumbnailUrl;
this.displayIndex = item.displayIndex; this.displayIndex = item.getDisplayIndex();
} }
public long getUid() { public long getUid() {

View File

@ -105,6 +105,7 @@ public class PlaylistRemoteEntity implements PlaylistLocalItem {
&& TextUtils.equals(getUploader(), info.getUploaderName()); && TextUtils.equals(getUploader(), info.getUploaderName());
} }
@Override
public long getUid() { public long getUid() {
return uid; return uid;
} }
@ -158,6 +159,7 @@ public class PlaylistRemoteEntity implements PlaylistLocalItem {
return displayIndex; return displayIndex;
} }
@Override
public void setDisplayIndex(final long displayIndex) { public void setDisplayIndex(final long displayIndex) {
this.displayIndex = displayIndex; this.displayIndex = displayIndex;
} }

View File

@ -139,7 +139,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
if (selectedItem instanceof PlaylistMetadataEntry) { if (selectedItem instanceof PlaylistMetadataEntry) {
final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem); final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem);
NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid, NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.getUid(),
entry.name); entry.name);
} else if (selectedItem instanceof PlaylistRemoteEntity) { } else if (selectedItem instanceof PlaylistRemoteEntity) {
@ -181,7 +181,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
if (debounceSaver != null) { if (debounceSaver != null) {
disposables.add(debounceSaver.getDebouncedSaver()); disposables.add(debounceSaver.getDebouncedSaver());
debounceSaver.setIsModified(false); debounceSaver.setNoChangesToSave();
} }
isLoadingComplete.set(false); isLoadingComplete.set(false);
@ -371,16 +371,15 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
// Save the index read from the database. // Save the index read from the database.
if (item instanceof PlaylistMetadataEntry) { if (item instanceof PlaylistMetadataEntry) {
displayIndexInDatabase.put(new Pair<>(((PlaylistMetadataEntry) item).uid, displayIndexInDatabase.put(new Pair<>(item.getUid(),
LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM), item.getDisplayIndex()); LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM), item.getDisplayIndex());
((PlaylistMetadataEntry) item).displayIndex = i; item.setDisplayIndex(i);
} else if (item instanceof PlaylistRemoteEntity) { } else if (item instanceof PlaylistRemoteEntity) {
displayIndexInDatabase.put(new Pair<>(((PlaylistRemoteEntity) item).getUid(), displayIndexInDatabase.put(new Pair<>(item.getUid(),
LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM), LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM), item.getDisplayIndex());
item.getDisplayIndex()); item.setDisplayIndex(i);
((PlaylistRemoteEntity) item).setDisplayIndex(i);
} }
} }
@ -415,9 +414,9 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
final LocalItem item = items.get(i); final LocalItem item = items.get(i);
if (item instanceof PlaylistMetadataEntry) { if (item instanceof PlaylistMetadataEntry) {
((PlaylistMetadataEntry) item).displayIndex = i; ((PlaylistMetadataEntry) item).setDisplayIndex(i);
final Long uid = ((PlaylistMetadataEntry) item).uid; final Long uid = ((PlaylistMetadataEntry) item).getUid();
final Pair<Long, LocalItem.LocalItemType> key = new Pair<>(uid, final Pair<Long, LocalItem.LocalItemType> key = new Pair<>(uid,
LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM); LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM);
final Long databaseIndex = displayIndexInDatabase.remove(key); final Long databaseIndex = displayIndexInDatabase.remove(key);
@ -463,7 +462,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> { .subscribe(() -> {
if (debounceSaver != null) { if (debounceSaver != null) {
debounceSaver.setIsModified(false); debounceSaver.setNoChangesToSave();
} }
}, },
throwable -> showError(new ErrorInfo(throwable, throwable -> showError(new ErrorInfo(throwable,
@ -563,7 +562,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
builder.setView(dialogBinding.getRoot()) builder.setView(dialogBinding.getRoot())
.setPositiveButton(R.string.rename_playlist, (dialog, which) -> .setPositiveButton(R.string.rename_playlist, (dialog, which) ->
changeLocalPlaylistName( changeLocalPlaylistName(
selectedItem.uid, selectedItem.getUid(),
dialogBinding.dialogEditText.getText().toString())) dialogBinding.dialogEditText.getText().toString()))
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.delete, (dialog, which) -> { .setNeutralButton(R.string.delete, (dialog, which) -> {

View File

@ -147,12 +147,12 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
if (playlist.thumbnailUrl.equals("drawable://" + R.drawable.dummy_thumbnail_playlist)) { if (playlist.thumbnailUrl.equals("drawable://" + R.drawable.dummy_thumbnail_playlist)) {
playlistDisposables.add(manager playlistDisposables.add(manager
.changePlaylistThumbnail(playlist.uid, streams.get(0).getThumbnailUrl()) .changePlaylistThumbnail(playlist.getUid(), streams.get(0).getThumbnailUrl())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show())); .subscribe(ignored -> successToast.show()));
} }
playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams) playlistDisposables.add(manager.appendToPlaylist(playlist.getUid(), streams)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show())); .subscribe(ignored -> successToast.show()));

View File

@ -221,7 +221,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
if (debounceSaver != null) { if (debounceSaver != null) {
disposables.add(debounceSaver.getDebouncedSaver()); disposables.add(debounceSaver.getDebouncedSaver());
debounceSaver.setIsModified(false); debounceSaver.setNoChangesToSave();
} }
isLoadingComplete.set(false); isLoadingComplete.set(false);
@ -644,7 +644,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
.subscribe( .subscribe(
() -> { () -> {
if (debounceSaver != null) { if (debounceSaver != null) {
debounceSaver.setIsModified(false); debounceSaver.setNoChangesToSave();
} }
}, },
throwable -> showError(new ErrorInfo(throwable, throwable -> showError(new ErrorInfo(throwable,

View File

@ -118,7 +118,7 @@ public class SelectPlaylistFragment extends DialogFragment {
if (selectedItem instanceof PlaylistMetadataEntry) { if (selectedItem instanceof PlaylistMetadataEntry) {
final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem); final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem);
onSelectedListener.onLocalPlaylistSelected(entry.uid, entry.name); onSelectedListener.onLocalPlaylistSelected(entry.getUid(), entry.name);
} else if (selectedItem instanceof PlaylistRemoteEntity) { } else if (selectedItem instanceof PlaylistRemoteEntity) {
final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem); final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem);

View File

@ -53,8 +53,8 @@ public class DebounceSaver {
return isModified.get(); return isModified.get();
} }
public void setIsModified(final boolean isModified) { public void setNoChangesToSave() {
this.isModified.set(isModified); isModified.set(false);
} }
public PublishSubject<Long> getDebouncedSaveSignal() { public PublishSubject<Long> getDebouncedSaveSignal() {