Quran_android: remember scroll position on orientation change in translation

Created on 8 Jul 2016  路  9Comments  路  Source: quran/quran_android

if you scroll in portrait mode to an ayah and switch to landscape, it returns to the top. we should at least return to the top of the ayah that was last being read.

PRs Welcome

All 9 comments

this is much easier to do now that we're using RecyclerView - marking this as up for grabs, @hakimrie, feel free if you get a chance.

@ahmedre The fragment TranslationFragment creation (onCreateView) is triggered 3 times due to page number calculation, which mean that onViewStateRestoredis called 3 times, at the first time the position is valid but the second and the third it isn't (and the value is equal to 0).
Did I need to ignore the second and third call to onViewStateRestored by checking if the position is equal to 0 ? Because in my opinion there isn't an other way.

TranslationFragment creation (onCreateView) is triggered 3 times

Uh huh! Don't you think that that's the problem? Is there a way to _fix_ it and trigger onCreateView only once?

ViewPager generates no less than 3 pages - the current page, the page before, and the page after. so these "extra 2" are for the left and right page. there's no way to decrease this (nor do we want to, because otherwise, switching pages would be very slow, because you'd have to generate the page only once dragging started).

@selmanon you'd want to compare the page number to the page number known by PagerActivity.

@ahmedre my bad .. got it .. I believed that it's due to some calculation stuff to get the exact page index.

@ahmedre just to share the behavior that actually I found, RV normally persist the state of the position without any additional coding (Ref : https://github.com/googlesamples/android-RecyclerView) the ref code example of RV did use additional code to persist the position state but I deleted them and it still persist the RV scroll position.

Actually, the TranslationView use a custom view TranslationView with a RV as field member and with this design android do not play well.

@ahmedre I think we can close this issue now.

jazakAllah khairan @Ahmed9914

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmedre picture ahmedre  路  4Comments

Eng-Fouad picture Eng-Fouad  路  9Comments

MahmoudMabrok picture MahmoudMabrok  路  6Comments

mgalaleldin picture mgalaleldin  路  3Comments

ibnharoon picture ibnharoon  路  7Comments