beta 0.1.1
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / VorlesungsplanUpcomingCourseListItem.java
1 package de.dhbwloe.campusapp.fragments;
2
3 import android.content.Context;
4 import android.os.Bundle;
5 import android.view.LayoutInflater;
6 import android.view.View;
7 import android.widget.TextView;
8
9 import java.text.SimpleDateFormat;
10 import java.util.Date;
11
12 import de.dhbwloe.campusapp.CampusAppContext;
13 import de.dhbwloe.campusapp.R;
14 import de.dhbwloe.campusapp.vorlesungen.CourseEvent;
15 import de.dhbwloe.campusapp.vorlesungen.CourseGroup;
16
17 /**
18  * Created by pk910 on 20.02.2016.
19  */
20 public class VorlesungsplanUpcomingCourseListItem {
21     private CourseEvent event;
22
23     public VorlesungsplanUpcomingCourseListItem(CourseEvent event) {
24         this.event = event;
25     }
26
27     public void updateContainerView(View view) {
28
29         android.support.v7.widget.CardView cardView = (android.support.v7.widget.CardView) view.findViewById(R.id.card_upcomingday);
30         cardView.setOnClickListener(new View.OnClickListener() {
31             @Override
32             public void onClick(View v) {
33                 onEventClicked();
34             }
35         });
36
37         SimpleDateFormat dateFormat = new SimpleDateFormat(CampusAppContext.getInstance().getResString(R.string.timeformat_vorlesungsplan_time));
38         TextView timeFrom = (TextView) view.findViewById(R.id.timeFrom);
39         TextView timeTo = (TextView) view.findViewById(R.id.timeTo);
40         TextView location = (TextView) view.findViewById(R.id.location);
41         TextView courseTitle = (TextView) view.findViewById(R.id.courseTitle);
42
43         Date dateFrom = (new Date(event.getEventFrom() * 1000));
44         timeFrom.setText(dateFormat.format(dateFrom));
45
46         Date dateTo = (new Date(event.getEventTo() * 1000));
47         timeTo.setText(dateFormat.format(dateTo));
48
49         location.setText(event.getEventLocation());
50         courseTitle.setText(event.getEventTitle());
51     }
52
53     private void onEventClicked() {
54         Bundle args = new Bundle();
55         CourseGroup group = event.getCourseGroup();
56         if(group == null)
57             return;
58         args.putString("groupid", Integer.toString(group.getGroupId()));
59         CampusAppContext.getInstance().getNavigationManager().navigatePage("Vorlesungsplan", args);
60     }
61 }