6
6
*/
7
7
package it .niedermann .owncloud .notes .widget .notelist ;
8
8
9
+ import static it .niedermann .owncloud .notes .edit .EditNoteActivity .PARAM_CATEGORY ;
10
+ import static it .niedermann .owncloud .notes .persistence .entity .NotesListWidgetData .MODE_DISPLAY_ALL ;
11
+ import static it .niedermann .owncloud .notes .persistence .entity .NotesListWidgetData .MODE_DISPLAY_CATEGORY ;
12
+ import static it .niedermann .owncloud .notes .persistence .entity .NotesListWidgetData .MODE_DISPLAY_STARRED ;
13
+
9
14
import android .appwidget .AppWidgetManager ;
10
15
import android .content .ComponentName ;
11
16
import android .content .Context ;
33
38
import it .niedermann .owncloud .notes .shared .model .NavigationCategory ;
34
39
import it .niedermann .owncloud .notes .shared .util .NotesColorUtil ;
35
40
36
- import static it .niedermann .owncloud .notes .edit .EditNoteActivity .PARAM_CATEGORY ;
37
- import static it .niedermann .owncloud .notes .persistence .entity .NotesListWidgetData .MODE_DISPLAY_ALL ;
38
- import static it .niedermann .owncloud .notes .persistence .entity .NotesListWidgetData .MODE_DISPLAY_CATEGORY ;
39
- import static it .niedermann .owncloud .notes .persistence .entity .NotesListWidgetData .MODE_DISPLAY_STARRED ;
40
-
41
41
public class NoteListWidgetFactory implements RemoteViewsService .RemoteViewsFactory {
42
42
private static final String TAG = NoteListWidgetFactory .class .getSimpleName ();
43
43
@@ -79,7 +79,7 @@ public void onDataSetChanged() {
79
79
}
80
80
}
81
81
} catch (IllegalArgumentException e ) {
82
- e . printStackTrace ( );
82
+ Log . w ( TAG , "Error caught at onDataSetChanged: " + e );
83
83
}
84
84
}
85
85
@@ -93,25 +93,44 @@ public int getCount() {
93
93
return dbNotes .size () + 1 ;
94
94
}
95
95
96
+ private Intent getEditNoteIntent (Bundle bundle ) {
97
+ final Intent intent = new Intent (context , EditNoteActivity .class );
98
+ intent .setPackage (context .getPackageName ());
99
+ intent .putExtras (bundle );
100
+ intent .setData (Uri .parse (intent .toUri (Intent .URI_INTENT_SCHEME )));
101
+
102
+ return intent ;
103
+ }
104
+
105
+ private Intent getCreateNoteIntent (Account localAccount ) {
106
+ final Bundle bundle = new Bundle ();
107
+ bundle .putSerializable (PARAM_CATEGORY , data .getMode () == MODE_DISPLAY_STARRED ? new NavigationCategory (ENavigationCategoryType .FAVORITES ) : new NavigationCategory (localAccount .getId (), data .getCategory ()));
108
+ bundle .putLong (EditNoteActivity .PARAM_ACCOUNT_ID , data .getAccountId ());
109
+
110
+ return getEditNoteIntent (bundle );
111
+ }
112
+
113
+ private Intent getOpenNoteIntent (Note note ) {
114
+ final Bundle bundle = new Bundle ();
115
+ bundle .putLong (EditNoteActivity .PARAM_NOTE_ID , note .getId ());
116
+ bundle .putLong (EditNoteActivity .PARAM_ACCOUNT_ID , note .getAccountId ());
117
+
118
+ return getEditNoteIntent (bundle );
119
+ }
120
+
96
121
@ Override
97
122
public RemoteViews getViewAt (int position ) {
98
123
final RemoteViews note_content ;
99
124
100
125
if (position == 0 ) {
101
126
final Account localAccount = repo .getAccountById (data .getAccountId ());
102
- final Intent openIntent = new Intent (Intent .ACTION_MAIN ).setComponent (new ComponentName (context .getPackageName (), MainActivity .class .getName ()));
103
- final Intent createIntent = new Intent (context , EditNoteActivity .class );
104
- final Bundle extras = new Bundle ();
105
-
106
- extras .putSerializable (PARAM_CATEGORY , data .getMode () == MODE_DISPLAY_STARRED ? new NavigationCategory (ENavigationCategoryType .FAVORITES ) : new NavigationCategory (localAccount .getId (), data .getCategory ()));
107
- extras .putLong (EditNoteActivity .PARAM_ACCOUNT_ID , data .getAccountId ());
108
127
109
- createIntent . putExtras ( extras );
110
- createIntent . setData ( Uri . parse ( createIntent . toUri ( Intent . URI_INTENT_SCHEME )));
128
+ final Intent createNoteIntent = getCreateNoteIntent ( localAccount );
129
+ final Intent openIntent = new Intent ( Intent . ACTION_MAIN ). setComponent ( new ComponentName ( context . getPackageName (), MainActivity . class . getName ( )));
111
130
112
131
note_content = new RemoteViews (context .getPackageName (), R .layout .widget_entry_add );
113
132
note_content .setOnClickFillInIntent (R .id .widget_entry_content_tv , openIntent );
114
- note_content .setOnClickFillInIntent (R .id .widget_entry_fav_icon , createIntent );
133
+ note_content .setOnClickFillInIntent (R .id .widget_entry_fav_icon , createNoteIntent );
115
134
note_content .setTextViewText (R .id .widget_entry_content_tv , getCategoryTitle (context , data .getMode (), data .getCategory ()));
116
135
note_content .setImageViewResource (R .id .widget_entry_fav_icon , R .drawable .ic_add_blue_24dp );
117
136
note_content .setInt (R .id .widget_entry_fav_icon , "setColorFilter" , NotesColorUtil .contrastRatioIsSufficient (ContextCompat .getColor (context , R .color .widget_background ), localAccount .getColor ())
@@ -125,16 +144,10 @@ public RemoteViews getViewAt(int position) {
125
144
}
126
145
127
146
final Note note = dbNotes .get (position );
128
- final Intent fillInIntent = new Intent (context , EditNoteActivity .class );
129
- final Bundle extras = new Bundle ();
130
- extras .putLong (EditNoteActivity .PARAM_NOTE_ID , note .getId ());
131
- extras .putLong (EditNoteActivity .PARAM_ACCOUNT_ID , note .getAccountId ());
132
-
133
- fillInIntent .putExtras (extras );
134
- fillInIntent .setData (Uri .parse (fillInIntent .toUri (Intent .URI_INTENT_SCHEME )));
147
+ final Intent openNoteIntent = getOpenNoteIntent (note );
135
148
136
149
note_content = new RemoteViews (context .getPackageName (), R .layout .widget_entry );
137
- note_content .setOnClickFillInIntent (R .id .widget_note_list_entry , fillInIntent );
150
+ note_content .setOnClickFillInIntent (R .id .widget_note_list_entry , openNoteIntent );
138
151
note_content .setTextViewText (R .id .widget_entry_content_tv , note .getTitle ());
139
152
note_content .setImageViewResource (R .id .widget_entry_fav_icon , note .getFavorite ()
140
153
? R .drawable .ic_star_yellow_24dp
0 commit comments