22
22
import android .os .AsyncTask ;
23
23
import android .os .Bundle ;
24
24
import android .os .Looper ;
25
- import android .preference .PreferenceManager ;
26
25
import android .support .v4 .app .Fragment ;
27
26
import android .support .v4 .app .FragmentActivity ;
28
27
import android .support .v4 .app .FragmentManager ;
34
33
import android .view .View ;
35
34
import android .widget .TextView ;
36
35
36
+ import com .wanikani .androidnotifier .Tab .RefreshType ;
37
37
import com .wanikani .wklib .AuthenticationException ;
38
38
import com .wanikani .wklib .Connection ;
39
39
import com .wanikani .wklib .Item ;
40
40
import com .wanikani .wklib .ItemLibrary ;
41
41
import com .wanikani .wklib .ItemsCache ;
42
+ import com .wanikani .wklib .Kanji ;
42
43
import com .wanikani .wklib .LevelProgression ;
44
+ import com .wanikani .wklib .Radical ;
43
45
import com .wanikani .wklib .SRSDistribution ;
44
46
import com .wanikani .wklib .SRSLevel ;
45
47
import com .wanikani .wklib .StudyQueue ;
@@ -266,9 +268,21 @@ else if (action.equals (ACTION_REFRESH)) {
266
268
*/
267
269
private class RefreshTask extends AsyncTask <Connection , Void , DashboardData > {
268
270
271
+ /// The refresh type
272
+ RefreshType rtype ;
273
+
269
274
/// The default "turtle" avatar
270
275
Bitmap defAvatar ;
271
276
277
+ /**
278
+ * Constructor.
279
+ * @param rtype the type of refresh to be used
280
+ */
281
+ public RefreshTask (RefreshType rtype )
282
+ {
283
+ this .rtype = rtype ;
284
+ }
285
+
272
286
/**
273
287
* Called before starting the task, inside the activity thread.
274
288
*/
@@ -333,7 +347,7 @@ protected void onPostExecute (DashboardData dd)
333
347
334
348
refreshComplete (dd , true );
335
349
336
- new RefreshTaskPartII ().execute (conn );
350
+ new RefreshTaskPartII (rtype , dd . level ).execute (conn );
337
351
} catch (AuthenticationException e ) {
338
352
error (R .string .status_msg_unauthorized );
339
353
} catch (IOException e ) {
@@ -348,7 +362,24 @@ protected void onPostExecute (DashboardData dd)
348
362
* so it can be run after the splash screen disappears (and the startup is faster).
349
363
*/
350
364
private class RefreshTaskPartII extends AsyncTask <Connection , Void , DashboardData .OptionalData > {
351
-
365
+
366
+ /// The refresh type
367
+ RefreshType rtype ;
368
+
369
+ /// User level
370
+ int level ;
371
+
372
+ /**
373
+ * Constructor
374
+ * @param rtype refresh type
375
+ * @param level current user level
376
+ */
377
+ public RefreshTaskPartII (RefreshType rtype , int level )
378
+ {
379
+ this .rtype = rtype ;
380
+ this .level = level ;
381
+ }
382
+
352
383
/**
353
384
* Called before starting the task, inside the activity thread.
354
385
*/
@@ -368,10 +399,12 @@ protected void onPreExecute ()
368
399
@ Override
369
400
protected DashboardData .OptionalData doInBackground (Connection ... conn )
370
401
{
371
- DashboardData .OptionalDataStatus srsStatus , lpStatus , ciStatus ;
402
+ DashboardData .OptionalDataStatus srsStatus , lpStatus , ciStatus , tlStatus ;
372
403
SRSDistribution srs ;
373
404
LevelProgression lp ;
374
405
ItemLibrary <Item > critical ;
406
+ ItemLibrary <Radical > tlradicals ;
407
+ ItemLibrary <Kanji > tlkanji ;
375
408
int cis ;
376
409
377
410
try {
@@ -399,8 +432,24 @@ protected DashboardData.OptionalData doInBackground (Connection... conn)
399
432
cis = 0 ;
400
433
}
401
434
435
+ if (rtype == RefreshType .FULL ) {
436
+ try {
437
+ tlradicals = conn [0 ].getRadicals (MeterSpec .T .DASHBOARD_REFRESH .get (MainActivity .this ), level );
438
+ tlkanji = conn [0 ].getKanji (MeterSpec .T .DASHBOARD_REFRESH .get (MainActivity .this ), level );
439
+ tlStatus = DashboardData .OptionalDataStatus .RETRIEVED ;
440
+ } catch (IOException e ) {
441
+ tlStatus = DashboardData .OptionalDataStatus .FAILED ;
442
+ tlradicals = null ;
443
+ tlkanji = null ;
444
+ }
445
+ } else {
446
+ tlradicals = null ;
447
+ tlkanji = null ; /* Failed is weak enough to make merge choose for the older status */
448
+ tlStatus = DashboardData .OptionalDataStatus .FAILED ;
449
+ }
450
+
402
451
return new DashboardData .OptionalData (srs , srsStatus , lp , lpStatus ,
403
- cis , ciStatus );
452
+ cis , ciStatus , tlradicals , tlkanji );
404
453
}
405
454
406
455
/**
@@ -729,9 +778,9 @@ public void onStart ()
729
778
if (resumeRefresh )
730
779
refresh (Tab .RefreshType .LIGHT );
731
780
else if (ldd .isIncomplete ())
732
- refreshOptional ();
781
+ refreshOptional (ldd . level );
733
782
} else
734
- refresh (Tab .RefreshType .LIGHT );
783
+ refresh (Tab .RefreshType .FULL );
735
784
}
736
785
737
786
resumeRefresh = false ;
@@ -914,19 +963,19 @@ private void refresh (Tab.RefreshType rtype)
914
963
915
964
pad .flush (rtype , pager .getCurrentItem ());
916
965
917
- rtask = new RefreshTask ();
966
+ rtask = new RefreshTask (rtype );
918
967
rtask .execute (conn );
919
968
}
920
969
921
970
/**
922
- * Called when optional data needs to be refreshed. This happen in
971
+ * Called when optional data needs to be refreshed. This happens in
923
972
* some strange situations, e.g. when the application is stopped before
924
973
* optional data, and then is resumed from a bundle. I'm not even
925
974
* sure it can happen, however...
926
975
*/
927
- private void refreshOptional ()
976
+ private void refreshOptional (int level )
928
977
{
929
- new RefreshTaskPartII ().execute (conn );
978
+ new RefreshTaskPartII (RefreshType . FULL , level ).execute (conn );
930
979
}
931
980
932
981
/**
0 commit comments