Fixing potential null pointers
This commit is contained in:
parent
5c8773cd98
commit
63e77995ac
@ -750,7 +750,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
// Keyboard shortcuts
|
||||
if (event.isCtrlPressed() && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
switch(event.getKeyCode()) {
|
||||
switch (event.getKeyCode()) {
|
||||
case KeyEvent.KEYCODE_T:
|
||||
// Open new tab
|
||||
newTab(null, true);
|
||||
@ -765,23 +765,32 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_R:
|
||||
// Refresh current tab
|
||||
mTabsManager.getCurrentTab().reload();
|
||||
LightningView currentTab = mTabsManager.getCurrentTab();
|
||||
if (currentTab != null) {
|
||||
currentTab.reload();
|
||||
}
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_TAB:
|
||||
int nextIndex = 0;
|
||||
if(event.isShiftPressed()) {
|
||||
if (event.isShiftPressed()) {
|
||||
// Go back one tab
|
||||
if(mTabsManager.indexOfCurrentTab() > 0) nextIndex = mTabsManager.indexOfCurrentTab() - 1;
|
||||
else nextIndex = mTabsManager.last();
|
||||
if (mTabsManager.indexOfCurrentTab() > 0) {
|
||||
nextIndex = mTabsManager.indexOfCurrentTab() - 1;
|
||||
} else {
|
||||
nextIndex = mTabsManager.last();
|
||||
}
|
||||
} else {
|
||||
// Go forward one tab
|
||||
if(mTabsManager.indexOfCurrentTab() < mTabsManager.last()) nextIndex = mTabsManager.indexOfCurrentTab() + 1;
|
||||
else nextIndex = 0;
|
||||
if (mTabsManager.indexOfCurrentTab() < mTabsManager.last()) {
|
||||
nextIndex = mTabsManager.indexOfCurrentTab() + 1;
|
||||
} else {
|
||||
nextIndex = 0;
|
||||
}
|
||||
}
|
||||
mPresenter.tabChanged(nextIndex);
|
||||
return true;
|
||||
}
|
||||
} else if(event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
|
||||
} else if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
|
||||
// Highlight search field
|
||||
mSearch.requestFocus();
|
||||
mSearch.selectAll();
|
||||
@ -1648,18 +1657,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
|
||||
private void openDownloads() {
|
||||
new DownloadsPage().getDownloadsPage()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void onItem(@Nullable String item) {
|
||||
Preconditions.checkNonNull(item);
|
||||
LightningView view = mTabsManager.getCurrentTab();
|
||||
if (view != null) {
|
||||
view.loadUrl(item);
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void onItem(@Nullable String item) {
|
||||
Preconditions.checkNonNull(item);
|
||||
LightningView view = mTabsManager.getCurrentTab();
|
||||
if (view != null) {
|
||||
view.loadUrl(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private View getBookmarkDrawer() {
|
||||
@ -2178,7 +2187,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
public void handleDownloadDeleted() {
|
||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
|
||||
&& currentTab.getUrl().endsWith(DownloadsPage.FILENAME)) {
|
||||
&& currentTab.getUrl().endsWith(DownloadsPage.FILENAME)) {
|
||||
currentTab.loadDownloadspage();
|
||||
}
|
||||
if (currentTab != null) {
|
||||
|
@ -16,7 +16,6 @@ import android.widget.AutoCompleteTextView;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.anthonycr.bonsai.CompletableOnSubscribe;
|
||||
import com.anthonycr.bonsai.CompletableSubscriber;
|
||||
import com.anthonycr.bonsai.Schedulers;
|
||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||
|
||||
|
@ -8,12 +8,14 @@ import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import acr.browser.lightning.utils.Utils;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
/**
|
||||
* An image fetcher that creates image
|
||||
@ -65,11 +67,17 @@ class ImageFetcher {
|
||||
Request imageRequest = new Request.Builder().url(url).build();
|
||||
|
||||
Response boundsResponse = mHttpClient.newCall(imageRequest).execute();
|
||||
boundsStream = boundsResponse.body().byteStream();
|
||||
ResponseBody boundsBody = boundsResponse.body();
|
||||
|
||||
if (boundsBody == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
boundsStream = boundsBody.byteStream();
|
||||
|
||||
BitmapFactory.decodeStream(boundsStream, null, mLoaderOptions);
|
||||
|
||||
boundsResponse.body().close();
|
||||
boundsBody.close();
|
||||
|
||||
int size = Utils.dpToPx(24);
|
||||
|
||||
@ -77,12 +85,19 @@ class ImageFetcher {
|
||||
mLoaderOptions.inJustDecodeBounds = false;
|
||||
|
||||
Response imageResponse = mHttpClient.newCall(imageRequest).execute();
|
||||
iconStream = imageResponse.body().byteStream();
|
||||
|
||||
ResponseBody imageBody = imageResponse.body();
|
||||
|
||||
if (imageBody == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
iconStream = imageBody.byteStream();
|
||||
|
||||
icon = BitmapFactory.decodeStream(iconStream, null, mLoaderOptions);
|
||||
|
||||
imageResponse.body().close();
|
||||
} catch (Exception e) {
|
||||
imageBody.close();
|
||||
} catch (IOException exception) {
|
||||
Log.d(TAG, "Unable to download icon: " + url);
|
||||
} finally {
|
||||
Utils.close(boundsStream);
|
||||
|
@ -26,6 +26,7 @@ import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
abstract class BaseSuggestionsModel {
|
||||
|
||||
@ -112,9 +113,10 @@ abstract class BaseSuggestionsModel {
|
||||
|
||||
Response suggestionsResponse = mHttpClient.newCall(suggestionsRequest).execute();
|
||||
|
||||
return suggestionsResponse.body().byteStream();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Problem getting search suggestions", e);
|
||||
ResponseBody responseBody = suggestionsResponse.body();
|
||||
return responseBody != null ? responseBody.byteStream() : null;
|
||||
} catch (IOException exception) {
|
||||
Log.e(TAG, "Problem getting search suggestions", exception);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user