Grundaufbau der App
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / news / NewsItem.java
1 package de.dhbwloe.campusapp.news;
2
3 import java.text.DateFormat;
4 import java.text.SimpleDateFormat;
5 import java.util.Date;
6 import java.util.Locale;
7 import java.util.zip.CRC32;
8
9 /**
10  * Created by pk910 on 23.01.2016.
11  */
12 public class NewsItem {
13     private int id;
14     private String sSource;
15     private long iTime;
16     private String sUniqueId;
17     private long iChkSum;
18     private String sTitle;
19     private String sSummary;
20     private String sContent;
21     private String sLink;
22     private String sCategories;
23
24     private boolean bIsNew;
25
26     public NewsItem(int id, String source, long time, String uniqueid, long chksum, String title, String summary, String content, String link, String categories) {
27         this.id = id;
28         sSource= source;
29         iTime = time;
30         sUniqueId = uniqueid;
31         sTitle = title.trim();
32         sSummary = summary;
33         sContent = content;
34         sLink = link;
35         sCategories = categories;
36     }
37
38     public long calculateChkSum() {
39         CRC32 crc = new CRC32();
40         crc.update(sTitle.getBytes());
41         crc.update(sUniqueId.getBytes());
42         crc.update((int)iTime);
43         crc.update(sSummary.getBytes());
44         if(sContent != null)
45             crc.update(sContent.getBytes());
46         if(sLink != null)
47             crc.update(sLink.getBytes());
48         if(sCategories != null)
49             crc.update(sCategories.getBytes());
50
51         long crcvalue = crc.getValue();
52         iChkSum = crcvalue;
53         return crcvalue;
54     }
55
56     public long getChkSum() {
57         return iChkSum;
58     }
59
60     public void setIsNew(int id) {
61         bIsNew = true;
62         this.id = id;
63     }
64
65     public boolean getIsNew(boolean reset) {
66         boolean isnew = bIsNew;
67         if(reset)
68             bIsNew = false;
69         return isnew;
70     }
71
72     public int getId() {
73         return id;
74     }
75
76     public String getSource() {
77         return sSource;
78     }
79
80     public long getTime() {
81         return iTime;
82     }
83
84     public String getFormatedDate() {
85         return getFormatedDate("dd.MM.yyyy");
86     }
87
88     public String getFormatedDate(String format) {
89         DateFormat df = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
90         return df.format(new Date(iTime * 1000));
91     }
92
93     public String getUniqueId() {
94         return sUniqueId;
95     }
96
97     public String getTitle() {
98         return sTitle;
99     }
100
101     public String getSummary() {
102         return sSummary;
103     }
104
105     public String getContent() {
106         return sContent;
107     }
108
109     public String getLink() {
110         return sLink;
111     }
112
113     public String getCategories() {
114         return sCategories;
115     }
116 }