some fixes
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / NavigationManager.java
index 33d2f1c541938de315e4281b30e7bb31fb07e013..1330940689b5f8bb3efcfdf4821e1f8a7ff18b15 100644 (file)
@@ -50,6 +50,13 @@ public class NavigationManager {
     public String getCurrentPageName() {
         if(oCurrentPage == null)
             return null;
+        if(oCurrentPage.fragmentType == 3 && oParentFragment != null){
+            if(oCurrentFragment.isAdded())
+                return oCurrentPage.name;
+            else {
+                closeDialog();
+            }
+        }
         return oCurrentPage.name;
     }
 
@@ -160,18 +167,22 @@ public class NavigationManager {
     public boolean closeDialog() {
         if(oCurrentPage != null && oCurrentPage.fragmentType == 3) {
             PopupFragment fragment = (PopupFragment) oCurrentFragment;
-            fragment.destroyView();
+            boolean wasAdded = false;
+            if(oCurrentFragment.isAdded()) {
+                fragment.destroyView();
 
-            FragmentActivity fragmentActivity = (FragmentActivity) AppContext.getMainActivity();
-            FragmentTransaction transaction = fragmentActivity.getSupportFragmentManager().beginTransaction();
+                FragmentActivity fragmentActivity = (FragmentActivity) AppContext.getMainActivity();
+                FragmentTransaction transaction = fragmentActivity.getSupportFragmentManager().beginTransaction();
 
-            transaction.remove(oCurrentFragment);
+                transaction.remove(oCurrentFragment);
+                transaction.commit();
+                wasAdded = true;
+            }
 
             oCurrentPage = oParentPage;
             oCurrentFragment = oParentFragment;
 
-            transaction.commit();
-            return true;
+            return wasAdded;
         }
         return false;
     }