1 |
|
|
2 |
|
package pl.magot.vetch.ancal.dataview; |
3 |
|
|
4 |
|
|
5 |
|
import java.util.*; |
6 |
|
|
7 |
|
import pl.magot.vetch.ancal.Prefs; |
8 |
|
import pl.magot.vetch.ancal.RepeatData; |
9 |
|
import pl.magot.vetch.ancal.RepeatDataValue; |
10 |
|
import pl.magot.vetch.ancal.agenda.AgendaViewType; |
11 |
|
import pl.magot.vetch.ancal.database.DataRowAppointment; |
12 |
|
import pl.magot.vetch.ancal.database.Database; |
13 |
|
import android.database.Cursor; |
14 |
|
|
15 |
|
|
|
|
| 98,8% |
Uncovered Elements: 1 (80) |
Complexity: 17 |
Complexity Density: 0,33 |
|
16 |
|
public class DataViewAppointment extends DataView |
17 |
|
{ |
18 |
|
|
19 |
|
private Calendar calUtilDate = Calendar.getInstance(); |
20 |
|
|
21 |
|
|
22 |
|
private RepeatData repeat = new RepeatData(); |
23 |
|
|
24 |
|
|
25 |
|
protected Calendar calStartDateForCache = Calendar.getInstance(); |
26 |
|
protected RepeatDataValue[] vecDateRangeCache = new RepeatDataValue[42]; |
27 |
|
|
28 |
|
|
29 |
|
private Calendar date1cmp = Calendar.getInstance(); |
30 |
|
private Calendar date2cmp = Calendar.getInstance(); |
31 |
|
|
32 |
|
|
33 |
|
private Calendar calItemStartDate = Calendar.getInstance(); |
34 |
|
|
35 |
|
|
|
|
| 92,6% |
Uncovered Elements: 2 (27) |
Complexity: 6 |
Complexity Density: 0,33 |
|
36 |
|
public class RowsComparator implements Comparator<DataViewItem> |
37 |
|
{ |
|
|
| 92,3% |
Uncovered Elements: 2 (26) |
Complexity: 6 |
Complexity Density: 0,33 |
|
38 |
88
|
public int compare(DataViewItem item1, DataViewItem item2)... |
39 |
|
{ |
40 |
88
|
date1cmp.setTimeInMillis(item1.GetStartDateAsLong()); |
41 |
88
|
date2cmp.setTimeInMillis(item2.GetStartDateAsLong()); |
42 |
|
|
43 |
88
|
boolean bAllDay1 = (item1.bAllDay); |
44 |
88
|
boolean bAllDay2 = (item2.bAllDay); |
45 |
|
|
46 |
88
|
if (bAllDay1 && bAllDay2) |
47 |
|
{ |
48 |
36
|
String s1 = item1.sSubject; |
49 |
36
|
String s2 = item2.sSubject; |
50 |
36
|
return s1.compareTo(s2); |
51 |
|
} else { |
52 |
52
|
if (bAllDay1) |
53 |
0
|
return -1; |
54 |
52
|
if (bAllDay2) |
55 |
33
|
return 1; |
56 |
|
|
57 |
19
|
final int dateCompare = date1cmp.compareTo(date2cmp); |
58 |
19
|
if (dateCompare == 0) { |
59 |
3
|
String s1 = item1.sSubject; |
60 |
3
|
String s2 = item2.sSubject; |
61 |
3
|
return s1.compareTo(s2); |
62 |
|
} else { |
63 |
16
|
return dateCompare; |
64 |
|
} |
65 |
|
} |
66 |
|
} |
67 |
|
}; |
68 |
|
|
69 |
|
|
70 |
|
private RowsComparator fnCmp = null; |
71 |
|
|
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
73 |
2
|
public DataViewAppointment(Database db, Prefs prefs)... |
74 |
|
{ |
75 |
2
|
super(db, prefs); |
76 |
2
|
sTableName = Database.sTableNameAppointments; |
77 |
2
|
fnCmp = new RowsComparator(); |
78 |
|
|
79 |
|
|
80 |
86
|
for (int iDay = 0; iDay < 42; iDay++) |
81 |
|
{ |
82 |
84
|
vecDateRangeCache[iDay] = new RepeatDataValue(); |
83 |
|
} |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 3 |
Complexity Density: 0,23 |
|
86 |
105
|
@Override... |
87 |
|
public void AddItem(Cursor cr) |
88 |
|
{ |
89 |
105
|
DataViewItem item = new DataViewItem(); |
90 |
|
|
91 |
105
|
item.lID = cr.getLong(DataRowAppointment.fid.ID); |
92 |
105
|
item.sSubject = cr.getString(DataRowAppointment.fid.Subject); |
93 |
105
|
item.SetStartDate(calUtilDate, cr.getLong(DataRowAppointment.fid.StartDate)); |
94 |
105
|
item.iDurationInMinutes = cr.getInt(DataRowAppointment.fid.DurationInMinutes); |
95 |
105
|
item.bAllDay = (cr.getLong(DataRowAppointment.fid.AllDay) == 1); |
96 |
105
|
item.bAlarm = (cr.getLong(DataRowAppointment.fid.Alarm) == 1); |
97 |
|
|
98 |
105
|
item.iRepeatType = cr.getInt(DataRowAppointment.fid.RepeatType); |
99 |
|
|
100 |
105
|
if (!cr.isNull(DataRowAppointment.fid.RepeatEvery)) |
101 |
94
|
item.iRepeatEvery = cr.getInt(DataRowAppointment.fid.RepeatEvery); |
102 |
|
|
103 |
105
|
if (!cr.isNull(DataRowAppointment.fid.RepeatEndOnDate)) |
104 |
36
|
item.lRepeatEndOnDate = cr.getLong(DataRowAppointment.fid.RepeatEndOnDate); |
105 |
|
|
106 |
105
|
rows.add(item); |
107 |
|
} |
108 |
|
|
|
|
| 97,3% |
Uncovered Elements: 1 (37) |
Complexity: 8 |
Complexity Density: 0,35 |
|
109 |
443
|
@Override... |
110 |
|
public void FilterDataForView(DataViewItem item, final Calendar calStartDate, final AgendaViewType agendaViewType) |
111 |
|
{ |
112 |
|
|
113 |
443
|
repeat.SetRepeatTypeAsInt(item.iRepeatType); |
114 |
443
|
repeat.SetEndOnDate(null); |
115 |
443
|
repeat.SetEvery(1); |
116 |
|
|
117 |
|
|
118 |
443
|
if (item.IsRepeat()) |
119 |
|
{ |
120 |
381
|
repeat.SetEvery(item.iRepeatEvery); |
121 |
381
|
if (item.UseRepeatEndOnDate()) |
122 |
132
|
repeat.SetEndOnDate(item.lRepeatEndOnDate); |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
443
|
calItemStartDate.setTimeInMillis(item.GetStartDateAsLong()); |
127 |
443
|
calItemStartDate.setFirstDayOfWeek(prefs.iFirstDayOfWeek); |
128 |
443
|
repeat.SetStartDate(calItemStartDate); |
129 |
|
|
130 |
|
|
131 |
443
|
if (agendaViewType != AgendaViewType.NONE) |
132 |
|
{ |
133 |
443
|
item.Clear(); |
134 |
|
|
135 |
443
|
final int iDaysCount = getDaysRangeForView(agendaViewType); |
136 |
|
|
137 |
443
|
if (iDaysCount == 0) |
138 |
|
{ |
139 |
|
|
140 |
145
|
if (repeat.IsDateEqual(calStartDate)) |
141 |
|
{ |
142 |
51
|
item.SetVisibleDay(0); |
143 |
51
|
item.viewMode = agendaViewType; |
144 |
|
} |
145 |
|
|
146 |
|
} else { |
147 |
|
|
148 |
298
|
RepeatDataValue dvDate = null; |
149 |
|
|
150 |
4659
|
for (int iDay = 0; iDay < iDaysCount; iDay++) |
151 |
|
{ |
152 |
4361
|
dvDate = vecDateRangeCache[iDay]; |
153 |
|
|
154 |
4361
|
if (repeat.IsDateEqual(dvDate)) |
155 |
|
{ |
156 |
105
|
item.SetVisibleDay(iDay); |
157 |
105
|
item.viewMode = agendaViewType; |
158 |
|
} |
159 |
|
|
160 |
|
} |
161 |
|
|
162 |
|
} |
163 |
|
} |
164 |
|
|
165 |
|
} |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
167 |
137
|
@Override... |
168 |
|
protected void FilterDataPrepare(final Calendar calStartDate, final AgendaViewType agendaViewType) |
169 |
|
{ |
170 |
137
|
final int iDaysCount = getDaysRangeForView(agendaViewType); |
171 |
|
|
172 |
137
|
int iDayValue = 1; |
173 |
|
|
174 |
137
|
if (agendaViewType == AgendaViewType.TODAY_ALARM) |
175 |
30
|
iDayValue = -1; |
176 |
|
|
177 |
137
|
calStartDateForCache.setTimeInMillis(calStartDate.getTimeInMillis()); |
178 |
137
|
calStartDateForCache.setFirstDayOfWeek(prefs.iFirstDayOfWeek); |
179 |
|
|
180 |
1481
|
for (int iDay = 0; iDay < (iDaysCount); iDay++) |
181 |
|
{ |
182 |
1344
|
vecDateRangeCache[iDay].getFromCalendar(calStartDateForCache); |
183 |
1344
|
calStartDateForCache.add(Calendar.DAY_OF_YEAR, iDayValue); |
184 |
|
} |
185 |
|
|
186 |
|
} |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
39
|
@Override... |
189 |
|
public void SortView() |
190 |
|
{ |
191 |
39
|
Collections.sort(rows, fnCmp); |
192 |
|
} |
193 |
|
|
194 |
|
} |