Cleaning up potential NPEs and other lint warnings

This commit is contained in:
anthony restaino 2017-04-22 18:32:55 -04:00
parent 103eea9fcb
commit 38bb96d4f2
14 changed files with 29 additions and 36 deletions

View File

@ -161,6 +161,7 @@ public class TabsManager {
@Override
public void onNext(@Nullable Bundle item) {
final LightningView tab = newTab(activity, "", false);
Preconditions.checkNonNull(item);
String url = item.getString(URL_KEY);
if (url != null && tab.getWebView() != null) {
if (UrlUtils.isBookmarkUrl(url)) {

View File

@ -24,12 +24,7 @@ public final class BookmarkEvents {
*/
public static class BookmarkChanged {
public final HistoryItem oldBookmark;
public final HistoryItem newBookmark;
public BookmarkChanged(final HistoryItem oldItem, final HistoryItem newItem) {
oldBookmark = oldItem;
newBookmark = newItem;
public BookmarkChanged() {
}
}
}

View File

@ -30,8 +30,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.inject.Inject;
import javax.inject.Singleton;

View File

@ -12,6 +12,7 @@ import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
@ -179,7 +180,10 @@ public class BrowserDialog {
if (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);
}
}
}

View File

@ -151,7 +151,7 @@ public class LightningDialogBuilder {
editedItem.setUrl(getUrl.getText().toString());
editedItem.setFolder(getFolder.getText().toString());
mBookmarkManager.editBookmark(item, editedItem);
mEventBus.post(new BookmarkEvents.BookmarkChanged(item, editedItem));
mEventBus.post(new BookmarkEvents.BookmarkChanged());
}
});
Dialog dialog = editBookmarkDialog.show();
@ -190,7 +190,7 @@ public class LightningDialogBuilder {
editedItem.setFolder(item.getFolder());
editedItem.setIsFolder(true);
mBookmarkManager.renameFolder(oldTitle, text);
mEventBus.post(new BookmarkEvents.BookmarkChanged(item, editedItem));
mEventBus.post(new BookmarkEvents.BookmarkChanged());
}
}
});

View File

@ -13,14 +13,12 @@ import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
import com.anthonycr.bonsai.Schedulers;
import com.squareup.otto.Bus;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.utils.Utils;
/**

View File

@ -299,6 +299,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
@Override
public void onClick(DialogInterface dialog, int which) {
String title = adapter.getItem(which);
Preconditions.checkNonNull(title);
Source source = null;
if (title.equals(getString(R.string.stock_browser))) {
source = Source.STOCK;

View File

@ -34,10 +34,11 @@ abstract class BaseSuggestionsModel {
static final int MAX_RESULTS = 5;
private static final long INTERVAL_DAY = TimeUnit.DAYS.toSeconds(1);
@NonNull private static final String DEFAULT_LANGUAGE = "en";
@Nullable private static String sLanguage;
@NonNull private final OkHttpClient mHttpClient;
@NonNull private final CacheControl mCacheControl;
@NonNull private final String mEncoding;
@NonNull private final String mLanguage;
@NonNull
protected abstract String createQueryUrl(@NonNull String query, @NonNull String language);
@ -46,6 +47,7 @@ abstract class BaseSuggestionsModel {
BaseSuggestionsModel(@NonNull Application application, @NonNull String encoding) {
mEncoding = encoding;
mLanguage = getLanguage();
File suggestionsCache = new File(application.getCacheDir(), "suggestion_responses");
mHttpClient = new OkHttpClient.Builder()
.cache(new Cache(suggestionsCache, FileUtils.megabytesToBytes(1)))
@ -55,14 +57,12 @@ abstract class BaseSuggestionsModel {
}
@NonNull
private static synchronized String getLanguage() {
if (sLanguage == null) {
sLanguage = Locale.getDefault().getLanguage();
private static String getLanguage() {
String language = Locale.getDefault().getLanguage();
if (TextUtils.isEmpty(language)) {
language = DEFAULT_LANGUAGE;
}
if (TextUtils.isEmpty(sLanguage)) {
sLanguage = DEFAULT_LANGUAGE;
}
return sLanguage;
return language;
}
@NonNull
@ -73,7 +73,7 @@ abstract class BaseSuggestionsModel {
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unable to encode the URL", e);
}
InputStream inputStream = downloadSuggestionsForQuery(query, getLanguage());
InputStream inputStream = downloadSuggestionsForQuery(query, mLanguage);
if (inputStream == null) {
// There are no suggestions for this query, return an empty list.
return filter;

View File

@ -6,7 +6,6 @@ import android.support.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;

View File

@ -9,7 +9,6 @@ import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;

View File

@ -33,7 +33,6 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;

View File

@ -114,8 +114,9 @@ public class ProxyUtils {
// We shouldn't be here
return;
case Constants.PROXY_ORBOT:
if (!OrbotHelper.isOrbotRunning(activity))
if (!OrbotHelper.isOrbotRunning(activity)) {
OrbotHelper.requestStartTor(activity);
}
host = "localhost";
port = 8118;
break;

View File

@ -70,12 +70,7 @@ public class ThemeUtils {
@NonNull
private static Drawable getVectorDrawable(@NonNull Context context, int drawableId) {
Drawable drawable;
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
drawable = context.getDrawable(drawableId);
} else {
drawable = context.getResources().getDrawable(drawableId);
}
Drawable drawable = ContextCompat.getDrawable(context, drawableId);
Preconditions.checkNonNull(drawable);
@ -91,7 +86,7 @@ public class ThemeUtils {
Drawable drawable = getVectorDrawable(context, drawableId);
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
@ -104,7 +99,7 @@ public class ThemeUtils {
int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
Bitmap sourceBitmap = getBitmapFromVectorDrawable(context, res);
Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(),
Bitmap.Config.ARGB_8888);
Bitmap.Config.ARGB_8888);
Paint p = new Paint();
ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
p.setColorFilter(filter);
@ -126,8 +121,8 @@ public class ThemeUtils {
@NonNull
public static ColorDrawable getSelectedBackground(@NonNull Context context, boolean dark) {
@ColorInt final int color =
(dark) ? ContextCompat.getColor(context, R.color.selected_dark) : ContextCompat.getColor(
context, R.color.selected_light);
(dark) ? ContextCompat.getColor(context, R.color.selected_dark) : ContextCompat.getColor(
context, R.color.selected_light);
return new ColorDrawable(color);
}

View File

@ -427,6 +427,7 @@ public class LightningView {
.subscribe(new SingleOnSubscribe<File>() {
@Override
public void onItem(@Nullable File item) {
Preconditions.checkNonNull(item);
settings.setAppCachePath(item.getPath());
}
});
@ -437,6 +438,7 @@ public class LightningView {
.subscribe(new SingleOnSubscribe<File>() {
@Override
public void onItem(@Nullable File item) {
Preconditions.checkNonNull(item);
//noinspection deprecation
settings.setGeolocationDatabasePath(item.getPath());
}
@ -449,6 +451,7 @@ public class LightningView {
@Override
public void onItem(@Nullable File item) {
if (API < Build.VERSION_CODES.KITKAT) {
Preconditions.checkNonNull(item);
//noinspection deprecation
settings.setDatabasePath(item.getPath());
}