Skip to content

Commit

Permalink
Potential fix for app crashes due to IndexOutOfBoundsException
Browse files Browse the repository at this point in the history
Signed-off-by: sunilpaulmathew <[email protected]>
  • Loading branch information
sunilpaulmathew committed Dec 7, 2023
1 parent 13ad76a commit 3c3f73e
Showing 1 changed file with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,50 @@ public PackageTasksAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int v
@SuppressLint({"StringFormatInvalid", "StringFormatMatches"})
@Override
public void onBindViewHolder(@NonNull PackageTasksAdapter.ViewHolder holder, int position) {
if (!sPackageUtils.isPackageInstalled(data.get(position).getPackageName(), holder.appID.getContext())) {
return;
}
holder.appIcon.setImageDrawable(data.get(position).getIcon());
if (Common.getSearchText() != null && Common.isTextMatched(data.get(position).getPackageName())) {
holder.appID.setTypeface(null, Typeface.BOLD);
holder.appID.setText(Utils.fromHtml(data.get(position).getPackageName().replace(Common.getSearchText(),"<b><i><font color=\"" +
Color.RED + "\">" + Common.getSearchText() + "</font></i></b>")));
} else {
holder.appID.setText(data.get(position).getPackageName());
}
if (Common.getSearchText() != null && Common.isTextMatched(data.get(position).getAppName())) {
holder.appName.setTypeface(null, Typeface.BOLD);
}
holder.appName.setText(data.get(position).getAppName());
holder.appIcon.setOnClickListener(v -> {
if (!sPackageUtils.isPackageInstalled(data.get(position).getPackageName(), v.getContext())) {
sCommonUtils.snackBar(v, v.getContext().getString(R.string.package_removed)).show();
try {
if (!sPackageUtils.isPackageInstalled(data.get(position).getPackageName(), holder.appID.getContext())) {
return;
}
Common.setApplicationName(data.get(position).getAppName());
Common.setApplicationIcon(data.get(position).getIcon());
Intent imageView = new Intent(holder.appIcon.getContext(), ImageViewActivity.class);
holder.appIcon.getContext().startActivity(imageView);
});
holder.checkBox.setChecked(Common.getBatchList().contains(data.get(position).getPackageName()));
holder.checkBox.setOnClickListener(v -> {
if (!sPackageUtils.isPackageInstalled(data.get(position).getPackageName(), v.getContext())) {
sCommonUtils.snackBar(v, v.getContext().getString(R.string.package_removed)).show();
holder.checkBox.setChecked(false);
return;
}
if (Common.getBatchList().contains(data.get(position).getPackageName())) {
Common.getBatchList().remove(data.get(position).getPackageName());
sCommonUtils.snackBar(v, v.getContext().getString(R.string.batch_list_removed, data.get(position).getAppName())).show();
holder.appIcon.setImageDrawable(data.get(position).getIcon());
if (Common.getSearchText() != null && Common.isTextMatched(data.get(position).getPackageName())) {
holder.appID.setTypeface(null, Typeface.BOLD);
holder.appID.setText(Utils.fromHtml(data.get(position).getPackageName().replace(Common.getSearchText(), "<b><i><font color=\"" +
Color.RED + "\">" + Common.getSearchText() + "</font></i></b>")));
} else {
Common.getBatchList().add(data.get(position).getPackageName());
sCommonUtils.snackBar(v, v.getContext().getString(R.string.batch_list_added, data.get(position).getAppName())).show();
holder.appID.setText(data.get(position).getPackageName());
}
if (Common.getSearchText() != null && Common.isTextMatched(data.get(position).getAppName())) {
holder.appName.setTypeface(null, Typeface.BOLD);
}
Common.getBatchOptionsCard().setVisibility(Common.getBatchList().size() > 0 ? View.VISIBLE : View.GONE);
Common.getBatchOptionTitle().setText(v.getContext().getString(R.string.batch_options, Common.getBatchList().size()));
});
holder.appName.setText(data.get(position).getAppName());
holder.appIcon.setOnClickListener(v -> {
if (!sPackageUtils.isPackageInstalled(data.get(position).getPackageName(), v.getContext())) {
sCommonUtils.snackBar(v, v.getContext().getString(R.string.package_removed)).show();
return;
}
Common.setApplicationName(data.get(position).getAppName());
Common.setApplicationIcon(data.get(position).getIcon());
Intent imageView = new Intent(holder.appIcon.getContext(), ImageViewActivity.class);
holder.appIcon.getContext().startActivity(imageView);
});
holder.checkBox.setChecked(Common.getBatchList().contains(data.get(position).getPackageName()));
holder.checkBox.setOnClickListener(v -> {
if (!sPackageUtils.isPackageInstalled(data.get(position).getPackageName(), v.getContext())) {
sCommonUtils.snackBar(v, v.getContext().getString(R.string.package_removed)).show();
holder.checkBox.setChecked(false);
return;
}
if (Common.getBatchList().contains(data.get(position).getPackageName())) {
Common.getBatchList().remove(data.get(position).getPackageName());
sCommonUtils.snackBar(v, v.getContext().getString(R.string.batch_list_removed, data.get(position).getAppName())).show();
} else {
Common.getBatchList().add(data.get(position).getPackageName());
sCommonUtils.snackBar(v, v.getContext().getString(R.string.batch_list_added, data.get(position).getAppName())).show();
}
Common.getBatchOptionsCard().setVisibility(Common.getBatchList().size() > 0 ? View.VISIBLE : View.GONE);
Common.getBatchOptionTitle().setText(v.getContext().getString(R.string.batch_options, Common.getBatchList().size()));
});
} catch (IndexOutOfBoundsException ignored) {}
}

@Override
Expand Down

0 comments on commit 3c3f73e

Please sign in to comment.