Merge pull request #1753 from mfietz/issue/simpleanimator_npe

Fix RecyclerView reorder crash
This commit is contained in:
Tom Hennen 2016-03-10 16:35:11 -05:00
commit cac5667744
5 changed files with 11 additions and 2 deletions

View File

@ -202,7 +202,8 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
@Override
public long getItemId(int position) {
return position;
FeedItem item = itemAccess.getItem(position);
return item != null ? item.getId() : RecyclerView.NO_POSITION;
}
@Override

View File

@ -109,6 +109,12 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap
return selectedItem;
}
@Override
public long getItemId(int position) {
FeedItem item = itemAccess.getItem(position);
return item != null ? item.getId() : RecyclerView.NO_POSITION;
}
public int getItemCount() {
return itemAccess.getCount();
}

View File

@ -337,6 +337,7 @@ public class AllEpisodesFragment extends Fragment {
MainActivity mainActivity = activity.get();
listAdapter = new AllEpisodesRecycleAdapter(mainActivity, itemAccess,
new DefaultActionButtonCallback(mainActivity), showOnlyNewEpisodes());
listAdapter.setHasStableIds(true);
recyclerView.setAdapter(listAdapter);
}
listAdapter.notifyDataSetChanged();

View File

@ -474,6 +474,7 @@ public class QueueFragment extends Fragment {
MainActivity activity = (MainActivity) getActivity();
recyclerAdapter = new QueueRecyclerAdapter(activity, itemAccess,
new DefaultActionButtonCallback(activity), itemTouchHelper);
recyclerAdapter.setHasStableIds(true);
recyclerView.setAdapter(recyclerAdapter);
}
if(queue == null || queue.size() == 0) {

View File

@ -23,7 +23,7 @@
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/divider"
android:scrollbars="vertical"/>