Cleaning up potential NPEs and other lint warnings
This commit is contained in:
parent
103eea9fcb
commit
38bb96d4f2
@ -161,6 +161,7 @@ public class TabsManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onNext(@Nullable Bundle item) {
|
public void onNext(@Nullable Bundle item) {
|
||||||
final LightningView tab = newTab(activity, "", false);
|
final LightningView tab = newTab(activity, "", false);
|
||||||
|
Preconditions.checkNonNull(item);
|
||||||
String url = item.getString(URL_KEY);
|
String url = item.getString(URL_KEY);
|
||||||
if (url != null && tab.getWebView() != null) {
|
if (url != null && tab.getWebView() != null) {
|
||||||
if (UrlUtils.isBookmarkUrl(url)) {
|
if (UrlUtils.isBookmarkUrl(url)) {
|
||||||
|
@ -24,12 +24,7 @@ public final class BookmarkEvents {
|
|||||||
*/
|
*/
|
||||||
public static class BookmarkChanged {
|
public static class BookmarkChanged {
|
||||||
|
|
||||||
public final HistoryItem oldBookmark;
|
public BookmarkChanged() {
|
||||||
public final HistoryItem newBookmark;
|
|
||||||
|
|
||||||
public BookmarkChanged(final HistoryItem oldItem, final HistoryItem newItem) {
|
|
||||||
oldBookmark = oldItem;
|
|
||||||
newBookmark = newItem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,6 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -12,6 +12,7 @@ import android.text.TextUtils;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -179,7 +180,10 @@ public class BrowserDialog {
|
|||||||
if (maxWidth > screenSize - 2 * padding) {
|
if (maxWidth > screenSize - 2 * padding) {
|
||||||
maxWidth = screenSize - 2 * padding;
|
maxWidth = screenSize - 2 * padding;
|
||||||
}
|
}
|
||||||
dialog.getWindow().setLayout(maxWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
|
Window window = dialog.getWindow();
|
||||||
|
if (window != null) {
|
||||||
|
window.setLayout(maxWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ public class LightningDialogBuilder {
|
|||||||
editedItem.setUrl(getUrl.getText().toString());
|
editedItem.setUrl(getUrl.getText().toString());
|
||||||
editedItem.setFolder(getFolder.getText().toString());
|
editedItem.setFolder(getFolder.getText().toString());
|
||||||
mBookmarkManager.editBookmark(item, editedItem);
|
mBookmarkManager.editBookmark(item, editedItem);
|
||||||
mEventBus.post(new BookmarkEvents.BookmarkChanged(item, editedItem));
|
mEventBus.post(new BookmarkEvents.BookmarkChanged());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Dialog dialog = editBookmarkDialog.show();
|
Dialog dialog = editBookmarkDialog.show();
|
||||||
@ -190,7 +190,7 @@ public class LightningDialogBuilder {
|
|||||||
editedItem.setFolder(item.getFolder());
|
editedItem.setFolder(item.getFolder());
|
||||||
editedItem.setIsFolder(true);
|
editedItem.setIsFolder(true);
|
||||||
mBookmarkManager.renameFolder(oldTitle, text);
|
mBookmarkManager.renameFolder(oldTitle, text);
|
||||||
mEventBus.post(new BookmarkEvents.BookmarkChanged(item, editedItem));
|
mEventBus.post(new BookmarkEvents.BookmarkChanged());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -13,14 +13,12 @@ import android.webkit.MimeTypeMap;
|
|||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
import com.anthonycr.bonsai.Schedulers;
|
import com.anthonycr.bonsai.Schedulers;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -299,6 +299,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
String title = adapter.getItem(which);
|
String title = adapter.getItem(which);
|
||||||
|
Preconditions.checkNonNull(title);
|
||||||
Source source = null;
|
Source source = null;
|
||||||
if (title.equals(getString(R.string.stock_browser))) {
|
if (title.equals(getString(R.string.stock_browser))) {
|
||||||
source = Source.STOCK;
|
source = Source.STOCK;
|
||||||
|
@ -34,10 +34,11 @@ abstract class BaseSuggestionsModel {
|
|||||||
static final int MAX_RESULTS = 5;
|
static final int MAX_RESULTS = 5;
|
||||||
private static final long INTERVAL_DAY = TimeUnit.DAYS.toSeconds(1);
|
private static final long INTERVAL_DAY = TimeUnit.DAYS.toSeconds(1);
|
||||||
@NonNull private static final String DEFAULT_LANGUAGE = "en";
|
@NonNull private static final String DEFAULT_LANGUAGE = "en";
|
||||||
@Nullable private static String sLanguage;
|
|
||||||
@NonNull private final OkHttpClient mHttpClient;
|
@NonNull private final OkHttpClient mHttpClient;
|
||||||
@NonNull private final CacheControl mCacheControl;
|
@NonNull private final CacheControl mCacheControl;
|
||||||
@NonNull private final String mEncoding;
|
@NonNull private final String mEncoding;
|
||||||
|
@NonNull private final String mLanguage;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
protected abstract String createQueryUrl(@NonNull String query, @NonNull String language);
|
protected abstract String createQueryUrl(@NonNull String query, @NonNull String language);
|
||||||
@ -46,6 +47,7 @@ abstract class BaseSuggestionsModel {
|
|||||||
|
|
||||||
BaseSuggestionsModel(@NonNull Application application, @NonNull String encoding) {
|
BaseSuggestionsModel(@NonNull Application application, @NonNull String encoding) {
|
||||||
mEncoding = encoding;
|
mEncoding = encoding;
|
||||||
|
mLanguage = getLanguage();
|
||||||
File suggestionsCache = new File(application.getCacheDir(), "suggestion_responses");
|
File suggestionsCache = new File(application.getCacheDir(), "suggestion_responses");
|
||||||
mHttpClient = new OkHttpClient.Builder()
|
mHttpClient = new OkHttpClient.Builder()
|
||||||
.cache(new Cache(suggestionsCache, FileUtils.megabytesToBytes(1)))
|
.cache(new Cache(suggestionsCache, FileUtils.megabytesToBytes(1)))
|
||||||
@ -55,14 +57,12 @@ abstract class BaseSuggestionsModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static synchronized String getLanguage() {
|
private static String getLanguage() {
|
||||||
if (sLanguage == null) {
|
String language = Locale.getDefault().getLanguage();
|
||||||
sLanguage = Locale.getDefault().getLanguage();
|
if (TextUtils.isEmpty(language)) {
|
||||||
|
language = DEFAULT_LANGUAGE;
|
||||||
}
|
}
|
||||||
if (TextUtils.isEmpty(sLanguage)) {
|
return language;
|
||||||
sLanguage = DEFAULT_LANGUAGE;
|
|
||||||
}
|
|
||||||
return sLanguage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -73,7 +73,7 @@ abstract class BaseSuggestionsModel {
|
|||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
Log.e(TAG, "Unable to encode the URL", e);
|
Log.e(TAG, "Unable to encode the URL", e);
|
||||||
}
|
}
|
||||||
InputStream inputStream = downloadSuggestionsForQuery(query, getLanguage());
|
InputStream inputStream = downloadSuggestionsForQuery(query, mLanguage);
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
// There are no suggestions for this query, return an empty list.
|
// There are no suggestions for this query, return an empty list.
|
||||||
return filter;
|
return filter;
|
||||||
|
@ -6,7 +6,6 @@ import android.support.annotation.NonNull;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
import org.xmlpull.v1.XmlPullParserFactory;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ import java.util.Comparator;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@ -114,8 +114,9 @@ public class ProxyUtils {
|
|||||||
// We shouldn't be here
|
// We shouldn't be here
|
||||||
return;
|
return;
|
||||||
case Constants.PROXY_ORBOT:
|
case Constants.PROXY_ORBOT:
|
||||||
if (!OrbotHelper.isOrbotRunning(activity))
|
if (!OrbotHelper.isOrbotRunning(activity)) {
|
||||||
OrbotHelper.requestStartTor(activity);
|
OrbotHelper.requestStartTor(activity);
|
||||||
|
}
|
||||||
host = "localhost";
|
host = "localhost";
|
||||||
port = 8118;
|
port = 8118;
|
||||||
break;
|
break;
|
||||||
|
@ -70,12 +70,7 @@ public class ThemeUtils {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static Drawable getVectorDrawable(@NonNull Context context, int drawableId) {
|
private static Drawable getVectorDrawable(@NonNull Context context, int drawableId) {
|
||||||
Drawable drawable;
|
Drawable drawable = ContextCompat.getDrawable(context, drawableId);
|
||||||
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
|
||||||
drawable = context.getDrawable(drawableId);
|
|
||||||
} else {
|
|
||||||
drawable = context.getResources().getDrawable(drawableId);
|
|
||||||
}
|
|
||||||
|
|
||||||
Preconditions.checkNonNull(drawable);
|
Preconditions.checkNonNull(drawable);
|
||||||
|
|
||||||
|
@ -427,6 +427,7 @@ public class LightningView {
|
|||||||
.subscribe(new SingleOnSubscribe<File>() {
|
.subscribe(new SingleOnSubscribe<File>() {
|
||||||
@Override
|
@Override
|
||||||
public void onItem(@Nullable File item) {
|
public void onItem(@Nullable File item) {
|
||||||
|
Preconditions.checkNonNull(item);
|
||||||
settings.setAppCachePath(item.getPath());
|
settings.setAppCachePath(item.getPath());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -437,6 +438,7 @@ public class LightningView {
|
|||||||
.subscribe(new SingleOnSubscribe<File>() {
|
.subscribe(new SingleOnSubscribe<File>() {
|
||||||
@Override
|
@Override
|
||||||
public void onItem(@Nullable File item) {
|
public void onItem(@Nullable File item) {
|
||||||
|
Preconditions.checkNonNull(item);
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
settings.setGeolocationDatabasePath(item.getPath());
|
settings.setGeolocationDatabasePath(item.getPath());
|
||||||
}
|
}
|
||||||
@ -449,6 +451,7 @@ public class LightningView {
|
|||||||
@Override
|
@Override
|
||||||
public void onItem(@Nullable File item) {
|
public void onItem(@Nullable File item) {
|
||||||
if (API < Build.VERSION_CODES.KITKAT) {
|
if (API < Build.VERSION_CODES.KITKAT) {
|
||||||
|
Preconditions.checkNonNull(item);
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
settings.setDatabasePath(item.getPath());
|
settings.setDatabasePath(item.getPath());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user