Fix crashes on rotation by checking for `null`

This commit is contained in:
Stypox 2020-04-26 21:41:09 +02:00
parent b0c0249ce6
commit d8d9c7e171
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 7 additions and 8 deletions

View File

@ -131,16 +131,15 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
}
private int getFocusedPosition() {
View focusedItem = itemsList.getFocusedChild();
if (focusedItem != null) {
RecyclerView.ViewHolder itemHolder = itemsList.findContainingViewHolder(focusedItem);
if (itemHolder != null) {
try {
final View focusedItem = itemsList.getFocusedChild();
final RecyclerView.ViewHolder itemHolder =
itemsList.findContainingViewHolder(focusedItem);
return itemHolder.getAdapterPosition();
}
}
} catch (NullPointerException e) {
return -1;
}
}
@Override
public void writeTo(final Queue<Object> objectsToSave) {