Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit bf8c90f

Browse files
kunall17niftynei
authored andcommitted
Setup AsycGetEvents in ZulipWidget
1 parent 03de63f commit bf8c90f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

app/src/main/java/com/zulip/android/widget/ZulipWidget.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
import com.zulip.android.R;
1313
import com.zulip.android.ZulipApp;
14+
import com.zulip.android.networking.AsyncGetEvents;
1415

1516
import static com.zulip.android.widget.WidgetPreferenceFragment.FROM_PREFERENCE;
1617
import static com.zulip.android.widget.WidgetPreferenceFragment.INTERVAL_PREFERENCE;
1718
import static com.zulip.android.widget.WidgetPreferenceFragment.TITLE_PREFRENCE;
1819

1920

2021
public class ZulipWidget extends AppWidgetProvider {
22+
private static AsyncGetEvents asyncGetEvents;
2123
private static int intervalMilliseconds = 0;
2224

2325
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
@@ -37,13 +39,19 @@ static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
3739
remoteViews.setRemoteAdapter(appWidgetId, R.id.widget_list, intent);
3840
remoteViews.setEmptyView(R.id.widget_list, R.id.widget_nomsg);
3941

42+
if (asyncGetEvents == null) {
43+
setupGetEvents();
44+
}
4045
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
4146
}
4247
}
4348

4449
@Override
4550
public void onReceive(Context context, Intent intent) {
4651
final String action = intent.getAction();
52+
if (asyncGetEvents == null) {
53+
setupGetEvents();
54+
}
4755
super.onReceive(context, intent);
4856
}
4957

@@ -55,6 +63,10 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
5563
}
5664
}
5765

66+
private static void setupGetEvents() {
67+
asyncGetEvents = new AsyncGetEvents(ZulipApp.get(), intervalMilliseconds);
68+
asyncGetEvents.start();
69+
}
5870

5971
@Override
6072
public void onDeleted(Context context, int[] appWidgetIds) {
@@ -66,6 +78,7 @@ public void onEnabled(Context context) {
6678

6779
@Override
6880
public void onDisabled(Context context) {
81+
asyncGetEvents = null;
6982
}
7083
}
7184

0 commit comments

Comments
 (0)