Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media details lost on device rotation #894

Closed
psh opened this issue Sep 30, 2017 · 4 comments
Closed

Media details lost on device rotation #894

psh opened this issue Sep 30, 2017 · 4 comments

Comments

@psh
Copy link
Collaborator

psh commented Sep 30, 2017

I happened to be testing the app on a tablet (real hardware) and rotated the screen. I then verified and it also occurs on a phone (emulator) -

media-details-landscape

config-change-bug

This is a bug that is present on current master but not present in the released version in the Google Play Store.

@psh
Copy link
Collaborator Author

psh commented Sep 30, 2017

Looking into things a little more: each of the media pager adapter fragments reach back to the ContributionsActivity for data. After rotation, the adapter in contributionsList is null.

@Override
public Media getMediaAtPosition(int i) {
    if (contributionsList.getAdapter() == null) {
        // not yet ready to return data
        return null;
    } else {
        return Contribution.fromCursor((Cursor) contributionsList.getAdapter().getItem(i));
    }
}

The problem isn't so much that the adapter is null, it's that we are relying on the adapter to be our source of truth. Android configuration change will drop and recreate the GUI and steps need to be taken to hold data in a location that will persist across configuration changes. Since we have data that is shared between the ContributionsActivity and multiple MediaDetailFragment instances, there probably should be some kind of external view model that they share.

Google haven't yet released their "architecture components" but they are close - the release notes on 9/21 say

We are not planning any more API changes. Unplanned changes might happen, but the bar for changing any API before 1.0.0 stable is very high and unlikely to happen

so it might still be early days to adopt them directly, but they do have an excellent write up of the problem of configuration change, and what the role of a view model should be - https://developer.android.com/topic/libraries/architecture/viewmodel.html

Also, it doesn't inspire me with confidence when a comment in the MediaDetailPagerFragment says,

if (savedInstanceState != null) {
    final int pageNumber = savedInstanceState.getInt("current-page");
    // Adapter doesn't seem to be loading immediately.
    // Dear God, please forgive us for our sins
    view.postDelayed(() -> {
        ...
    }, 100);
} else {
    ...
}

@JohnKal
Copy link
Contributor

JohnKal commented Nov 8, 2017

I am working to fix this issue.

@misaochan
Copy link
Member

@JohnKal great, thanks! :)

@neslihanturan
Copy link
Collaborator

This bug seems solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants