Created
May 9, 2016 20:52
-
-
Save nbarishok/eaf0657c618d41e6fbfc81e0f23f8c87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MovieStaticListFragment extends Fragment { | |
MovieViewModel viewModel; | |
CompositeSubscription subscriptions; | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
if (savedInstanceState != null) { | |
viewModel = savedInstanceState.getParcelable(VIEW_MODEL); | |
} | |
} | |
@Override | |
public void onViewCreated() { | |
if (viewModel != null) { | |
udpateUi(viewModel); | |
} else { | |
Subscription subscription = api.getMovieList().subscribe(movieList -> { | |
viewModel = MovieMapper.map(movieList); | |
updateUi(viewModel); | |
}, throwable -> { | |
viewModel = null; | |
}); | |
subscriptions.add(subscription); | |
} | |
} | |
@Override | |
public void onSaveInstanceState(Bundle outState) { | |
outState.putParcelable(VIEW_MODEL, viewModel); | |
} | |
@Override | |
public void onDestroy() { | |
if (!subscriptions.isUnsubscribed()) { | |
subscriptions.clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment