Skip to content

Commit 46853fd

Browse files
committed
Fix NPE and bug in PolicyFragment.
1 parent 192d61e commit 46853fd

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

app/src/main/java/net/kollnig/missioncontrol/details/PolicyFragment.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.support.design.widget.FloatingActionButton;
2424
import android.support.design.widget.Snackbar;
2525
import android.support.v4.app.Fragment;
26+
import android.support.v4.app.FragmentActivity;
2627
import android.text.Html;
2728
import android.text.method.LinkMovementMethod;
2829
import android.util.Log;
@@ -109,7 +110,7 @@ public void onViewCreated (View v, Bundle savedInstanceState) {
109110
startActivity(browserIntent);
110111
}
111112
});
112-
fab.setVisibility(View.GONE);
113+
fab.hide();
113114

114115
((DetailsActivity) getActivity()).addListener(this);
115116

@@ -146,7 +147,7 @@ public void displayHtml (String html) {
146147
public void loadingFinished () {
147148
txtPolicy.setVisibility(View.VISIBLE);
148149
pbPolicy.setVisibility(View.GONE);
149-
fab.setVisibility(View.VISIBLE);
150+
fab.show();
150151
}
151152

152153
@Override
@@ -156,16 +157,17 @@ public void appInfoLoaded () {
156157

157158
private class PolicyLoader implements Runnable {
158159
private void onError (final String url) {
159-
getActivity().runOnUiThread(new Runnable() {
160-
public void run () {
161-
if (url != null) {
162-
html = getString(R.string.parse_error, Html.escapeHtml(url));
163-
displayHtml(html);
164-
} else {
165-
txtPolicy.setText(getString(R.string.policy_loading_error));
166-
}
167-
loadingFinished();
160+
FragmentActivity a = getActivity();
161+
if (a == null) return;
162+
163+
a.runOnUiThread(() -> {
164+
if (url != null) {
165+
html = getString(R.string.parse_error, Html.escapeHtml(url));
166+
displayHtml(html);
167+
} else {
168+
txtPolicy.setText(getString(R.string.policy_loading_error));
168169
}
170+
loadingFinished();
169171
});
170172
}
171173

@@ -201,11 +203,11 @@ public void run () {
201203
html = "<h1>" + Html.escapeHtml(title) + "</h1>" + content;
202204

203205
// Display in UI
204-
getActivity().runOnUiThread(new Runnable() {
205-
public void run () {
206-
displayHtml(html);
207-
loadingFinished();
208-
}
206+
FragmentActivity a = getActivity();
207+
if (a == null) return;
208+
a.runOnUiThread(() -> {
209+
displayHtml(html);
210+
loadingFinished();
209211
});
210212
}
211213
}

0 commit comments

Comments
 (0)