6
6
*/
7
7
package it .niedermann .owncloud .notes .widget .notelist ;
8
8
9
- import static it .niedermann .owncloud .notes .edit .EditNoteActivity .PARAM_NOTE_ID ;
10
9
import static it .niedermann .owncloud .notes .shared .util .WidgetUtil .pendingIntentFlagCompat ;
11
10
12
11
import android .app .PendingIntent ;
@@ -46,20 +45,15 @@ static void updateAppWidget(Context context, AppWidgetManager awm, int[] appWidg
46
45
47
46
Log .v (TAG , "-- data - " + data );
48
47
49
- Intent createNewNoteIntent = new Intent (context , EditNoteActivity .class );
50
- createNewNoteIntent .setAction ("android.intent.action.SEND" );
51
- createNewNoteIntent .setPackage (context .getPackageName ());
52
-
53
- // TODO distinguish between add and view
54
- // TODO add note it
55
- createNewNoteIntent .putExtra (PARAM_NOTE_ID , -1L );
48
+ Intent editNoteIntent = new Intent (context , EditNoteActivity .class );
49
+ editNoteIntent .setPackage (context .getPackageName ());
56
50
57
51
int pendingIntentFlags = pendingIntentFlagCompat (PendingIntent .FLAG_UPDATE_CURRENT | Intent .FILL_IN_COMPONENT );
58
- PendingIntent createNewNotePendingIntent = PendingIntent .getActivity (context , 0 , createNewNoteIntent , pendingIntentFlags );
52
+ PendingIntent editNotePendingIntent = PendingIntent .getActivity (context , 0 , editNoteIntent , pendingIntentFlags );
59
53
60
54
views = new RemoteViews (context .getPackageName (), R .layout .widget_note_list );
61
55
views .setRemoteAdapter (R .id .note_list_widget_lv , serviceIntent );
62
- views .setPendingIntentTemplate (R .id .note_list_widget_lv , createNewNotePendingIntent );
56
+ views .setPendingIntentTemplate (R .id .note_list_widget_lv , editNotePendingIntent );
63
57
views .setEmptyView (R .id .note_list_widget_lv , R .id .widget_note_list_placeholder_tv );
64
58
65
59
awm .notifyAppWidgetViewDataChanged (appWidgetId , R .id .note_list_widget_lv );
@@ -81,21 +75,28 @@ public void onReceive(Context context, Intent intent) {
81
75
super .onReceive (context , intent );
82
76
final var awm = AppWidgetManager .getInstance (context );
83
77
84
- if (intent .getAction () != null ) {
85
- if (intent .getAction ().equals (AppWidgetManager .ACTION_APPWIDGET_UPDATE )) {
86
- if (intent .hasExtra (AppWidgetManager .EXTRA_APPWIDGET_ID )) {
87
- if (intent .getExtras () != null ) {
88
- updateAppWidget (context , awm , new int []{intent .getExtras ().getInt (AppWidgetManager .EXTRA_APPWIDGET_ID , -1 )});
89
- } else {
90
- Log .w (TAG , "intent.getExtras() is null" );
91
- }
92
- } else {
93
- updateAppWidget (context , awm , awm .getAppWidgetIds (new ComponentName (context , NoteListWidget .class )));
94
- }
95
- }
96
- } else {
97
- Log .w (TAG , "intent.getAction() is null" );
78
+ if (intent .getAction () == null ) {
79
+ Log .w (TAG , "Intent action is null" );
80
+ return ;
98
81
}
82
+
83
+ if (!intent .getAction ().equals (AppWidgetManager .ACTION_APPWIDGET_UPDATE )) {
84
+ Log .w (TAG , "Intent action is not ACTION_APPWIDGET_UPDATE" );
85
+ return ;
86
+ }
87
+
88
+ if (!intent .hasExtra (AppWidgetManager .EXTRA_APPWIDGET_ID )) {
89
+ Log .w (TAG ,"Update widget via default appWidgetIds" );
90
+ updateAppWidget (context , awm , awm .getAppWidgetIds (new ComponentName (context , NoteListWidget .class )));
91
+ }
92
+
93
+ if (intent .getExtras () == null ) {
94
+ Log .w (TAG , "Intent doesn't have bundle" );
95
+ return ;
96
+ }
97
+
98
+ Log .w (TAG ,"Update widget via given appWidgetIds" );
99
+ updateAppWidget (context , awm , new int []{intent .getExtras ().getInt (AppWidgetManager .EXTRA_APPWIDGET_ID , -1 )});
99
100
}
100
101
101
102
@ Override
0 commit comments