Removed need for upcast by parameterising mIntents over ResolveInfo instead of Object

Allows the type checking to be done by the compiler rather than the developer.
It was possible here because there is only two types of view, and the first type
will only have one or zero entries in the adapter. Thus, I've swapped the usage
of a `String` type for a `null` and checked for null instead of `instanceof String`.
This commit is contained in:
Peter Serwylo 2016-12-01 09:39:44 +11:00
parent 0b09d591ea
commit 003b9459da

View File

@ -134,13 +134,13 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
}
mRecyclerView.setAdapter(new RecyclerView.Adapter<VH>() {
private ArrayList<Object> mIntents;
private ArrayList<ResolveInfo> mIntents;
RecyclerView.Adapter init(List<ResolveInfo> targetedShareIntents) {
mIntents = new ArrayList<>();
if (mShowNearby) {
mIntents.add("Nearby (string contents do not matter!)");
}
if (mShowNearby) {
mIntents.add(null);
}
for (ResolveInfo ri : targetedShareIntents) {
mIntents.add(ri);
}
@ -149,7 +149,7 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
@Override
public int getItemViewType(int position) {
if (mIntents.get(position) instanceof String)
if (mIntents.get(position) == null)
return VIEWTYPE_SWAP;
return VIEWTYPE_INTENT;
}
@ -174,7 +174,7 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
});
return;
}
final ResolveInfo ri = (ResolveInfo) mIntents.get(position);
final ResolveInfo ri = mIntents.get(position);
holder.icon.setImageDrawable(ri.loadIcon(getContext().getPackageManager()));
holder.label.setText(ri.loadLabel(getContext().getPackageManager()));
holder.itemView.setOnClickListener(new View.OnClickListener() {