@@ -282,38 +282,43 @@ public boolean onOptionsItemSelected(MenuItem item) {
282282 shareNote ();
283283 return false ;
284284 } else if (itemId == MENU_ID_PIN ) {
285- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
286- return true ;
287- }
285+ return pinNoteToHome ();
286+ }
288287
289- if (!ShortcutManagerCompat .isRequestPinShortcutSupported (requireContext ())) {
290- Log .i (TAG , "RequestPinShortcut is not supported" );
291- return true ;
292- }
288+ return super .onOptionsItemSelected (item );
289+ }
293290
294- final var iconId = note .getFavorite () ? R .drawable .ic_star_yellow_24dp : R .drawable .ic_star_border_grey_ccc_24dp ;
295- final var icon = IconCompat .createWithResource (requireContext ().getApplicationContext (), iconId );
296- final var intent = new Intent (getActivity (), EditNoteActivity .class )
297- .putExtra (EditNoteActivity .PARAM_NOTE_ID , note .getRemoteId ())
298- .setAction (ACTION_SHORTCUT );
299- final var noteId = String .valueOf (note .getRemoteId ());
300-
301- final var pinShortcutInfo = new ShortcutInfoCompat .Builder (requireContext (), noteId )
302- .setShortLabel (note .getTitle ())
303- .setIcon (icon )
304- .setIntent (intent )
305- .build ();
306-
307- final var broadcastIntent = ShortcutManagerCompat .createShortcutResultIntent (requireContext (), pinShortcutInfo );
308- final var intentFlag = pendingIntentFlagCompat (0 );
309- final var intentSender = PendingIntent
310- .getBroadcast (requireContext (), 0 , broadcastIntent , intentFlag )
311- .getIntentSender ();
312- ShortcutManagerCompat .requestPinShortcut (requireContext (), pinShortcutInfo , intentSender );
291+ private boolean pinNoteToHome () {
292+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
293+ return true ;
294+ }
313295
296+ if (!ShortcutManagerCompat .isRequestPinShortcutSupported (requireContext ())) {
297+ Log .i (TAG , "RequestPinShortcut is not supported" );
314298 return true ;
315299 }
316- return super .onOptionsItemSelected (item );
300+
301+ final var iconId = note .getFavorite () ? R .drawable .ic_star_yellow_24dp : R .drawable .ic_star_border_grey_ccc_24dp ;
302+ final var icon = IconCompat .createWithResource (requireContext ().getApplicationContext (), iconId );
303+ final var intent = new Intent (getActivity (), EditNoteActivity .class )
304+ .putExtra (EditNoteActivity .PARAM_NOTE_ID , note .getRemoteId ())
305+ .setAction (ACTION_SHORTCUT );
306+ final var noteId = String .valueOf (note .getRemoteId ());
307+
308+ final var pinShortcutInfo = new ShortcutInfoCompat .Builder (requireContext (), noteId )
309+ .setShortLabel (note .getTitle ())
310+ .setIcon (icon )
311+ .setIntent (intent )
312+ .build ();
313+
314+ final var broadcastIntent = ShortcutManagerCompat .createShortcutResultIntent (requireContext (), pinShortcutInfo );
315+ final var intentFlag = pendingIntentFlagCompat (0 );
316+ final var intentSender = PendingIntent
317+ .getBroadcast (requireContext (), 0 , broadcastIntent , intentFlag )
318+ .getIntentSender ();
319+ ShortcutManagerCompat .requestPinShortcut (requireContext (), pinShortcutInfo , intentSender );
320+
321+ return true ;
317322 }
318323
319324 protected void shareNote () {
0 commit comments