beta 0.1.5
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / CampusAppContext.java
index 89cbc7c8da971d2764d08f0afe515665d468c856..06751e80b83f9b62b623b5c56bcb5f2a8d0d0eb5 100644 (file)
@@ -1,3 +1,18 @@
+/* CampusAppContext.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 <http://www.gnu.org/licenses/>.
+ */
 package de.dhbwloe.campusapp;
 
 import android.app.Activity;
@@ -14,9 +29,9 @@ import de.dhbwloe.campusapp.fragments.FirstRun;
 import de.dhbwloe.campusapp.fragments.Impressum;
 import de.dhbwloe.campusapp.fragments.Mensa;
 import de.dhbwloe.campusapp.fragments.MensaCard;
-import de.dhbwloe.campusapp.fragments.MensaWochenplan;
 import de.dhbwloe.campusapp.fragments.News;
 import de.dhbwloe.campusapp.fragments.PopupFragment;
+import de.dhbwloe.campusapp.fragments.Settings;
 import de.dhbwloe.campusapp.fragments.SplashScreen;
 import de.dhbwloe.campusapp.fragments.Vorlesungsplan;
 import de.dhbwloe.campusapp.fragments.WebBrowser;
@@ -47,7 +62,49 @@ public class CampusAppContext {
             this.fragementType = type;
         }
     }
-    private final AppPage[] PAGES = {
+    public class NavigationItem {
+        int navItemId;
+        String navTarget;
+    };
+
+    public static final String APPVERSION = "0.1.5 (beta)";
+    public static final boolean DEBUG = true;
+    public final NavigationItem[] NAVIGATION_TARGETS = new NavigationItem[] {
+            new NavigationItem() {{
+                navItemId = R.id.nav_dashboard;
+                navTarget = "Dashboard";
+            }},
+            new NavigationItem() {{
+                navItemId = R.id.nav_vorlesungsplan;
+                navTarget = "Vorlesungsplan";
+            }},
+            new NavigationItem() {{
+                navItemId = R.id.nav_mensa;
+                navTarget = "Mensa";
+            }},
+            new NavigationItem() {{
+                navItemId = R.id.nav_mensa;
+                navTarget = "Mensa";
+            }},
+            new NavigationItem() {{
+                navItemId = R.id.nav_news;
+                navTarget = "News";
+            }},
+            new NavigationItem() {{
+                navItemId = R.id.nav_settings;
+                navTarget = "Settings";
+            }},
+            new NavigationItem() {{
+                navItemId = R.id.nav_wifi;
+                navTarget = "WifiSettings";
+            }},
+            new NavigationItem() {{
+                navItemId = R.id.nav_impressum;
+                navTarget = "Impressum";
+            }},
+
+    };
+    private final AppPage[] PAGES = { // Hier müssen alle Fragmente, die auf der Activity angezeigt werden sollen eingetragen werden.
             new AppPage("SplashScreen", SplashScreen.class),
             new AppPage("Dashboard", Dashboard.class),
             new AppPage("AppSearch", AppSearch.class),
@@ -57,6 +114,7 @@ public class CampusAppContext {
             new AppPage("News", News.class),
             new AppPage("WifiSettings", WifiSettings.class),
             new AppPage("FirstRun", FirstRun.class),
+            new AppPage("Settings", Settings.class),
             new AppPage("Impressum", Impressum.class),
             new AppPage("WebBrowser", WebBrowser.class),
             new AppPage("WebBrowserPopup", WebBrowser.class, 3)
@@ -64,7 +122,6 @@ public class CampusAppContext {
 
     private static CampusAppContext instance;
     public static CampusAppContext getInstance() {
-        Log.i("AppContext", "Request new context instance");
         return instance;
     }
 
@@ -73,16 +130,19 @@ public class CampusAppContext {
     private DatabaseManager oDatabaseManager;
     private NfcCardListener oNfcCardListener;
     private Bundle oContextVariables;
+    private CampusAppCrashHandler oExceptionHandler;
 
-    public CampusAppContext(CampusApp mainActivity, int fragmentContainerId) {
+    public CampusAppContext(CampusApp mainActivity, int fragmentContainerId, int navigationViewId) {
         final CampusAppContext AppContext = this;
         instance = this;
+
         oMainActivity = mainActivity;
         oContextVariables = new Bundle();
-        oNavigationManager = new NavigationManager(this, fragmentContainerId);
+        oNavigationManager = new NavigationManager(this, fragmentContainerId, navigationViewId);
         oDatabaseManager = new DatabaseManager(this);
         oNfcCardListener = new NfcCardListener(this);
 
+        // Alle Fragmente "registrieren"
         for(int i = 0; i < PAGES.length; i++)
             oNavigationManager.registerPage(PAGES[i].name, PAGES[i].fragment, PAGES[i].fragementType);
 
@@ -112,6 +172,7 @@ public class CampusAppContext {
     }
 
     public void setTitle(String title) {
+        // Ändern des Titels (Im App Header angezeigt)
         PopupFragment popup = oNavigationManager.getDialog();
         if(popup != null) {
             if(popup.getDialog() != null)
@@ -127,6 +188,7 @@ public class CampusAppContext {
     }
 
     public void addDefaultSearchIndexes() {
+        // Alle Search Indices der eigetragenen Seiten beziehen und in der Datenbank speichern
         for(int i = 0; i < PAGES.length; i++) {
             try {
                 Method m = PAGES[i].fragment.getMethod("GetSearchIndices");
@@ -147,6 +209,7 @@ public class CampusAppContext {
     }
 
     private void onNfcCardDataReceived(NfcCardData data) {
+        // NFC Daten erhalten
         Bundle bundle = new Bundle();
         double cardBalance = data.getBalance() / 100.0;
         bundle.putDouble("balance", cardBalance);
@@ -156,6 +219,7 @@ public class CampusAppContext {
         oContextVariables.putDouble("nfcCardBalance", cardBalance);
 
         String pagename = oNavigationManager.getCurrentPageName();
+        // Update angezeigtes Guthaben lediglich, wenn das Fragment bereits angezeigt wird
         if(pagename != null && pagename.equalsIgnoreCase("MensaCard")) {
             MensaCard fragment = (MensaCard) oNavigationManager.getCurrentFragment();
             fragment.showNfcCardData(bundle);
@@ -167,4 +231,15 @@ public class CampusAppContext {
         return oContextVariables;
     }
 
+    public String getResString(int id, Object... arguments) {
+        // printf like resource strings
+        String format = getResString(id);
+        String res = String.format(format, arguments);
+        return res;
+    }
+    public String getResString(int id) {
+        String str = oMainActivity.getResources().getString(id);
+        return str;
+    }
+
 }