Fix null annotations, issues in various classes
This commit is contained in:
parent
9cf0a7e11e
commit
17e2640248
@ -50,15 +50,15 @@ public class BookmarkManager {
|
|||||||
private static final String ORDER = "order";
|
private static final String ORDER = "order";
|
||||||
private static final String FILE_BOOKMARKS = "bookmarks.dat";
|
private static final String FILE_BOOKMARKS = "bookmarks.dat";
|
||||||
|
|
||||||
private final String DEFAULT_BOOKMARK_TITLE;
|
@NonNull private final String DEFAULT_BOOKMARK_TITLE;
|
||||||
|
|
||||||
private Map<String, HistoryItem> mBookmarksMap;
|
private Map<String, HistoryItem> mBookmarksMap;
|
||||||
private String mCurrentFolder = "";
|
@NonNull private String mCurrentFolder = "";
|
||||||
private final ExecutorService mExecutor;
|
@NonNull private final ExecutorService mExecutor;
|
||||||
private final File mFilesDir;
|
private final File mFilesDir;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BookmarkManager(Context context) {
|
public BookmarkManager(@NonNull Context context) {
|
||||||
mExecutor = Executors.newSingleThreadExecutor();
|
mExecutor = Executors.newSingleThreadExecutor();
|
||||||
mFilesDir = context.getFilesDir();
|
mFilesDir = context.getFilesDir();
|
||||||
DEFAULT_BOOKMARK_TITLE = context.getString(R.string.untitled);
|
DEFAULT_BOOKMARK_TITLE = context.getString(R.string.untitled);
|
||||||
@ -163,7 +163,7 @@ public class BookmarkManager {
|
|||||||
bookmarkWriter.newLine();
|
bookmarkWriter.newLine();
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} catch (IOException | JSONException e) {
|
} catch (@NonNull IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
Utils.close(bookmarkWriter);
|
Utils.close(bookmarkWriter);
|
||||||
@ -196,7 +196,7 @@ public class BookmarkManager {
|
|||||||
*/
|
*/
|
||||||
public synchronized boolean addBookmark(@NonNull HistoryItem item) {
|
public synchronized boolean addBookmark(@NonNull HistoryItem item) {
|
||||||
final String url = item.getUrl();
|
final String url = item.getUrl();
|
||||||
if (url == null || mBookmarksMap.containsKey(url)) {
|
if (mBookmarksMap.containsKey(url)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mBookmarksMap.put(url, item);
|
mBookmarksMap.put(url, item);
|
||||||
@ -209,13 +209,13 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @param list the list of HistoryItems to add to bookmarks
|
* @param list the list of HistoryItems to add to bookmarks
|
||||||
*/
|
*/
|
||||||
public synchronized void addBookmarkList(List<HistoryItem> list) {
|
public synchronized void addBookmarkList(@Nullable List<HistoryItem> list) {
|
||||||
if (list == null || list.isEmpty()) {
|
if (list == null || list.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (HistoryItem item : list) {
|
for (HistoryItem item : list) {
|
||||||
final String url = item.getUrl();
|
final String url = item.getUrl();
|
||||||
if (url != null && !mBookmarksMap.containsKey(url)) {
|
if (!mBookmarksMap.containsKey(url)) {
|
||||||
mBookmarksMap.put(url, item);
|
mBookmarksMap.put(url, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,7 +228,7 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @param deleteItem the bookmark item to delete
|
* @param deleteItem the bookmark item to delete
|
||||||
*/
|
*/
|
||||||
public synchronized boolean deleteBookmark(HistoryItem deleteItem) {
|
public synchronized boolean deleteBookmark(@Nullable HistoryItem deleteItem) {
|
||||||
if (deleteItem == null || deleteItem.isFolder()) {
|
if (deleteItem == null || deleteItem.isFolder()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ public class BookmarkManager {
|
|||||||
* @param oldItem This is the old item that you wish to edit
|
* @param oldItem This is the old item that you wish to edit
|
||||||
* @param newItem This is the new item that will overwrite the old item
|
* @param newItem This is the new item that will overwrite the old item
|
||||||
*/
|
*/
|
||||||
public synchronized void editBookmark(HistoryItem oldItem, HistoryItem newItem) {
|
public synchronized void editBookmark(@Nullable HistoryItem oldItem, @Nullable HistoryItem newItem) {
|
||||||
if (oldItem == null || newItem == null || oldItem.isFolder()) {
|
if (oldItem == null || newItem == null || oldItem.isFolder()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -313,7 +313,7 @@ public class BookmarkManager {
|
|||||||
* This method exports the stored bookmarks to a text file in the device's
|
* This method exports the stored bookmarks to a text file in the device's
|
||||||
* external download directory
|
* external download directory
|
||||||
*/
|
*/
|
||||||
public synchronized void exportBookmarks(Activity activity) {
|
public synchronized void exportBookmarks(@NonNull Activity activity) {
|
||||||
List<HistoryItem> bookmarkList = getAllBookmarks(true);
|
List<HistoryItem> bookmarkList = getAllBookmarks(true);
|
||||||
File bookmarksExport = new File(
|
File bookmarksExport = new File(
|
||||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
|
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
|
||||||
@ -341,7 +341,7 @@ public class BookmarkManager {
|
|||||||
}
|
}
|
||||||
Utils.showSnackbar(activity, activity.getString(R.string.bookmark_export_path)
|
Utils.showSnackbar(activity, activity.getString(R.string.bookmark_export_path)
|
||||||
+ ' ' + bookmarksExport.getPath());
|
+ ' ' + bookmarksExport.getPath());
|
||||||
} catch (IOException | JSONException e) {
|
} catch (@NonNull IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
Utils.close(bookmarkWriter);
|
Utils.close(bookmarkWriter);
|
||||||
@ -357,6 +357,7 @@ public class BookmarkManager {
|
|||||||
* @param sort force to sort the returned bookmarkList
|
* @param sort force to sort the returned bookmarkList
|
||||||
* @return returns a list of bookmarks that can be sorted
|
* @return returns a list of bookmarks that can be sorted
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public synchronized List<HistoryItem> getAllBookmarks(boolean sort) {
|
public synchronized List<HistoryItem> getAllBookmarks(boolean sort) {
|
||||||
final List<HistoryItem> bookmarks = new ArrayList<>(mBookmarksMap.values());
|
final List<HistoryItem> bookmarks = new ArrayList<>(mBookmarksMap.values());
|
||||||
if (sort) {
|
if (sort) {
|
||||||
@ -374,7 +375,8 @@ public class BookmarkManager {
|
|||||||
* @param folder the name of the folder to retrieve bookmarks from
|
* @param folder the name of the folder to retrieve bookmarks from
|
||||||
* @return a list of bookmarks found in that folder
|
* @return a list of bookmarks found in that folder
|
||||||
*/
|
*/
|
||||||
public synchronized List<HistoryItem> getBookmarksFromFolder(String folder, boolean sort) {
|
@NonNull
|
||||||
|
public synchronized List<HistoryItem> getBookmarksFromFolder(@Nullable String folder, boolean sort) {
|
||||||
List<HistoryItem> bookmarks = new ArrayList<>();
|
List<HistoryItem> bookmarks = new ArrayList<>();
|
||||||
if (folder == null || folder.isEmpty()) {
|
if (folder == null || folder.isEmpty()) {
|
||||||
bookmarks.addAll(getFolders(sort));
|
bookmarks.addAll(getFolders(sort));
|
||||||
@ -405,6 +407,7 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @return the current folder
|
* @return the current folder
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getCurrentFolder() {
|
public String getCurrentFolder() {
|
||||||
return mCurrentFolder;
|
return mCurrentFolder;
|
||||||
}
|
}
|
||||||
@ -416,11 +419,12 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @return a list of all folders
|
* @return a list of all folders
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
private synchronized List<HistoryItem> getFolders(boolean sort) {
|
private synchronized List<HistoryItem> getFolders(boolean sort) {
|
||||||
final HashMap<String, HistoryItem> folders = new HashMap<>();
|
final HashMap<String, HistoryItem> folders = new HashMap<>();
|
||||||
for (HistoryItem item : mBookmarksMap.values()) {
|
for (HistoryItem item : mBookmarksMap.values()) {
|
||||||
final String folderName = item.getFolder();
|
final String folderName = item.getFolder();
|
||||||
if (folderName != null && !folderName.isEmpty() && !folders.containsKey(folderName)) {
|
if (!folderName.isEmpty() && !folders.containsKey(folderName)) {
|
||||||
final HistoryItem folder = new HistoryItem();
|
final HistoryItem folder = new HistoryItem();
|
||||||
folder.setIsFolder(true);
|
folder.setIsFolder(true);
|
||||||
folder.setTitle(folderName);
|
folder.setTitle(folderName);
|
||||||
@ -442,11 +446,12 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @return a list of folder title strings
|
* @return a list of folder title strings
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public synchronized List<String> getFolderTitles() {
|
public synchronized List<String> getFolderTitles() {
|
||||||
final Set<String> folders = new HashSet<>();
|
final Set<String> folders = new HashSet<>();
|
||||||
for (HistoryItem item : mBookmarksMap.values()) {
|
for (HistoryItem item : mBookmarksMap.values()) {
|
||||||
final String folderName = item.getFolder();
|
final String folderName = item.getFolder();
|
||||||
if (folderName != null && !folderName.isEmpty()) {
|
if (!folderName.isEmpty()) {
|
||||||
folders.add(folderName);
|
folders.add(folderName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,7 +464,7 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @param file the file to attempt to import bookmarks from
|
* @param file the file to attempt to import bookmarks from
|
||||||
*/
|
*/
|
||||||
public synchronized void importBookmarksFromFile(File file, Activity activity) {
|
public synchronized void importBookmarksFromFile(@Nullable File file, @NonNull Activity activity) {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -483,7 +488,7 @@ public class BookmarkManager {
|
|||||||
addBookmarkList(list);
|
addBookmarkList(list);
|
||||||
String message = activity.getResources().getString(R.string.message_import);
|
String message = activity.getResources().getString(R.string.message_import);
|
||||||
Utils.showSnackbar(activity, number + " " + message);
|
Utils.showSnackbar(activity, number + " " + message);
|
||||||
} catch (IOException | JSONException e) {
|
} catch (@NonNull IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Utils.createInformativeDialog(activity, R.string.title_error, R.string.import_bookmark_error);
|
Utils.createInformativeDialog(activity, R.string.title_error, R.string.import_bookmark_error);
|
||||||
} finally {
|
} finally {
|
||||||
@ -496,8 +501,8 @@ public class BookmarkManager {
|
|||||||
*/
|
*/
|
||||||
private static class SortIgnoreCase implements Comparator<HistoryItem> {
|
private static class SortIgnoreCase implements Comparator<HistoryItem> {
|
||||||
|
|
||||||
public int compare(HistoryItem o1, HistoryItem o2) {
|
public int compare(@Nullable HistoryItem o1, @Nullable HistoryItem o2) {
|
||||||
if (o1 == null || o2 == null || o1.getTitle() == null || o2.getTitle() == null) {
|
if (o1 == null || o2 == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (o1.isFolder() == o2.isFolder()) {
|
if (o1.isFolder() == o2.isFolder()) {
|
||||||
|
@ -38,17 +38,17 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
private static final String KEY_TITLE = "title";
|
private static final String KEY_TITLE = "title";
|
||||||
private static final String KEY_TIME_VISITED = "time";
|
private static final String KEY_TIME_VISITED = "time";
|
||||||
|
|
||||||
private SQLiteDatabase mDatabase;
|
@Nullable private SQLiteDatabase mDatabase;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public HistoryDatabase(Context context) {
|
public HistoryDatabase(@NonNull Context context) {
|
||||||
super(context.getApplicationContext(), DATABASE_NAME, null, DATABASE_VERSION);
|
super(context.getApplicationContext(), DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
mDatabase = this.getWritableDatabase();
|
mDatabase = this.getWritableDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creating Tables
|
// Creating Tables
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(@NonNull SQLiteDatabase db) {
|
||||||
String CREATE_HISTORY_TABLE = "CREATE TABLE " + TABLE_HISTORY + '(' + KEY_ID
|
String CREATE_HISTORY_TABLE = "CREATE TABLE " + TABLE_HISTORY + '(' + KEY_ID
|
||||||
+ " INTEGER PRIMARY KEY," + KEY_URL + " TEXT," + KEY_TITLE + " TEXT,"
|
+ " INTEGER PRIMARY KEY," + KEY_URL + " TEXT," + KEY_TITLE + " TEXT,"
|
||||||
+ KEY_TIME_VISITED + " INTEGER" + ')';
|
+ KEY_TIME_VISITED + " INTEGER" + ')';
|
||||||
@ -57,7 +57,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
// Upgrading database
|
// Upgrading database
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
// Drop older table if it exists
|
// Drop older table if it exists
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_HISTORY);
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_HISTORY);
|
||||||
// Create tables again
|
// Create tables again
|
||||||
@ -65,15 +65,12 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void deleteHistory() {
|
public synchronized void deleteHistory() {
|
||||||
|
mDatabase = openIfNecessary();
|
||||||
mDatabase.delete(TABLE_HISTORY, null, null);
|
mDatabase.delete(TABLE_HISTORY, null, null);
|
||||||
mDatabase.close();
|
mDatabase.close();
|
||||||
mDatabase = this.getWritableDatabase();
|
mDatabase = this.getWritableDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean isClosed() {
|
|
||||||
return mDatabase == null || !mDatabase.isOpen();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
if (mDatabase != null) {
|
if (mDatabase != null) {
|
||||||
@ -83,19 +80,21 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openIfNecessary() {
|
@NonNull
|
||||||
if (isClosed()) {
|
private SQLiteDatabase openIfNecessary() {
|
||||||
|
if (mDatabase == null || !mDatabase.isOpen()) {
|
||||||
mDatabase = this.getWritableDatabase();
|
mDatabase = this.getWritableDatabase();
|
||||||
}
|
}
|
||||||
|
return mDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void deleteHistoryItem(@NonNull String url) {
|
public synchronized void deleteHistoryItem(@NonNull String url) {
|
||||||
openIfNecessary();
|
mDatabase = openIfNecessary();
|
||||||
mDatabase.delete(TABLE_HISTORY, KEY_URL + " = ?", new String[]{url});
|
mDatabase.delete(TABLE_HISTORY, KEY_URL + " = ?", new String[]{url});
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void visitHistoryItem(@NonNull String url, @Nullable String title) {
|
public synchronized void visitHistoryItem(@NonNull String url, @Nullable String title) {
|
||||||
openIfNecessary();
|
mDatabase = openIfNecessary();
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY_TITLE, title == null ? "" : title);
|
values.put(KEY_TITLE, title == null ? "" : title);
|
||||||
values.put(KEY_TIME_VISITED, System.currentTimeMillis());
|
values.put(KEY_TIME_VISITED, System.currentTimeMillis());
|
||||||
@ -110,7 +109,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void addHistoryItem(@NonNull HistoryItem item) {
|
private synchronized void addHistoryItem(@NonNull HistoryItem item) {
|
||||||
openIfNecessary();
|
mDatabase = openIfNecessary();
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY_URL, item.getUrl());
|
values.put(KEY_URL, item.getUrl());
|
||||||
values.put(KEY_TITLE, item.getTitle());
|
values.put(KEY_TITLE, item.getTitle());
|
||||||
@ -118,8 +117,9 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
mDatabase.insert(TABLE_HISTORY, null, values);
|
mDatabase.insert(TABLE_HISTORY, null, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
synchronized String getHistoryItem(@NonNull String url) {
|
synchronized String getHistoryItem(@NonNull String url) {
|
||||||
openIfNecessary();
|
mDatabase = openIfNecessary();
|
||||||
Cursor cursor = mDatabase.query(TABLE_HISTORY, new String[]{KEY_ID, KEY_URL, KEY_TITLE},
|
Cursor cursor = mDatabase.query(TABLE_HISTORY, new String[]{KEY_ID, KEY_URL, KEY_TITLE},
|
||||||
KEY_URL + " = ?", new String[]{url}, null, null, null, null);
|
KEY_URL + " = ?", new String[]{url}, null, null, null, null);
|
||||||
String m = null;
|
String m = null;
|
||||||
@ -132,8 +132,9 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public synchronized List<HistoryItem> findItemsContaining(@Nullable String search) {
|
public synchronized List<HistoryItem> findItemsContaining(@Nullable String search) {
|
||||||
openIfNecessary();
|
mDatabase = openIfNecessary();
|
||||||
List<HistoryItem> itemList = new ArrayList<>(5);
|
List<HistoryItem> itemList = new ArrayList<>(5);
|
||||||
if (search == null) {
|
if (search == null) {
|
||||||
return itemList;
|
return itemList;
|
||||||
@ -160,7 +161,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public synchronized List<HistoryItem> getLastHundredItems() {
|
public synchronized List<HistoryItem> getLastHundredItems() {
|
||||||
openIfNecessary();
|
mDatabase = openIfNecessary();
|
||||||
List<HistoryItem> itemList = new ArrayList<>(100);
|
List<HistoryItem> itemList = new ArrayList<>(100);
|
||||||
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
|
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
|
||||||
+ " DESC";
|
+ " DESC";
|
||||||
@ -183,7 +184,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public synchronized List<HistoryItem> getAllHistoryItems() {
|
public synchronized List<HistoryItem> getAllHistoryItems() {
|
||||||
openIfNecessary();
|
mDatabase = openIfNecessary();
|
||||||
List<HistoryItem> itemList = new ArrayList<>();
|
List<HistoryItem> itemList = new ArrayList<>();
|
||||||
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
|
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
|
||||||
+ " DESC";
|
+ " DESC";
|
||||||
@ -204,7 +205,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int getHistoryItemsCount() {
|
public synchronized int getHistoryItemsCount() {
|
||||||
openIfNecessary();
|
mDatabase = openIfNecessary();
|
||||||
String countQuery = "SELECT * FROM " + TABLE_HISTORY;
|
String countQuery = "SELECT * FROM " + TABLE_HISTORY;
|
||||||
Cursor cursor = mDatabase.rawQuery(countQuery, null);
|
Cursor cursor = mDatabase.rawQuery(countQuery, null);
|
||||||
int n = cursor.getCount();
|
int n = cursor.getCount();
|
||||||
|
@ -7,6 +7,8 @@ import android.graphics.Bitmap;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import acr.browser.lightning.utils.Preconditions;
|
||||||
|
|
||||||
public class HistoryItem implements Comparable<HistoryItem> {
|
public class HistoryItem implements Comparable<HistoryItem> {
|
||||||
|
|
||||||
// private variables
|
// private variables
|
||||||
@ -26,7 +28,6 @@ public class HistoryItem implements Comparable<HistoryItem> {
|
|||||||
private int mOrder = 0;
|
private int mOrder = 0;
|
||||||
private boolean mIsFolder = false;
|
private boolean mIsFolder = false;
|
||||||
|
|
||||||
// Empty constructor
|
|
||||||
public HistoryItem() {}
|
public HistoryItem() {}
|
||||||
|
|
||||||
public HistoryItem(@NonNull HistoryItem item) {
|
public HistoryItem(@NonNull HistoryItem item) {
|
||||||
@ -37,15 +38,17 @@ public class HistoryItem implements Comparable<HistoryItem> {
|
|||||||
this.mIsFolder = item.mIsFolder;
|
this.mIsFolder = item.mIsFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
|
||||||
public HistoryItem(@NonNull String url, @NonNull String title) {
|
public HistoryItem(@NonNull String url, @NonNull String title) {
|
||||||
|
Preconditions.checkNonNull(url);
|
||||||
|
Preconditions.checkNonNull(title);
|
||||||
this.mUrl = url;
|
this.mUrl = url;
|
||||||
this.mTitle = title;
|
this.mTitle = title;
|
||||||
this.mBitmap = null;
|
this.mBitmap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
|
||||||
public HistoryItem(@NonNull String url, @NonNull String title, int imageId) {
|
public HistoryItem(@NonNull String url, @NonNull String title, int imageId) {
|
||||||
|
Preconditions.checkNonNull(url);
|
||||||
|
Preconditions.checkNonNull(title);
|
||||||
this.mUrl = url;
|
this.mUrl = url;
|
||||||
this.mTitle = title;
|
this.mTitle = title;
|
||||||
this.mBitmap = null;
|
this.mBitmap = null;
|
||||||
@ -86,24 +89,20 @@ public class HistoryItem implements Comparable<HistoryItem> {
|
|||||||
return mBitmap;
|
return mBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getting name
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return this.mUrl;
|
return this.mUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setting name
|
|
||||||
public void setUrl(@Nullable String url) {
|
public void setUrl(@Nullable String url) {
|
||||||
this.mUrl = (url == null) ? "" : url;
|
this.mUrl = (url == null) ? "" : url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getting phone number
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return this.mTitle;
|
return this.mTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setting phone number
|
|
||||||
public void setTitle(@Nullable String title) {
|
public void setTitle(@Nullable String title) {
|
||||||
this.mTitle = (title == null) ? "" : title;
|
this.mTitle = (title == null) ? "" : title;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -59,7 +61,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
private final List<HistoryItem> mFilteredList = new ArrayList<>(5);
|
private final List<HistoryItem> mFilteredList = new ArrayList<>(5);
|
||||||
private final List<HistoryItem> mAllBookmarks = new ArrayList<>(5);
|
private final List<HistoryItem> mAllBookmarks = new ArrayList<>(5);
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private final Context mContext;
|
@NonNull private final Context mContext;
|
||||||
private boolean mUseGoogle = true;
|
private boolean mUseGoogle = true;
|
||||||
private boolean mIsExecuting = false;
|
private boolean mIsExecuting = false;
|
||||||
private final boolean mDarkTheme;
|
private final boolean mDarkTheme;
|
||||||
@ -70,11 +72,11 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
private static final long INTERVAL_DAY = 86400000;
|
private static final long INTERVAL_DAY = 86400000;
|
||||||
private static final int MAX_SUGGESTIONS = 5;
|
private static final int MAX_SUGGESTIONS = 5;
|
||||||
private static final SuggestionsComparator mComparator = new SuggestionsComparator();
|
private static final SuggestionsComparator mComparator = new SuggestionsComparator();
|
||||||
private final String mSearchSubtitle;
|
@NonNull private final String mSearchSubtitle;
|
||||||
private SearchFilter mFilter;
|
private SearchFilter mFilter;
|
||||||
private final Drawable mSearchDrawable;
|
@NonNull private final Drawable mSearchDrawable;
|
||||||
private final Drawable mHistoryDrawable;
|
@NonNull private final Drawable mHistoryDrawable;
|
||||||
private final Drawable mBookmarkDrawable;
|
@NonNull private final Drawable mBookmarkDrawable;
|
||||||
private String mLanguage;
|
private String mLanguage;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -86,7 +88,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
@Inject
|
@Inject
|
||||||
PreferenceManager mPreferenceManager;
|
PreferenceManager mPreferenceManager;
|
||||||
|
|
||||||
public SearchAdapter(Context context, boolean dark, boolean incognito) {
|
public SearchAdapter(@NonNull Context context, boolean dark, boolean incognito) {
|
||||||
BrowserApp.getAppComponent().inject(this);
|
BrowserApp.getAppComponent().inject(this);
|
||||||
mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true));
|
mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true));
|
||||||
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
|
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
|
||||||
@ -109,7 +111,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
private static class NameFilter implements FilenameFilter {
|
private static class NameFilter implements FilenameFilter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File dir, String filename) {
|
public boolean accept(File dir, @NonNull String filename) {
|
||||||
return filename.endsWith(CACHE_FILE_TYPE);
|
return filename.endsWith(CACHE_FILE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,8 +148,9 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
|
||||||
SuggestionHolder holder;
|
SuggestionHolder holder;
|
||||||
|
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
@ -232,8 +235,9 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
|
|
||||||
private class SearchFilter extends Filter {
|
private class SearchFilter extends Filter {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(@Nullable CharSequence constraint) {
|
||||||
FilterResults results = new FilterResults();
|
FilterResults results = new FilterResults();
|
||||||
if (constraint == null) {
|
if (constraint == null) {
|
||||||
return results;
|
return results;
|
||||||
@ -273,7 +277,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence convertResultToString(Object resultValue) {
|
public CharSequence convertResultToString(@NonNull Object resultValue) {
|
||||||
return ((HistoryItem) resultValue).getUrl();
|
return ((HistoryItem) resultValue).getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,6 +305,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
private XmlPullParserFactory mFactory;
|
private XmlPullParserFactory mFactory;
|
||||||
private XmlPullParser mXpp;
|
private XmlPullParser mXpp;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected List<HistoryItem> doInBackground(String... arg0) {
|
protected List<HistoryItem> doInBackground(String... arg0) {
|
||||||
mIsExecuting = true;
|
mIsExecuting = true;
|
||||||
@ -351,7 +356,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(List<HistoryItem> result) {
|
protected void onPostExecute(@NonNull List<HistoryItem> result) {
|
||||||
mIsExecuting = false;
|
mIsExecuting = false;
|
||||||
synchronized (mSuggestions) {
|
synchronized (mSuggestions) {
|
||||||
mSuggestions.clear();
|
mSuggestions.clear();
|
||||||
@ -375,7 +380,8 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
* @param query the query to get suggestions for
|
* @param query the query to get suggestions for
|
||||||
* @return the cache file containing the suggestions
|
* @return the cache file containing the suggestions
|
||||||
*/
|
*/
|
||||||
private static File downloadSuggestionsForQuery(String query, String language, Application app) {
|
@NonNull
|
||||||
|
private static File downloadSuggestionsForQuery(@NonNull String query, String language, @NonNull Application app) {
|
||||||
File cacheFile = new File(app.getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
|
File cacheFile = new File(app.getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
|
||||||
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
|
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
|
||||||
return cacheFile;
|
return cacheFile;
|
||||||
@ -419,12 +425,12 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
return cacheFile;
|
return cacheFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNetworkConnected(Context context) {
|
private static boolean isNetworkConnected(@NonNull Context context) {
|
||||||
NetworkInfo networkInfo = getActiveNetworkInfo(context);
|
NetworkInfo networkInfo = getActiveNetworkInfo(context);
|
||||||
return networkInfo != null && networkInfo.isConnected();
|
return networkInfo != null && networkInfo.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NetworkInfo getActiveNetworkInfo(Context context) {
|
private static NetworkInfo getActiveNetworkInfo(@NonNull Context context) {
|
||||||
ConnectivityManager connectivity = (ConnectivityManager) context
|
ConnectivityManager connectivity = (ConnectivityManager) context
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
if (connectivity == null) {
|
if (connectivity == null) {
|
||||||
@ -433,6 +439,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
return connectivity.getActiveNetworkInfo();
|
return connectivity.getActiveNetworkInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private synchronized List<HistoryItem> getFilteredList() {
|
private synchronized List<HistoryItem> getFilteredList() {
|
||||||
List<HistoryItem> list = new ArrayList<>(5);
|
List<HistoryItem> list = new ArrayList<>(5);
|
||||||
synchronized (mBookmarks) {
|
synchronized (mBookmarks) {
|
||||||
@ -464,7 +471,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
private static class SuggestionsComparator implements Comparator<HistoryItem> {
|
private static class SuggestionsComparator implements Comparator<HistoryItem> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(HistoryItem lhs, HistoryItem rhs) {
|
public int compare(@NonNull HistoryItem lhs, @NonNull HistoryItem rhs) {
|
||||||
if (lhs.getImageId() == rhs.getImageId()) return 0;
|
if (lhs.getImageId() == rhs.getImageId()) return 0;
|
||||||
if (lhs.getImageId() == R.drawable.ic_bookmark) return -1;
|
if (lhs.getImageId() == R.drawable.ic_bookmark) return -1;
|
||||||
if (rhs.getImageId() == R.drawable.ic_bookmark) return 1;
|
if (rhs.getImageId() == R.drawable.ic_bookmark) return 1;
|
||||||
|
@ -2,6 +2,8 @@ package acr.browser.lightning.preference;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -66,7 +68,7 @@ public class PreferenceManager {
|
|||||||
private static final String PREFERENCES = "settings";
|
private static final String PREFERENCES = "settings";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PreferenceManager(final Context context) {
|
PreferenceManager(@NonNull final Context context) {
|
||||||
mPrefs = context.getSharedPreferences(PREFERENCES, 0);
|
mPrefs = context.getSharedPreferences(PREFERENCES, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +116,7 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getBoolean(Name.COOKIES, true);
|
return mPrefs.getBoolean(Name.COOKIES, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getDownloadDirectory() {
|
public String getDownloadDirectory() {
|
||||||
return mPrefs.getString(Name.DOWNLOAD_DIRECTORY, DownloadHandler.DEFAULT_DOWNLOAD_PATH);
|
return mPrefs.getString(Name.DOWNLOAD_DIRECTORY, DownloadHandler.DEFAULT_DOWNLOAD_PATH);
|
||||||
}
|
}
|
||||||
@ -134,6 +137,7 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getBoolean(Name.HIDE_STATUS_BAR, false);
|
return mPrefs.getBoolean(Name.HIDE_STATUS_BAR, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getHomepage() {
|
public String getHomepage() {
|
||||||
return mPrefs.getString(Name.HOMEPAGE, Constants.HOMEPAGE);
|
return mPrefs.getString(Name.HOMEPAGE, Constants.HOMEPAGE);
|
||||||
}
|
}
|
||||||
@ -162,6 +166,7 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getBoolean(Name.POPUPS, true);
|
return mPrefs.getBoolean(Name.POPUPS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getProxyHost() {
|
public String getProxyHost() {
|
||||||
return mPrefs.getString(Name.USE_PROXY_HOST, "localhost");
|
return mPrefs.getString(Name.USE_PROXY_HOST, "localhost");
|
||||||
}
|
}
|
||||||
@ -182,6 +187,7 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getBoolean(Name.RESTORE_LOST_TABS, true);
|
return mPrefs.getBoolean(Name.RESTORE_LOST_TABS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getSavedUrl() {
|
public String getSavedUrl() {
|
||||||
return mPrefs.getString(Name.SAVE_URL, null);
|
return mPrefs.getString(Name.SAVE_URL, null);
|
||||||
}
|
}
|
||||||
@ -194,6 +200,7 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getInt(Name.SEARCH, 1);
|
return mPrefs.getInt(Name.SEARCH, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getSearchUrl() {
|
public String getSearchUrl() {
|
||||||
return mPrefs.getString(Name.SEARCH_URL, Constants.GOOGLE_SEARCH);
|
return mPrefs.getString(Name.SEARCH_URL, Constants.GOOGLE_SEARCH);
|
||||||
}
|
}
|
||||||
@ -226,7 +233,8 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getInt(Name.USER_AGENT, 1);
|
return mPrefs.getInt(Name.USER_AGENT, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserAgentString(String def) {
|
@Nullable
|
||||||
|
public String getUserAgentString(@Nullable String def) {
|
||||||
return mPrefs.getString(Name.USER_AGENT_STRING, def);
|
return mPrefs.getString(Name.USER_AGENT_STRING, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +242,7 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getBoolean(Name.USE_WIDE_VIEWPORT, true);
|
return mPrefs.getBoolean(Name.USE_WIDE_VIEWPORT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getTextEncoding() {
|
public String getTextEncoding() {
|
||||||
return mPrefs.getString(Name.TEXT_ENCODING, Constants.DEFAULT_ENCODING);
|
return mPrefs.getString(Name.TEXT_ENCODING, Constants.DEFAULT_ENCODING);
|
||||||
}
|
}
|
||||||
@ -250,15 +259,15 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getBoolean(Name.IDENTIFYING_HEADERS, false);
|
return mPrefs.getBoolean(Name.IDENTIFYING_HEADERS, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putBoolean(String name, boolean value) {
|
private void putBoolean(@NonNull String name, boolean value) {
|
||||||
mPrefs.edit().putBoolean(name, value).apply();
|
mPrefs.edit().putBoolean(name, value).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putInt(String name, int value) {
|
private void putInt(@NonNull String name, int value) {
|
||||||
mPrefs.edit().putInt(name, value).apply();
|
mPrefs.edit().putInt(name, value).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putString(String name, String value) {
|
private void putString(@NonNull String name, @Nullable String value) {
|
||||||
mPrefs.edit().putString(name, value).apply();
|
mPrefs.edit().putString(name, value).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +283,7 @@ public class PreferenceManager {
|
|||||||
putBoolean(Name.SHOW_TABS_IN_DRAWER, show);
|
putBoolean(Name.SHOW_TABS_IN_DRAWER, show);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTextEncoding(String encoding) {
|
public void setTextEncoding(@NonNull String encoding) {
|
||||||
putString(Name.TEXT_ENCODING, encoding);
|
putString(Name.TEXT_ENCODING, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,7 +391,7 @@ public class PreferenceManager {
|
|||||||
putBoolean(Name.RESTORE_LOST_TABS, enable);
|
putBoolean(Name.RESTORE_LOST_TABS, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSavedUrl(String url) {
|
public void setSavedUrl(@NonNull String url) {
|
||||||
putString(Name.SAVE_URL, url);
|
putString(Name.SAVE_URL, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +403,7 @@ public class PreferenceManager {
|
|||||||
putInt(Name.SEARCH, choice);
|
putInt(Name.SEARCH, choice);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchUrl(String url) {
|
public void setSearchUrl(@NonNull String url) {
|
||||||
putString(Name.SEARCH_URL, url);
|
putString(Name.SEARCH_URL, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
@ -31,7 +33,7 @@ public class IntentUtils {
|
|||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startActivityForUrl(WebView tab, String url) {
|
public boolean startActivityForUrl(@Nullable WebView tab, @NonNull String url) {
|
||||||
Intent intent;
|
Intent intent;
|
||||||
try {
|
try {
|
||||||
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
|
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
|
||||||
|
@ -74,12 +74,10 @@ public class ThemeUtils {
|
|||||||
return resultBitmap;
|
return resultBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
public static Drawable getThemedDrawable(@NonNull Context context, @DrawableRes int res, boolean dark) {
|
public static Drawable getThemedDrawable(@NonNull Context context, @DrawableRes int res, boolean dark) {
|
||||||
int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
|
int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
|
||||||
final Drawable drawable = ContextCompat.getDrawable(context, res);
|
final Drawable drawable = ContextCompat.getDrawable(context, res);
|
||||||
if (drawable == null)
|
|
||||||
return null;
|
|
||||||
drawable.mutate();
|
drawable.mutate();
|
||||||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
return drawable;
|
return drawable;
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package acr.browser.lightning.utils;
|
package acr.browser.lightning.utils;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
@ -58,7 +60,8 @@ public class UrlUtils {
|
|||||||
* @return a stripped url like "www.google.com", or the original string if it could
|
* @return a stripped url like "www.google.com", or the original string if it could
|
||||||
* not be stripped
|
* not be stripped
|
||||||
*/
|
*/
|
||||||
public static String stripUrl(String url) {
|
@Nullable
|
||||||
|
public static String stripUrl(@Nullable String url) {
|
||||||
if (url == null) return null;
|
if (url == null) return null;
|
||||||
Matcher m = STRIP_URL_PATTERN.matcher(url);
|
Matcher m = STRIP_URL_PATTERN.matcher(url);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
@ -79,7 +82,7 @@ public class UrlUtils {
|
|||||||
* URL. If false, invalid URLs will return null
|
* URL. If false, invalid URLs will return null
|
||||||
* @return Original or modified URL
|
* @return Original or modified URL
|
||||||
*/
|
*/
|
||||||
public static String smartUrlFilter(String url, boolean canBeSearch, String searchUrl) {
|
public static String smartUrlFilter(@NonNull String url, boolean canBeSearch, String searchUrl) {
|
||||||
String inUrl = url.trim();
|
String inUrl = url.trim();
|
||||||
boolean hasSpace = inUrl.indexOf(' ') != -1;
|
boolean hasSpace = inUrl.indexOf(' ') != -1;
|
||||||
Matcher matcher = ACCEPTED_URI_SCHEMA.matcher(inUrl);
|
Matcher matcher = ACCEPTED_URI_SCHEMA.matcher(inUrl);
|
||||||
@ -108,7 +111,8 @@ public class UrlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* package */
|
/* package */
|
||||||
static String fixUrl(String inUrl) {
|
@NonNull
|
||||||
|
static String fixUrl(@NonNull String inUrl) {
|
||||||
// FIXME: Converting the url to lower case
|
// FIXME: Converting the url to lower case
|
||||||
// duplicates functionality in smartUrlFilter().
|
// duplicates functionality in smartUrlFilter().
|
||||||
// However, changing all current callers of fixUrl to
|
// However, changing all current callers of fixUrl to
|
||||||
@ -140,7 +144,8 @@ public class UrlUtils {
|
|||||||
|
|
||||||
// Returns the filtered URL. Cannot return null, but can return an empty string
|
// Returns the filtered URL. Cannot return null, but can return an empty string
|
||||||
/* package */
|
/* package */
|
||||||
static String filteredUrl(String inUrl) {
|
@Nullable
|
||||||
|
static String filteredUrl(@Nullable String inUrl) {
|
||||||
if (inUrl == null) {
|
if (inUrl == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -154,7 +159,7 @@ public class UrlUtils {
|
|||||||
/**
|
/**
|
||||||
* Returns whether the given url is the bookmarks/history page or a normal website
|
* Returns whether the given url is the bookmarks/history page or a normal website
|
||||||
*/
|
*/
|
||||||
public static boolean isSpecialUrl(String url) {
|
public static boolean isSpecialUrl(@Nullable String url) {
|
||||||
return url != null && url.startsWith(Constants.FILE) &&
|
return url != null && url.startsWith(Constants.FILE) &&
|
||||||
(url.endsWith(BookmarkPage.FILENAME) ||
|
(url.endsWith(BookmarkPage.FILENAME) ||
|
||||||
url.endsWith(HistoryPage.FILENAME) ||
|
url.endsWith(HistoryPage.FILENAME) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user