Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / VorlesungsplanUpcomingCourseListItem.java
1 /* VorlesungsplanUpcomingCourseListItem.java
2  *
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.
7  *
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.
12  *
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/>.
15  */
16 package de.dhbwloe.campusapp.fragments;
17 import android.content.Context;
18 import android.os.Bundle;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.widget.TextView;
22
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25
26 import de.dhbwloe.campusapp.CampusAppContext;
27 import de.dhbwloe.campusapp.R;
28 import de.dhbwloe.campusapp.vorlesungen.CourseEvent;
29 import de.dhbwloe.campusapp.vorlesungen.CourseGroup;
30
31 /**
32  * Created by pk910 on 20.02.2016.
33  */
34 public class VorlesungsplanUpcomingCourseListItem {
35     private CourseEvent event;
36
37     public VorlesungsplanUpcomingCourseListItem(CourseEvent event) {
38         this.event = event;
39     }
40
41     public void updateContainerView(View view) {
42
43         android.support.v7.widget.CardView cardView = (android.support.v7.widget.CardView) view.findViewById(R.id.card_upcomingday);
44         cardView.setOnClickListener(new View.OnClickListener() {
45             @Override
46             public void onClick(View v) {
47                 onEventClicked();
48             }
49         });
50
51         SimpleDateFormat dateFormat = new SimpleDateFormat(CampusAppContext.getInstance().getResString(R.string.timeformat_vorlesungsplan_time));
52         TextView timeFrom = (TextView) view.findViewById(R.id.timeFrom);
53         TextView timeTo = (TextView) view.findViewById(R.id.timeTo);
54         TextView location = (TextView) view.findViewById(R.id.location);
55         TextView courseTitle = (TextView) view.findViewById(R.id.courseTitle);
56
57         Date dateFrom = (new Date(event.getEventFrom() * 1000));
58         timeFrom.setText(dateFormat.format(dateFrom));
59
60         Date dateTo = (new Date(event.getEventTo() * 1000));
61         timeTo.setText(dateFormat.format(dateTo));
62
63         location.setText(event.getEventLocation());
64         courseTitle.setText(event.getEventTitle());
65     }
66
67     private void onEventClicked() {
68         Bundle args = new Bundle();
69         CourseGroup group = event.getCourseGroup();
70         if(group == null)
71             return;
72         args.putString("groupid", Integer.toString(group.getGroupId()));
73         CampusAppContext.getInstance().getNavigationManager().navigatePage("Vorlesungsplan", args);
74     }
75 }