X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fde%2Fdhbwloe%2Fcampusapp%2FCampusAppContext.java;h=80db8ac27284c5f22b0b69c934f8ae7597c03de6;hb=c4e0d3507469d88f6cd210a8dacb23289daeeca3;hp=4f42cb5da519b54626630c39b06e345041269414;hpb=a0f644715b43af1e4acf2513b972c3f980efdaca;p=DHBWCampusApp.git diff --git a/app/src/main/java/de/dhbwloe/campusapp/CampusAppContext.java b/app/src/main/java/de/dhbwloe/campusapp/CampusAppContext.java index 4f42cb5..80db8ac 100644 --- a/app/src/main/java/de/dhbwloe/campusapp/CampusAppContext.java +++ b/app/src/main/java/de/dhbwloe/campusapp/CampusAppContext.java @@ -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 . + */ 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,9 @@ public class CampusAppContext { this.fragementType = type; } } - private final AppPage[] PAGES = { + + public static final String APPVERSION = "0.1.3 (beta)"; + 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 +74,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) @@ -72,15 +90,18 @@ public class CampusAppContext { private NavigationManager oNavigationManager; private DatabaseManager oDatabaseManager; private NfcCardListener oNfcCardListener; + private Bundle oContextVariables; public CampusAppContext(CampusApp mainActivity, int fragmentContainerId) { final CampusAppContext AppContext = this; instance = this; oMainActivity = mainActivity; + oContextVariables = new Bundle(); oNavigationManager = new NavigationManager(this, fragmentContainerId); 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); @@ -110,9 +131,11 @@ public class CampusAppContext { } public void setTitle(String title) { + // Ändern des Titels (Im App Header angezeigt) PopupFragment popup = oNavigationManager.getDialog(); if(popup != null) { - popup.getDialog().setTitle(title); + if(popup.getDialog() != null) + popup.getDialog().setTitle(title); } else { TextView titleView = (TextView)oMainActivity.findViewById(R.id.title); titleView.setText(title); @@ -124,6 +147,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"); @@ -144,11 +168,17 @@ public class CampusAppContext { } private void onNfcCardDataReceived(NfcCardData data) { + // NFC Daten erhalten Bundle bundle = new Bundle(); - bundle.putDouble("balance", data.getBalance() / 100.0); - bundle.putString("data", data.getCardData()); + double cardBalance = data.getBalance() / 100.0; + bundle.putDouble("balance", cardBalance); + bundle.putDouble("transaction", data.getLastTransaction() / 100.0); + + oContextVariables.putInt("nfcCardUniqueId", data.getUniqueId()); + 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); @@ -156,4 +186,19 @@ public class CampusAppContext { oNavigationManager.navigatePage("MensaCard", bundle); } + public Bundle getContextVariables() { + 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; + } + }