@@ -114,6 +114,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
114114 }
115115 isNew = false ;
116116 note = originalNote = repo .getNoteById (id );
117+ if (note == null ) {
118+ Log_OC .d (TAG , "remoteNoteId will be used to get note" );
119+ note = repo .getNoteByRemoteId (id );
120+ }
117121 requireActivity ().runOnUiThread (() -> onNoteLoaded (note ));
118122 requireActivity ().invalidateOptionsMenu ();
119123 } else {
@@ -278,21 +282,35 @@ public boolean onOptionsItemSelected(MenuItem item) {
278282 shareNote ();
279283 return false ;
280284 } else if (itemId == MENU_ID_PIN ) {
281- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
282- final var context = requireContext ();
283- if (ShortcutManagerCompat .isRequestPinShortcutSupported (context )) {
284- final var pinShortcutInfo = new ShortcutInfoCompat .Builder (context , String .valueOf (note .getId ()))
285- .setShortLabel (note .getTitle ())
286- .setIcon (IconCompat .createWithResource (context .getApplicationContext (), TRUE .equals (note .getFavorite ()) ? R .drawable .ic_star_yellow_24dp : R .drawable .ic_star_border_grey_ccc_24dp ))
287- .setIntent (new Intent (getActivity (), EditNoteActivity .class ).putExtra (EditNoteActivity .PARAM_NOTE_ID , note .getId ()).setAction (ACTION_SHORTCUT ))
288- .build ();
289-
290- ShortcutManagerCompat .requestPinShortcut (context , pinShortcutInfo , PendingIntent .getBroadcast (context , 0 , ShortcutManagerCompat .createShortcutResultIntent (context , pinShortcutInfo ), pendingIntentFlagCompat (0 )).getIntentSender ());
291- } else {
292- Log .i (TAG , "RequestPinShortcut is not supported" );
293- }
285+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
286+ return true ;
294287 }
295288
289+ if (!ShortcutManagerCompat .isRequestPinShortcutSupported (requireContext ())) {
290+ Log .i (TAG , "RequestPinShortcut is not supported" );
291+ return true ;
292+ }
293+
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 );
313+
296314 return true ;
297315 }
298316 return super .onOptionsItemSelected (item );
0 commit comments