From: Soren Stoutner Date: Fri, 15 Jul 2016 20:44:38 +0000 (-0700) Subject: Add the ability to create and edit bookmark folders. X-Git-Tag: v1.8~2 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff_plain;h=c4ad9f457f41cbc86391e0099629cd94a235258a Add the ability to create and edit bookmark folders. --- diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml index 2d91de18..f6e91ca9 100644 --- a/.idea/dictionaries/soren.xml +++ b/.idea/dictionaries/soren.xml @@ -35,6 +35,8 @@ orbot panopticlick parentfolder + radiobutton + radiogroup redmine referer relativelayout diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 17fb93ab..60d1f3aa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,7 +28,7 @@ - + - + - + - + @@ -69,48 +69,54 @@ - + - + android:persistableMode="persistNever" /> + + + - + - + android:persistableMode="persistNever" /> - + - + android:persistableMode="persistNever" /> - + - + android:persistableMode="persistNever" /> diff --git a/app/src/main/assets/about_licenses.html b/app/src/main/assets/about_licenses.html index 63e79966..f09fbb42 100644 --- a/app/src/main/assets/about_licenses.html +++ b/app/src/main/assets/about_licenses.html @@ -23,8 +23,10 @@ color: 0D4781; } - img.center { + img.icon { vertical-align: middle; + height: 32; + width: 32; } img.left { @@ -55,37 +57,43 @@ are derived from ic_security and ic_language. Modifications were made by Soren Stoutner in 2016.

-

ic_language.

+

ic_language.

-

ic_home.

+

ic_home.

-

ic_arrow_back.

+

ic_arrow_back.

-

ic_arrow_forward.

+

ic_arrow_forward.

-

ic_bookmark_border.

+

ic_bookmark_border.

-

ic_file_download.

+

ic_file_download.

-

ic_settings.

+

ic_settings.

-

ic_import_contacts.

+

ic_import_contacts.

-

ic_info_outline.

+

ic_info_outline.

-

ic_exit_to_app.

+

ic_exit_to_app.

-

ic_add.

+

ic_add.

-

ic_vertical_align_top

+

ic_vertical_align_top

-

ic_vertical_align_bottom

+

ic_vertical_align_bottom

-

ic_edit.

+

ic_folder

-

ic_download.

+

ic_create_new_folder

-

ic_select_all

+

ic_folder_special

+ +

ic_edit.

+ +

ic_download.

+ +

ic_select_all


GNU General Public License

diff --git a/app/src/main/assets/images/ic_create_new_folder.png b/app/src/main/assets/images/ic_create_new_folder.png new file mode 100644 index 00000000..db0234d7 Binary files /dev/null and b/app/src/main/assets/images/ic_create_new_folder.png differ diff --git a/app/src/main/assets/images/ic_folder.png b/app/src/main/assets/images/ic_folder.png new file mode 100644 index 00000000..e1b3183d Binary files /dev/null and b/app/src/main/assets/images/ic_folder.png differ diff --git a/app/src/main/assets/images/ic_folder_special.png b/app/src/main/assets/images/ic_folder_special.png new file mode 100644 index 00000000..2eef308a Binary files /dev/null and b/app/src/main/assets/images/ic_folder_special.png differ diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java index 75a34021..ca004072 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java @@ -22,15 +22,19 @@ package com.stoutner.privacybrowser; import android.app.Activity; import android.app.DialogFragment; import android.content.Context; +import android.content.Intent; import android.database.Cursor; +import android.database.DatabaseUtils; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v4.app.NavUtils; +import android.support.v4.content.ContextCompat; import android.support.v4.widget.CursorAdapter; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; @@ -47,11 +51,14 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; +import android.widget.RadioButton; import android.widget.TextView; import java.io.ByteArrayOutputStream; -public class BookmarksActivity extends AppCompatActivity implements CreateBookmark.CreateBookmarkListener, EditBookmark.EditBookmarkListener { +public class BookmarksActivity extends AppCompatActivity implements CreateBookmark.CreateBookmarkListener, + CreateBookmarkFolder.CreateBookmarkFolderListener, EditBookmark.EditBookmarkListener, + EditBookmarkFolder.EditBookmarkFolderListener { // `bookmarksDatabaseHandler` is public static so it can be accessed from EditBookmark. It is also used in `onCreate()`, // `onCreateBookmarkCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`. public static BookmarksDatabaseHandler bookmarksDatabaseHandler; @@ -60,34 +67,50 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // It is also used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`. public static ListView bookmarksListView; + // `currentFolder` is used in `onCreate`, `onOptionsItemSelected()`, `onCreateBookmarkCreate`, `onCreateBookmarkFolderCreate`, and `onEditBookmarkSave`. + private String currentFolder; + // `contextualActionMode` is used in `onCreate()` and `onEditBookmarkSave()`. private ActionMode contextualActionMode; // `selectedBookmarkPosition` is used in `onCreate()` and `onEditBookarkSave()`. private int selectedBookmarkPosition; + // `appBar` is used in `onCreate()` and `updateBookmarksListView()`. + private ActionBar appBar; + + // `bookmarksCursor` is used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`. + private Cursor bookmarksCursor; + + // `oldFolderName` is used in `onCreate()` and `onEditBookmarkFolderSave()`. + private String oldFolderNameString; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bookmarks_coordinatorlayout); - // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21. + // We need to use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21. final Toolbar bookmarksAppBar = (Toolbar) findViewById(R.id.bookmarks_toolbar); setSupportActionBar(bookmarksAppBar); - // Display the home arrow on supportAppBar. - final ActionBar appBar = getSupportActionBar(); + // Display the home arrow on `SupportActionBar`. + appBar = getSupportActionBar(); assert appBar != null;// This assert removes the incorrect warning in Android Studio on the following line that appBar might be null. appBar.setDisplayHomeAsUpEnabled(true); + // Initialize the database handler and the ListView. // `this` specifies the context. The two `null`s do not specify the database name or a `CursorFactory`. - // The `0` is to specify a database version, but that is set instead using a constant in BookmarksDatabaseHandler. + // The `0` is to specify a database version, but that is set instead using a constant in `BookmarksDatabaseHandler`. bookmarksDatabaseHandler = new BookmarksDatabaseHandler(this, null, null, 0); bookmarksListView = (ListView) findViewById(R.id.bookmarks_listview); + // Set currentFolder to the home folder, which is null in the database. + currentFolder = ""; + // Display the bookmarks in the ListView. - updateBookmarksListView(); + updateBookmarksListView(currentFolder); // Set a listener so that tapping a list item loads the URL. We need to store the activity // in a variable so that we can return to the parent activity after loading the URL. @@ -98,12 +121,28 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Convert the id from long to int to match the format of the bookmarks database. int databaseID = (int) id; - // Get the bookmark URL and assign it to formattedUrlString. - MainWebViewActivity.formattedUrlString = bookmarksDatabaseHandler.getBookmarkURL(databaseID); + // Get the bookmark `Cursor` and move it to the first row. + Cursor bookmarkCursor = bookmarksDatabaseHandler.getBookmarkCursor(databaseID); + bookmarkCursor.moveToFirst(); + + // If the bookmark is a folder load its contents into the ListView. + if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1) { + // Update `currentFolder`. + currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + + // Reload the ListView with `currentFolder`. + updateBookmarksListView(currentFolder); + } else { // Load the URL into `mainWebView`. + // Get the bookmark URL and assign it to formattedUrlString. + MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_URL)); + + // Load formattedUrlString and return to the main activity. + MainWebViewActivity.mainWebView.loadUrl(MainWebViewActivity.formattedUrlString); + NavUtils.navigateUpFromSameTask(bookmarksActivity); + } - // Load formattedUrlString and return to the main activity. - MainWebViewActivity.mainWebView.loadUrl(MainWebViewActivity.formattedUrlString); - NavUtils.navigateUpFromSameTask(bookmarksActivity); + // Close the `Cursor`. + bookmarkCursor.close(); } }); @@ -125,7 +164,14 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate the menu for the contextual app bar and set the title. getMenuInflater().inflate(R.menu.bookmarks_context_menu, menu); - mode.setTitle(R.string.bookmarks); + + // Set the title. + if (currentFolder.isEmpty()) { + // Use `R.string.bookmarks` if we are in the home folder. + mode.setTitle(R.string.bookmarks); + } else { // Use the current folder name as the title. + mode.setTitle(currentFolder); + } // Get a handle for MenuItems we need to selectively disable. moveBookmarkUpMenuItem = menu.findItem(R.id.move_bookmark_up); @@ -202,12 +248,14 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // `numberOfBookmarks` is used in `R.id.move_bookmark_up_enabled`, `R.id.move_bookmark_down_enabled`, and `R.id.context_menu_select_all_bookmarks`. int numberOfBookmarks; - // `selectedBookmarkLongArray` is used in `R.id.move_bookmark_up` and `R.id.move_bookmark_down`. + // `selectedBookmarkLongArray` is used in `R.id.move_bookmark_up`, `R.id.move_bookmark_down`, and `R.id.edit_bookmark`. long[]selectedBookmarkLongArray; - // `selectedBookmarkDatabaseId` is used in `R.id.move_bookmark_up` and `R.id.move_bookmark_down`. + // `selectedBookmarkDatabaseId` is used in `R.id.move_bookmark_up`, `R.id.move_bookmark_down`, and `R.id.edit_bookmark`. int selectedBookmarkDatabaseId; // `selectedBookmarkNewPosition` is used in `R.id.move_bookmark_up` and `R.id.move_bookmark_down`. int selectedBookmarkNewPosition; + // `bookmarkPositionSparseBooleanArray` is used in `R.id.edit_bookmark` and `R.id.delete_bookmark`. + SparseBooleanArray bookmarkPositionSparseBooleanArray; switch (menuItemId) { case R.id.move_bookmark_up: @@ -238,7 +286,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } // Refresh the ListView. - updateBookmarksListView(); + updateBookmarksListView(currentFolder); // Select the previously selected bookmark in the new location. bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true); @@ -275,7 +323,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } // Refresh the ListView. - updateBookmarksListView(); + updateBookmarksListView(currentFolder); // Select the previously selected bookmark in the new location. bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true); @@ -284,22 +332,44 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma break; case R.id.edit_bookmark: + // Get a handle for `contextualActionMode` so we can close it when `editBookmarkDialog` is finished. + contextualActionMode = mode; + // Get a handle for `selectedBookmarkPosition` so we can scroll to it after refreshing the ListView. - SparseBooleanArray bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions(); + bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions(); selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0); - // Get a handle for `contextualActionMode` so we can close it when `editBookmarkDialog` is finished. - contextualActionMode = mode; + // Move to the selected database ID and find out if it is a folder. + bookmarksCursor.moveToPosition(selectedBookmarkPosition); + boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1); - // Show the `EditBookmark` `AlertDialog` and name the instance `@string/edit_bookmark`. - DialogFragment editBookmarkDialog = new EditBookmark(); - editBookmarkDialog.show(getFragmentManager(), "@string/edit_bookmark"); + if (isFolder) { + // Save the current folder name. + oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + + // Show the `EditBookmarkFolder` `AlertDialog` and name the instance `@string/edit_folder`. + DialogFragment editFolderDialog = new EditBookmarkFolder(); + editFolderDialog.show(getFragmentManager(), getResources().getString(R.string.edit_folder)); + } else { + // Show the `EditBookmark` `AlertDialog` and name the instance `@string/edit_bookmark`. + DialogFragment editBookmarkDialog = new EditBookmark(); + editBookmarkDialog.show(getFragmentManager(), getResources().getString(R.string.edit_bookmark)); + } break; case R.id.delete_bookmark: // Get an array of the selected rows. final long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds(); + // Get a handle for `selectedBookmarkPosition` so we can scroll to it after refreshing the ListView. + bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions(); + selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0); + + updateBookmarksListViewExcept(selectedBookmarksLongArray, currentFolder); + + // Scroll to where the deleted bookmark was located. + bookmarksListView.setSelection(selectedBookmarkPosition); + String snackbarMessage; // Determine how many items are in the array and prepare an appropriate Snackbar message. @@ -309,8 +379,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma snackbarMessage = selectedBookmarksLongArray.length + " " + getString(R.string.bookmarks_deleted); } - updateBookmarksListViewExcept(selectedBookmarksLongArray); - // Show a SnackBar. Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), snackbarMessage, Snackbar.LENGTH_LONG) .setAction(R.string.undo, new View.OnClickListener() { @@ -326,7 +394,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // The user pushed the "Undo" button. case Snackbar.Callback.DISMISS_EVENT_ACTION: // Refresh the ListView to show the rows again. - updateBookmarksListView(); + updateBookmarksListView(currentFolder); break; @@ -376,7 +444,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma public void onClick(View view) { // Show the `CreateBookmark` `AlertDialog` and name the instance `@string/create_bookmark`. DialogFragment createBookmarkDialog = new CreateBookmark(); - createBookmarkDialog.show(getFragmentManager(), "@string/create_bookmark"); + createBookmarkDialog.show(getFragmentManager(), getResources().getString(R.string.create_bookmark)); } }); } @@ -402,7 +470,21 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma switch (menuItemId) { case android.R.id.home: - NavUtils.navigateUpFromSameTask(this); + // Exit BookmarksActivity if currently at the home folder. + if (currentFolder.isEmpty()) { + NavUtils.navigateUpFromSameTask(this); + } else { // Navigate up one folder. + // Place the former parent folder in `currentFolder`. + currentFolder = bookmarksDatabaseHandler.getParentFolder(currentFolder); + + updateBookmarksListView(currentFolder); + } + break; + + case R.id.create_folder: + // Show the `CreateBookmarkFolder` `AlertDialog` and name the instance `@string/create_folder`. + DialogFragment createBookmarkFolderDialog = new CreateBookmarkFolder(); + createBookmarkFolderDialog.show(getFragmentManager(), getResources().getString(R.string.create_folder)); break; case R.id.options_menu_select_all_bookmarks: @@ -412,21 +494,27 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma bookmarksListView.setItemChecked(i, true); } break; + + case R.id.bookmarks_database_view: + // Launch `BookmarksDatabaseViewActivity`. + Intent bookmarksDatabaseViewIntent = new Intent(this, BookmarksDatabaseViewActivity.class); + startActivity(bookmarksDatabaseViewIntent); + break; } return true; } @Override - public void onCreateBookmarkCancel(DialogFragment createBookmarkDialogFragment) { + public void onCancelCreateBookmark(DialogFragment dialogFragment) { // Do nothing because the user selected `Cancel`. } @Override - public void onCreateBookmarkCreate(DialogFragment createBookmarkDialogFragment) { + public void onCreateBookmark(DialogFragment dialogFragment) { // Get the `EditText`s from the `createBookmarkDialogFragment` and extract the strings. - EditText createBookmarkNameEditText = (EditText) createBookmarkDialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext); + EditText createBookmarkNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext); String bookmarkNameString = createBookmarkNameEditText.getText().toString(); - EditText createBookmarkUrlEditText = (EditText) createBookmarkDialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext); + EditText createBookmarkUrlEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext); String bookmarkUrlString = createBookmarkUrlEditText.getText().toString(); // Convert the favoriteIcon Bitmap to a byte array. `0` is for lossless compression (the only option for a PNG). @@ -438,63 +526,175 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma int newBookmarkDisplayOrder = bookmarksListView.getCount(); // Create the bookmark. - bookmarksDatabaseHandler.createBookmark(bookmarkNameString, bookmarkUrlString, newBookmarkDisplayOrder, favoriteIconByteArray); + bookmarksDatabaseHandler.createBookmark(bookmarkNameString, bookmarkUrlString, newBookmarkDisplayOrder, currentFolder, favoriteIconByteArray); // Refresh the ListView. `setSelection` scrolls to the bottom of the list. - updateBookmarksListView(); - bookmarksListView.setSelection(bookmarksListView.getCount()); + updateBookmarksListView(currentFolder); + bookmarksListView.setSelection(newBookmarkDisplayOrder); } @Override - public void onEditBookmarkCancel(DialogFragment editBookmarkDialogFragment) { + public void onCancelCreateBookmarkFolder(DialogFragment dialogFragment) { // Do nothing because the user selected `Cancel`. } @Override - public void onEditBookmarkSave(DialogFragment editBookmarkDialogFragment) { - // Get the `EditText`s from the `editBookmarkDialogFragment` and extract the strings. - EditText editBookmarkNameEditText = (EditText) editBookmarkDialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext); - String bookmarkNameString = editBookmarkNameEditText.getText().toString(); - EditText editBookmarkUrlEditText = (EditText) editBookmarkDialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext); - String bookmarkUrlString = editBookmarkUrlEditText.getText().toString(); + public void onCreateBookmarkFolder(DialogFragment dialogFragment) { + // Get `create_folder_name_edit_text` and extract the string. + EditText createFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext); + String folderNameString = createFolderNameEditText.getText().toString(); + + // Check to see if the folder already exists. + Cursor bookmarkFolderCursor = bookmarksDatabaseHandler.getFolderCursor(folderNameString); + int existingFoldersWithNewName = bookmarkFolderCursor.getCount(); + bookmarkFolderCursor.close(); + if (folderNameString.isEmpty() || (existingFoldersWithNewName > 0)) { + String cannotCreateFolder = getResources().getString(R.string.cannot_create_folder) + " \"" + folderNameString + "\""; + Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), cannotCreateFolder, Snackbar.LENGTH_INDEFINITE).show(); + } else { // Create the folder. + // Get the new folder icon. + RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobuttion); + Bitmap folderIconBitmap; + if (defaultFolderIconRadioButton.isChecked()) { + // Get the default folder icon drawable and convert it to a `Bitmap`. `this` specifies the current context. + Drawable folderIconDrawable = ContextCompat.getDrawable(this, R.drawable.folder_blue_bitmap); + BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable; + folderIconBitmap = folderIconBitmapDrawable.getBitmap(); + } else { + folderIconBitmap = MainWebViewActivity.favoriteIcon; + } - CheckBox useNewFavoriteIconBitmap = (CheckBox) editBookmarkDialogFragment.getDialog().findViewById(R.id.edit_bookmark_use_new_favorite_icon_checkbox); - byte[] favoriteIconByteArray; + // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG). + ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream(); + folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream); + byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray(); + + // Move all the bookmarks down one in the display order. + for (int i = 0; i < bookmarksListView.getCount(); i++) { + int databaseId = (int) bookmarksListView.getItemIdAtPosition(i); + bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i + 1); + } + // Create the folder, placing it at the top of the ListView + bookmarksDatabaseHandler.createFolder(folderNameString, 0, currentFolder, folderIconByteArray); + + // Refresh the ListView. + updateBookmarksListView(currentFolder); + } + } + + @Override + public void onCancelEditBookmark(DialogFragment dialogFragment) { + // Do nothing because the user selected `Cancel`. + } + + @Override + public void onSaveEditBookmark(DialogFragment dialogFragment) { // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`. long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds(); int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0]; - if (useNewFavoriteIconBitmap.isChecked()) { - // Get the new favorite icon from the Dialog and convert it into a Bitmap. - ImageView newFavoriteIconImageView = (ImageView) editBookmarkDialogFragment.getDialog().findViewById(R.id.edit_bookmark_new_favorite_icon); - Drawable favoriteIconDrawable = newFavoriteIconImageView.getDrawable(); - Bitmap favoriteIconBitmap = ((BitmapDrawable) favoriteIconDrawable).getBitmap(); + // Get the `EditText`s from the `editBookmarkDialogFragment` and extract the strings. + EditText editBookmarkNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext); + String bookmarkNameString = editBookmarkNameEditText.getText().toString(); + EditText editBookmarkUrlEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext); + String bookmarkUrlString = editBookmarkUrlEditText.getText().toString(); - // Convert the new `favoriteIconBitmap` into a Byte Array. - ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream(); - favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream); - favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray(); + // Get `edit_bookmark_current_icon_radiobutton`. + RadioButton currentBookmarkIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton); - // Update the bookmark and the favorite icon. - bookmarksDatabaseHandler.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, favoriteIconByteArray); - } else { // Update the bookmark without changing the favorite icon. + if (currentBookmarkIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon. bookmarksDatabaseHandler.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString); + } else { // Update the bookmark and the favorite icon. + // Get the new favorite icon from the `Dialog` and convert it into a `Bitmap`. + ImageView newFavoriteIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_web_page_favorite_icon); + Drawable newFavoriteIconDrawable = newFavoriteIconImageView.getDrawable(); + Bitmap newFavoriteIconBitmap = ((BitmapDrawable) newFavoriteIconDrawable).getBitmap(); + + // Convert `newFavoriteIconBitmap` into a Byte Array. + ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream(); + newFavoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream); + byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray(); + + // Update the bookmark and the favorite icon. + bookmarksDatabaseHandler.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, newFavoriteIconByteArray); } // Close the contextual action mode. contextualActionMode.finish(); - // Refresh the `ListView`. `setSelection` scrolls to that position. - updateBookmarksListView(); + // Refresh the `ListView`. `setSelection` scrolls to the position of the bookmark that was edited. + updateBookmarksListView(currentFolder); bookmarksListView.setSelection(selectedBookmarkPosition); } - private void updateBookmarksListView() { - // Get a Cursor with the current contents of the bookmarks database. - final Cursor bookmarksCursor = bookmarksDatabaseHandler.getAllBookmarksCursor(); + @Override + public void onCancelEditBookmarkFolder(DialogFragment dialogFragment) { + // Do nothing because the user selected `Cancel`. + } + + @Override + public void onSaveEditBookmarkFolder(DialogFragment dialogFragment) { + // Get the new folder name. + EditText editFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext); + String newFolderNameString = editFolderNameEditText.getText().toString(); + + // Check to see if the new folder name is unique. + Cursor bookmarkFolderCursor = bookmarksDatabaseHandler.getFolderCursor(newFolderNameString); + int existingFoldersWithNewName = bookmarkFolderCursor.getCount(); + bookmarkFolderCursor.close(); + if ( ((existingFoldersWithNewName == 0) || newFolderNameString.equals(oldFolderNameString)) && !newFolderNameString.isEmpty()) { + // Get a long array with the the databaseId of the selected folder and convert it to an `int`. + long[] selectedFolderLongArray = bookmarksListView.getCheckedItemIds(); + int selectedFolderDatabaseId = (int) selectedFolderLongArray[0]; + + // Get the `RadioButtons` from the `Dialog`. + RadioButton currentFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton); + RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton); + Bitmap folderIconBitmap; + + // Prepare the favorite icon. + if (currentFolderIconRadioButton.isChecked()) { + // Update the folder name if it has changed. + if (!newFolderNameString.equals(oldFolderNameString)) { + bookmarksDatabaseHandler.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString); + + // Refresh the `ListView`. `setSelection` scrolls to the position of the folder that was edited. + updateBookmarksListView(currentFolder); + bookmarksListView.setSelection(selectedBookmarkPosition); + } + } else { // Prepare the new favorite icon. + if (defaultFolderIconRadioButton.isChecked()) { + // Get the default folder icon drawable and convert it to a `Bitmap`. `this` specifies the current context. + Drawable folderIconDrawable = ContextCompat.getDrawable(this, R.drawable.folder_blue_bitmap); + BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable; + folderIconBitmap = folderIconBitmapDrawable.getBitmap(); + } else { // Use the web page favorite icon. + folderIconBitmap = MainWebViewActivity.favoriteIcon; + } + + // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG). + ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream(); + folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream); + byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray(); + + bookmarksDatabaseHandler.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray); + + // Refresh the `ListView`. `setSelection` scrolls to the position of the folder that was edited. + updateBookmarksListView(currentFolder); + bookmarksListView.setSelection(selectedBookmarkPosition); + } + } else { // Don't edit the folder because the new name is not unique. + String cannot_rename_folder = getResources().getString(R.string.cannot_rename_folder) + " \"" + newFolderNameString + "\""; + Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), cannot_rename_folder, Snackbar.LENGTH_INDEFINITE).show(); + } + } + + private void updateBookmarksListView(String folderName) { + // Get a `Cursor` with the current contents of the bookmarks database. + bookmarksCursor = bookmarksDatabaseHandler.getAllBookmarksCursorByDisplayOrder(folderName); - // Setup bookmarksCursorAdapter with `this` context. The `false` disables autoRequery. + // Setup `bookmarksCursorAdapter` with `this` context. The `false` disables autoRequery. CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { @@ -518,20 +718,34 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`. String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmark_name); - assert bookmarkNameTextView != null; // This assert removes the warning that bookmarkNameTextView might be null. bookmarkNameTextView.setText(bookmarkNameString); + + // Make the font bold for folders. + if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1) { + // The first argument is `null` because we don't want to chage the font. + bookmarkNameTextView.setTypeface(null, Typeface.BOLD); + } else { // Reset the font to default. + bookmarkNameTextView.setTypeface(Typeface.DEFAULT); + } } }; // Update the ListView. bookmarksListView.setAdapter(bookmarksCursorAdapter); + + // Set the AppBar title. + if (currentFolder.isEmpty()) { + appBar.setTitle(R.string.bookmarks); + } else { + appBar.setTitle(currentFolder); + } } - private void updateBookmarksListViewExcept(long[] exceptIdLongArray) { - // Get a Cursor with the current contents of the bookmarks database except for the specified database IDs. - final Cursor bookmarksCursor = bookmarksDatabaseHandler.getBookmarksCursorExcept(exceptIdLongArray); + private void updateBookmarksListViewExcept(long[] exceptIdLongArray, String folderName) { + // Get a `Cursor` with the current contents of the bookmarks database except for the specified database IDs. + bookmarksCursor = bookmarksDatabaseHandler.getBookmarksCursorExcept(exceptIdLongArray, folderName); - // Setup bookmarksCursorAdapter with `this` context. The `false` disables autoRequery. + // Setup `bookmarksCursorAdapter` with `this` context. The `false` disables autoRequery. CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { @@ -555,8 +769,15 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`. String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmark_name); - assert bookmarkNameTextView != null; // This assert removes the warning that bookmarkNameTextView might be null. bookmarkNameTextView.setText(bookmarkNameString); + + // Make the font bold for folders. + if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1) { + // The first argument is `null` because we don't want to chage the font. + bookmarkNameTextView.setTypeface(null, Typeface.BOLD); + } else { // Reset the font to default. + bookmarkNameTextView.setTypeface(Typeface.DEFAULT); + } } }; diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java b/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java index 5a5a025a..bc17bc7d 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java +++ b/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java @@ -22,8 +22,10 @@ package com.stoutner.privacybrowser; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; +import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import android.provider.ContactsContract; public class BookmarksDatabaseHandler extends SQLiteOpenHelper { private static final int SCHEMA_VERSION = 1; @@ -62,21 +64,41 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { // Code for upgrading the database will be added here when the schema version > 1. } - public void createBookmark(String bookmarkName, String bookmarkURL, int displayOrder, byte[] favoriteIcon) { + public void createBookmark(String bookmarkName, String bookmarkURL, int displayOrder, String parentFolder, byte[] favoriteIcon) { ContentValues bookmarkContentValues = new ContentValues(); // ID is created automatically. bookmarkContentValues.put(DISPLAY_ORDER, displayOrder); bookmarkContentValues.put(BOOKMARK_NAME, bookmarkName); bookmarkContentValues.put(BOOKMARK_URL, bookmarkURL); - bookmarkContentValues.put(PARENT_FOLDER, ""); + bookmarkContentValues.put(PARENT_FOLDER, parentFolder); bookmarkContentValues.put(IS_FOLDER, false); bookmarkContentValues.put(FAVORITE_ICON, favoriteIcon); // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); - // The second argument is "null", which makes it so that completely null rows cannot be created. Not a problem in our case. + // The second argument is `null`, which makes it so that completely null rows cannot be created. Not a problem in our case. + bookmarksDatabase.insert(BOOKMARKS_TABLE, null, bookmarkContentValues); + + // Close the database handle. + bookmarksDatabase.close(); + } + + public void createFolder(String folderName, int displayOrder, String parentFolder, byte[] favoriteIcon) { + ContentValues bookmarkContentValues = new ContentValues(); + + // ID is created automatically. + bookmarkContentValues.put(DISPLAY_ORDER, displayOrder); + bookmarkContentValues.put(BOOKMARK_NAME, folderName); + bookmarkContentValues.put(PARENT_FOLDER, parentFolder); + bookmarkContentValues.put(IS_FOLDER, true); + bookmarkContentValues.put(FAVORITE_ICON, favoriteIcon); + + // Get a writable database handle. + SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); + + // The second argument is `null`, which makes it so that completely null rows cannot be created. Not a problem in our case. bookmarksDatabase.insert(BOOKMARKS_TABLE, null, bookmarkContentValues); // Close the database handle. @@ -87,38 +109,54 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); - // Prepare the SQL statement to get the cursor for `databaseId` + // Prepare the SQL statement to get the `Cursor` for `databaseId` final String GET_ONE_BOOKMARK = "Select * FROM " + BOOKMARKS_TABLE + " WHERE " + _ID + " = " + databaseId; - // Return the results as a `Cursor`. The second argument is `null` because there are no selectionArgs. + // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. // We can't close the `Cursor` because we need to use it in the parent activity. return bookmarksDatabase.rawQuery(GET_ONE_BOOKMARK, null); } - public Cursor getBookmarksCursorExcept(long[] exceptIdLongArray) { + public Cursor getFolderCursor(String folderName) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); - // Prepare a string that contains the comma-separated list of IDs not to get. - String doNotGetIdsString = ""; - // Extract the array to `doNotGetIdsString`. - for (long databaseIdLong : exceptIdLongArray) { - // If this is the first number, only add the number. - if (doNotGetIdsString.isEmpty()) { - doNotGetIdsString = String.valueOf(databaseIdLong); - } else { // If there already is a number in the string, place a `,` before the number. - doNotGetIdsString = doNotGetIdsString + "," + databaseIdLong; - } - } + // SQL escape `folderName`. + folderName = DatabaseUtils.sqlEscapeString(folderName); - // Prepare the SQL statement to select all items except those with the specified IDs. - final String GET_All_BOOKMARKS_EXCEPT_SPECIFIED = "Select * FROM " + BOOKMARKS_TABLE + - " WHERE " + _ID + " NOT IN (" + doNotGetIdsString + ") ORDER BY " + DISPLAY_ORDER + " ASC"; + // Prepare the SQL statement to get the `Cursor` for the folder. + final String GET_FOLDER = "Select * FROM " + BOOKMARKS_TABLE + + " WHERE " + BOOKMARK_NAME + " = " + folderName + + " AND " + IS_FOLDER + " = " + 1; - // Return the results as a `Cursor`. The second argument is `null` because there are no selectionArgs. + // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. // We can't close the `Cursor` because we need to use it in the parent activity. - return bookmarksDatabase.rawQuery(GET_All_BOOKMARKS_EXCEPT_SPECIFIED, null); + return bookmarksDatabase.rawQuery(GET_FOLDER, null); + } + + public String getParentFolder(String currentFolder) { + // Get a readable database handle. + SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); + + // SQL escape `currentFolder`. + currentFolder = DatabaseUtils.sqlEscapeString(currentFolder); + + // Prepare the SQL statement to get the parent folder. + final String GET_PARENT_FOLDER = "Select * FROM " + BOOKMARKS_TABLE + + " WHERE " + IS_FOLDER + " = " + 1 + " AND " + BOOKMARK_NAME + " = " + currentFolder; + + // The second argument is `null` because there are no `selectionArgs`. + Cursor bookmarkCursor = bookmarksDatabase.rawQuery(GET_PARENT_FOLDER, null); + bookmarkCursor.moveToFirst(); + + // Store the name of the parent folder. + String parentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(PARENT_FOLDER)); + + // Close the `Cursor`. + bookmarkCursor.close(); + + return parentFolder; } public Cursor getAllBookmarksCursor() { @@ -126,35 +164,55 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); // Get everything in the BOOKMARKS_TABLE. - final String GET_ALL_BOOKMARKS = "Select * FROM " + BOOKMARKS_TABLE + " ORDER BY " + DISPLAY_ORDER + " ASC"; + final String GET_ALL_BOOKMARKS = "Select * FROM " + BOOKMARKS_TABLE; // Return the results as a Cursor. The second argument is `null` because there are no selectionArgs. // We can't close the Cursor because we need to use it in the parent activity. return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS, null); } - public String getBookmarkURL(int databaseId) { + public Cursor getAllBookmarksCursorByDisplayOrder(String folderName) { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); - // Prepare the SQL statement to get the row for the selected databaseId. - final String GET_BOOKMARK_URL = "Select * FROM " + BOOKMARKS_TABLE + - " WHERE " + _ID + " = " + databaseId; + // SQL escape `folderName`. + folderName = DatabaseUtils.sqlEscapeString(folderName); - // Save the results as Cursor and move it to the first (only) row. The second argument is "null" because there are no selectionArgs. - Cursor bookmarksCursor = bookmarksDatabase.rawQuery(GET_BOOKMARK_URL, null); - bookmarksCursor.moveToFirst(); + // Get everything in the BOOKMARKS_TABLE. + final String GET_ALL_BOOKMARKS = "Select * FROM " + BOOKMARKS_TABLE + + " WHERE " + PARENT_FOLDER + " = " + folderName + " ORDER BY " + DISPLAY_ORDER + " ASC"; - // Get the int that identifies the "BOOKMARK_URL" column and save the string as bookmarkURL. - int urlColumnInt = bookmarksCursor.getColumnIndex(BOOKMARK_URL); - String bookmarkURLString = bookmarksCursor.getString(urlColumnInt); + // Return the results as a Cursor. The second argument is `null` because there are no selectionArgs. + // We can't close the Cursor because we need to use it in the parent activity. + return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS, null); + } - // Close the Cursor and the database handle. - bookmarksCursor.close(); - bookmarksDatabase.close(); + public Cursor getBookmarksCursorExcept(long[] exceptIdLongArray, String folderName) { + // Get a readable database handle. + SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); - // Return the bookmarkURLString. - return bookmarkURLString; + // Prepare a string that contains the comma-separated list of IDs not to get. + String doNotGetIdsString = ""; + // Extract the array to `doNotGetIdsString`. + for (long databaseIdLong : exceptIdLongArray) { + // If this is the first number, only add the number. + if (doNotGetIdsString.isEmpty()) { + doNotGetIdsString = String.valueOf(databaseIdLong); + } else { // If there already is a number in the string, place a `,` before the number. + doNotGetIdsString = doNotGetIdsString + "," + databaseIdLong; + } + } + + // SQL escape `folderName`. + folderName = DatabaseUtils.sqlEscapeString(folderName); + + // Prepare the SQL statement to select all items except those with the specified IDs. + final String GET_All_BOOKMARKS_EXCEPT_SPECIFIED = "Select * FROM " + BOOKMARKS_TABLE + + " WHERE " + PARENT_FOLDER + " = " + folderName + " AND " + _ID + " NOT IN (" + doNotGetIdsString + ") ORDER BY " + DISPLAY_ORDER + " ASC"; + + // Return the results as a `Cursor`. The second argument is `null` because there are no selectionArgs. + // We can't close the `Cursor` because we need to use it in the parent activity. + return bookmarksDatabase.rawQuery(GET_All_BOOKMARKS_EXCEPT_SPECIFIED, null); } public void updateBookmark(int databaseId, String bookmarkName, String bookmarkUrl) { @@ -167,7 +225,7 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); - // Update the database. The last argument is `null` because there are no `whereArgs`. + // Update the bookmark. The last argument is `null` because there are no `whereArgs`. bookmarksDatabase.update(BOOKMARKS_TABLE, bookmarkContentValues, _ID + " = " + databaseId, null); // Close the database handle. @@ -185,13 +243,70 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); - // Update the database. The last argument is `null` because there are no `whereArgs`. + // Update the bookmark. The last argument is `null` because there are no `whereArgs`. bookmarksDatabase.update(BOOKMARKS_TABLE, bookmarkContentValues, _ID + " = " + databaseId, null); // Close the database handle. bookmarksDatabase.close(); } + public void updateFolder(int databaseId, String oldFolderName, String newFolderName) { + // Get a writable database handle. + SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); + + // Update the folder first. Store the updated values in `folderContentValues`. + ContentValues folderContentValues = new ContentValues(); + + folderContentValues.put(BOOKMARK_NAME, newFolderName); + + // Run the update on the folder. The last argument is `null` because there are no `whereArgs`. + bookmarksDatabase.update(BOOKMARKS_TABLE, folderContentValues, _ID + " = " + databaseId, null); + + + // Update the bookmarks inside the folder with the new parent folder name. + ContentValues bookmarkContentValues = new ContentValues(); + + bookmarkContentValues.put(PARENT_FOLDER, newFolderName); + + // SQL escape `oldFolderName`. + oldFolderName = DatabaseUtils.sqlEscapeString(oldFolderName); + + // Run the update on the bookmarks. The last argument is `null` because there are no `whereArgs`. + bookmarksDatabase.update(BOOKMARKS_TABLE, bookmarkContentValues, PARENT_FOLDER + " = " + oldFolderName, null); + + // Close the database handle. + bookmarksDatabase.close(); + } + + public void updateFolder(int databaseId, String oldFolderName, String newFolderName, byte[] folderIcon) { + // Get a writable database handle. + SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); + + // Update the folder first. Store the updated values in `folderContentValues`. + ContentValues folderContentValues = new ContentValues(); + + folderContentValues.put(BOOKMARK_NAME, newFolderName); + folderContentValues.put(FAVORITE_ICON, folderIcon); + + // Run the update on the folder. The last argument is `null` because there are no `whereArgs`. + bookmarksDatabase.update(BOOKMARKS_TABLE, folderContentValues, _ID + " = " + databaseId, null); + + + // Update the bookmarks inside the folder with the new parent folder name. + ContentValues bookmarkContentValues = new ContentValues(); + + bookmarkContentValues.put(PARENT_FOLDER, newFolderName); + + // SQL escape `oldFolderName`. + oldFolderName = DatabaseUtils.sqlEscapeString(oldFolderName); + + // Run the update on the bookmarks. The last argument is `null` because there are no `whereArgs`. + bookmarksDatabase.update(BOOKMARKS_TABLE, bookmarkContentValues, PARENT_FOLDER + " = " + oldFolderName, null); + + // Close the database handle. + bookmarksDatabase.close(); + } + public void updateBookmarkDisplayOrder(int databaseId, int displayOrder) { // Store the updated values in `bookmarkContentValues`. ContentValues bookmarkContentValues = new ContentValues(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseViewActivity.java new file mode 100644 index 00000000..00bad900 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseViewActivity.java @@ -0,0 +1,144 @@ +/** + * Copyright 2016 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser 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, + * 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 . + */ + +package com.stoutner.privacybrowser; + +import android.content.Context; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Typeface; +import android.os.Bundle; +import android.support.v4.content.ContextCompat; +import android.support.v4.widget.CursorAdapter; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + +public class BookmarksDatabaseViewActivity extends AppCompatActivity { + // `bookmarksDatabaseHandler` is used in `onCreate()` and `updateBookmarksListView()`. + BookmarksDatabaseHandler bookmarksDatabaseHandler; + + // `bookmarksListView` is used in `onCreate()` and `updateBookmarksListView()`. + ListView bookmarksListView; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.bookmarks_database_view_coordinatorlayout); + + // We need to use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21. + final Toolbar bookmarksDatabaseViewAppBar = (Toolbar) findViewById(R.id.bookmarks_database_view_toolbar); + setSupportActionBar(bookmarksDatabaseViewAppBar); + + // Display the home arrow on `SupportActionBar`. + final ActionBar appBar = getSupportActionBar(); + assert appBar != null; // This assert removes the incorrect warning in Android Studio on the following line that appBar might be null. + appBar.setDisplayHomeAsUpEnabled(true); + + // Initialize the database handler and the ListView. + // `this` specifies the context. The two `null`s do not specify the database name or a `CursorFactory`. + // The `0` is to specify a database version, but that is set instead using a constant in `BookmarksDatabaseHandler`. + bookmarksDatabaseHandler = new BookmarksDatabaseHandler(this, null, null, 0); + bookmarksListView = (ListView) findViewById(R.id.bookmarks_database_view_listview); + + // Display the bookmarks in the ListView. + updateBookmarksListView(); + + } + + private void updateBookmarksListView() { + // Get a `Cursor` with the current contents of the bookmarks database. + final Cursor bookmarksCursor = bookmarksDatabaseHandler.getAllBookmarksCursor(); + + // Setup `bookmarksCursorAdapter` with `this` context. The `false` disables autoRequery. + CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) { + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + // Inflate the individual item layout. `false` does not attach it to the root. + return getLayoutInflater().inflate(R.layout.bookmarks_database_view_linearlayout, parent, false); + } + + @Override + public void bindView(View view, Context context, Cursor cursor) { + boolean isFolder = (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1); + + // Get the database ID from the `Cursor` and display it in `bookmarkDatabaseIdTextView`. + int bookmarkDatabaseId = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler._ID)); + TextView bookmarkDatabaseIdTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_database_id); + bookmarkDatabaseIdTextView.setText(String.valueOf(bookmarkDatabaseId)); + + // Get the favorite icon byte array from the `Cursor`. + byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + // Convert the byte array to a `Bitmap` beginning at the beginning at the first byte and ending at the last. + Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length); + // Display the bitmap in `bookmarkFavoriteIcon`. + ImageView bookmarkFavoriteIcon = (ImageView) view.findViewById(R.id.bookmarks_database_view_favorite_icon); + bookmarkFavoriteIcon.setImageBitmap(favoriteIconBitmap); + + // Get the bookmark name from the `Cursor` and display it in `bookmarkNameTextView`. + String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); + TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_bookmark_name); + bookmarkNameTextView.setText(bookmarkNameString); + // Make the font bold for folders. + if (isFolder) { + // The first argument is `null` because we don't want to chage the font. + bookmarkNameTextView.setTypeface(null, Typeface.BOLD); + } else { // Reset the font to default. + bookmarkNameTextView.setTypeface(Typeface.DEFAULT); + } + + // Get the display order from the `Cursor` and display it in `bookmarkDisplayOrderTextView`. + int bookmarkDisplayOrder = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.DISPLAY_ORDER)); + TextView bookmarkDisplayOrderTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_display_order); + bookmarkDisplayOrderTextView.setText(String.valueOf(bookmarkDisplayOrder)); + + // Get the parent folder from the `Cursor` and display it in `bookmarkParentFolder`. + String bookmarkParentFolder = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.PARENT_FOLDER)); + TextView bookmarkParentFolderTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_parent_folder); + // Make the folder name gray if it is the home folder. + if (bookmarkParentFolder.isEmpty()) { + bookmarkParentFolderTextView.setText(R.string.home_folder); + bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.grey)); + } else { + bookmarkParentFolderTextView.setText(bookmarkParentFolder); + bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black)); + } + + // Get the bookmark URL form the `Cursor` and display it in `bookmarkUrlTextView`. + String bookmarkUrlString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_URL)); + TextView bookmarkUrlTextView = (TextView) view.findViewById(R.id.bookmarks_database_view_bookmark_url); + bookmarkUrlTextView.setText(bookmarkUrlString); + if (isFolder) { + bookmarkUrlTextView.setVisibility(View.GONE); + } else { + bookmarkUrlTextView.setVisibility(View.VISIBLE); + } + } + }; + + // Update the ListView. + bookmarksListView.setAdapter(bookmarksCursorAdapter); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java index c5acd035..b779709c 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java @@ -36,9 +36,9 @@ import android.widget.EditText; public class CreateBookmark extends DialogFragment { // The public interface is used to send information back to the parent activity. public interface CreateBookmarkListener { - void onCreateBookmarkCancel(DialogFragment createBookmarkDialogFragment); + void onCancelCreateBookmark(DialogFragment dialogFragment); - void onCreateBookmarkCreate(DialogFragment createBookmarkDialogFragment); + void onCreateBookmark(DialogFragment dialogFragment); } // `createBookmarkListener` is used in `onAttach()` and `onCreateDialog()` @@ -48,7 +48,7 @@ public class CreateBookmark extends DialogFragment { public void onAttach(Activity parentActivity) { super.onAttach(parentActivity); - // Get a handle for `CreateBookmarkListener` from the `parentActivity`. + // Get a handle for `CreateBookmarkListener` from `parentActivity`. try { createBookmarkListener = (CreateBookmarkListener) parentActivity; } catch(ClassCastException exception) { @@ -62,51 +62,51 @@ public class CreateBookmark extends DialogFragment { Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon); // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. - AlertDialog.Builder createBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); - createBookmarkDialogBuilder.setTitle(R.string.create_bookmark); - createBookmarkDialogBuilder.setIcon(favoriteIconDrawable); - // The parent view is `null` because it will be assigned by `AlertDialog`. - createBookmarkDialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.create_bookmark_dialog, null)); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); + dialogBuilder.setTitle(R.string.create_bookmark); + dialogBuilder.setIcon(favoriteIconDrawable); + // The parent view is `null` because it will be assigned by the `AlertDialog`. + dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.create_bookmark_dialog, null)); // Set an `onClick()` listener for the negative button. - createBookmarkDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Return the `DialogFragment` to the parent activity on cancel. - createBookmarkListener.onCreateBookmarkCancel(CreateBookmark.this); + createBookmarkListener.onCancelCreateBookmark(CreateBookmark.this); } }); // Set an `onClick()` listener for the positive button. - createBookmarkDialogBuilder.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { + dialogBuilder.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Return the `DialogFragment` to the parent activity on create. - createBookmarkListener.onCreateBookmarkCreate(CreateBookmark.this); + createBookmarkListener.onCreateBookmark(CreateBookmark.this); } }); // Create an `AlertDialog` from the `AlertDialog.Builder`. - final AlertDialog createBookmarkDialog = createBookmarkDialogBuilder.create(); + final AlertDialog alertDialog = dialogBuilder.create(); // Show the keyboard when the `Dialog` is displayed on the screen. - createBookmarkDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); // We need to show the `AlertDialog` before we can call `setOnKeyListener()` below. - createBookmarkDialog.show(); + alertDialog.show(); // Allow the `enter` key on the keyboard to create the bookmark from `create_bookmark_name_edittext`. - EditText createBookmarkNameEditText = (EditText) createBookmarkDialog.findViewById(R.id.create_bookmark_name_edittext); - assert createBookmarkNameEditText != null; // Remove the warning below that createBookmarkNameEditText might be null. + EditText createBookmarkNameEditText = (EditText) alertDialog.findViewById(R.id.create_bookmark_name_edittext); + assert createBookmarkNameEditText != null; // Remove the warning below that `createBookmarkNameEditText` might be `null`. createBookmarkNameEditText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { - // If the event is a key-down on the `enter` button, select the PositiveButton `Create`. + // If the event is a key-down on the `enter` button, select the `PositiveButton` `Create`. if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { - // Trigger `createBookmarkListener` and return the DialogFragment to the parent activity. - createBookmarkListener.onCreateBookmarkCreate(CreateBookmark.this); + // Trigger `createBookmarkListener` and return the `DialogFragment` to the parent activity. + createBookmarkListener.onCreateBookmark(CreateBookmark.this); // Manually dismiss the `AlertDialog`. - createBookmarkDialog.dismiss(); + alertDialog.dismiss(); // Consume the event. return true; } else { // If any other key was pressed, do not consume the event. @@ -116,8 +116,8 @@ public class CreateBookmark extends DialogFragment { }); // Set the formattedUrlString as the initial text of `create_bookmark_url_edittext`. - EditText createBookmarkUrlEditText = (EditText) createBookmarkDialog.findViewById(R.id.create_bookmark_url_edittext); - assert createBookmarkUrlEditText != null;// Remove the warning below that `createBookmarkUrlEditText` might be null. + EditText createBookmarkUrlEditText = (EditText) alertDialog.findViewById(R.id.create_bookmark_url_edittext); + assert createBookmarkUrlEditText != null;// Remove the warning below that `createBookmarkUrlEditText` might be `null`. createBookmarkUrlEditText.setText(MainWebViewActivity.formattedUrlString); // Allow the `enter` key on the keyboard to create the bookmark from `create_bookmark_url_edittext`. @@ -126,9 +126,9 @@ public class CreateBookmark extends DialogFragment { // If the event is a key-down on the "enter" button, select the PositiveButton "Create". if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Trigger `createBookmarkListener` and return the DialogFragment to the parent activity. - createBookmarkListener.onCreateBookmarkCreate(CreateBookmark.this); + createBookmarkListener.onCreateBookmark(CreateBookmark.this); // Manually dismiss the `AlertDialog`. - createBookmarkDialog.dismiss(); + alertDialog.dismiss(); // Consume the event. return true; } else { // If any other key was pressed, do not consume the event. @@ -138,6 +138,6 @@ public class CreateBookmark extends DialogFragment { }); // `onCreateDialog()` requires the return of an `AlertDialog`. - return createBookmarkDialog; + return alertDialog; } } \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java new file mode 100644 index 00000000..0847ce3f --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java @@ -0,0 +1,120 @@ +/** + * Copyright 2016 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser 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, + * 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 . + */ + +package com.stoutner.privacybrowser; + +import android.app.Activity; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.os.Bundle; +// If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. +import android.support.v7.app.AlertDialog; +import android.view.KeyEvent; +import android.view.View; +import android.view.WindowManager; +import android.widget.EditText; +import android.widget.ImageView; + +public class CreateBookmarkFolder extends DialogFragment { + // The public interface is used to send information back to the parent activity. + public interface CreateBookmarkFolderListener { + void onCancelCreateBookmarkFolder(DialogFragment dialogFragment); + + void onCreateBookmarkFolder(DialogFragment dialogFragment); + } + + // `createBookmarkFolderListener` is used in `onAttach()` and `onCreateDialog`. + private CreateBookmarkFolderListener createBookmarkFolderListener; + + public void onAttach(Activity parentActivity) { + super.onAttach(parentActivity); + + // Get a handle for `createBookmarkFolderListener` from `parentActivity`. + try { + createBookmarkFolderListener = (CreateBookmarkFolderListener) parentActivity; + } catch(ClassCastException exception) { + throw new ClassCastException(parentActivity.toString() + " must implement CreateBookmarkFolderListener."); + } + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. + final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); + dialogBuilder.setTitle(R.string.create_folder); + // The parent view is `null` because it will be assigned by the `AlertDialog`. + dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.create_bookmark_folder_dialog, null)); + + // Set an `onClick()` listener for the negative button. + dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Return the `DialogFragment` to the parent activity on cancel. + createBookmarkFolderListener.onCancelCreateBookmarkFolder(CreateBookmarkFolder.this); + } + }); + + // Set an `onClick()` listener fo the positive button. + dialogBuilder.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Return the `DialogFragment` to the parent activity on create. + createBookmarkFolderListener.onCreateBookmarkFolder(CreateBookmarkFolder.this); + } + }); + + + // Create an `AlertDialog` from the `AlertDialog.Builder`. + final AlertDialog alertDialog = dialogBuilder.create(); + + // Show the keyboard when the `Dialog` is displayed on the screen. + alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + + // We need to show the `AlertDialog` before we can call `setOnKeyListener()` below. + alertDialog.show(); + + // Allow the `enter` key on the keyboard to create the folder from `create_folder_name_edittext`. + EditText createFolderNameEditText = (EditText) alertDialog.findViewById(R.id.create_folder_name_edittext); + assert createFolderNameEditText != null; // Remove the warning below that `createFolderNameEditText` might be `null`. + createFolderNameEditText.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down on the `enter` key, select the `PositiveButton` `Create`. + if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Trigger `createBookmarkFolderListener` and return the `DialogFragment` to the parent activity. + createBookmarkFolderListener.onCreateBookmarkFolder(CreateBookmarkFolder.this); + // Manually dismiss the `AlertDialog`. + alertDialog.dismiss(); + // Consume the event. + return true; + } else { // If any other key was pressed do not consume the event. + return false; + } + } + }); + + // Display the current favorite icon. + ImageView webPageIconImageView = (ImageView) alertDialog.findViewById(R.id.create_folder_web_page_icon); + assert webPageIconImageView != null; // Remove the warning that `webPageIconImageView` may be null. + webPageIconImageView.setImageBitmap(MainWebViewActivity.favoriteIcon); + + // `onCreateDialog()` requires the return of an `AlertDialog`. + return alertDialog; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java index 71e84ab3..4a6b2fa7 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java @@ -37,9 +37,9 @@ import android.widget.EditText; public class CreateHomeScreenShortcut extends DialogFragment { // The public interface is used to send information back to the parent activity. public interface CreateHomeScreenSchortcutListener { - void onCreateHomeScreenShortcutCancel(DialogFragment dialogFragment); + void onCancelCreateHomeScreenShortcut(DialogFragment dialogFragment); - void onCreateHomeScreenShortcutCreate(DialogFragment dialogFragment); + void onCreateHomeScreenShortcut(DialogFragment dialogFragment); } //createHomeScreenShortcutListener is used in onAttach and and onCreateDialog. @@ -64,50 +64,50 @@ public class CreateHomeScreenShortcut extends DialogFragment { LayoutInflater customDialogInflater = getActivity().getLayoutInflater(); // Use AlertDialog.Builder to create the AlertDialog. The style formats the color of the button text. - AlertDialog.Builder createHomeScreenShorcutDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); - createHomeScreenShorcutDialogBuilder.setTitle(R.string.create_shortcut); - createHomeScreenShorcutDialogBuilder.setIcon(favoriteIconDrawable); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); + dialogBuilder.setTitle(R.string.create_shortcut); + dialogBuilder.setIcon(favoriteIconDrawable); // The parent view is "null" because it will be assigned by AlertDialog. - createHomeScreenShorcutDialogBuilder.setView(customDialogInflater.inflate(R.layout.create_home_screen_shortcut_dialog, null)); + dialogBuilder.setView(customDialogInflater.inflate(R.layout.create_home_screen_shortcut_dialog, null)); // Set an onClick listener on the negative button. - createHomeScreenShorcutDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - createHomeScreenShortcutListener.onCreateHomeScreenShortcutCancel(CreateHomeScreenShortcut.this); + createHomeScreenShortcutListener.onCancelCreateHomeScreenShortcut(CreateHomeScreenShortcut.this); } }); // Set an onClick listener on the positive button. - createHomeScreenShorcutDialogBuilder.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { + dialogBuilder.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - createHomeScreenShortcutListener.onCreateHomeScreenShortcutCreate(CreateHomeScreenShortcut.this); + createHomeScreenShortcutListener.onCreateHomeScreenShortcut(CreateHomeScreenShortcut.this); } }); // Create an AlertDialog from the AlertDialogBuilder. - final AlertDialog createHomeScreenShortcutAlertDialog = createHomeScreenShorcutDialogBuilder.create(); + final AlertDialog alertDialog = dialogBuilder.create(); // Show the keyboard when the Dialog is displayed on the screen. - createHomeScreenShortcutAlertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); // We need to show the AlertDialog before we can call setOnKeyListener() below. - createHomeScreenShortcutAlertDialog.show(); + alertDialog.show(); // Allow the "enter" key on the keyboard to create the shortcut. - EditText shortcutNameEditText = (EditText) createHomeScreenShortcutAlertDialog.findViewById(R.id.shortcut_name_edittext); + EditText shortcutNameEditText = (EditText) alertDialog.findViewById(R.id.shortcut_name_edittext); assert shortcutNameEditText != null; // Remove the warning below that shortcutNameEditText might be null. shortcutNameEditText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down on the "enter" button, select the PositiveButton "Create". if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Trigger the create listener. - createHomeScreenShortcutListener.onCreateHomeScreenShortcutCreate(CreateHomeScreenShortcut.this); + createHomeScreenShortcutListener.onCreateHomeScreenShortcut(CreateHomeScreenShortcut.this); - // Manually dismiss the AlertDialog. - createHomeScreenShortcutAlertDialog.dismiss(); + // Manually dismiss `alertDialog`. + alertDialog.dismiss(); // Consume the event. return true; @@ -118,6 +118,6 @@ public class CreateHomeScreenShortcut extends DialogFragment { }); // onCreateDialog requires the return of an AlertDialog. - return createHomeScreenShortcutAlertDialog; + return alertDialog; } } \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java index 8eee58d6..8343ace2 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java @@ -40,9 +40,9 @@ import android.widget.ImageView; public class EditBookmark extends DialogFragment { // The public interface is used to send information back to the parent activity. public interface EditBookmarkListener { - void onEditBookmarkCancel(DialogFragment editBookmarkDialogFragment); + void onCancelEditBookmark(DialogFragment dialogFragment); - void onEditBookmarkSave(DialogFragment editBookmarkDialogFragment); + void onSaveEditBookmark(DialogFragment dialogFragment); } // `editBookmarkListener` is used in `onAttach()` and `onCreateDialog()` @@ -51,7 +51,7 @@ public class EditBookmark extends DialogFragment { public void onAttach(Activity parentActivity) { super.onAttach(parentActivity); - // Get a handle for `EditBookmarkListener` from the `parentActivity`. + // Get a handle for `EditBookmarkListener` from `parentActivity`. try { editBookmarkListener = (EditBookmarkListener) parentActivity; } catch(ClassCastException exception) { @@ -62,62 +62,63 @@ public class EditBookmark extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`. - long[] selectedBookmarksLongArray = BookmarksActivity.bookmarksListView.getCheckedItemIds(); - int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0]; + long[] selectedBookmarkLongArray = BookmarksActivity.bookmarksListView.getCheckedItemIds(); + int selectedBookmarkDatabaseId = (int) selectedBookmarkLongArray[0]; // Get a `Cursor` with the specified bookmark and move it to the first position. Cursor bookmarkCursor = BookmarksActivity.bookmarksDatabaseHandler.getBookmarkCursor(selectedBookmarkDatabaseId); bookmarkCursor.moveToFirst(); - // Get the favorite icon byte array from the `Cursor`. - byte[] favoriteIconByteArray = bookmarkCursor.getBlob(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); - // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last. - Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length); - // Convert the `Bitmap` to a `Drawable`. - Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), favoriteIconBitmap); - // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. - AlertDialog.Builder editBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); - editBookmarkDialogBuilder.setTitle(R.string.edit_bookmark); - editBookmarkDialogBuilder.setIcon(favoriteIconDrawable); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); + dialogBuilder.setTitle(R.string.edit_bookmark); // The parent view is `null` because it will be assigned by `AlertDialog`. - editBookmarkDialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.edit_bookmark_dialog, null)); + dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.edit_bookmark_dialog, null)); // Set an `onClick()` listener for the negative button. - editBookmarkDialogBuilder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() { + dialogBuilder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Return the `DialogFragment` to the parent activity on cancel. - editBookmarkListener.onEditBookmarkCancel(EditBookmark.this); + editBookmarkListener.onCancelEditBookmark(EditBookmark.this); } }); // Set the `onClick()` listener fo the positive button. - editBookmarkDialogBuilder.setPositiveButton(R.string.save, new Dialog.OnClickListener() { + dialogBuilder.setPositiveButton(R.string.save, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Return the `DialogFragment` to the parent activity on save. - editBookmarkListener.onEditBookmarkSave(EditBookmark.this); + editBookmarkListener.onSaveEditBookmark(EditBookmark.this); } }); // Create an `AlertDialog` from the `AlertDialog.Builder`. - final AlertDialog editBookmarkDialog = editBookmarkDialogBuilder.create(); + final AlertDialog alertDialog = dialogBuilder.create(); // Show the keyboard when the `Dialog` is displayed on the screen. - editBookmarkDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); - // We need to show the `AlertDialog` before we can call `setOnKeyListener()` below. - editBookmarkDialog.show(); + // We need to show the `AlertDialog` before we can modify items in the layout. + alertDialog.show(); - // Get a `Drawable` of the favorite icon from `mainWebView` and display it in `edit_bookmark_new_favorite_icon`. - ImageView newFavoriteIcon = (ImageView) editBookmarkDialog.findViewById(R.id.edit_bookmark_new_favorite_icon); - assert newFavoriteIcon != null; // Remove the warning below that `newFavoriteIcon` might be null. - newFavoriteIcon.setImageBitmap(MainWebViewActivity.favoriteIcon); + // Get the current favorite icon byte array from the `Cursor`. + byte[] currentIconByteArray = bookmarkCursor.getBlob(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last. + Bitmap currentIconBitmap = BitmapFactory.decodeByteArray(currentIconByteArray, 0, currentIconByteArray.length); + // Display `currentIconBitmap` in `edit_bookmark_current_icon`. + ImageView currentIconImageView = (ImageView) alertDialog.findViewById(R.id.edit_bookmark_current_icon); + assert currentIconImageView != null; // Remove the warning below that `currentIconImageView` might be null; + currentIconImageView.setImageBitmap(currentIconBitmap); + + // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_bookmark_web_page_favorite_icon`. + ImageView newFavoriteIconImageView = (ImageView) alertDialog.findViewById(R.id.edit_bookmark_web_page_favorite_icon); + assert newFavoriteIconImageView != null; // Remove the warning below that `newFavoriteIcon` might be null. + newFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIcon); // Load the text for `edit_bookmark_name_edittext`. - EditText bookmarkNameEditText = (EditText) editBookmarkDialog.findViewById(R.id.edit_bookmark_name_edittext); + EditText bookmarkNameEditText = (EditText) alertDialog.findViewById(R.id.edit_bookmark_name_edittext); assert bookmarkNameEditText != null; // Remove the warning below that `bookmarkNameEditText` might be null. bookmarkNameEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME))); @@ -127,9 +128,9 @@ public class EditBookmark extends DialogFragment { // If the event is a key-down on the "enter" button, select the PositiveButton `Save`. if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Trigger `editBookmarkListener` and return the DialogFragment to the parent activity. - editBookmarkListener.onEditBookmarkSave(EditBookmark.this); - // Manually dismiss the `AlertDialog`. - editBookmarkDialog.dismiss(); + editBookmarkListener.onSaveEditBookmark(EditBookmark.this); + // Manually dismiss `alertDialog`. + alertDialog.dismiss(); // Consume the event. return true; } else { // If any other key was pressed, do not consume the event. @@ -138,8 +139,8 @@ public class EditBookmark extends DialogFragment { } }); - // Load the text for `create_bookmark_url_edittext`. - EditText bookmarkUrlEditText = (EditText) editBookmarkDialog.findViewById(R.id.edit_bookmark_url_edittext); + // Load the text for `edit_bookmark_url_edittext`. + EditText bookmarkUrlEditText = (EditText) alertDialog.findViewById(R.id.edit_bookmark_url_edittext); assert bookmarkUrlEditText != null;// Remove the warning below that `bookmarkUrlEditText` might be null. bookmarkUrlEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_URL))); @@ -149,9 +150,9 @@ public class EditBookmark extends DialogFragment { // If the event is a key-down on the `enter` button, select the PositiveButton `Save`. if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Trigger `editBookmarkListener` and return the DialogFragment to the parent activity. - editBookmarkListener.onEditBookmarkSave(EditBookmark.this); + editBookmarkListener.onSaveEditBookmark(EditBookmark.this); // Manually dismiss the `AlertDialog`. - editBookmarkDialog.dismiss(); + alertDialog.dismiss(); // Consume the event. return true; } else { // If any other key was pressed, do not consume the event. @@ -161,6 +162,6 @@ public class EditBookmark extends DialogFragment { }); // `onCreateDialog` requires the return of an `AlertDialog`. - return editBookmarkDialog; + return alertDialog; } } \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java b/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java new file mode 100644 index 00000000..c27b963d --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java @@ -0,0 +1,143 @@ +/** + * Copyright 2016 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser 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, + * 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 . + */ + +package com.stoutner.privacybrowser; + +import android.app.Activity; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +// If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. +import android.support.v7.app.AlertDialog; +import android.view.KeyEvent; +import android.view.View; +import android.view.WindowManager; +import android.widget.EditText; +import android.widget.ImageView; + +public class EditBookmarkFolder extends DialogFragment { + // The public interface is used to send information back to the parent activity. + public interface EditBookmarkFolderListener { + void onCancelEditBookmarkFolder(DialogFragment dialogFragment); + + void onSaveEditBookmarkFolder(DialogFragment dialogFragment); + } + + // `editFolderListener` is used in `onAttach()` and `onCreateDialog`. + private EditBookmarkFolderListener editBookmarkFolderListener; + + public void onAttach(Activity parentActivity) { + super.onAttach(parentActivity); + + // Get a handle for `EditFolderListener` from `parentActivity`. + try { + editBookmarkFolderListener = (EditBookmarkFolderListener) parentActivity; + } catch(ClassCastException exception) { + throw new ClassCastException(parentActivity.toString() + " must implement EditBookmarkFolderListener."); + } + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`. + long[] selectedBookmarkLongArray = BookmarksActivity.bookmarksListView.getCheckedItemIds(); + int selectedBookmarkDatabaseId = (int) selectedBookmarkLongArray[0]; + + // Get a `Cursor` with the specified bookmark and move it to the first position. + Cursor bookmarkCursor = BookmarksActivity.bookmarksDatabaseHandler.getBookmarkCursor(selectedBookmarkDatabaseId); + bookmarkCursor.moveToFirst(); + + // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); + dialogBuilder.setTitle(R.string.edit_folder); + // The parent view is `null` because it will be assigned by `AlertDialog`. + dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.edit_bookmark_folder_dialog, null)); + + // Set an `onClick()` listener for the negative button. + dialogBuilder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Return the `DialogFragment` to the parent activity on cancel. + editBookmarkFolderListener.onCancelEditBookmarkFolder(EditBookmarkFolder.this); + } + }); + + // Set the `onClick()` listener fo the positive button. + dialogBuilder.setPositiveButton(R.string.save, new Dialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Return the `DialogFragment` to the parent activity on save. + editBookmarkFolderListener.onSaveEditBookmarkFolder(EditBookmarkFolder.this); + } + }); + + + // Create an `AlertDialog` from the `AlertDialog.Builder`. + final AlertDialog alertDialog = dialogBuilder.create(); + + // Show the keyboard when the `Dialog` is displayed on the screen. + alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + + // We need to show the `AlertDialog` before we can modify items in the layout. + alertDialog.show(); + + // Get the current favorite icon byte array from the `Cursor`. + byte[] currentIconByteArray = bookmarkCursor.getBlob(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.FAVORITE_ICON)); + // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last. + Bitmap currentIconBitmap = BitmapFactory.decodeByteArray(currentIconByteArray, 0, currentIconByteArray.length); + // Display `currentIconBitmap` in `edit_folder_current_icon`. + ImageView currentIconImageView = (ImageView) alertDialog.findViewById(R.id.edit_folder_current_icon); + assert currentIconImageView != null; // Remove the warning below that `currentIconImageView` might be null. + currentIconImageView.setImageBitmap(currentIconBitmap); + + // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_folder_web_page_favorite_icon`. + ImageView webPageFavoriteIcon = (ImageView) alertDialog.findViewById(R.id.edit_folder_web_page_favorite_icon); + assert webPageFavoriteIcon != null; // Remove the warning below that `webPageFavoriteIcon` might be null. + webPageFavoriteIcon.setImageBitmap(MainWebViewActivity.favoriteIcon); + + // Load the text for `edit_folder_name_edittext`. + EditText folderNameEditText = (EditText) alertDialog.findViewById(R.id.edit_folder_name_edittext); + assert folderNameEditText != null; // Remove the warning below that `bookmarkNameEditText` might be null. + folderNameEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME))); + + // Allow the `enter` key on the keyboard to save the bookmark from `edit_bookmark_name_edittext`. + folderNameEditText.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down on the "enter" button, select the PositiveButton `Save`. + if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Trigger `editBookmarkListener` and return the DialogFragment to the parent activity. + editBookmarkFolderListener.onSaveEditBookmarkFolder(EditBookmarkFolder.this); + // Manually dismiss the `AlertDialog`. + alertDialog.dismiss(); + // Consume the event. + return true; + } else { // If any other key was pressed, do not consume the event. + return false; + } + } + }); + + // `onCreateDialog` requires the return of an `AlertDialog`. + return alertDialog; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index e59168fe..f10c2e45 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -65,7 +65,7 @@ import java.net.URLEncoder; // We need to use AppCompatActivity from android.support.v7.app.AppCompatActivity to have access to the SupportActionBar until the minimum API is >= 21. public class MainWebViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener { - // `favoriteIcon` is public static so it can be accessed from `CreateHomeScreenShortcut`, `BookmarksActivity`, and `EditBookmark`. + // `favoriteIcon` is public static so it can be accessed from `CreateHomeScreenShortcut`, `BookmarksActivity`, `CreateBookmark`, `CreateBookmarkFolder`, and `EditBookmark`. // It is also used in `onCreate()` and `onCreateHomeScreenShortcutCreate()`. public static Bitmap favoriteIcon; @@ -629,7 +629,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation case R.id.addToHomescreen: // Show the CreateHomeScreenShortcut AlertDialog and name this instance "@string/create_shortcut". DialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcut(); - createHomeScreenShortcutDialogFragment.show(getFragmentManager(), "@string/create_shortcut"); + createHomeScreenShortcutDialogFragment.show(getFragmentManager(), getResources().getString(R.string.create_shortcut)); //Everything else will be handled by CreateHomeScreenShortcut and the associated listeners below. return true; @@ -684,19 +684,19 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation break; case R.id.settings: - // Launch SettingsActivity. + // Launch `SettingsActivity`. Intent settingsIntent = new Intent(this, SettingsActivity.class); startActivity(settingsIntent); break; case R.id.guide: - // Launch GuideActivity. + // Launch `GuideActivity`. Intent guideIntent = new Intent(this, GuideActivity.class); startActivity(guideIntent); break; case R.id.about: - // Launch AboutActivity. + // Launch `AboutActivity`. Intent aboutIntent = new Intent(this, AboutActivity.class); startActivity(aboutIntent); break; @@ -765,12 +765,12 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } @Override - public void onCreateHomeScreenShortcutCancel(DialogFragment dialogFragment) { + public void onCancelCreateHomeScreenShortcut(DialogFragment dialogFragment) { // Do nothing because the user selected "Cancel". } @Override - public void onCreateHomeScreenShortcutCreate(DialogFragment dialogFragment) { + public void onCreateHomeScreenShortcut(DialogFragment dialogFragment) { // Get shortcutNameEditText from the alert dialog. EditText shortcutNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.shortcut_name_edittext); diff --git a/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java b/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java new file mode 100644 index 00000000..2ae2cc65 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java @@ -0,0 +1,25 @@ +/** + * Copyright 2016 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser 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, + * 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 . + */ + +package com.stoutner.privacybrowser; + +import android.app.DialogFragment; + +public class MoveToFolder extends DialogFragment { +} diff --git a/app/src/main/res/drawable-hdpi/folder_blue_bitmap.png b/app/src/main/res/drawable-hdpi/folder_blue_bitmap.png new file mode 100644 index 00000000..0b5f4911 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/folder_blue_bitmap.png differ diff --git a/app/src/main/res/drawable-mdpi/folder_blue_bitmap.png b/app/src/main/res/drawable-mdpi/folder_blue_bitmap.png new file mode 100644 index 00000000..2e8e77df Binary files /dev/null and b/app/src/main/res/drawable-mdpi/folder_blue_bitmap.png differ diff --git a/app/src/main/res/drawable-xhdpi/folder_blue_bitmap.png b/app/src/main/res/drawable-xhdpi/folder_blue_bitmap.png new file mode 100644 index 00000000..ab7a3083 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/folder_blue_bitmap.png differ diff --git a/app/src/main/res/drawable-xxhdpi/folder_blue_bitmap.png b/app/src/main/res/drawable-xxhdpi/folder_blue_bitmap.png new file mode 100644 index 00000000..8c1be731 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/folder_blue_bitmap.png differ diff --git a/app/src/main/res/drawable/back.xml b/app/src/main/res/drawable/back.xml index e69b5ad5..a49efd8b 100644 --- a/app/src/main/res/drawable/back.xml +++ b/app/src/main/res/drawable/back.xml @@ -3,11 +3,11 @@ + android:viewportWidth="24.0" + android:autoMirrored="true" > . --> + + + + + diff --git a/app/src/main/res/drawable/edit.xml b/app/src/main/res/drawable/edit.xml index d5164881..89a86c32 100644 --- a/app/src/main/res/drawable/edit.xml +++ b/app/src/main/res/drawable/edit.xml @@ -3,11 +3,11 @@ + android:viewportWidth="24.0" + android:autoMirrored="true" > + android:viewportWidth="24.0" + android:autoMirrored="true" > . --> + + + + + diff --git a/app/src/main/res/drawable/forward.xml b/app/src/main/res/drawable/forward.xml index e8ccd370..dfa9e066 100644 --- a/app/src/main/res/drawable/forward.xml +++ b/app/src/main/res/drawable/forward.xml @@ -3,11 +3,11 @@ + android:viewportWidth="24.0" + android:autoMirrored="true" > . --> . --> . --> . --> . --> + + + + + diff --git a/app/src/main/res/layout/bookmarks_coordinatorlayout.xml b/app/src/main/res/layout/bookmarks_coordinatorlayout.xml index 783a19bc..4ebdaaa5 100644 --- a/app/src/main/res/layout/bookmarks_coordinatorlayout.xml +++ b/app/src/main/res/layout/bookmarks_coordinatorlayout.xml @@ -18,9 +18,9 @@ You should have received a copy of the GNU General Public License along with Privacy Browser. If not, see . --> - + - + - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bookmarks_database_view_linearlayout.xml b/app/src/main/res/layout/bookmarks_database_view_linearlayout.xml new file mode 100644 index 00000000..f1949e89 --- /dev/null +++ b/app/src/main/res/layout/bookmarks_database_view_linearlayout.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bookmarks_item_linearlayout.xml b/app/src/main/res/layout/bookmarks_item_linearlayout.xml index 408844fe..cbb12038 100644 --- a/app/src/main/res/layout/bookmarks_item_linearlayout.xml +++ b/app/src/main/res/layout/bookmarks_item_linearlayout.xml @@ -21,11 +21,11 @@ + android:background="@drawable/bookmarks_list_selector" > + android:layout_marginEnd="4dp" > + `android:inputType="textUri"` disables spell check in the EditText. --> + `android:inputType="textUri"` disables spell check in the EditText.--> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml b/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml index 5e924111..11469aff 100644 --- a/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml +++ b/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml @@ -18,25 +18,29 @@ You should have received a copy of the GNU General Public License along with Privacy Browser. If not, see . --> - - - - + + - \ No newline at end of file + android:layout_marginBottom="10dp" + android:layout_marginStart="4dp" + android:layout_marginEnd="4dp" > + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/edit_bookmark_dialog.xml b/app/src/main/res/layout/edit_bookmark_dialog.xml index 1768ca08..7bb2e454 100644 --- a/app/src/main/res/layout/edit_bookmark_dialog.xml +++ b/app/src/main/res/layout/edit_bookmark_dialog.xml @@ -20,40 +20,66 @@ + android:orientation="vertical"> + - - - - + + + - - + + + + + + + + + android:layout_width="match_parent" + android:checkedButton="@+id/edit_bookmark_current_icon_radiobutton" > + + + + + @@ -61,7 +87,9 @@ android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginTop="12dp" - android:layout_marginBottom="6dp" > + android:layout_marginBottom="6dp" + android:layout_marginStart="4dp" + android:layout_marginEnd="4dp" > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/bookmarks_context_menu.xml b/app/src/main/res/menu/bookmarks_context_menu.xml index ba1139ee..1f880e39 100644 --- a/app/src/main/res/menu/bookmarks_context_menu.xml +++ b/app/src/main/res/menu/bookmarks_context_menu.xml @@ -36,24 +36,31 @@ android:icon="@drawable/move_bookmark_down_enabled" app:showAsAction="ifRoom" /> + + \ No newline at end of file diff --git a/app/src/main/res/menu/bookmarks_options_menu.xml b/app/src/main/res/menu/bookmarks_options_menu.xml index 856594ce..41b7b86f 100644 --- a/app/src/main/res/menu/bookmarks_options_menu.xml +++ b/app/src/main/res/menu/bookmarks_options_menu.xml @@ -22,10 +22,23 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 02fa590f..598c51b7 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -23,9 +23,11 @@ #FF000000 #FF1976D2 #FF0D47A1 - #FF607d8b + #FF607D8B + #FF9E9E9E #FF64DD17 #FFBBDEFB + #FF42A5F5 #FFD50000 #FFFFFFFF #FFFFD600 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a4a030e0..42396d59 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -70,18 +70,28 @@ Create + Database View Create bookmark + Create folder + Current folder icon + Default folder icon + Web page favorite icon + Folder name + Folder names must be unique + Cannot create the folder because the name is not unique: + Cannot rename the folder because the new name is not unique: Edit bookmark + Edit folder + Move to Folder Save Bookmark name Bookmark URL - New favorite icon - Use new icon + Current bookmark icon Selected Move Up - Move down + Move Down Edit Delete Select All @@ -89,6 +99,10 @@ Bookmarks Deleted Undo + + Bookmarks Database View + Home folder + Privacy Browser Guide Overview