From 9b29503b1717d5bd1ea530dfeb80180c500fa9a1 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Mon, 27 Jul 2026 10:08:16 +0500 Subject: [PATCH] mobile: added onRestored() that migrates each stored note in the appPreview prefs from its old widget ID key to the new one. --- .../android/app/src/main/AndroidManifest.xml | 1 + .../notesnook/NotePreviewWidget.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/apps/mobile/android/app/src/main/AndroidManifest.xml b/apps/mobile/android/app/src/main/AndroidManifest.xml index 4f46df45c..877df5eca 100644 --- a/apps/mobile/android/app/src/main/AndroidManifest.xml +++ b/apps/mobile/android/app/src/main/AndroidManifest.xml @@ -88,6 +88,7 @@ android:label="@string/note"> " + newKeys = new HashSet<>(); + for (int i = 0; i < count; i++) { + notes[i] = preferences.getString(String.valueOf(oldWidgetIds[i]), ""); + newKeys.add(String.valueOf(newWidgetIds[i])); + } + + SharedPreferences.Editor edit = preferences.edit(); + for (int i = 0; i < count; i++) { + String oldKey = String.valueOf(oldWidgetIds[i]); + if (!newKeys.contains(oldKey)) { + edit.remove(oldKey); + } + } + for (int i = 0; i < count; i++) { + if (notes[i].isEmpty()) continue; + edit.putString(String.valueOf(newWidgetIds[i]), notes[i]); + } + edit.apply(); + } + @Override public void onDeleted(Context context, int[] appWidgetIds) { super.onDeleted(context, appWidgetIds);