Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / NewsListItem.java
1 /* NewsListItem.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 java.text.SimpleDateFormat;
18 import java.util.Date;
19
20 import de.dhbwloe.campusapp.CampusAppContext;
21 import de.dhbwloe.campusapp.R;
22 import de.dhbwloe.campusapp.news.NewsItem;
23 import de.dhbwloe.campusapp.vorlesungen.CourseEvent;
24
25 /**
26  * Created by pk910 on 27.02.2016.
27  */
28 public class NewsListItem {
29     private String sNewsTitle;
30     private String sNewsDescription;
31     private String sNewsLink;
32     private long lNewsDate;
33     private boolean bIsDhbwNews;
34     private boolean bIsEvent;
35
36     public NewsListItem(NewsItem newsItem, boolean isDhbwNews) {
37         sNewsTitle = newsItem.getTitle();
38         sNewsDescription = newsItem.getSummary();
39         sNewsLink = newsItem.getLink();
40         lNewsDate = newsItem.getTime();
41         bIsDhbwNews = isDhbwNews;
42         bIsEvent = false;
43     }
44
45     public NewsListItem(CourseEvent newsEvent, boolean isDhbwEvent) {
46         sNewsTitle = newsEvent.getEventTitle();
47         sNewsDescription = newsEvent.getEventLocation();
48         sNewsLink = null;
49         lNewsDate = newsEvent.getEventFrom();
50         bIsDhbwNews = isDhbwEvent;
51         bIsEvent = true;
52     }
53
54     public long getTimeDifference(long now) {
55         return Math.abs(now - lNewsDate);
56     }
57
58     public String getTitle() {
59         return sNewsTitle;
60     }
61
62     public String getDescription() {
63         return sNewsDescription;
64     }
65
66     public boolean isDhbwNews() {
67         return bIsDhbwNews;
68     }
69
70     public String getFormatedDate() {
71         String dateFormat;
72         if(bIsEvent)
73             dateFormat = CampusAppContext.getInstance().getResString(R.string.timeformat_news_event);
74         else
75             dateFormat = CampusAppContext.getInstance().getResString(R.string.timeformat_news_news);
76         SimpleDateFormat format = new SimpleDateFormat(dateFormat);
77         return format.format(new Date(lNewsDate * 1000));
78     }
79
80     public String getLink() {
81         return sNewsLink;
82     }
83 }