NullPointerException checks in MainActivity

This commit is contained in:
Sonu Sourav 2019-03-02 18:21:43 +05:30 committed by Isaac Hutt
parent 04b6d07b2b
commit c34934c8b9

View File

@ -532,15 +532,20 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
} }
private void updateBottomToolbarArrowsAlpha() { private void updateBottomToolbarArrowsAlpha() {
if (getCurrentWebView().canGoForward()) { if (checkNull(bottomToolbarArrowBack)) {
bottomToolbarArrowForward.setAlpha(1f); if (getCurrentWebView().canGoForward()) {
} else { bottomToolbarArrowForward.setAlpha(1f);
bottomToolbarArrowForward.setAlpha(0.6f); } else {
bottomToolbarArrowForward.setAlpha(0.6f);
}
} }
if (getCurrentWebView().canGoBack()) {
bottomToolbarArrowBack.setAlpha(1f); if (checkNull(bottomToolbarArrowForward)) {
} else { if (getCurrentWebView().canGoBack()) {
bottomToolbarArrowBack.setAlpha(0.6f); bottomToolbarArrowBack.setAlpha(1f);
} else {
bottomToolbarArrowBack.setAlpha(0.6f);
}
} }
} }
@ -1284,20 +1289,22 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
} }
private void updateBottomToolbarVisibility() { private void updateBottomToolbarVisibility() {
if (sharedPreferenceUtil.getPrefBottomToolbar() && !HOME_URL.equals( if (checkNull(bottomToolbar)) {
getCurrentWebView().getUrl()) if (sharedPreferenceUtil.getPrefBottomToolbar() && !HOME_URL.equals(
&& tabSwitcherRoot.getVisibility() != View.VISIBLE) { getCurrentWebView().getUrl())
bottomToolbar.setVisibility(View.VISIBLE); && tabSwitcherRoot.getVisibility() != View.VISIBLE) {
if (getCurrentWebView() instanceof ToolbarStaticKiwixWebView bottomToolbar.setVisibility(View.VISIBLE);
&& sharedPreferenceUtil.getPrefBottomToolbar()) { if (getCurrentWebView() instanceof ToolbarStaticKiwixWebView
contentFrame.setPadding(0, 0, 0, && sharedPreferenceUtil.getPrefBottomToolbar()) {
(int) getResources().getDimension(R.dimen.bottom_toolbar_height)); contentFrame.setPadding(0, 0, 0,
(int) getResources().getDimension(R.dimen.bottom_toolbar_height));
} else {
contentFrame.setPadding(0, 0, 0, 0);
}
} else { } else {
bottomToolbar.setVisibility(View.GONE);
contentFrame.setPadding(0, 0, 0, 0); contentFrame.setPadding(0, 0, 0, 0);
} }
} else {
bottomToolbar.setVisibility(View.GONE);
contentFrame.setPadding(0, 0, 0, 0);
} }
} }
@ -1574,14 +1581,16 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
} }
private void refreshBookmarkSymbol() { private void refreshBookmarkSymbol() {
if (getCurrentWebView().getUrl() != null && if (checkNull(bottomToolbarBookmark)) {
ZimContentProvider.getId() != null && if (getCurrentWebView().getUrl() != null &&
!getCurrentWebView().getUrl().equals(HOME_URL)) { ZimContentProvider.getId() != null &&
int icon = bookmarks.contains(getCurrentWebView().getUrl()) ? R.drawable.ic_bookmark_24dp !getCurrentWebView().getUrl().equals(HOME_URL)) {
: R.drawable.ic_bookmark_border_24dp; int icon = bookmarks.contains(getCurrentWebView().getUrl()) ? R.drawable.ic_bookmark_24dp
bottomToolbarBookmark.setImageResource(icon); : R.drawable.ic_bookmark_border_24dp;
} else { bottomToolbarBookmark.setImageResource(icon);
bottomToolbarBookmark.setImageResource(R.drawable.ic_bookmark_border_24dp); } else {
bottomToolbarBookmark.setImageResource(R.drawable.ic_bookmark_border_24dp);
}
} }
} }
@ -1832,16 +1841,18 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
@Override @Override
public void webViewProgressChanged(int progress) { public void webViewProgressChanged(int progress) {
progressBar.setProgress(progress); if (checkNull(progressBar)) {
if (progress == 100) { progressBar.setProgress(progress);
if (requestClearHistoryAfterLoad) { if (progress == 100) {
Log.d(TAG_KIWIX, if (requestClearHistoryAfterLoad) {
"Loading article finished and requestClearHistoryAfterLoad -> clearHistory"); Log.d(TAG_KIWIX,
getCurrentWebView().clearHistory(); "Loading article finished and requestClearHistoryAfterLoad -> clearHistory");
requestClearHistoryAfterLoad = false; getCurrentWebView().clearHistory();
} requestClearHistoryAfterLoad = false;
}
Log.d(TAG_KIWIX, "Loaded URL: " + getCurrentWebView().getUrl()); Log.d(TAG_KIWIX, "Loaded URL: " + getCurrentWebView().getUrl());
}
} }
} }
@ -1941,4 +1952,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
fileSearch.scan(sharedPreferenceUtil.getPrefStorage()); fileSearch.scan(sharedPreferenceUtil.getPrefStorage());
} }
} }
public boolean checkNull(View view) {
return view != null;
}
} }