@@ -153,6 +153,10 @@ private void loadExistingNote(long noteId) {
153153
154154 isNew = false ;
155155 note = originalNote = repo .getNoteById (noteId );
156+ if (note == null ) {
157+ Log_OC .d (TAG , "remoteNoteId will be used to get note" );
158+ note = repo .getNoteByRemoteId (noteId );
159+ }
156160 }
157161
158162 private void createNewNote () {
@@ -305,26 +309,43 @@ public boolean onOptionsItemSelected(MenuItem item) {
305309 shareNote ();
306310 return false ;
307311 } else if (itemId == MENU_ID_PIN ) {
308- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
309- final var context = requireContext ();
310- if (ShortcutManagerCompat .isRequestPinShortcutSupported (context )) {
311- final var pinShortcutInfo = new ShortcutInfoCompat .Builder (context , String .valueOf (note .getId ()))
312- .setShortLabel (note .getTitle ())
313- .setIcon (IconCompat .createWithResource (context .getApplicationContext (), TRUE .equals (note .getFavorite ()) ? R .drawable .ic_star_yellow_24dp : R .drawable .ic_star_border_grey_ccc_24dp ))
314- .setIntent (new Intent (getActivity (), EditNoteActivity .class ).putExtra (EditNoteActivity .PARAM_NOTE_ID , note .getId ()).setAction (ACTION_SHORTCUT ))
315- .build ();
316-
317- ShortcutManagerCompat .requestPinShortcut (context , pinShortcutInfo , PendingIntent .getBroadcast (context , 0 , ShortcutManagerCompat .createShortcutResultIntent (context , pinShortcutInfo ), pendingIntentFlagCompat (0 )).getIntentSender ());
318- } else {
319- Log .i (TAG , "RequestPinShortcut is not supported" );
320- }
321- }
322-
312+ pinNoteToHome ();
323313 return true ;
324314 }
325315 return super .onOptionsItemSelected (item );
326316 }
327317
318+ private void pinNoteToHome () {
319+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
320+ return ;
321+ }
322+
323+ if (!ShortcutManagerCompat .isRequestPinShortcutSupported (requireContext ())) {
324+ Log .i (TAG , "RequestPinShortcut is not supported" );
325+ return ;
326+ }
327+
328+ final var iconId = note .getFavorite () ? R .drawable .ic_star_yellow_24dp : R .drawable .ic_star_border_grey_ccc_24dp ;
329+ final var icon = IconCompat .createWithResource (requireContext ().getApplicationContext (), iconId );
330+ final var intent = new Intent (getActivity (), EditNoteActivity .class )
331+ .putExtra (EditNoteActivity .PARAM_NOTE_ID , note .getRemoteId ())
332+ .setAction (ACTION_SHORTCUT );
333+ final var noteId = String .valueOf (note .getRemoteId ());
334+
335+ final var pinShortcutInfo = new ShortcutInfoCompat .Builder (requireContext (), noteId )
336+ .setShortLabel (note .getTitle ())
337+ .setIcon (icon )
338+ .setIntent (intent )
339+ .build ();
340+
341+ final var broadcastIntent = ShortcutManagerCompat .createShortcutResultIntent (requireContext (), pinShortcutInfo );
342+ final var intentFlag = pendingIntentFlagCompat (0 );
343+ final var intentSender = PendingIntent
344+ .getBroadcast (requireContext (), 0 , broadcastIntent , intentFlag )
345+ .getIntentSender ();
346+ ShortcutManagerCompat .requestPinShortcut (requireContext (), pinShortcutInfo , intentSender );
347+ }
348+
328349 protected void shareNote () {
329350 if (note == null ) {
330351 Log_OC .w (TAG , "Note is null in shareNote" );
0 commit comments