Fix sonar warning and typo
This commit is contained in:
parent
0aa08a5e40
commit
c24aed054f
7 changed files with 53 additions and 78 deletions
|
@ -195,8 +195,8 @@ public final class Migrations {
|
||||||
try {
|
try {
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
|
|
||||||
// update playlists
|
// Update playlists.
|
||||||
// create a temp table to initialize display_index
|
// Create a temp table to initialize display_index.
|
||||||
database.execSQL("CREATE TABLE `playlists_tmp` "
|
database.execSQL("CREATE TABLE `playlists_tmp` "
|
||||||
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
|
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
|
||||||
+ "`name` TEXT, `thumbnail_url` TEXT,"
|
+ "`name` TEXT, `thumbnail_url` TEXT,"
|
||||||
|
@ -204,16 +204,16 @@ public final class Migrations {
|
||||||
database.execSQL("INSERT INTO `playlists_tmp` (`uid`, `name`, `thumbnail_url`)"
|
database.execSQL("INSERT INTO `playlists_tmp` (`uid`, `name`, `thumbnail_url`)"
|
||||||
+ "SELECT `uid`, `name`, `thumbnail_url` FROM `playlists`");
|
+ "SELECT `uid`, `name`, `thumbnail_url` FROM `playlists`");
|
||||||
|
|
||||||
// replace the old table
|
// Replace the old table.
|
||||||
database.execSQL("DROP TABLE `playlists`");
|
database.execSQL("DROP TABLE `playlists`");
|
||||||
database.execSQL("ALTER TABLE `playlists_tmp` RENAME TO `playlists`");
|
database.execSQL("ALTER TABLE `playlists_tmp` RENAME TO `playlists`");
|
||||||
|
|
||||||
// create index on the new table
|
// Create index on the new table.
|
||||||
database.execSQL("CREATE INDEX `index_playlists_name` ON `playlists` (`name`)");
|
database.execSQL("CREATE INDEX `index_playlists_name` ON `playlists` (`name`)");
|
||||||
|
|
||||||
|
|
||||||
// update remote_playlists
|
// Update remote_playlists.
|
||||||
// create a temp table to initialize display_index
|
// Create a temp table to initialize display_index.
|
||||||
database.execSQL("CREATE TABLE `remote_playlists_tmp` "
|
database.execSQL("CREATE TABLE `remote_playlists_tmp` "
|
||||||
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
|
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
|
||||||
+ "`service_id` INTEGER NOT NULL, `name` TEXT, `url` TEXT, "
|
+ "`service_id` INTEGER NOT NULL, `name` TEXT, `url` TEXT, "
|
||||||
|
@ -225,11 +225,11 @@ public final class Migrations {
|
||||||
+ "SELECT `uid`, `service_id`, `name`, `url`, `thumbnail_url`, `uploader`, "
|
+ "SELECT `uid`, `service_id`, `name`, `url`, `thumbnail_url`, `uploader`, "
|
||||||
+ "`stream_count` FROM `remote_playlists`");
|
+ "`stream_count` FROM `remote_playlists`");
|
||||||
|
|
||||||
// replace the old table
|
// Replace the old table.
|
||||||
database.execSQL("DROP TABLE `remote_playlists`");
|
database.execSQL("DROP TABLE `remote_playlists`");
|
||||||
database.execSQL("ALTER TABLE `remote_playlists_tmp` RENAME TO `remote_playlists`");
|
database.execSQL("ALTER TABLE `remote_playlists_tmp` RENAME TO `remote_playlists`");
|
||||||
|
|
||||||
// create index on the new table
|
// Create index on the new table.
|
||||||
database.execSQL("CREATE INDEX `index_remote_playlists_name` "
|
database.execSQL("CREATE INDEX `index_remote_playlists_name` "
|
||||||
+ "ON `remote_playlists` (`name`)");
|
+ "ON `remote_playlists` (`name`)");
|
||||||
database.execSQL("CREATE UNIQUE INDEX `index_remote_playlists_service_id_url` "
|
database.execSQL("CREATE UNIQUE INDEX `index_remote_playlists_service_id_url` "
|
||||||
|
|
|
@ -256,12 +256,17 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||||
|
|
||||||
switch (item.getLocalItemType()) {
|
switch (item.getLocalItemType()) {
|
||||||
case PLAYLIST_LOCAL_ITEM:
|
case PLAYLIST_LOCAL_ITEM:
|
||||||
return useItemHandle ? LOCAL_BOOKMARK_PLAYLIST_HOLDER_TYPE : (useGridVariant
|
if (useItemHandle) {
|
||||||
? LOCAL_PLAYLIST_GRID_HOLDER_TYPE : LOCAL_PLAYLIST_HOLDER_TYPE);
|
return LOCAL_BOOKMARK_PLAYLIST_HOLDER_TYPE;
|
||||||
|
}
|
||||||
|
return useGridVariant ? LOCAL_PLAYLIST_GRID_HOLDER_TYPE
|
||||||
|
: LOCAL_PLAYLIST_HOLDER_TYPE;
|
||||||
case PLAYLIST_REMOTE_ITEM:
|
case PLAYLIST_REMOTE_ITEM:
|
||||||
return useItemHandle ? REMOTE_BOOKMARK_PLAYLIST_HOLDER_TYPE : (useGridVariant
|
if (useItemHandle) {
|
||||||
? REMOTE_PLAYLIST_GRID_HOLDER_TYPE : REMOTE_PLAYLIST_HOLDER_TYPE);
|
return REMOTE_BOOKMARK_PLAYLIST_HOLDER_TYPE;
|
||||||
|
}
|
||||||
|
return useGridVariant ? REMOTE_PLAYLIST_GRID_HOLDER_TYPE
|
||||||
|
: REMOTE_PLAYLIST_HOLDER_TYPE;
|
||||||
case PLAYLIST_STREAM_ITEM:
|
case PLAYLIST_STREAM_ITEM:
|
||||||
return useGridVariant
|
return useGridVariant
|
||||||
? STREAM_PLAYLIST_GRID_HOLDER_TYPE : STREAM_PLAYLIST_HOLDER_TYPE;
|
? STREAM_PLAYLIST_GRID_HOLDER_TYPE : STREAM_PLAYLIST_HOLDER_TYPE;
|
||||||
|
|
|
@ -54,7 +54,7 @@ import io.reactivex.rxjava3.subjects.PublishSubject;
|
||||||
|
|
||||||
public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
|
public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
|
||||||
|
|
||||||
// Save the list 10s after the last change occurred
|
// Save the list 10 seconds after the last change occurred
|
||||||
private static final long SAVE_DEBOUNCE_MILLIS = 10000;
|
private static final long SAVE_DEBOUNCE_MILLIS = 10000;
|
||||||
private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12;
|
private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12;
|
||||||
@State
|
@State
|
||||||
|
@ -281,6 +281,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
|
// Do nothing.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -444,13 +445,13 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||||
LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM);
|
LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM);
|
||||||
final Long databaseIndex = displayIndexInDatabase.remove(key);
|
final Long databaseIndex = displayIndexInDatabase.remove(key);
|
||||||
|
|
||||||
|
// The database index should not be null because inserting new item into database
|
||||||
|
// is not dealt here. NullPointerException has occurred once, but I can't reproduce
|
||||||
|
// it. Enhance robustness here.
|
||||||
if (databaseIndex != null) {
|
if (databaseIndex != null) {
|
||||||
if (databaseIndex != i) {
|
if (databaseIndex != i) {
|
||||||
localItemsUpdate.add((PlaylistMetadataEntry) item);
|
localItemsUpdate.add((PlaylistMetadataEntry) item);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// This should be impossible.
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
} else if (item instanceof PlaylistRemoteEntity) {
|
} else if (item instanceof PlaylistRemoteEntity) {
|
||||||
((PlaylistRemoteEntity) item).setDisplayIndex(i);
|
((PlaylistRemoteEntity) item).setDisplayIndex(i);
|
||||||
|
@ -464,9 +465,6 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||||
if (databaseIndex != i) {
|
if (databaseIndex != i) {
|
||||||
remoteItemsUpdate.add((PlaylistRemoteEntity) item);
|
remoteItemsUpdate.add((PlaylistRemoteEntity) item);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// This should be impossible.
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -489,16 +487,16 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(() -> disposables.add(remotePlaylistManager.updatePlaylists(
|
.subscribe(() -> disposables.add(remotePlaylistManager.updatePlaylists(
|
||||||
remoteItemsUpdate, remoteItemsDeleteUid)
|
remoteItemsUpdate, remoteItemsDeleteUid)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(() -> {
|
.subscribe(() -> {
|
||||||
if (isModified != null) {
|
if (isModified != null) {
|
||||||
isModified.set(false);
|
isModified.set(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
throwable -> showError(new ErrorInfo(throwable,
|
throwable -> showError(new ErrorInfo(throwable,
|
||||||
UserAction.REQUESTED_BOOKMARK,
|
UserAction.REQUESTED_BOOKMARK,
|
||||||
"Saving playlist"))
|
"Saving playlist"))
|
||||||
)),
|
)),
|
||||||
throwable -> showError(new ErrorInfo(throwable,
|
throwable -> showError(new ErrorInfo(throwable,
|
||||||
UserAction.REQUESTED_BOOKMARK, "Saving playlist"))
|
UserAction.REQUESTED_BOOKMARK, "Saving playlist"))
|
||||||
));
|
));
|
||||||
|
@ -529,22 +527,21 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||||
public boolean onMove(@NonNull final RecyclerView recyclerView,
|
public boolean onMove(@NonNull final RecyclerView recyclerView,
|
||||||
@NonNull final RecyclerView.ViewHolder source,
|
@NonNull final RecyclerView.ViewHolder source,
|
||||||
@NonNull final RecyclerView.ViewHolder target) {
|
@NonNull final RecyclerView.ViewHolder target) {
|
||||||
if (source.getItemViewType() != target.getItemViewType()
|
|
||||||
|| itemListAdapter == null) {
|
// Allow swap LocalBookmarkPlaylistItemHolder and RemoteBookmarkPlaylistItemHolder.
|
||||||
// Allow swap LocalBookmarkPlaylistItemHolder and
|
if (itemListAdapter == null
|
||||||
// RemoteBookmarkPlaylistItemHolder.
|
|| source.getItemViewType() != target.getItemViewType()
|
||||||
if (!(
|
&& !(
|
||||||
(
|
(
|
||||||
(source instanceof LocalBookmarkPlaylistItemHolder)
|
(source instanceof LocalBookmarkPlaylistItemHolder)
|
||||||
|| (source instanceof RemoteBookmarkPlaylistItemHolder)
|
|| (source instanceof RemoteBookmarkPlaylistItemHolder)
|
||||||
)
|
)
|
||||||
&& (
|
&& (
|
||||||
(target instanceof LocalBookmarkPlaylistItemHolder)
|
(target instanceof LocalBookmarkPlaylistItemHolder)
|
||||||
|| (target instanceof RemoteBookmarkPlaylistItemHolder)
|
|| (target instanceof RemoteBookmarkPlaylistItemHolder)
|
||||||
)
|
))
|
||||||
)) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final int sourceIndex = source.getBindingAdapterPosition();
|
final int sourceIndex = source.getBindingAdapterPosition();
|
||||||
|
@ -569,6 +566,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||||
@Override
|
@Override
|
||||||
public void onSwiped(@NonNull final RecyclerView.ViewHolder viewHolder,
|
public void onSwiped(@NonNull final RecyclerView.ViewHolder viewHolder,
|
||||||
final int swipeDir) {
|
final int swipeDir) {
|
||||||
|
// Do nothing.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,10 @@ import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
||||||
import org.schabi.newpipe.local.LocalItemBuilder;
|
import org.schabi.newpipe.local.LocalItemBuilder;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.util.Localization;
|
|
||||||
import org.schabi.newpipe.util.PicassoHelper;
|
|
||||||
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class LocalBookmarkPlaylistItemHolder extends PlaylistItemHolder {
|
public class LocalBookmarkPlaylistItemHolder extends LocalPlaylistItemHolder {
|
||||||
private final View itemHandleView;
|
private final View itemHandleView;
|
||||||
|
|
||||||
public LocalBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
|
public LocalBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
|
||||||
|
@ -37,13 +35,6 @@ public class LocalBookmarkPlaylistItemHolder extends PlaylistItemHolder {
|
||||||
}
|
}
|
||||||
final PlaylistMetadataEntry item = (PlaylistMetadataEntry) localItem;
|
final PlaylistMetadataEntry item = (PlaylistMetadataEntry) localItem;
|
||||||
|
|
||||||
itemTitleView.setText(item.name);
|
|
||||||
itemStreamCountView.setText(Localization.localizeStreamCountMini(
|
|
||||||
itemStreamCountView.getContext(), item.streamCount));
|
|
||||||
itemUploaderView.setVisibility(View.INVISIBLE);
|
|
||||||
|
|
||||||
PicassoHelper.loadPlaylistThumbnail(item.thumbnailUrl).into(itemThumbnailView);
|
|
||||||
|
|
||||||
itemHandleView.setOnTouchListener(getOnTouchListener(item));
|
itemHandleView.setOnTouchListener(getOnTouchListener(item));
|
||||||
|
|
||||||
super.updateFromItem(localItem, historyRecordManager, dateTimeFormatter);
|
super.updateFromItem(localItem, historyRecordManager, dateTimeFormatter);
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.schabi.newpipe.local.holder;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
||||||
import org.schabi.newpipe.local.LocalItemBuilder;
|
import org.schabi.newpipe.local.LocalItemBuilder;
|
||||||
|
@ -16,7 +15,7 @@ import java.time.format.DateTimeFormatter;
|
||||||
public class LocalPlaylistItemHolder extends PlaylistItemHolder {
|
public class LocalPlaylistItemHolder extends PlaylistItemHolder {
|
||||||
|
|
||||||
public LocalPlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final ViewGroup parent) {
|
public LocalPlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final ViewGroup parent) {
|
||||||
this(infoItemBuilder, R.layout.list_playlist_mini_item, parent);
|
super(infoItemBuilder, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalPlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final int layoutId,
|
LocalPlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final int layoutId,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.schabi.newpipe.local.holder;
|
package org.schabi.newpipe.local.holder;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -8,15 +7,12 @@ import android.view.ViewGroup;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.local.LocalItemBuilder;
|
import org.schabi.newpipe.local.LocalItemBuilder;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.util.Localization;
|
|
||||||
import org.schabi.newpipe.util.PicassoHelper;
|
|
||||||
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class RemoteBookmarkPlaylistItemHolder extends PlaylistItemHolder {
|
public class RemoteBookmarkPlaylistItemHolder extends RemotePlaylistItemHolder {
|
||||||
private final View itemHandleView;
|
private final View itemHandleView;
|
||||||
|
|
||||||
public RemoteBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
|
public RemoteBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
|
||||||
|
@ -39,19 +35,6 @@ public class RemoteBookmarkPlaylistItemHolder extends PlaylistItemHolder {
|
||||||
}
|
}
|
||||||
final PlaylistRemoteEntity item = (PlaylistRemoteEntity) localItem;
|
final PlaylistRemoteEntity item = (PlaylistRemoteEntity) localItem;
|
||||||
|
|
||||||
itemTitleView.setText(item.getName());
|
|
||||||
itemStreamCountView.setText(Localization.localizeStreamCountMini(
|
|
||||||
itemStreamCountView.getContext(), item.getStreamCount()));
|
|
||||||
// Here is where the uploader name is set in the bookmarked playlists library
|
|
||||||
if (!TextUtils.isEmpty(item.getUploader())) {
|
|
||||||
itemUploaderView.setText(Localization.concatenateStrings(item.getUploader(),
|
|
||||||
NewPipe.getNameOfService(item.getServiceId())));
|
|
||||||
} else {
|
|
||||||
itemUploaderView.setText(NewPipe.getNameOfService(item.getServiceId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
PicassoHelper.loadPlaylistThumbnail(item.getThumbnailUrl()).into(itemThumbnailView);
|
|
||||||
|
|
||||||
itemHandleView.setOnTouchListener(getOnTouchListener(item));
|
itemHandleView.setOnTouchListener(getOnTouchListener(item));
|
||||||
|
|
||||||
super.updateFromItem(localItem, historyRecordManager, dateTimeFormatter);
|
super.updateFromItem(localItem, historyRecordManager, dateTimeFormatter);
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.schabi.newpipe.local.holder;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
@ -18,7 +17,7 @@ public class RemotePlaylistItemHolder extends PlaylistItemHolder {
|
||||||
|
|
||||||
public RemotePlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
|
public RemotePlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
|
||||||
final ViewGroup parent) {
|
final ViewGroup parent) {
|
||||||
this(infoItemBuilder, R.layout.list_playlist_mini_item, parent);
|
super(infoItemBuilder, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemotePlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final int layoutId,
|
RemotePlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final int layoutId,
|
||||||
|
|
Loading…
Reference in a new issue