1
1
package it .niedermann .owncloud .notes .edit ;
2
2
3
- import android .app .PendingIntent ;
4
3
import android .content .Context ;
5
- import android .content .Intent ;
6
- import android .content .pm .ShortcutInfo ;
7
- import android .content .pm .ShortcutManager ;
8
4
import android .graphics .Color ;
9
- import android .graphics .drawable .Icon ;
10
5
import android .os .Build ;
11
6
import android .os .Bundle ;
12
7
import android .util .Log ;
42
37
import it .niedermann .owncloud .notes .branding .BrandedFragment ;
43
38
import it .niedermann .owncloud .notes .edit .category .CategoryDialogFragment ;
44
39
import it .niedermann .owncloud .notes .edit .category .CategoryDialogFragment .CategoryDialogListener ;
40
+ import it .niedermann .owncloud .notes .edit .details .NoteDetailsDialogFragment ;
45
41
import it .niedermann .owncloud .notes .edit .title .EditTitleDialogFragment ;
46
42
import it .niedermann .owncloud .notes .edit .title .EditTitleDialogFragment .EditTitleListener ;
47
43
import it .niedermann .owncloud .notes .persistence .NotesRepository ;
48
44
import it .niedermann .owncloud .notes .persistence .entity .Account ;
49
45
import it .niedermann .owncloud .notes .persistence .entity .Note ;
50
- import it .niedermann .owncloud .notes .shared .model .ApiVersion ;
51
46
import it .niedermann .owncloud .notes .shared .model .DBStatus ;
52
47
import it .niedermann .owncloud .notes .shared .model .ISyncCallback ;
53
- import it .niedermann .owncloud .notes .shared .util .ApiVersionUtil ;
54
48
import it .niedermann .owncloud .notes .shared .util .NoteUtil ;
55
49
import it .niedermann .owncloud .notes .shared .util .NotesColorUtil ;
56
50
import it .niedermann .owncloud .notes .shared .util .ShareUtil ;
57
51
58
- import static androidx .core .content .pm .ShortcutManagerCompat .isRequestPinShortcutSupported ;
59
52
import static it .niedermann .owncloud .notes .NotesApplication .isDarkThemeActive ;
60
- import static it .niedermann .owncloud .notes .branding .BrandingUtil .tintMenuIcon ;
61
- import static it .niedermann .owncloud .notes .edit .EditNoteActivity .ACTION_SHORTCUT ;
62
- import static java .lang .Boolean .TRUE ;
63
53
64
54
public abstract class BaseNoteFragment extends BrandedFragment implements CategoryDialogListener , EditTitleListener {
65
55
66
56
private static final String TAG = BaseNoteFragment .class .getSimpleName ();
67
57
protected final ExecutorService executor = Executors .newCachedThreadPool ();
68
58
69
- protected static final int MENU_ID_PIN = -1 ;
70
59
public static final String PARAM_NOTE_ID = "noteId" ;
71
60
public static final String PARAM_ACCOUNT_ID = "accountId" ;
72
61
public static final String PARAM_CONTENT = "content" ;
@@ -185,31 +174,9 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
185
174
public void onCreateOptionsMenu (@ NonNull Menu menu , @ NonNull MenuInflater inflater ) {
186
175
inflater .inflate (R .menu .menu_note_fragment , menu );
187
176
188
- if (isRequestPinShortcutSupported (requireActivity ()) && Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
189
- menu .add (Menu .NONE , MENU_ID_PIN , 110 , R .string .pin_to_homescreen );
190
- }
191
-
192
177
super .onCreateOptionsMenu (menu , inflater );
193
178
}
194
179
195
- @ Override
196
- public void onPrepareOptionsMenu (@ NonNull Menu menu ) {
197
- super .onPrepareOptionsMenu (menu );
198
- if (note != null ) {
199
- prepareFavoriteOption (menu .findItem (R .id .menu_favorite ));
200
-
201
- final ApiVersion preferredApiVersion = ApiVersionUtil .getPreferredApiVersion (localAccount .getApiVersion ());
202
- menu .findItem (R .id .menu_title ).setVisible (preferredApiVersion != null && preferredApiVersion .compareTo (ApiVersion .API_VERSION_1_0 ) >= 0 );
203
- menu .findItem (R .id .menu_delete ).setVisible (!isNew );
204
- }
205
- }
206
-
207
- private void prepareFavoriteOption (MenuItem item ) {
208
- item .setIcon (TRUE .equals (note .getFavorite ()) ? R .drawable .ic_star_white_24dp : R .drawable .ic_star_border_white_24dp );
209
- item .setChecked (note .getFavorite ());
210
- tintMenuIcon (item , colorAccent );
211
- }
212
-
213
180
/**
214
181
* Main-Menu-Handler
215
182
*/
@@ -230,46 +197,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
230
197
repo .deleteNoteAndSync (localAccount , note .getId ());
231
198
listener .close ();
232
199
return true ;
233
- } else if (itemId == R .id .menu_favorite ) {
234
- repo .toggleFavoriteAndSync (localAccount , note .getId ());
235
- listener .onNoteUpdated (note );
236
- prepareFavoriteOption (item );
237
- return true ;
238
- } else if (itemId == R .id .menu_category ) {
239
- showCategorySelector ();
240
- return true ;
241
- } else if (itemId == R .id .menu_title ) {
242
- showEditTitleDialog ();
243
- return true ;
244
200
} else if (itemId == R .id .menu_move ) {
245
201
executor .submit (() -> AccountPickerDialogFragment
246
202
.newInstance (new ArrayList <>(repo .getAccounts ()), note .getAccountId ())
247
203
.show (requireActivity ().getSupportFragmentManager (), BaseNoteFragment .class .getSimpleName ()));
248
204
return true ;
249
- } else if (itemId == R .id .menu_share ) {
250
- ShareUtil .openShareDialog (requireContext (), note .getTitle (), note .getContent ());
251
- return false ;
252
- } else if (itemId == MENU_ID_PIN ) {
253
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
254
- final ShortcutManager shortcutManager = requireActivity ().getSystemService (ShortcutManager .class );
255
- if (shortcutManager != null ) {
256
- if (shortcutManager .isRequestPinShortcutSupported ()) {
257
- final ShortcutInfo pinShortcutInfo = new ShortcutInfo .Builder (getActivity (), note .getId () + "" )
258
- .setShortLabel (note .getTitle ())
259
- .setIcon (Icon .createWithResource (requireActivity ().getApplicationContext (), TRUE .equals (note .getFavorite ()) ? R .drawable .ic_star_yellow_24dp : R .drawable .ic_star_grey_ccc_24dp ))
260
- .setIntent (new Intent (getActivity (), EditNoteActivity .class ).putExtra (EditNoteActivity .PARAM_NOTE_ID , note .getId ()).setAction (ACTION_SHORTCUT ))
261
- .build ();
262
-
263
- shortcutManager .requestPinShortcut (pinShortcutInfo , PendingIntent .getBroadcast (getActivity (), 0 , shortcutManager .createShortcutResultIntent (pinShortcutInfo ), 0 ).getIntentSender ());
264
- } else {
265
- Log .i (TAG , "RequestPinShortcut is not supported" );
266
- }
267
- } else {
268
- Log .e (TAG , ShortcutManager .class .getSimpleName () + " is null" );
269
- }
270
- }
271
-
272
- return true ;
273
205
}
274
206
return super .onOptionsItemSelected (item );
275
207
}
@@ -312,6 +244,7 @@ protected void saveNote(@Nullable ISyncCallback callback) {
312
244
} else {
313
245
Log .v (TAG , "... not saving, since nothing has changed" );
314
246
}
247
+ if (callback != null ) callback .onScheduled ();
315
248
} else {
316
249
// FIXME requires database queries on main thread!
317
250
note = repo .updateNoteAndSync (localAccount , note , newContent , null , callback );
@@ -328,32 +261,26 @@ protected void saveNote(@Nullable ISyncCallback callback) {
328
261
/**
329
262
* Opens a dialog in order to chose a category
330
263
*/
331
- private void showCategorySelector () {
332
- final String fragmentId = "fragment_category" ;
333
- FragmentManager manager = requireActivity ().getSupportFragmentManager ();
334
- Fragment frag = manager .findFragmentByTag (fragmentId );
335
- if (frag != null ) {
336
- manager .beginTransaction ().remove (frag ).commit ();
337
- }
338
- final DialogFragment categoryFragment = CategoryDialogFragment .newInstance (note .getAccountId (), note .getCategory ());
339
- categoryFragment .setTargetFragment (this , 0 );
340
- categoryFragment .show (manager , fragmentId );
341
- }
264
+ public void showNoteDetailsDialog () {
265
+ saveNote (new ISyncCallback () {
266
+ @ Override
267
+ public void onFinish () {
342
268
343
- /**
344
- * Opens a dialog in order to chose a category
345
- */
346
- public void showEditTitleDialog () {
347
- saveNote (null );
348
- final String fragmentId = "fragment_edit_title" ;
349
- FragmentManager manager = requireActivity ().getSupportFragmentManager ();
350
- Fragment frag = manager .findFragmentByTag (fragmentId );
351
- if (frag != null ) {
352
- manager .beginTransaction ().remove (frag ).commit ();
353
- }
354
- DialogFragment editTitleFragment = EditTitleDialogFragment .newInstance (note .getTitle ());
355
- editTitleFragment .setTargetFragment (this , 0 );
356
- editTitleFragment .show (manager , fragmentId );
269
+ }
270
+
271
+ @ Override
272
+ public void onScheduled () {
273
+ final String fragmentId = "fragment_note_details" ;
274
+ final FragmentManager manager = requireActivity ().getSupportFragmentManager ();
275
+ Fragment frag = manager .findFragmentByTag (fragmentId );
276
+ if (frag != null ) {
277
+ manager .beginTransaction ().remove (frag ).commit ();
278
+ }
279
+ DialogFragment noteDetailsFragment = NoteDetailsDialogFragment .newInstance (localAccount , note .getId ());
280
+ noteDetailsFragment .setTargetFragment (BaseNoteFragment .this , 0 );
281
+ noteDetailsFragment .show (manager , fragmentId );
282
+ }
283
+ });
357
284
}
358
285
359
286
@ Override
0 commit comments