From bfd163ec6f232e32ab6b69368a9d7a653c1fb3a0 Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 14 May 2024 13:03:12 -0700 Subject: [PATCH] add functions to module --- .../ExpoBackgroundNotificationHandlerModule.kt | 17 +++++++++++++++++ .../NotificationPrefs.kt | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt index 1f377e75a5..a646d55d97 100644 --- a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt +++ b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt @@ -15,6 +15,23 @@ class ExpoBackgroundNotificationHandlerModule : Module() { Name("ExpoBackgroundNotificationHandler") AsyncFunction("getAllPrefsAsync") { + return@AsyncFunction NotificationPrefs(appContext.reactContext).getAllPrefs() + } + + AsyncFunction("getBoolAsync") { forKey: String -> + return@AsyncFunction NotificationPrefs(appContext.reactContext).getBoolean(forKey) + } + + AsyncFunction("getStringAsync") { forKey: String -> + return@AsyncFunction NotificationPrefs(appContext.reactContext).getString(forKey) + } + + AsyncFunction("setBoolAsync") { forKey: String, value: Boolean -> + NotificationPrefs(appContext.reactContext).setBoolean(forKey, value) + } + + AsyncFunction("setStringAsync") { forKey: String, value: String -> + NotificationPrefs(appContext.reactContext).setString(forKey, value) } OnActivityEntersForeground { diff --git a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt index 8525e722f8..b13749309f 100644 --- a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt +++ b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt @@ -2,8 +2,8 @@ package expo.modules.backgroundnotificationhandler import android.content.Context -class NotificationPrefs (private val context: Context) { - private val prefs = context.getSharedPreferences("xyz.blueskyweb.app", Context.MODE_PRIVATE) +class NotificationPrefs (private val context: Context?) { + private val prefs = context?.getSharedPreferences("xyz.blueskyweb.app", Context.MODE_PRIVATE) ?: throw Error("Context is null") init { if (!prefs.getBoolean("initialized", false)) {