WifiSettings überarbeitet, kleine fixes
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / mensaplan / MensaTagesplan.java
1 package de.dhbwloe.campusapp.mensaplan;
2
3 import java.text.DateFormat;
4 import java.text.DecimalFormat;
5 import java.text.ParseException;
6 import java.text.SimpleDateFormat;
7 import java.util.Date;
8 import java.util.Locale;
9 import java.util.zip.CRC32;
10
11 import de.dhbwloe.campusapp.CampusAppContext;
12 import de.dhbwloe.campusapp.R;
13
14 /**
15  * Created by pk910 on 22.01.2016.
16  */
17 public class MensaTagesplan {
18     private long iPlanDate;
19     private long iChkSum;
20     private String sMenuName, sName, sNameHtml, sAdditional, sNotes;
21     private int[] aPriceArray = new int[4];
22
23     private boolean bIsNew = false;
24
25     public MensaTagesplan(long plandate, String menuname, long chksum, String name, String namehtml, String additional, String notes, int price1, int price2, int price3, int price4) {
26         iPlanDate = plandate;
27         sMenuName = menuname;
28         iChkSum = chksum;
29         sName = name;
30         sNameHtml = namehtml;
31         sAdditional = (additional == null ? "" : additional);
32         sNotes = notes;
33         aPriceArray[0] = price1; // Student
34         aPriceArray[1] = price2; // Employees
35         aPriceArray[2] = price3; // Guest
36         aPriceArray[3] = price4; // School
37     }
38
39     public long calculateChkSum() {
40         CRC32 crc = new CRC32();
41         crc.update(sMenuName.getBytes());
42         if(sName != null)
43             crc.update(sName.getBytes());
44         if(sNameHtml != null)
45             crc.update(sNameHtml.getBytes());
46         if(sAdditional!= null)
47             crc.update(sAdditional.getBytes());
48         if(sNotes!= null)
49             crc.update(sNotes.getBytes());
50         crc.update(aPriceArray[0]);
51         crc.update(aPriceArray[1]);
52         crc.update(aPriceArray[2]);
53         crc.update(aPriceArray[3]);
54
55         long crcvalue = crc.getValue();
56         iChkSum = crcvalue;
57         return crcvalue;
58     }
59
60     public long getPlanDate() {
61         return iPlanDate;
62     }
63
64     public String getFormatedDate() {
65         DateFormat df = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
66         return df.format(new Date(iPlanDate * 1000));
67     }
68
69     public long getChkSum() {
70         return iChkSum;
71     }
72
73     public String getMenuName() {
74         return sMenuName;
75     }
76
77     public String getName() {
78         return sName;
79     }
80
81     public String getNameHtml() {
82         return sNameHtml;
83     }
84
85     public String getAdditional() {
86         return sAdditional;
87     }
88
89     public String getNotes() {
90         return sNotes;
91     }
92
93     public int[] getPlainPrice() {
94         return aPriceArray;
95     }
96
97     public double getStudentPrice() {
98         double price = (aPriceArray[0] / 100.0);
99         return price;
100     }
101
102     public double getEmployeePrice() {
103         double price = (aPriceArray[1] / 100.0);
104         return price;
105     }
106
107     public double getGuestPrice() {
108         double price = (aPriceArray[2] / 100.0);
109         return price;
110     }
111
112     public double getSchoolPrice() {
113         double price = (aPriceArray[3] / 100.0);
114         return price;
115     }
116
117     public String getFormatedRolePrice() {
118         String mensaRoleName = CampusAppContext.getInstance().getDatabaseManager().getRuntimeCache("MensaRole");
119         if (mensaRoleName == null || mensaRoleName.isEmpty())
120             mensaRoleName = "0";
121         int mensaRole = Integer.parseInt(mensaRoleName);
122         double price = (aPriceArray[mensaRole] / 100.0);
123
124         DecimalFormat df = new DecimalFormat(CampusAppContext.getInstance().getResString(R.string.mensaformat_price));
125         String formatedPrice = df.format(price);
126         return formatedPrice;
127     }
128
129     public void setIsNew() {
130         bIsNew = true;
131     }
132
133     public boolean getIsNew(boolean reset) {
134         boolean isnew = bIsNew;
135         if(reset)
136             bIsNew = false;
137         return isnew;
138     }
139
140 }