Fix crash due to unknown suggested version.

There may be a bigger problem around suggested versions being null at
all, but that is getting looked at in a different feature set (i.e.
multi signature support) and will come in time. This fixes the immediate
problem some people were having and sending crash reports for in 0.104.

STACK_TRACE=java.lang.NullPointerException: Attempt to read from field 'java.lang.String org.fdroid.fdroid.data.Apk.versionName' on a null object reference
	at org.fdroid.fdroid.views.AppDetailsRecyclerViewAdapter$HeaderViewHolder.bindModel(AppDetailsRecyclerViewAdapter.java:425)
	at org.fdroid.fdroid.views.AppDetailsRecyclerViewAdapter.onBindViewHolder(AppDetailsRecyclerViewAdapter.java:244)
	at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6310)
	at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6343)
	...

Introduced in 97fd3f0.
This commit is contained in:
Peter Serwylo 2017-06-23 16:11:30 +10:00
parent eabec87a4c
commit 79ede18259

View File

@ -414,7 +414,8 @@ public class AppDetailsRecyclerViewAdapter
lastUpdateView.setVisibility(View.GONE); lastUpdateView.setVisibility(View.GONE);
} }
if (TextUtils.isEmpty(app.whatsNew)) { Apk suggestedApk = getSuggestedApk();
if (suggestedApk == null || TextUtils.isEmpty(app.whatsNew)) {
whatsNewView.setVisibility(View.GONE); whatsNewView.setVisibility(View.GONE);
} else { } else {
//noinspection deprecation Ignore deprecation because the suggested way is only available in API 24. //noinspection deprecation Ignore deprecation because the suggested way is only available in API 24.
@ -422,7 +423,7 @@ public class AppDetailsRecyclerViewAdapter
StringBuilder sbWhatsNew = new StringBuilder(); StringBuilder sbWhatsNew = new StringBuilder();
sbWhatsNew.append(whatsNewView.getContext().getString(R.string.details_new_in_version, sbWhatsNew.append(whatsNewView.getContext().getString(R.string.details_new_in_version,
getSuggestedApk().versionName).toUpperCase(locale)); suggestedApk.versionName).toUpperCase(locale));
sbWhatsNew.append("\n\n"); sbWhatsNew.append("\n\n");
sbWhatsNew.append(app.whatsNew); sbWhatsNew.append(app.whatsNew);
whatsNewView.setText(sbWhatsNew); whatsNewView.setText(sbWhatsNew);