3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.fragments;
17 import android.os.Bundle;
18 import android.support.v4.app.Fragment;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.widget.LinearLayout;
23 import android.widget.RelativeLayout;
24 import android.widget.TextView;
26 import java.text.SimpleDateFormat;
27 import java.util.Calendar;
28 import java.util.Date;
30 import de.dhbwloe.campusapp.CampusAppContext;
31 import de.dhbwloe.campusapp.CampusAppFragment;
32 import de.dhbwloe.campusapp.R;
33 import de.dhbwloe.campusapp.Tools;
34 import de.dhbwloe.campusapp.mensaplan.MensaTagesplan;
37 * A simple {@link Fragment} subclass.
39 public class DashboardMensa extends CampusAppFragment {
42 public DashboardMensa() {
43 // Required empty public constructor
48 public View onCreateView(LayoutInflater inflater, ViewGroup container,
49 Bundle savedInstanceState) {
50 view = inflater.inflate(R.layout.fragment_dashboard_mensa, container, false);
53 LinearLayout linearcontainer = (LinearLayout)view.findViewById(R.id.menuList);
54 linearcontainer.setOnClickListener(new View.OnClickListener() {
56 public void onClick(View v) {
57 AppContext.getNavigationManager().navigatePage("Mensa");
64 private void refreshMensaMenue() {
65 if(AppContext == null)
66 AppContext = CampusAppContext.getInstance();
67 Calendar cal = Calendar.getInstance();
68 cal.setTime(new Date());
69 cal.set(Calendar.HOUR_OF_DAY, 0);
70 cal.set(Calendar.MINUTE, 0);
71 cal.set(Calendar.SECOND, 0);
72 cal.set(Calendar.MILLISECOND, 0);
73 long now = (new Date()).getTime() / 1000;
74 long mensaCloseTime = (3600 * 13); // 13 uhr
75 long timeFrom = cal.getTime().getTime() / 1000;
76 if(now > timeFrom + mensaCloseTime)
78 long timeTo = timeFrom + (86400 * 3) + 86399; // +3days for weekend
80 MensaTagesplan[] dayplans = AppContext.getDatabaseManager().getMensaTagesplan(timeFrom, timeTo);
81 if(dayplans.length == 0) {
85 MensaTagesplan dayplan = dayplans[0];
86 TextView dateTextView = (TextView) view.findViewById(R.id.menuDate);
87 dateTextView.setText(getDateText(dayplan.getPlanDate(), now));
89 LinearLayout menueContainer = (LinearLayout) view.findViewById(R.id.menuList);
90 menueContainer.removeAllViews();
92 MensaTagesplan cmenue = dayplan;
94 LayoutInflater li = LayoutInflater.from(AppContext.getMainActivity());
96 String menuTitle = cmenue.getMenuName();
97 if(menuTitle == null || menuTitle.matches("^Buffet"))
100 LinearLayout menu = (LinearLayout) li.inflate(R.layout.fragment_dashboard_mensa_menu, null, false);
101 menueContainer.addView(menu);
103 TextView menuName = (TextView) menu.findViewById(R.id.menuName);
104 TextView menuPrice = (TextView) menu.findViewById(R.id.menuPrice);
106 menuName.setText(cmenue.getName());
107 String priceStr = cmenue.getFormatedRolePrice();
108 menuPrice.setText(priceStr);
109 } while(i < dayplans.length && (cmenue = dayplans[++i]) != null && cmenue.getPlanDate() == dayplan.getPlanDate());
112 private String getDateText(long date, long now) {
115 datetext = AppContext.getResString(R.string.dashboard_calendar_today);
116 else if(now < date + (86400*2))
117 datetext = AppContext.getResString(R.string.dashboard_calendar_tomorrow);
119 Date dateObj = new Date(date * 1000);
120 String dayStr = Tools.getWeekdayString(dateObj);
121 SimpleDateFormat dateFormat = new SimpleDateFormat(AppContext.getResString(R.string.timeformat_dashboard_mensa));
123 datetext = dayStr + ", " + dateFormat.format(dateObj);