1 |
|
package pl.magot.vetch.ancal; |
2 |
|
|
3 |
|
import java.util.Calendar; |
4 |
|
|
5 |
|
import pl.magot.vetch.ancal.database.DataTable; |
6 |
|
import pl.magot.vetch.ancal.database.Database; |
7 |
|
import pl.magot.vetch.ancal.reminder.*; |
8 |
|
import android.app.Activity; |
9 |
|
import android.content.Intent; |
10 |
|
import android.os.Bundle; |
11 |
|
|
|
|
| 78,3% |
Uncovered Elements: 39 (180) |
Complexity: 48 |
Complexity Density: 0,44 |
|
12 |
|
public abstract class CommonActivity extends Activity |
13 |
|
{ |
14 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
15 |
|
public enum StartMode |
16 |
|
{ |
17 |
|
Default, EDIT, NEW, VIEW |
18 |
|
}; |
19 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
20 |
|
public enum Action |
21 |
|
{ |
22 |
|
Default, ShowMsg |
23 |
|
}; |
24 |
|
|
25 |
|
|
26 |
|
public static final String bundleOptionsUpdated = "OptionsUpdated"; |
27 |
|
public static final String bundleTableUpdated = "TableUpdated"; |
28 |
|
public static final String bundleRowId = "RowId"; |
29 |
|
public static final String bundleHourOfDay = "HourOfDay"; |
30 |
|
public static final String bundleMinutes = "Minutes"; |
31 |
|
public static final String bundleAgendaView = "CurrentAgendaView"; |
32 |
|
public static final String bundleAgendaViewStartDate = "AgendaViewStartDate"; |
33 |
|
|
34 |
|
|
35 |
|
private StartMode startMode = StartMode.Default; |
36 |
|
private Bundle bundleDataStartup = new Bundle(); |
37 |
|
protected Bundle bundleOtherDataStartup = new Bundle(); |
38 |
|
protected Bundle bundleDateValues = new Bundle(); |
39 |
|
|
40 |
|
|
41 |
|
public Prefs prefs = null; |
42 |
|
public Utils utils = null; |
43 |
|
public Database userdb = null; |
44 |
|
|
45 |
|
protected Bundle freeze = null; |
46 |
|
|
47 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
48 |
27
|
public CommonActivity()... |
49 |
|
{ |
50 |
|
} |
51 |
|
|
|
|
| 77,8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0,29 |
|
52 |
27
|
@Override... |
53 |
|
public void onCreate(Bundle icicle) |
54 |
|
{ |
55 |
27
|
super.onCreate(icicle); |
56 |
|
|
57 |
27
|
freeze = null; |
58 |
27
|
if (icicle != null) |
59 |
0
|
freeze = new Bundle(icicle); |
60 |
|
|
61 |
|
|
62 |
27
|
prefs = new Prefs(this); |
63 |
27
|
utils = new Utils(this); |
64 |
27
|
userdb = new Database(this); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
50
|
@Override... |
68 |
|
public void onStart() |
69 |
|
{ |
70 |
50
|
super.onStart(); |
71 |
|
|
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
66
|
@Override... |
75 |
|
public void onResume() |
76 |
|
{ |
77 |
66
|
super.onResume(); |
78 |
|
|
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
50
|
@Override... |
82 |
|
public void onStop() |
83 |
|
{ |
84 |
50
|
super.onStop(); |
85 |
|
|
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
88 |
26
|
@Override... |
89 |
|
public void onDestroy() |
90 |
|
{ |
91 |
26
|
super.onDestroy(); |
92 |
|
|
93 |
|
|
94 |
26
|
userdb.Close(); |
95 |
|
} |
96 |
|
|
|
|
| 86,7% |
Uncovered Elements: 2 (15) |
Complexity: 4 |
Complexity Density: 0,44 |
|
97 |
122
|
public StartMode GetStartMode()... |
98 |
|
{ |
99 |
122
|
startMode = StartMode.Default; |
100 |
122
|
String sAction = getIntent().getAction(); |
101 |
122
|
if (sAction.contains("ACTION_MODE_NEW")) |
102 |
75
|
startMode = StartMode.NEW; |
103 |
122
|
if (sAction.contains("ACTION_MODE_EDIT")) |
104 |
47
|
startMode = StartMode.EDIT; |
105 |
122
|
if (sAction.contains("ACTION_MODE_VIEW")) |
106 |
0
|
startMode = StartMode.VIEW; |
107 |
122
|
return startMode; |
108 |
|
} |
109 |
|
|
|
|
| 83,3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
110 |
75
|
public void SetActivityTitle(String sSubTitle)... |
111 |
|
{ |
112 |
75
|
String sTitle = getResources().getString(R.string.app_name); |
113 |
75
|
if (sSubTitle.length() > 0) |
114 |
75
|
sTitle += ": " + sSubTitle; |
115 |
75
|
setTitle(sTitle); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
19
|
public void OpenActivity(int iActivityRequestCode, String sAction)... |
119 |
|
{ |
120 |
19
|
OpenActivity(iActivityRequestCode, sAction, -1); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
123 |
27
|
public void OpenActivity(int iActivityRequestCode, String sAction, long lRowId)... |
124 |
|
{ |
125 |
27
|
bundleDataStartup.clear(); |
126 |
27
|
bundleDataStartup.putLong(CommonActivity.bundleRowId, lRowId); |
127 |
27
|
bundleDataStartup.putAll(bundleOtherDataStartup); |
128 |
27
|
Intent it = new Intent(sAction); |
129 |
27
|
it.putExtras(bundleDataStartup); |
130 |
27
|
startActivityForResult(it, iActivityRequestCode); |
131 |
|
} |
132 |
|
|
|
|
| 20% |
Uncovered Elements: 8 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
133 |
1
|
private void ParseBundledAction(Bundle extras)... |
134 |
|
{ |
135 |
1
|
if (extras.containsKey("action")) |
136 |
|
{ |
137 |
0
|
Action an = Action.valueOf(extras.getString("action")); |
138 |
|
|
139 |
|
|
140 |
0
|
if (an == Action.ShowMsg) |
141 |
|
{ |
142 |
0
|
int iMsgId = extras.getInt("msgResStrId"); |
143 |
0
|
MessageType msgType = MessageType.create(extras.getInt("msgType")); |
144 |
|
|
145 |
0
|
utils.ShowMsgResStr(iMsgId, msgType); |
146 |
|
} |
147 |
|
} |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
150 |
0
|
private Bundle PutBundledMessage(int iMsgId)... |
151 |
|
{ |
152 |
0
|
Bundle extras = new Bundle(); |
153 |
0
|
extras.putInt("msgResStrId", iMsgId); |
154 |
0
|
extras.putInt("msgType", MessageType.ERROR.getId()); |
155 |
0
|
extras.putString("action", Action.ShowMsg.toString()); |
156 |
0
|
return extras; |
157 |
|
} |
158 |
|
|
|
|
| 88,9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0,6 |
|
159 |
76
|
public static Bundle getIntentExtras(Intent data)... |
160 |
|
{ |
161 |
|
|
162 |
76
|
if (data != null) |
163 |
|
{ |
164 |
74
|
Bundle extras = data.getExtras(); |
165 |
74
|
if (extras != null) |
166 |
|
{ |
167 |
74
|
return extras; |
168 |
|
} |
169 |
|
} |
170 |
2
|
return null; |
171 |
|
} |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0,67 |
|
173 |
37
|
@Override... |
174 |
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) |
175 |
|
{ |
176 |
37
|
super.onActivityResult(requestCode, resultCode, data); |
177 |
|
|
178 |
37
|
Bundle extras = getIntentExtras(data); |
179 |
37
|
if (extras != null) |
180 |
|
{ |
181 |
36
|
if (resultCode == RESULT_CANCELED) |
182 |
|
{ |
183 |
1
|
ParseBundledAction(extras); |
184 |
|
} |
185 |
36
|
if (resultCode == RESULT_OK) |
186 |
|
{ |
187 |
|
|
188 |
|
} |
189 |
|
} |
190 |
|
} |
191 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
192 |
22
|
protected void setIntentResult(String action, int resultCode, Bundle bundle)... |
193 |
|
{ |
194 |
22
|
Intent intentData = new Intent(action); |
195 |
22
|
intentData.putExtras(bundle); |
196 |
22
|
setResult(resultCode, intentData); |
197 |
|
} |
198 |
|
|
|
|
| 54,5% |
Uncovered Elements: 5 (11) |
Complexity: 2 |
Complexity Density: 0,22 |
|
199 |
8
|
public boolean OpenDataForEdit(DataTable data)... |
200 |
|
{ |
201 |
8
|
long lRowId = RequestedRowId(); |
202 |
8
|
Database.Result result = data.GetRowDataForEdit(lRowId); |
203 |
8
|
if (result == Database.Result.Success) |
204 |
|
{ |
205 |
|
|
206 |
8
|
SaveDateValuesBeforeChange(bundleDateValues); |
207 |
|
|
208 |
8
|
return true; |
209 |
|
} else |
210 |
|
{ |
211 |
|
|
212 |
0
|
int iMsgId = Database.GetErrDesc(result); |
213 |
0
|
Bundle extras = PutBundledMessage(iMsgId); |
214 |
0
|
setIntentResult("", RESULT_CANCELED, extras); |
215 |
|
|
216 |
0
|
return false; |
217 |
|
} |
218 |
|
} |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
220 |
29
|
public long RequestedRowId()... |
221 |
|
{ |
222 |
29
|
return getIntent().getExtras().getLong(CommonActivity.bundleRowId); |
223 |
|
} |
224 |
|
|
|
|
| 77,8% |
Uncovered Elements: 4 (18) |
Complexity: 4 |
Complexity Density: 0,33 |
|
225 |
18
|
public boolean SaveDataToTable(DataTable data)... |
226 |
|
{ |
227 |
18
|
boolean bSuccess = false; |
228 |
|
|
229 |
18
|
if (data.GetDataRow().Validate()) |
230 |
|
{ |
231 |
18
|
boolean bInsertMode = (GetStartMode() == StartMode.NEW); |
232 |
18
|
long lRowId = RequestedRowId(); |
233 |
18
|
Database.Result result = data.UpdateData(bInsertMode, lRowId); |
234 |
18
|
if (result == Database.Result.Success) |
235 |
|
{ |
236 |
|
|
237 |
18
|
if (DateValuesChanged(bundleDateValues)) |
238 |
1
|
AlarmsManager.ResetAlarm(userdb, prefs, data, lRowId); |
239 |
|
|
240 |
18
|
bSuccess = true; |
241 |
|
} else |
242 |
|
{ |
243 |
0
|
utils.ShowMsgResStr(Database.GetErrDesc(result), MessageType.ERROR); |
244 |
|
} |
245 |
|
} else |
246 |
|
{ |
247 |
0
|
utils |
248 |
|
.ShowMsgResStr(R.string.infoEnterAllRequiredData, MessageType.INFO); |
249 |
|
} |
250 |
18
|
return bSuccess; |
251 |
|
} |
252 |
|
|
|
|
| 70,6% |
Uncovered Elements: 5 (17) |
Complexity: 5 |
Complexity Density: 0,56 |
|
253 |
5
|
public boolean DateBeforeNow(Calendar calDate)... |
254 |
|
{ |
255 |
5
|
Calendar calNow = Calendar.getInstance(); |
256 |
5
|
if (calNow.get(Calendar.YEAR) == calDate.get(Calendar.YEAR)) |
257 |
4
|
if (calNow.get(Calendar.MONTH) == calDate.get(Calendar.MONTH)) |
258 |
4
|
if (calNow.get(Calendar.DAY_OF_MONTH) == calDate |
259 |
|
.get(Calendar.DAY_OF_MONTH)) |
260 |
4
|
return false; |
261 |
1
|
if (calDate.before(calNow)) |
262 |
|
{ |
263 |
0
|
utils.ShowMsgResStr(R.string.infoEnterValidDate, MessageType.INFO); |
264 |
0
|
return true; |
265 |
|
} |
266 |
1
|
return false; |
267 |
|
} |
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
269 |
1
|
public void CloseActivity(String sCode, String sValue)... |
270 |
|
{ |
271 |
1
|
Bundle bundleDataResult = new Bundle(); |
272 |
1
|
bundleDataResult.putString(sCode, sValue); |
273 |
|
|
274 |
1
|
setIntentResult("", RESULT_OK, bundleDataResult); |
275 |
1
|
finish(); |
276 |
|
} |
277 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
278 |
21
|
public void CloseActivity(DataTable data)... |
279 |
|
{ |
280 |
21
|
Bundle bundleDataResult = new Bundle(); |
281 |
21
|
bundleDataResult.putString(bundleTableUpdated, data.GetTableName()); |
282 |
|
|
283 |
21
|
setIntentResult("", RESULT_OK, bundleDataResult); |
284 |
21
|
finish(); |
285 |
|
} |
286 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
287 |
3
|
public boolean DeleteDataFromTable(DataTable data)... |
288 |
|
{ |
289 |
3
|
boolean bSuccess = false; |
290 |
3
|
long lRowId = RequestedRowId(); |
291 |
3
|
Database.Result result = data.DeleteData(lRowId); |
292 |
3
|
if (result == Database.Result.Success) |
293 |
|
{ |
294 |
|
|
295 |
3
|
AlarmsManager.DeleteAlarm(userdb, prefs, data, lRowId); |
296 |
|
|
297 |
3
|
bSuccess = true; |
298 |
|
} else |
299 |
|
{ |
300 |
0
|
utils.ShowMsgResStr(Database.GetErrDesc(result), MessageType.ERROR); |
301 |
|
} |
302 |
3
|
return bSuccess; |
303 |
|
} |
304 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
305 |
8
|
public void SaveDateValuesBeforeChange(Bundle data)... |
306 |
|
{ |
307 |
8
|
if (data != null) |
308 |
8
|
data.clear(); |
309 |
|
} |
310 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
311 |
18
|
public boolean DateValuesChanged(Bundle data)... |
312 |
|
{ |
313 |
18
|
return false; |
314 |
|
} |
315 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
316 |
21
|
protected void restoreStateFromFreezeIfRequired()... |
317 |
|
{ |
318 |
21
|
if (freeze != null) |
319 |
|
{ |
320 |
0
|
restoreStateFromFreeze(); |
321 |
|
} |
322 |
|
} |
323 |
|
|
324 |
|
abstract protected void restoreStateFromFreeze(); |
325 |
|
|
326 |
|
} |