Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / mensaplan / MensaTagesplan.java
index 79c33e4627b06889c58a47557e53728cdba924d6..c3a1be47022f5b9c4d37017542ebded5aa4b77dc 100644 (file)
@@ -1,12 +1,30 @@
+/* MensaTagesplan.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.mensaplan;
-
 import java.text.DateFormat;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Locale;
 import java.util.zip.CRC32;
 
+import de.dhbwloe.campusapp.CampusAppContext;
+import de.dhbwloe.campusapp.R;
+
 /**
  * Created by pk910 on 22.01.2016.
  */
@@ -35,8 +53,10 @@ public class MensaTagesplan {
     public long calculateChkSum() {
         CRC32 crc = new CRC32();
         crc.update(sMenuName.getBytes());
-        crc.update(sName.getBytes());
-        crc.update(sNameHtml.getBytes());
+        if(sName != null)
+            crc.update(sName.getBytes());
+        if(sNameHtml != null)
+            crc.update(sNameHtml.getBytes());
         if(sAdditional!= null)
             crc.update(sAdditional.getBytes());
         if(sNotes!= null)
@@ -108,6 +128,18 @@ public class MensaTagesplan {
         return price;
     }
 
+    public String getFormatedRolePrice() {
+        String mensaRoleName = CampusAppContext.getInstance().getDatabaseManager().getRuntimeCache("MensaRole");
+        if (mensaRoleName == null || mensaRoleName.isEmpty())
+            mensaRoleName = "0";
+        int mensaRole = Integer.parseInt(mensaRoleName);
+        double price = (aPriceArray[mensaRole] / 100.0);
+
+        DecimalFormat df = new DecimalFormat(CampusAppContext.getInstance().getResString(R.string.mensaformat_price));
+        String formatedPrice = df.format(price);
+        return formatedPrice;
+    }
+
     public void setIsNew() {
         bIsNew = true;
     }