swipe to dismiss: animate item undo

This commit is contained in:
Andrew Dolgov 2017-06-02 00:02:58 +03:00
parent 7d59182a9b
commit b5398ea340

View File

@ -368,7 +368,8 @@ public class HeadlinesFragment extends Fragment {
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
final int position = viewHolder.getAdapterPosition() - m_adapter.getHeaderCount();
final int adapterPosition = viewHolder.getAdapterPosition();
final int position = adapterPosition - m_adapter.getHeaderCount();
try {
final Article article = getArticleAtPosition(position);
@ -398,7 +399,8 @@ public class HeadlinesFragment extends Fragment {
}
m_articles.add(position, article);
m_adapter.notifyDataSetChanged();
m_adapter.notifyItemInserted(adapterPosition);
m_adapter.notifyItemRangeChanged(adapterPosition, 1);
}
}).show();