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