I'm skeptical about this code.  First, I don't know why you need an if here.  Is that just because you're trying to maintain compatibility with the video app?  But more importantly, I don't see any code for setting firstThumbnailPosition or for updating the data set index when firstThumbnailPosition changes.

I know that you need a way to determine which photo to show when the user taps on a thumbnail. But maybe with this new organization, trying to always maintain a numbering scheme is not the way to go. Every photo has a unique filename, so maybe you could use the filename as the dataset value.  Gallery still needs to maintain the order of the thumbnails for the swipe left and swipe right, of course, but maybe it doesn't have to involve code like this.