Fix sonar warning and typo

This commit is contained in:
GGAutomaton 2022-04-16 12:00:02 +08:00
parent 0aa08a5e40
commit c24aed054f
7 changed files with 53 additions and 78 deletions

View File

@ -195,8 +195,8 @@ public final class Migrations {
try {
database.beginTransaction();
// update playlists
// create a temp table to initialize display_index
// Update playlists.
// Create a temp table to initialize display_index.
database.execSQL("CREATE TABLE `playlists_tmp` "
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
+ "`name` TEXT, `thumbnail_url` TEXT,"
@ -204,16 +204,16 @@ public final class Migrations {
database.execSQL("INSERT INTO `playlists_tmp` (`uid`, `name`, `thumbnail_url`)"
+ "SELECT `uid`, `name`, `thumbnail_url` FROM `playlists`");
// replace the old table
// Replace the old table.
database.execSQL("DROP TABLE `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`)");
// update remote_playlists
// create a temp table to initialize display_index
// Update remote_playlists.
// Create a temp table to initialize display_index.
database.execSQL("CREATE TABLE `remote_playlists_tmp` "
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
+ "`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`, "
+ "`stream_count` FROM `remote_playlists`");
// replace the old table
// Replace the old table.
database.execSQL("DROP TABLE `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` "
+ "ON `remote_playlists` (`name`)");
database.execSQL("CREATE UNIQUE INDEX `index_remote_playlists_service_id_url` "

View File

@ -256,12 +256,17 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
switch (item.getLocalItemType()) {
case PLAYLIST_LOCAL_ITEM:
return useItemHandle ? LOCAL_BOOKMARK_PLAYLIST_HOLDER_TYPE : (useGridVariant
? LOCAL_PLAYLIST_GRID_HOLDER_TYPE : LOCAL_PLAYLIST_HOLDER_TYPE);
if (useItemHandle) {
return LOCAL_BOOKMARK_PLAYLIST_HOLDER_TYPE;
}
return useGridVariant ? LOCAL_PLAYLIST_GRID_HOLDER_TYPE
: LOCAL_PLAYLIST_HOLDER_TYPE;
case PLAYLIST_REMOTE_ITEM:
return useItemHandle ? REMOTE_BOOKMARK_PLAYLIST_HOLDER_TYPE : (useGridVariant
? REMOTE_PLAYLIST_GRID_HOLDER_TYPE : REMOTE_PLAYLIST_HOLDER_TYPE);
if (useItemHandle) {
return REMOTE_BOOKMARK_PLAYLIST_HOLDER_TYPE;
}
return useGridVariant ? REMOTE_PLAYLIST_GRID_HOLDER_TYPE
: REMOTE_PLAYLIST_HOLDER_TYPE;
case PLAYLIST_STREAM_ITEM:
return useGridVariant
? STREAM_PLAYLIST_GRID_HOLDER_TYPE : STREAM_PLAYLIST_HOLDER_TYPE;

View File

@ -54,7 +54,7 @@ import io.reactivex.rxjava3.subjects.PublishSubject;
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 int MINIMUM_INITIAL_DRAG_VELOCITY = 12;
@State
@ -281,6 +281,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
@Override
public void onComplete() {
// Do nothing.
}
};
}
@ -444,13 +445,13 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM);
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 != i) {
localItemsUpdate.add((PlaylistMetadataEntry) item);
}
} else {
// This should be impossible.
continue;
}
} else if (item instanceof PlaylistRemoteEntity) {
((PlaylistRemoteEntity) item).setDisplayIndex(i);
@ -464,9 +465,6 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
if (databaseIndex != i) {
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())
.subscribe(() -> disposables.add(remotePlaylistManager.updatePlaylists(
remoteItemsUpdate, remoteItemsDeleteUid)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> {
if (isModified != null) {
isModified.set(false);
}
},
throwable -> showError(new ErrorInfo(throwable,
UserAction.REQUESTED_BOOKMARK,
"Saving playlist"))
)),
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> {
if (isModified != null) {
isModified.set(false);
}
},
throwable -> showError(new ErrorInfo(throwable,
UserAction.REQUESTED_BOOKMARK,
"Saving playlist"))
)),
throwable -> showError(new ErrorInfo(throwable,
UserAction.REQUESTED_BOOKMARK, "Saving playlist"))
));
@ -529,22 +527,21 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
public boolean onMove(@NonNull final RecyclerView recyclerView,
@NonNull final RecyclerView.ViewHolder source,
@NonNull final RecyclerView.ViewHolder target) {
if (source.getItemViewType() != target.getItemViewType()
|| itemListAdapter == null) {
// Allow swap LocalBookmarkPlaylistItemHolder and
// RemoteBookmarkPlaylistItemHolder.
if (!(
(
(source instanceof LocalBookmarkPlaylistItemHolder)
|| (source instanceof RemoteBookmarkPlaylistItemHolder)
)
&& (
(target instanceof LocalBookmarkPlaylistItemHolder)
|| (target instanceof RemoteBookmarkPlaylistItemHolder)
)
)) {
return false;
}
// Allow swap LocalBookmarkPlaylistItemHolder and RemoteBookmarkPlaylistItemHolder.
if (itemListAdapter == null
|| source.getItemViewType() != target.getItemViewType()
&& !(
(
(source instanceof LocalBookmarkPlaylistItemHolder)
|| (source instanceof RemoteBookmarkPlaylistItemHolder)
)
&& (
(target instanceof LocalBookmarkPlaylistItemHolder)
|| (target instanceof RemoteBookmarkPlaylistItemHolder)
))
) {
return false;
}
final int sourceIndex = source.getBindingAdapterPosition();
@ -569,6 +566,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
@Override
public void onSwiped(@NonNull final RecyclerView.ViewHolder viewHolder,
final int swipeDir) {
// Do nothing.
}
};
}

