partially solve retention of status on orientation change

This commit is contained in:
Felix 2017-09-20 19:45:25 +02:00
parent 65d47fe85a
commit d34c977abf
3 changed files with 23 additions and 13 deletions

View file

@ -32,27 +32,35 @@ public class BrowseActivity extends TouchBaseActivity implements
EventDetailsFragment.OnEventDetailsFragmentInteractionListener{
private static final String TAG = BrowseActivity.class.getSimpleName();
private static final String TAG_RETAINED_FRAGMENT = "retained_fragment";
CompositeDisposable mDisposables = new CompositeDisposable();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_container_layout);
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag(TAG_RETAINED_FRAGMENT);
if(fragment != null){
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.fragment_container,fragment,TAG_RETAINED_FRAGMENT);
ft.commit();
} else {
Disposable disposable = getApiServiceObservable()
.subscribe(mediaApiService -> {
mediaApiService.getConferences()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(conferencesWrapper -> {
ConferencesBrowseFragment browseFragment
= ConferencesBrowseFragment.newInstance(getNumColumns());
ConferencesTabBrowseFragment browseFragment
= ConferencesTabBrowseFragment.newInstance(getNumColumns());
browseFragment.setContent(conferencesWrapper);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.fragment_container,browseFragment);
ft.commit();
});
});
mDisposables.add(disposable);
getSupportActionBar().setLogo(R.drawable.icon_notext);
}
}
@Override

View file

@ -61,6 +61,7 @@ public class EventDetailsFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
postponeEnterTransition();
Transition transition = TransitionInflater.from(getContext())
.inflateTransition(android.R.transition.move);

View file

@ -58,6 +58,7 @@ public class EventsFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
if (getArguments() != null) {
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
mConference = getArguments().getParcelable(ARG_CONFERENCE);