Skip to content

Commit

Permalink
add functions to module
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed May 14, 2024
1 parent 967c39f commit bfd163e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit bfd163e

Please sign in to comment.