Mutable FragmentStatePagerAdapter or how to reorder pages in ViewPager or tabs

For our latest iteration of Guidants Mobile we wanted a carousel-like view of information panels. The user can reorder these, add new ones or delete the ones he doesn’t like. To this end I used ViewPager together with FragmentStatePagerAdapter and Fragments.

The problem here is that FragmentStatePagerAdapter restores its exact state when the ViewPager is restored, so that the original ordering of the Fragments is restored. There is a discussion of the cause and possible workarounds at this  Android issue. I took the code posted there, ported it to the latest version of the support library code and published it as a Gist.