X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fde%2Fdhbwloe%2Fcampusapp%2FNavigationManager.java;h=073bf190bab359bda77f0c1fd2c33ed42840e275;hb=424a4c7c41d015392a4984ef0eab35de507da39c;hp=daa84eabf49d4cf158f53ededd30729b99ccae77;hpb=89252e3c22caf6dcccd0c50ad3a9282a53b5a890;p=DHBWCampusApp.git
diff --git a/app/src/main/java/de/dhbwloe/campusapp/NavigationManager.java b/app/src/main/java/de/dhbwloe/campusapp/NavigationManager.java
index daa84ea..073bf19 100644
--- a/app/src/main/java/de/dhbwloe/campusapp/NavigationManager.java
+++ b/app/src/main/java/de/dhbwloe/campusapp/NavigationManager.java
@@ -1,6 +1,22 @@
+/* NavigationManager.java
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package de.dhbwloe.campusapp;
import android.os.Bundle;
+import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
@@ -27,16 +43,26 @@ public class NavigationManager {
};
private CampusAppContext AppContext;
+
+ // Derzeitig angezeigtes Fragment
private NavPage oCurrentPage;
- private NavPage oParentPage;
private Fragment oCurrentFragment;
+
+ // Hintergrund Fragment (bei Popups)
+ private NavPage oParentPage;
private Fragment oParentFragment;
+
+ // Container ID
private int iFragmentContainerId;
+ private int iNavigationViewId;
+
+ // Alle registrierte Fragmente mit Name
private ArrayList lNavigationPages = new ArrayList();
- public NavigationManager(CampusAppContext context, int fragmentContainer) {
+ public NavigationManager(CampusAppContext context, int fragmentContainer, int navigationView) {
AppContext = context;
iFragmentContainerId = fragmentContainer;
+ iNavigationViewId = navigationView;
oCurrentPage = null;
}
@@ -79,12 +105,13 @@ public class NavigationManager {
}
public void navigatePage(String name, Bundle args, boolean history) {
-
+ // Suche Fragment
NavPage page = getPageByName(name);
if(page == null)
return;
Fragment fragment;
+ // Wenn das Fragment als Popup angeziegt werden soll, muss zunächst das Popup Fragment geladen werden.
if(page.fragmentType == 3) {
PopupFragment popupFragment = new PopupFragment();
if(args == null)
@@ -122,12 +149,14 @@ public class NavigationManager {
}
transaction.add(iFragmentContainerId, fragment);
}
- if (history)
+ if (history) // Hinzufügen zur App History (Zurück Button)
transaction.addToBackStack(null);
oCurrentPage = page;
oCurrentFragment = fragment;
+ updateNavigationHighlight();
+
transaction.commit();
}
@@ -174,6 +203,7 @@ public class NavigationManager {
}
public boolean closeDialog() {
+ // Popup schlieÃen
if(oCurrentPage != null && oCurrentPage.fragmentType == 3) {
PopupFragment fragment = (PopupFragment) oCurrentFragment;
boolean wasAdded = false;
@@ -200,4 +230,22 @@ public class NavigationManager {
return closeDialog();
}
+ private void updateNavigationHighlight() {
+ NavigationView navigationView = (NavigationView) AppContext.getMainActivity().findViewById(iNavigationViewId);
+
+ if(oCurrentPage == null)
+ return;
+
+ int activeItemId = 0;
+ for(CampusAppContext.NavigationItem navitem : AppContext.NAVIGATION_TARGETS) {
+ if(oCurrentPage.name.equalsIgnoreCase(navitem.navTarget)) {
+ activeItemId = navitem.navItemId;
+ }
+ }
+ if(activeItemId == 0)
+ return;
+
+ navigationView.setCheckedItem(activeItemId);
+ }
+
}