Skip to content

Commit 2534348

Browse files
alperozturk96backportbot[bot]
authored andcommitted
fix git conflict
Signed-off-by: alperozturk <[email protected]> [skip ci]
1 parent 4dede7c commit 2534348

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {
@@ -325,6 +329,37 @@ public boolean onOptionsItemSelected(MenuItem item) {
325329
return super.onOptionsItemSelected(item);
326330
}
327331

332+
private void pinNoteToHome() {
333+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
334+
return;
335+
}
336+
337+
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(requireContext())) {
338+
Log.i(TAG, "RequestPinShortcut is not supported");
339+
return;
340+
}
341+
342+
final var iconId = note.getFavorite() ? R.drawable.ic_star_yellow_24dp : R.drawable.ic_star_border_grey_ccc_24dp;
343+
final var icon = IconCompat.createWithResource(requireContext().getApplicationContext(), iconId);
344+
final var intent = new Intent(getActivity(), EditNoteActivity.class)
345+
.putExtra(EditNoteActivity.PARAM_NOTE_ID, note.getRemoteId())
346+
.setAction(ACTION_SHORTCUT);
347+
final var noteId = String.valueOf(note.getRemoteId());
348+
349+
final var pinShortcutInfo = new ShortcutInfoCompat.Builder(requireContext(), noteId)
350+
.setShortLabel(note.getTitle())
351+
.setIcon(icon)
352+
.setIntent(intent)
353+
.build();
354+
355+
final var broadcastIntent = ShortcutManagerCompat.createShortcutResultIntent(requireContext(), pinShortcutInfo);
356+
final var intentFlag = pendingIntentFlagCompat(0);
357+
final var intentSender = PendingIntent
358+
.getBroadcast(requireContext(), 0, broadcastIntent, intentFlag)
359+
.getIntentSender();
360+
ShortcutManagerCompat.requestPinShortcut(requireContext(), pinShortcutInfo, intentSender);
361+
}
362+
328363
protected void shareNote() {
329364
if (note == null) {
330365
Log_OC.w(TAG, "Note is null in shareNote");

0 commit comments

Comments
 (0)