3
3
import android .app .PendingIntent ;
4
4
import android .appwidget .AppWidgetManager ;
5
5
import android .appwidget .AppWidgetProvider ;
6
+ import android .content .ComponentName ;
6
7
import android .content .Context ;
7
8
import android .content .Intent ;
8
9
import android .net .Uri ;
21
22
public class ZulipWidget extends AppWidgetProvider {
22
23
private static AsyncGetEvents asyncGetEvents ;
23
24
private static int intervalMilliseconds = 0 ;
25
+ public static String WIDGET_REFRESH = "com.zulip.android.zulipwidget.REFRESH" ;
24
26
25
27
static void updateAppWidget (Context context , AppWidgetManager appWidgetManager , int appWidgetId ) {
26
28
String title = ZulipWidgetConfigureActivity .loadPref (context , appWidgetId , TITLE_PREFRENCE );
@@ -42,6 +44,10 @@ static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
42
44
if (asyncGetEvents == null ) {
43
45
setupGetEvents ();
44
46
}
47
+ final Intent refreshIntent = new Intent (context , ZulipWidget .class );
48
+ refreshIntent .setAction (ZulipWidget .WIDGET_REFRESH );
49
+ final PendingIntent refreshPendingIntent = PendingIntent .getBroadcast (context , 0 , refreshIntent , PendingIntent .FLAG_UPDATE_CURRENT );
50
+ remoteViews .setOnClickPendingIntent (R .id .widget_refresh , refreshPendingIntent );
45
51
appWidgetManager .updateAppWidget (appWidgetId , remoteViews );
46
52
}
47
53
}
@@ -52,6 +58,12 @@ public void onReceive(Context context, Intent intent) {
52
58
if (asyncGetEvents == null ) {
53
59
setupGetEvents ();
54
60
}
61
+ if (action .equals (WIDGET_REFRESH )) {
62
+ final AppWidgetManager mgr = AppWidgetManager .getInstance (context );
63
+ final ComponentName cn = new ComponentName (context , ZulipWidget .class );
64
+ mgr .notifyAppWidgetViewDataChanged (mgr .getAppWidgetIds (cn ), R .id .widget_list );
65
+ asyncGetEvents .interrupt ();
66
+ }
55
67
super .onReceive (context , intent );
56
68
}
57
69
0 commit comments