X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksDatabaseView.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksDatabaseView.java;h=0000000000000000000000000000000000000000;hb=61a76e491469916f2f30aebb47b98cda7cceb557;hp=44f23bfc4de492fb526a78d78c28def87d11f750;hpb=348acd7bd2c9ba9638ff87b34df4e7501214ca27;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseView.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseView.java deleted file mode 100644 index 44f23bfc..00000000 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseView.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2016-2017 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.activities; - -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; - -import com.stoutner.privacybrowser.R; -import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; - -public class BookmarksDatabaseView extends AppCompatActivity { - // `bookmarksDatabaseHelper` is used in `onCreate()` and `updateBookmarksListView()`. - private BookmarksDatabaseHelper bookmarksDatabaseHelper; - - // `bookmarksListView` is used in `onCreate()` and `updateBookmarksListView()`. - private 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 `BookmarksDatabaseHelper`. - bookmarksDatabaseHelper = new BookmarksDatabaseHelper(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 = bookmarksDatabaseHelper.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_item_linearlayout, parent, false); - } - - @Override - public void bindView(View view, Context context, Cursor cursor) { - boolean isFolder = (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1); - - // Get the database ID from the `Cursor` and display it in `bookmarkDatabaseIdTextView`. - int bookmarkDatabaseId = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper._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(BookmarksDatabaseHelper.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(BookmarksDatabaseHelper.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 change 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(BookmarksDatabaseHelper.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(BookmarksDatabaseHelper.PARENT_FOLDER)); - ImageView parentFolderImageView = (ImageView) view.findViewById(R.id.bookmarks_database_view_parent_folder_icon); - 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()) { - parentFolderImageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.folder_gray)); - bookmarkParentFolderTextView.setText(R.string.home_folder); - bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.gray_500)); - } else { - parentFolderImageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.folder_dark_blue)); - 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(BookmarksDatabaseHelper.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