Skip to content

Commit c24aed0

Browse files
committed
Fix sonar warning and typo
1 parent 0aa08a5 commit c24aed0

7 files changed

Lines changed: 53 additions & 78 deletions

File tree

app/src/main/java/org/schabi/newpipe/database/Migrations.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,25 @@ public void migrate(@NonNull final SupportSQLiteDatabase database) {
195195
try {
196196
database.beginTransaction();
197197

198-
// update playlists
199-
// create a temp table to initialize display_index
198+
// Update playlists.
199+
// Create a temp table to initialize display_index.
200200
database.execSQL("CREATE TABLE `playlists_tmp` "
201201
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
202202
+ "`name` TEXT, `thumbnail_url` TEXT,"
203203
+ "`display_index` INTEGER NOT NULL DEFAULT 0)");
204204
database.execSQL("INSERT INTO `playlists_tmp` (`uid`, `name`, `thumbnail_url`)"
205205
+ "SELECT `uid`, `name`, `thumbnail_url` FROM `playlists`");
206206

207-
// replace the old table
207+
// Replace the old table.
208208
database.execSQL("DROP TABLE `playlists`");
209209
database.execSQL("ALTER TABLE `playlists_tmp` RENAME TO `playlists`");
210210

211-
// create index on the new table
211+
// Create index on the new table.
212212
database.execSQL("CREATE INDEX `index_playlists_name` ON `playlists` (`name`)");
213213

214214

215-
// update remote_playlists
216-
// create a temp table to initialize display_index
215+
// Update remote_playlists.
216+
// Create a temp table to initialize display_index.
217217
database.execSQL("CREATE TABLE `remote_playlists_tmp` "
218218
+ "(`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
219219
+ "`service_id` INTEGER NOT NULL, `name` TEXT, `url` TEXT, "
@@ -225,11 +225,11 @@ public void migrate(@NonNull final SupportSQLiteDatabase database) {
225225
+ "SELECT `uid`, `service_id`, `name`, `url`, `thumbnail_url`, `uploader`, "
226226
+ "`stream_count` FROM `remote_playlists`");
227227

228-
// replace the old table
228+
// Replace the old table.
229229
database.execSQL("DROP TABLE `remote_playlists`");
230230
database.execSQL("ALTER TABLE `remote_playlists_tmp` RENAME TO `remote_playlists`");
231231

232-
// create index on the new table
232+
// Create index on the new table.
233233
database.execSQL("CREATE INDEX `index_remote_playlists_name` "
234234
+ "ON `remote_playlists` (`name`)");
235235
database.execSQL("CREATE UNIQUE INDEX `index_remote_playlists_service_id_url` "

app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,17 @@ public int getItemViewType(int position) {
256256

257257
switch (item.getLocalItemType()) {
258258
case PLAYLIST_LOCAL_ITEM:
259-
return useItemHandle ? LOCAL_BOOKMARK_PLAYLIST_HOLDER_TYPE : (useGridVariant
260-
? LOCAL_PLAYLIST_GRID_HOLDER_TYPE : LOCAL_PLAYLIST_HOLDER_TYPE);
259+
if (useItemHandle) {
260+
return LOCAL_BOOKMARK_PLAYLIST_HOLDER_TYPE;
261+
}
262+
return useGridVariant ? LOCAL_PLAYLIST_GRID_HOLDER_TYPE
263+
: LOCAL_PLAYLIST_HOLDER_TYPE;
261264
case PLAYLIST_REMOTE_ITEM:
262-
return useItemHandle ? REMOTE_BOOKMARK_PLAYLIST_HOLDER_TYPE : (useGridVariant
263-
? REMOTE_PLAYLIST_GRID_HOLDER_TYPE : REMOTE_PLAYLIST_HOLDER_TYPE);
264-
265+
if (useItemHandle) {
266+
return REMOTE_BOOKMARK_PLAYLIST_HOLDER_TYPE;
267+
}
268+
return useGridVariant ? REMOTE_PLAYLIST_GRID_HOLDER_TYPE
269+
: REMOTE_PLAYLIST_HOLDER_TYPE;
265270
case PLAYLIST_STREAM_ITEM:
266271
return useGridVariant
267272
? STREAM_PLAYLIST_GRID_HOLDER_TYPE : STREAM_PLAYLIST_HOLDER_TYPE;

app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
5656

57-
// Save the list 10s after the last change occurred
57+
// Save the list 10 seconds after the last change occurred
5858
private static final long SAVE_DEBOUNCE_MILLIS = 10000;
5959
private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12;
6060
@State
@@ -281,6 +281,7 @@ public void onError(final Throwable exception) {
281281

282282
@Override
283283
public void onComplete() {
284+
// Do nothing.
284285
}
285286
};
286287
}
@@ -444,13 +445,13 @@ private void saveImmediate() {
444445
LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM);
445446
final Long databaseIndex = displayIndexInDatabase.remove(key);
446447

448+
// The database index should not be null because inserting new item into database
449+
// is not dealt here. NullPointerException has occurred once, but I can't reproduce
450+
// it. Enhance robustness here.
447451
if (databaseIndex != null) {
448452
if (databaseIndex != i) {
449453
localItemsUpdate.add((PlaylistMetadataEntry) item);
450454
}
451-
} else {
452-
// This should be impossible.
453-
continue;
454455
}
455456
} else if (item instanceof PlaylistRemoteEntity) {
456457
((PlaylistRemoteEntity) item).setDisplayIndex(i);
@@ -464,9 +465,6 @@ private void saveImmediate() {
464465
if (databaseIndex != i) {
465466
remoteItemsUpdate.add((PlaylistRemoteEntity) item);
466467
}
467-
} else {
468-
// This should be impossible.
469-
continue;
470468
}
471469
}
472470
}
@@ -489,16 +487,16 @@ private void saveImmediate() {
489487
.observeOn(AndroidSchedulers.mainThread())
490488
.subscribe(() -> disposables.add(remotePlaylistManager.updatePlaylists(
491489
remoteItemsUpdate, remoteItemsDeleteUid)
492-
.observeOn(AndroidSchedulers.mainThread())
493-
.subscribe(() -> {
494-
if (isModified != null) {
495-
isModified.set(false);
496-
}
497-
},
498-
throwable -> showError(new ErrorInfo(throwable,
499-
UserAction.REQUESTED_BOOKMARK,
500-
"Saving playlist"))
501-
)),
490+
.observeOn(AndroidSchedulers.mainThread())
491+
.subscribe(() -> {
492+
if (isModified != null) {
493+
isModified.set(false);
494+
}
495+
},
496+
throwable -> showError(new ErrorInfo(throwable,
497+
UserAction.REQUESTED_BOOKMARK,
498+
"Saving playlist"))
499+
)),
502500
throwable -> showError(new ErrorInfo(throwable,
503501
UserAction.REQUESTED_BOOKMARK, "Saving playlist"))
504502
));
@@ -529,22 +527,21 @@ public int interpolateOutOfBoundsScroll(@NonNull final RecyclerView recyclerView
529527
public boolean onMove(@NonNull final RecyclerView recyclerView,
530528
@NonNull final RecyclerView.ViewHolder source,
531529
@NonNull final RecyclerView.ViewHolder target) {
532-
if (source.getItemViewType() != target.getItemViewType()
533-
|| itemListAdapter == null) {
534-
// Allow swap LocalBookmarkPlaylistItemHolder and
535-
// RemoteBookmarkPlaylistItemHolder.
536-
if (!(
537-
(
538-
(source instanceof LocalBookmarkPlaylistItemHolder)
539-
|| (source instanceof RemoteBookmarkPlaylistItemHolder)
540-
)
541-
&& (
542-
(target instanceof LocalBookmarkPlaylistItemHolder)
543-
|| (target instanceof RemoteBookmarkPlaylistItemHolder)
544-
)
545-
)) {
546-
return false;
547-
}
530+
531+
// Allow swap LocalBookmarkPlaylistItemHolder and RemoteBookmarkPlaylistItemHolder.
532+
if (itemListAdapter == null
533+
|| source.getItemViewType() != target.getItemViewType()
534+
&& !(
535+
(
536+
(source instanceof LocalBookmarkPlaylistItemHolder)
537+
|| (source instanceof RemoteBookmarkPlaylistItemHolder)
538+
)
539+
&& (
540+
(target instanceof LocalBookmarkPlaylistItemHolder)
541+
|| (target instanceof RemoteBookmarkPlaylistItemHolder)
542+
))
543+
) {
544+
return false;
548545
}
549546

550547
final int sourceIndex = source.getBindingAdapterPosition();
@@ -569,6 +566,7 @@ public boolean isItemViewSwipeEnabled() {
569566
@Override
570567
public void onSwiped(@NonNull final RecyclerView.ViewHolder viewHolder,
571568
final int swipeDir) {
569+
// Do nothing.
572570
}
573571
};
574572
}

app/src/main/java/org/schabi/newpipe/local/holder/LocalBookmarkPlaylistItemHolder.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
1010
import org.schabi.newpipe.local.LocalItemBuilder;
1111
import org.schabi.newpipe.local.history.HistoryRecordManager;
12-
import org.schabi.newpipe.util.Localization;
13-
import org.schabi.newpipe.util.PicassoHelper;
1412

1513
import java.time.format.DateTimeFormatter;
1614

17-
public class LocalBookmarkPlaylistItemHolder extends PlaylistItemHolder {
15+
public class LocalBookmarkPlaylistItemHolder extends LocalPlaylistItemHolder {
1816
private final View itemHandleView;
1917

2018
public LocalBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
@@ -37,13 +35,6 @@ public void updateFromItem(final LocalItem localItem,
3735
}
3836
final PlaylistMetadataEntry item = (PlaylistMetadataEntry) localItem;
3937

40-
itemTitleView.setText(item.name);
41-
itemStreamCountView.setText(Localization.localizeStreamCountMini(
42-
itemStreamCountView.getContext(), item.streamCount));
43-
itemUploaderView.setVisibility(View.INVISIBLE);
44-
45-
PicassoHelper.loadPlaylistThumbnail(item.thumbnailUrl).into(itemThumbnailView);
46-
4738
itemHandleView.setOnTouchListener(getOnTouchListener(item));
4839

4940
super.updateFromItem(localItem, historyRecordManager, dateTimeFormatter);

app/src/main/java/org/schabi/newpipe/local/holder/LocalPlaylistItemHolder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.view.View;
44
import android.view.ViewGroup;
55

6-
import org.schabi.newpipe.R;
76
import org.schabi.newpipe.database.LocalItem;
87
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
98
import org.schabi.newpipe.local.LocalItemBuilder;
@@ -16,7 +15,7 @@
1615
public class LocalPlaylistItemHolder extends PlaylistItemHolder {
1716

1817
public LocalPlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final ViewGroup parent) {
19-
this(infoItemBuilder, R.layout.list_playlist_mini_item, parent);
18+
super(infoItemBuilder, parent);
2019
}
2120

2221
LocalPlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final int layoutId,

app/src/main/java/org/schabi/newpipe/local/holder/RemoteBookmarkPlaylistItemHolder.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
package org.schabi.newpipe.local.holder;
22

3-
import android.text.TextUtils;
43
import android.view.MotionEvent;
54
import android.view.View;
65
import android.view.ViewGroup;
76

87
import org.schabi.newpipe.R;
98
import org.schabi.newpipe.database.LocalItem;
109
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
11-
import org.schabi.newpipe.extractor.NewPipe;
1210
import org.schabi.newpipe.local.LocalItemBuilder;
1311
import org.schabi.newpipe.local.history.HistoryRecordManager;
14-
import org.schabi.newpipe.util.Localization;
15-
import org.schabi.newpipe.util.PicassoHelper;
1612

1713
import java.time.format.DateTimeFormatter;
1814

19-
public class RemoteBookmarkPlaylistItemHolder extends PlaylistItemHolder {
15+
public class RemoteBookmarkPlaylistItemHolder extends RemotePlaylistItemHolder {
2016
private final View itemHandleView;
2117

2218
public RemoteBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
@@ -39,19 +35,6 @@ public void updateFromItem(final LocalItem localItem,
3935
}
4036
final PlaylistRemoteEntity item = (PlaylistRemoteEntity) localItem;
4137

42-
itemTitleView.setText(item.getName());
43-
itemStreamCountView.setText(Localization.localizeStreamCountMini(
44-
itemStreamCountView.getContext(), item.getStreamCount()));
45-
// Here is where the uploader name is set in the bookmarked playlists library
46-
if (!TextUtils.isEmpty(item.getUploader())) {
47-
itemUploaderView.setText(Localization.concatenateStrings(item.getUploader(),
48-
NewPipe.getNameOfService(item.getServiceId())));
49-
} else {
50-
itemUploaderView.setText(NewPipe.getNameOfService(item.getServiceId()));
51-
}
52-
53-
PicassoHelper.loadPlaylistThumbnail(item.getThumbnailUrl()).into(itemThumbnailView);
54-
5538
itemHandleView.setOnTouchListener(getOnTouchListener(item));
5639

5740
super.updateFromItem(localItem, historyRecordManager, dateTimeFormatter);

app/src/main/java/org/schabi/newpipe/local/holder/RemotePlaylistItemHolder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.text.TextUtils;
44
import android.view.ViewGroup;
55

6-
import org.schabi.newpipe.R;
76
import org.schabi.newpipe.database.LocalItem;
87
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
98
import org.schabi.newpipe.extractor.NewPipe;
@@ -18,7 +17,7 @@ public class RemotePlaylistItemHolder extends PlaylistItemHolder {
1817

1918
public RemotePlaylistItemHolder(final LocalItemBuilder infoItemBuilder,
2019
final ViewGroup parent) {
21-
this(infoItemBuilder, R.layout.list_playlist_mini_item, parent);
20+
super(infoItemBuilder, parent);
2221
}
2322

2423
RemotePlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final int layoutId,

0 commit comments

Comments
 (0)