Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2211 fix rare crash #2224

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions app/src/main/java/io/pslab/fragment/HomeFragment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.pslab.fragment;

import static io.pslab.others.ScienceLabCommon.scienceLab;

import android.graphics.Bitmap;
import android.graphics.Paint;
import android.os.Bundle;
Expand Down Expand Up @@ -28,8 +30,6 @@
import io.pslab.others.InitializationVariable;
import io.pslab.others.ScienceLabCommon;

import static io.pslab.others.ScienceLabCommon.scienceLab;

/**
* Created by viveksb007 on 15/3/17.
*/
Expand Down Expand Up @@ -107,23 +107,42 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
imgViewDeviceStatus.setImageResource(R.drawable.icons_usb_disconnected_100);
tvDeviceStatus.setText(getString(R.string.device_not_found));
}

/*
* The null-checks in the OnClickListener may seem unnecessary, but even though the
* respective variables are initialized before the setter is called, they may contain null
* in later phases of the lifecycle of this Fragment and cause NullPointerExceptions if not
* checked before access.
*
* See: https://github.com/fossasia/pslab-android/issues/2211
*/
deviceDescription.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (webView == null) {
return;
}

webView.loadUrl("https://pslab.io");
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
svHomeContent.setVisibility(View.GONE);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
wvProgressBar.setIndeterminate(true);
wvProgressBar.setVisibility(View.VISIBLE);
if (wvProgressBar != null) {
wvProgressBar.setIndeterminate(true);
wvProgressBar.setVisibility(View.VISIBLE);
}
}

public void onPageFinished(WebView view, String url) {
wvProgressBar.setVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);
if (wvProgressBar != null) {
wvProgressBar.setVisibility(View.GONE);
}
if (webView != null) {
webView.setVisibility(View.VISIBLE);
}
}
});
isWebViewShowing = true;
Expand Down