X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fhelpers%2FBookmarksDatabaseHelper.java;h=cceebf02b4005bf13d2fda1abb19d3699992180f;hp=984402e826a077877b8117e0323d5a8e19a4b243;hb=333ec579b52efbfbad89e0150c7c320822ba9ecf;hpb=fbb7aef30a9417c42661a0f76b5836dcf6a40242 diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java index 984402e8..cceebf02 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java @@ -1,20 +1,20 @@ /* - * Copyright © 2016-2019 Soren Stoutner . + * Copyright © 2016-2022 Soren Stoutner . * - * This file is part of Privacy Browser . + * This file is part of Privacy Browser Android . * - * Privacy Browser is free software: you can redistribute it and/or modify + * Privacy Browser Android is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * Privacy Browser is distributed in the hope that it will be useful, + * Privacy Browser Android is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser. If not, see . + * along with Privacy Browser Android. If not, see . */ package com.stoutner.privacybrowser.helpers; @@ -147,7 +147,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { // Get the folder name. folderCursor.moveToFirst(); - String folderName = folderCursor.getString(folderCursor.getColumnIndex(BOOKMARK_NAME)); + String folderName = folderCursor.getString(folderCursor.getColumnIndexOrThrow(BOOKMARK_NAME)); // Close the cursor and the database handle. folderCursor.close(); @@ -175,7 +175,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { // Get the database ID. folderCursor.moveToFirst(); - int databaseId = folderCursor.getInt(folderCursor.getColumnIndex(_ID)); + int databaseId = folderCursor.getInt(folderCursor.getColumnIndexOrThrow(_ID)); // Close the cursor and the database handle. folderCursor.close(); @@ -255,7 +255,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { bookmarkCursor.moveToFirst(); // Store the name of the parent folder. - String parentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(PARENT_FOLDER)); + String parentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndexOrThrow(PARENT_FOLDER)); // Close the cursor. bookmarkCursor.close(); @@ -277,7 +277,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { bookmarkCursor.moveToFirst(); // Store the name of the parent folder. - String parentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(PARENT_FOLDER)); + String parentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndexOrThrow(PARENT_FOLDER)); // Close the cursor. bookmarkCursor.close(); @@ -334,12 +334,14 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { // Extract the array of IDs not to get to the string builder. for (long databaseIdLong : exceptIdLongArray) { - if (idsNotToGetStringBuilder.length() == 0) { // This is the first number, so only add the number. - idsNotToGetStringBuilder.append(databaseIdLong); - } else { // This is not the first number, so place a `,` before the new number. + // Check to see if there is already a number in the builder. + if (idsNotToGetStringBuilder.length() > 0) { + // This is not the first number, so place a `,` before the new number. idsNotToGetStringBuilder.append(","); - idsNotToGetStringBuilder.append(databaseIdLong); } + + // Add the new number to the builder. + idsNotToGetStringBuilder.append(databaseIdLong); } // Prepare the SQL statement to select all items except those with the specified IDs. @@ -360,12 +362,14 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { // Extract the array of IDs not to get to the string builder. for (long databaseIdLong : exceptIdLongArray) { - if (idsNotToGetStringBuilder.length() == 0) { // This is the first number, so only add the number. - idsNotToGetStringBuilder.append(databaseIdLong); - } else { // This is not the first number, so place a `,` before the new number. + // Check to see if there is already a number in the builder. + if (idsNotToGetStringBuilder.length() > 0) { + // This is not the first number, so place a `,` before the new number. idsNotToGetStringBuilder.append(","); - idsNotToGetStringBuilder.append(databaseIdLong); } + + // Add the new number to the builder. + idsNotToGetStringBuilder.append(databaseIdLong); } // Prepare the SQL statement to select all items except those with the specified IDs. @@ -411,7 +415,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { } // Get a cursor with just database ID of bookmarks and folders in the specified folder. This is useful for deleting folders with bookmarks that have favorite icons too large to fit in a cursor. - public Cursor getBookmarkIDs(String folderName) { + public Cursor getBookmarkIds(String folderName) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); @@ -436,12 +440,14 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { // Extract the array of IDs not to get to the string builder. for (long databaseIdLong : exceptIdLongArray) { - if (idsNotToGetStringBuilder.length() == 0) { // This is the first number, so only add the number. - idsNotToGetStringBuilder.append(databaseIdLong); - } else { // This is not the first number, so place a `,` before the new number. + // Check to see if there is already a number in the builder. + if (idsNotToGetStringBuilder.length() > 0) { + // This is not the first number, so place a `,` before the new number. idsNotToGetStringBuilder.append(","); - idsNotToGetStringBuilder.append(databaseIdLong); } + + // Add the new number to the builder. + idsNotToGetStringBuilder.append(databaseIdLong); } // SQL escape the folder name. @@ -466,12 +472,14 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { // Extract the array of IDs not to get to the string builder. for (long databaseIdLong : exceptIdLongArray) { - if (idsNotToGetStringBuilder.length() == 0) { // This is the first number, so only add the number. - idsNotToGetStringBuilder.append(databaseIdLong); - } else { // This is not the first number, so place a `,` before the new number. + // Check to see if there is already a number in the builder. + if (idsNotToGetStringBuilder.length() > 0) { + // This is not the first number, so place a `,` before the new number. idsNotToGetStringBuilder.append(","); - idsNotToGetStringBuilder.append(databaseIdLong); } + + // Add the new number to the builder. + idsNotToGetStringBuilder.append(databaseIdLong); } // SQL escape `folderName`. @@ -501,7 +509,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { // Ascertain if this database ID is a folder. folderCursor.moveToFirst(); - boolean isFolder = (folderCursor.getInt(folderCursor.getColumnIndex(IS_FOLDER)) == 1); + boolean isFolder = (folderCursor.getInt(folderCursor.getColumnIndexOrThrow(IS_FOLDER)) == 1); // Close the cursor and the database handle. folderCursor.close(); @@ -759,7 +767,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { newFolderCursor.moveToLast(); // Set the display order to be one greater that the last bookmark. - displayOrder = newFolderCursor.getInt(newFolderCursor.getColumnIndex(DISPLAY_ORDER)) + 1; + displayOrder = newFolderCursor.getInt(newFolderCursor.getColumnIndexOrThrow(DISPLAY_ORDER)) + 1; } else { // There are no bookmarks in the new folder. // Set the display order to be `0`. displayOrder = 0;