1 |
|
|
2 |
|
package pl.magot.vetch.ancal.dataview; |
3 |
|
|
4 |
|
|
5 |
|
import java.util.*; |
6 |
|
|
7 |
|
import pl.magot.vetch.ancal.agenda.AgendaViewType; |
8 |
|
import pl.magot.vetch.ancal.database.Database; |
9 |
|
import pl.magot.vetch.ancal.Prefs; |
10 |
|
import android.database.*; |
11 |
|
import android.database.sqlite.*; |
12 |
|
|
13 |
|
|
|
|
| 93,6% |
Uncovered Elements: 5 (78) |
Complexity: 23 |
Complexity Density: 0,43 |
|
14 |
|
public abstract class DataView |
15 |
|
{ |
16 |
|
|
17 |
|
private final String sQuery = "select * from %s"; |
18 |
|
protected Database db = null; |
19 |
|
protected Prefs prefs = null; |
20 |
|
protected String sTableName = ""; |
21 |
|
protected ArrayList<DataViewItem> rows = new ArrayList<DataViewItem>(); |
22 |
|
private Calendar calViewStartDate = Calendar.getInstance(); |
23 |
|
|
24 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
25 |
5
|
public DataView(Database db, Prefs prefs)... |
26 |
|
{ |
27 |
5
|
this.db = db; |
28 |
5
|
this.prefs = prefs; |
29 |
|
} |
30 |
|
|
31 |
|
protected abstract void AddItem(Cursor cr); |
32 |
|
|
33 |
|
protected abstract void FilterDataPrepare(final Calendar calStartDate, final AgendaViewType agendaViewType); |
34 |
|
|
35 |
|
protected abstract void FilterDataForView(DataViewItem item, final Calendar calStartDate, AgendaViewType agendaViewType); |
36 |
|
|
37 |
|
protected abstract void SortView(); |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
39 |
83
|
public boolean ReloadTable()... |
40 |
|
{ |
41 |
|
|
42 |
83
|
Database.Result result = CollectRowsData(); |
43 |
83
|
if (result == Database.Result.Success) |
44 |
65
|
return true; |
45 |
18
|
return false; |
46 |
|
} |
47 |
|
|
|
|
| 87,5% |
Uncovered Elements: 3 (24) |
Complexity: 5 |
Complexity Density: 0,28 |
|
48 |
83
|
public Database.Result CollectRowsData()... |
49 |
|
{ |
50 |
83
|
Database.Result result = Database.Result.errUnknown; |
51 |
83
|
rows.clear(); |
52 |
83
|
String sql = String.format(sQuery, sTableName); |
53 |
83
|
SQLiteDatabase sqldb = db.GetSQLiteDb(); |
54 |
83
|
Cursor cr = sqldb.rawQuery(sql, null); |
55 |
83
|
if (cr == null) |
56 |
|
{ |
57 |
0
|
result = Database.Result.errCantGetData; |
58 |
|
} else { |
59 |
83
|
if (cr.getCount() > 0) |
60 |
|
{ |
61 |
65
|
cr.moveToFirst(); |
62 |
235
|
while (!cr.isAfterLast()) |
63 |
|
{ |
64 |
170
|
try |
65 |
|
{ |
66 |
170
|
AddItem(cr); |
67 |
170
|
result = Database.Result.Success; |
68 |
|
} catch (Exception e) { |
69 |
0
|
return Database.Result.errCantGetDataFromTable; |
70 |
|
} |
71 |
170
|
cr.moveToNext(); |
72 |
|
} |
73 |
|
} else { |
74 |
18
|
result = Database.Result.errCantFindData; |
75 |
|
} |
76 |
83
|
SortView(); |
77 |
|
} |
78 |
83
|
return result; |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0,6 |
|
81 |
521
|
public DataViewItem GetRow(int index, final AgendaViewType agendaViewType) ... |
82 |
|
{ |
83 |
521
|
try |
84 |
|
{ |
85 |
521
|
DataViewItem values = rows.get(index); |
86 |
521
|
if (agendaViewType == values.viewMode) |
87 |
201
|
return values; |
88 |
|
} catch (IndexOutOfBoundsException e) { |
89 |
|
} |
90 |
320
|
return null; |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0,6 |
|
93 |
75
|
public int GetRowsCountForView(final AgendaViewType agendaViewType)... |
94 |
|
{ |
95 |
75
|
int iCount = 0; |
96 |
173
|
for (int i = 0; i < rows.size(); i++) |
97 |
98
|
if (rows.get(i).viewMode == agendaViewType) |
98 |
64
|
iCount++; |
99 |
75
|
return iCount; |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
738
|
public int GetRowsCountTotal()... |
103 |
|
{ |
104 |
738
|
return rows.size(); |
105 |
|
} |
106 |
|
|
|
|
| 83,3% |
Uncovered Elements: 2 (12) |
Complexity: 6 |
Complexity Density: 0,5 |
|
107 |
580
|
public int getDaysRangeForView(final AgendaViewType agendaViewType)... |
108 |
|
{ |
109 |
580
|
switch (agendaViewType) { |
110 |
85
|
case TODAY: |
111 |
110
|
case DAY: |
112 |
195
|
return 0; |
113 |
186
|
case WEEK: |
114 |
186
|
return 7; |
115 |
86
|
case MONTH: |
116 |
86
|
return 42; |
117 |
113
|
case TODAY_ALARM: |
118 |
113
|
return 7; |
119 |
0
|
default: |
120 |
0
|
throw new IllegalArgumentException("unknown ViewMode!"); |
121 |
|
} |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0,29 |
|
124 |
217
|
public void FilterData(final Calendar calStartDate, final AgendaViewType agendaViewType)... |
125 |
|
{ |
126 |
217
|
calViewStartDate.setTimeInMillis(calStartDate.getTimeInMillis()); |
127 |
217
|
calViewStartDate.setFirstDayOfWeek(prefs.iFirstDayOfWeek); |
128 |
|
|
129 |
217
|
FilterDataPrepare(calViewStartDate, agendaViewType); |
130 |
|
|
131 |
738
|
for (int i = 0; i < rows.size(); i++) |
132 |
|
{ |
133 |
521
|
DataViewItem item = rows.get(i); |
134 |
521
|
item.viewMode = AgendaViewType.NONE; |
135 |
521
|
FilterDataForView(item, calViewStartDate, agendaViewType); |
136 |
|
} |
137 |
|
} |
138 |
|
|
139 |
|
} |