Prevent null pointer exceptions

The main activity connects to the service after setting up the local
broadcast. This allows the service to send notification before the
activity is ready, causing null pointer exceptions. This happens for
example rotating the screen while an update is being installed.

Also, replace the existing check on mUpdaterController with a check
on mDownloadsId since the latter depends on the former and both are
required.

Change-Id: I620fd7aa1e90468ab40dfedaa06c23f96f3e6807
This commit is contained in:
Gabriele M
2018-05-16 17:44:21 +02:00
parent 4f7db45fa6
commit 8b300f0d05

View File

@@ -204,7 +204,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
@Override
public void onBindViewHolder(final ViewHolder viewHolder, int i) {
if (mUpdaterController == null) {
if (mDownloadIds == null) {
viewHolder.mAction.setEnabled(false);
return;
}
@@ -260,10 +260,16 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
}
public void notifyItemChanged(String downloadId) {
if (mDownloadIds == null) {
return;
}
notifyItemChanged(mDownloadIds.indexOf(downloadId));
}
public void removeItem(String downloadId) {
if (mDownloadIds == null) {
return;
}
int position = mDownloadIds.indexOf(downloadId);
mDownloadIds.remove(downloadId);
notifyItemRemoved(position);