import android.Manifest;
import android.app.Fragment;
+import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
setContentView(R.layout.main_layout);
- // Create fragment and give it an argument specifying the article it should show
+ // Retrieve Fragments and empty backstack
+
+ Fragment menuFragment = getFragmentManager().findFragmentByTag(NotuleMenuFragment.class.getSimpleName());
+ Fragment formFragment = getFragmentManager().findFragmentByTag(FormFragment.class.getSimpleName());
+ getFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+
+ // Restore Menu
+
+ if (menuFragment == null)
+ menuFragment = NotuleMenuFragment.newInstance();
- Fragment menuFragment = NotuleMenuFragment.newInstance();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
- transaction.replace(R.id.main_activity_main_fragment, menuFragment);
+ transaction.replace(R.id.main_activity_main_fragment, menuFragment, NotuleMenuFragment.class.getSimpleName());
transaction.commit();
+ // Restore MenuFramgent
+
+ if (formFragment != null)
+ replaceMainFragment(formFragment, FormFragment.class.getSimpleName());
+
//
ViewUtils.overrideOverviewIcon(this, R.mipmap.ic_overview);
// </editor-fold desc="LifeCycle">
+ // <editor-fold desc="Options menu">
+
@Override public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity, menu);
return super.onOptionsItemSelected(item);
}
- // <editor-fold desc="NotuleMenuFragmentListener">
+ // </editor-fold desc="Options menu">
- @Override public void onFormSelected(@NonNull Notule notule, @NonNull String collectivityId) {
-
- // Create fragment and give it an argument specifying the article it should show
- FormFragment newFragment = FormFragment.newInstance(notule, collectivityId);
+ private void replaceMainFragment(@NonNull Fragment fragment, @NonNull String fragmentTag) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out, android.R.animator.fade_in, android.R.animator.fade_out);
- // Replace whatever is in the fragment_container view with this fragment,
- // and add the transaction to the back stack so the user can navigate back
- transaction.replace(R.id.main_activity_main_fragment, newFragment);
+ transaction.replace(R.id.main_activity_main_fragment, fragment, fragmentTag);
transaction.addToBackStack(null);
- // Commit the transaction
transaction.commit();
}
+ // <editor-fold desc="NotuleMenuFragmentListener">
+
+ @Override public void onFormSelected(@NonNull Notule notule, @NonNull String collectivityId) {
+
+ FormFragment newFragment = FormFragment.newInstance(notule, collectivityId);
+ replaceMainFragment(newFragment, FormFragment.class.getSimpleName());
+ }
+
// </editor-fold desc="NotuleMenuFragmentListener">
}