Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix android widget bugs

Ammar Ahmed9661dd0c5e66
diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsx
index 4cfd4d822..a956f4ea7 100644
--- a/apps/mobile/app/hooks/use-app-events.tsx
+++ b/apps/mobile/app/hooks/use-app-events.tsx
@@ -106,6 +106,7 @@ import { getGithubVersion } from "../utils/github-version";
import { tabBarRef } from "../utils/global-refs";
import { NotesnookModule } from "../utils/notesnook-module";
import { sleep } from "../utils/time";
+import ReminderSheet from "../components/sheets/reminder";
const onCheckSyncStatus = async (type: SyncStatusEvent) => {
const { disableSync, disableAutoSync } = SettingsService.get();
@@ -160,6 +161,8 @@ const onUserSessionExpired = async () => {
const onAppOpenedFromURL = async (event: { url: string }) => {
const url = event.url;
+
+ console.log("URL", url);
try {
if (url.startsWith("https://app.notesnook.com/account/verified")) {
await onUserEmailVerified();
@@ -169,6 +172,25 @@ const onAppOpenedFromURL = async (event: { url: string }) => {
eSendEvent(eOnLoadNote, { newNote: true });
tabBarRef.current?.goToPage(1, false);
return;
+ } else if (url.startsWith("https://notesnook.com/open_note")) {
+ const id = new URL(url).searchParams.get("id");
+ if (id) {
+ const note = await db.notes.note(id);
+ if (note) {
+ eSendEvent(eOnLoadNote, {
+ item: note
+ });
+ tabBarRef.current?.goToPage(1, false);
+ }
+ }
+ } else if (url.startsWith("https://notesnook.com/open_reminder")) {
+ const id = new URL(url).searchParams.get("id");
+ if (id) {
+ const reminder = await db.reminders.reminder(id);
+ if (reminder) ReminderSheet.present(reminder);
+ }
+ } else if (url.startsWith("https://notesnook.com/new_reminder")) {
+ ReminderSheet.present();
}
} catch (e) {
console.error(e);
@@ -694,10 +716,6 @@ export const useAppEvents = () => {
// Reset the editor if the app has been in background for more than 10 minutes.
eSendEvent(eEditorReset);
}
-
- setTimeout(async () => {
- IntentService.onAppStateChanged();
- }, 100);
} else {
await saveEditorState();
if (
diff --git a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java
index 87a87aff2..a6116d8ae 100644
--- a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java
+++ b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/NotePreviewWidget.java
@@ -31,14 +31,20 @@ public class NotePreviewWidget extends AppWidgetProvider {
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(OpenNoteId, note.getId());
+ intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(RCTNNativeModule.IntentType, "OpenNote");
- intent.setData(Uri.parse("https://notesnook.com/open_note"));
+ intent.setData(Uri.parse("https://notesnook.com/open_note?id=" + note.getId()));
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE, getActivityOptionsBundle());
views.setOnClickPendingIntent(R.id.open_note, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
+ @Override
+ public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
+ super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
+ }
+
private static Bundle getActivityOptionsBundle() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ActivityOptions activityOptions = ActivityOptions.makeBasic();
diff --git a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/ReminderViewsService.java b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/ReminderViewsService.java
index 8449ca303..126e372b1 100644
--- a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/ReminderViewsService.java
+++ b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/ReminderViewsService.java
@@ -4,6 +4,7 @@ import android.app.ActivityOptions;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
@@ -45,6 +46,7 @@ class ReminderRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactor
SharedPreferences preferences = context.getSharedPreferences("appPreview", Context.MODE_PRIVATE);
Gson gson = new Gson();
reminders = gson.fromJson(preferences.getString("remindersList","[]"), new TypeToken<List<Reminder>>(){}.getType());
+
}
@Override
@@ -64,14 +66,16 @@ class ReminderRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactor
boolean useMiniLayout = reminder.getDescription() == null || reminder.getDescription().isEmpty();
RemoteViews views = new RemoteViews(context.getPackageName(), useMiniLayout ? R.layout.widget_reminder_layout_small : R.layout.widget_reminder_layout);
+
views.setTextViewText(R.id.reminder_title, reminder.getTitle());
- if (!useMiniLayout) {
+ if (!useMiniLayout) {
views.setTextViewText(R.id.reminder_description, reminder.getDescription());
- }
+ }
views.setTextViewText(R.id.reminder_time, reminder.getFormattedTime());
final Intent fillInIntent = new Intent();
final Bundle extras = new Bundle();
extras.putString(ReminderViewsService.OpenReminderId, reminder.getId());
+ fillInIntent.setData(Uri.parse("https://notesnook.com/open_reminder?id=" + reminder.getId()));
fillInIntent.putExtra(RCTNNativeModule.IntentType, "OpenReminder");
fillInIntent.putExtras(extras);
views.setOnClickFillInIntent(R.id.reminder_item_btn, fillInIntent);
@@ -86,11 +90,12 @@ class ReminderRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactor
@Override
public int getViewTypeCount() {
- return 1;
+ return 2;
}
@Override
public long getItemId(int position) {
+
return position;
}
diff --git a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/ReminderWidgetProvider.java b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/ReminderWidgetProvider.java
index 95c16887d..1b0faf560 100644
--- a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/ReminderWidgetProvider.java
+++ b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/ReminderWidgetProvider.java
@@ -34,12 +34,13 @@ public class ReminderWidgetProvider extends AppWidgetProvider {
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, RemoteViews views) {
Intent listview_intent_template = new Intent(context, MainActivity.class);
- listview_intent_template.setData(Uri.parse("https://notesnook.com/open_reminder"));
+ listview_intent_template.setAction(Intent.ACTION_VIEW);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, listview_intent_template, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE, getActivityOptionsBundle());
views.setPendingIntentTemplate(R.id.widget_list_view, pendingIntent);
Intent new_reminder_intent = new Intent(context, MainActivity.class);
new_reminder_intent.putExtra(NewReminder, NewReminder);
+ new_reminder_intent.setAction(Intent.ACTION_VIEW);
new_reminder_intent.putExtra(RCTNNativeModule.IntentType, "NewReminder");
new_reminder_intent.setData(Uri.parse("https://notesnook.com/new_reminder"));
PendingIntent pendingIntent2 = PendingIntent.getActivity(context, appWidgetId, new_reminder_intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, getActivityOptionsBundle());
diff --git a/apps/mobile/native/android/app/src/main/res/values/colors.xml b/apps/mobile/native/android/app/src/main/res/values/colors.xml
index ec65752c9..4ac8bc762 100644
--- a/apps/mobile/native/android/app/src/main/res/values/colors.xml
+++ b/apps/mobile/native/android/app/src/main/res/values/colors.xml
@@ -5,7 +5,7 @@
<color name="light_blue_600">#FF039BE5</color>
<color name="light_blue_900">#FF01579B</color>
<color name="bootsplash_background">#FFFFFF</color>
- <color name="background">#D8000000</color>
- <color name="border">#CCCCCC</color>
+ <color name="background">#DCEDEDED</color>
+ <color name="border">#BFBFBF</color>
<color name="text">#1D1D1D</color>
</resources>
\ No newline at end of file