~ubuntu-branches/ubuntu/utopic/mediathekview/utopic

« back to all changes in this revision

Viewing changes to src/msearch/filmeLaden/DatenFilmlisteUrl.java

  • Committer: Package Import Robot
  • Author(s): Markus Koschany
  • Date: 2014-07-24 12:04:16 UTC
  • mfrom: (4.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20140724120416-h9r0d70ql741jdnl
Tags: 7-1
* Imported Upstream version 7.
* Update debian/watch to detect new upstream tarballs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*    
 
2
 *    MediathekView
 
3
 *    Copyright (C) 2008   W. Xaver
 
4
 *    W.Xaver[at]googlemail.com
 
5
 *    http://zdfmediathk.sourceforge.net/
 
6
 *    
 
7
 *    This program is free software: you can redistribute it and/or modify
 
8
 *    it under the terms of the GNU General Public License as published by
 
9
 *    the Free Software Foundation, either version 3 of the License, or
 
10
 *    any later version.
 
11
 *
 
12
 *    This program is distributed in the hope that it will be useful,
 
13
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *    GNU General Public License for more details.
 
16
 *
 
17
 *    You should have received a copy of the GNU General Public License
 
18
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
package msearch.filmeLaden;
 
21
 
 
22
import java.text.ParseException;
 
23
import java.text.SimpleDateFormat;
 
24
import java.util.Calendar;
 
25
import java.util.Date;
 
26
import java.util.SimpleTimeZone;
 
27
import msearch.tool.MSLog;
 
28
 
 
29
public class DatenFilmlisteUrl implements Comparable<DatenFilmlisteUrl> {
 
30
 
 
31
    public static final String SERVER_ART_AKT = "akt";
 
32
    public static final String SERVER_ART_OLD = "old";
 
33
    public static final String SERVER_ART_DIFF = "diff";
 
34
 
 
35
    public static final String FILM_UPDATE_SERVER_PRIO_1 = "1";
 
36
    public static final String FILM_UPDATE_SERVER = "film-update-server";
 
37
    public static final String FILM_UPDATE_SERVER_NR = "film-update-server-nr";
 
38
    public static final int FILM_UPDATE_SERVER_NR_NR = 0;
 
39
    public static final String FILM_UPDATE_SERVER_URL = "film-update-server-url";
 
40
    public static final int FILM_UPDATE_SERVER_URL_NR = 1;
 
41
    public static final String FILM_UPDATE_SERVER_DATUM = "film-update-server-datum"; // Datum in UTC
 
42
    public static final int FILM_UPDATE_SERVER_DATUM_NR = 2;
 
43
    public static final String FILM_UPDATE_SERVER_ZEIT = "film-update-server-zeit"; // Zeit in UTC
 
44
    public static final int FILM_UPDATE_SERVER_ZEIT_NR = 3;
 
45
    public static final String FILM_UPDATE_SERVER_PRIO = "film-update-server-prio";
 
46
    public static final int FILM_UPDATE_SERVER_PRIO_NR = 4;
 
47
    public static final String FILM_UPDATE_SERVER_ART = "film-update-server-art";
 
48
    public static final int FILM_UPDATE_SERVER_ART_NR = 5;
 
49
    public static final int FILM_UPDATE_SERVER_MAX_ELEM = 6;
 
50
    public static final String[] FILM_UPDATE_SERVER_COLUMN_NAMES = {FILM_UPDATE_SERVER_NR, FILM_UPDATE_SERVER_URL,
 
51
        FILM_UPDATE_SERVER_DATUM, FILM_UPDATE_SERVER_ZEIT, FILM_UPDATE_SERVER_PRIO, FILM_UPDATE_SERVER_ART};
 
52
 
 
53
    public static final String[] FILM_UPDATE_SERVER_COLUMN_NAMES_ANZEIGE = {"Nr", "Update-Url", "Datum", "Zeit", "Prio", "Art"};
 
54
 
 
55
    public String[] arr;
 
56
    private SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
 
57
 
 
58
    public DatenFilmlisteUrl() {
 
59
        sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
 
60
        makeArr();
 
61
    }
 
62
 
 
63
    public DatenFilmlisteUrl(String url, String prio, String zeit, String datum, String art) {
 
64
        sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
 
65
        makeArr();
 
66
        arr[FILM_UPDATE_SERVER_URL_NR] = url;
 
67
        arr[FILM_UPDATE_SERVER_PRIO_NR] = prio;
 
68
        arr[FILM_UPDATE_SERVER_DATUM_NR] = datum;
 
69
        arr[FILM_UPDATE_SERVER_ZEIT_NR] = zeit;
 
70
        arr[FILM_UPDATE_SERVER_ART_NR] = art;
 
71
    }
 
72
 
 
73
    public Date getDate() {
 
74
        String date = arr[FILM_UPDATE_SERVER_DATUM_NR] + " " + arr[FILM_UPDATE_SERVER_ZEIT_NR];
 
75
        Date d;
 
76
        try {
 
77
            d = sdf.parse(date);
 
78
        } catch (Exception ex) {
 
79
            d = new Date();
 
80
        }
 
81
        return d;
 
82
    }
 
83
 
 
84
    public String getDateStr() {
 
85
        SimpleDateFormat sdf_ = new SimpleDateFormat("dd.MM.yyyy");
 
86
        sdf_.setTimeZone(SimpleTimeZone.getDefault());
 
87
        String d;
 
88
        try {
 
89
            d = sdf_.format(getDate());
 
90
        } catch (Exception ex) {
 
91
            d = sdf_.format(new Date());
 
92
        }
 
93
        return d;
 
94
    }
 
95
 
 
96
    public String getTimeStr() {
 
97
        SimpleDateFormat sdf_ = new SimpleDateFormat("HH:mm:ss");
 
98
        sdf_.setTimeZone(SimpleTimeZone.getDefault());
 
99
        String d;
 
100
        try {
 
101
            d = sdf_.format(getDate());
 
102
        } catch (Exception ex) {
 
103
            d = sdf_.format(new Date());
 
104
        }
 
105
        return d;
 
106
    }
 
107
 
 
108
    @Override
 
109
    public int compareTo(DatenFilmlisteUrl arg0) {
 
110
        int ret = 0;
 
111
        try {
 
112
            //31.10.2010        16:54:17
 
113
            String ich = arr[FILM_UPDATE_SERVER_DATUM_NR] + " " + arr[FILM_UPDATE_SERVER_ZEIT_NR];
 
114
            String du = arg0.arr[FILM_UPDATE_SERVER_DATUM_NR] + " " + arg0.arr[FILM_UPDATE_SERVER_ZEIT_NR];
 
115
            if (ich.equals(du)) {
 
116
                return 0;
 
117
            }
 
118
            Date d_ich = sdf.parse(ich);
 
119
            Date d_du = sdf.parse(du);
 
120
            ret = d_du.compareTo(d_ich);
 
121
        } catch (ParseException ex) {
 
122
            MSLog.fehlerMeldung(936542876, MSLog.FEHLER_ART_PROG, this.getClass().getName(), ex);
 
123
        }
 
124
        return ret;
 
125
    }
 
126
 
 
127
    public boolean aelterAls(int tage) {
 
128
        boolean ret = false;
 
129
        try {
 
130
            //31.10.2010        16:54:17
 
131
            String ich = arr[FILM_UPDATE_SERVER_DATUM_NR] + " " + arr[FILM_UPDATE_SERVER_ZEIT_NR];
 
132
            Date d_ich = sdf.parse(ich);
 
133
            Calendar cal = Calendar.getInstance();
 
134
            // tage vom calendar abziehen
 
135
            cal.add(Calendar.DATE, -tage);
 
136
            ret = d_ich.before(cal.getTime());
 
137
        } catch (ParseException ex) {
 
138
            MSLog.fehlerMeldung(915468973, MSLog.FEHLER_ART_PROG, this.getClass().getName(), ex);
 
139
        }
 
140
        return ret;
 
141
    }
 
142
 
 
143
    private void makeArr() {
 
144
        arr = new String[FILM_UPDATE_SERVER_MAX_ELEM];
 
145
        for (int i = 0; i < arr.length; ++i) {
 
146
            arr[i] = "";
 
147
        }
 
148
    }
 
149
}