11
11
12
12
import com .zulip .android .R ;
13
13
import com .zulip .android .ZulipApp ;
14
+ import com .zulip .android .networking .AsyncGetEvents ;
14
15
15
16
import static com .zulip .android .widget .WidgetPreferenceFragment .FROM_PREFERENCE ;
16
17
import static com .zulip .android .widget .WidgetPreferenceFragment .INTERVAL_PREFERENCE ;
17
18
import static com .zulip .android .widget .WidgetPreferenceFragment .TITLE_PREFRENCE ;
18
19
19
20
20
21
public class ZulipWidget extends AppWidgetProvider {
22
+ private static AsyncGetEvents asyncGetEvents ;
21
23
private static int intervalMilliseconds = 0 ;
22
24
23
25
static void updateAppWidget (Context context , AppWidgetManager appWidgetManager , int appWidgetId ) {
@@ -37,13 +39,19 @@ static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
37
39
remoteViews .setRemoteAdapter (appWidgetId , R .id .widget_list , intent );
38
40
remoteViews .setEmptyView (R .id .widget_list , R .id .widget_nomsg );
39
41
42
+ if (asyncGetEvents == null ) {
43
+ setupGetEvents ();
44
+ }
40
45
appWidgetManager .updateAppWidget (appWidgetId , remoteViews );
41
46
}
42
47
}
43
48
44
49
@ Override
45
50
public void onReceive (Context context , Intent intent ) {
46
51
final String action = intent .getAction ();
52
+ if (asyncGetEvents == null ) {
53
+ setupGetEvents ();
54
+ }
47
55
super .onReceive (context , intent );
48
56
}
49
57
@@ -55,6 +63,10 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
55
63
}
56
64
}
57
65
66
+ private static void setupGetEvents () {
67
+ asyncGetEvents = new AsyncGetEvents (ZulipApp .get (), intervalMilliseconds );
68
+ asyncGetEvents .start ();
69
+ }
58
70
59
71
@ Override
60
72
public void onDeleted (Context context , int [] appWidgetIds ) {
@@ -66,6 +78,7 @@ public void onEnabled(Context context) {
66
78
67
79
@ Override
68
80
public void onDisabled (Context context ) {
81
+ asyncGetEvents = null ;
69
82
}
70
83
}
71
84
0 commit comments