View File

@ -9,12 +9,10 @@ import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
import org.schabi.newpipe.local.LocalItemBuilder;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.PicassoHelper;
import java.time.format.DateTimeFormatter;
public class LocalBookmarkPlaylistItemHolder extends PlaylistItemHolder {
public class LocalBookmarkPlaylistItemHolder extends LocalPlaylistItemHolder {
private final View itemHandleView;
public LocalBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
@ -37,13 +35,6 @@ public class LocalBookmarkPlaylistItemHolder extends PlaylistItemHolder {
}
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));
super.updateFromItem(localItem, historyRecordManager, dateTimeFormatter);

View File

@ -3,7 +3,6 @@ package org.schabi.newpipe.local.holder;
import android.view.View;
import android.view.ViewGroup;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
import org.schabi.newpipe.local.LocalItemBuilder;
@ -16,7 +15,7 @@ import java.time.format.DateTimeFormatter;
public class LocalPlaylistItemHolder extends PlaylistItemHolder {
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,

View File

@ -1,6 +1,5 @@
package org.schabi.newpipe.local.holder;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -8,15 +7,12 @@ import android.view.ViewGroup;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.LocalItem;
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.history.HistoryRecordManager;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.PicassoHelper;
import java.time.format.DateTimeFormatter;
public class RemoteBookmarkPlaylistItemHolder extends PlaylistItemHolder {
public class RemoteBookmarkPlaylistItemHolder extends RemotePlaylistItemHolder {
private final View itemHandleView;
public RemoteBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
@ -39,19 +35,6 @@ public class RemoteBookmarkPlaylistItemHolder extends PlaylistItemHolder {
}
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));
super.updateFromItem(localItem, historyRecordManager, dateTimeFormatter);

View File

@ -3,7 +3,6 @@ package org.schabi.newpipe.local.holder;
import android.text.TextUtils;
import android.view.ViewGroup;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
import org.schabi.newpipe.extractor.NewPipe;
@ -18,7 +17,7 @@ public class RemotePlaylistItemHolder extends PlaylistItemHolder {
public RemotePlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
final ViewGroup parent) {
this(infoItemBuilder, R.layout.list_playlist_mini_item, parent);
super(infoItemBuilder, parent);
}
RemotePlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final int layoutId,