Skip to content

Commit

Permalink
Merge pull request #84 from godmodelabs/feature/MYR-8827
Browse files Browse the repository at this point in the history
[MYR-8827]: Listen to correct broadcast event
  • Loading branch information
TimPohrer authored Jan 9, 2024
2 parents 045ee6f + 6a6b73e commit aae56d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/main/java/ag/boersego/bgjs/modules/BGJSModuleLocalStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class BGJSModuleLocalStorage private constructor(applicationContext: Context) :
val key = arguments[0] as String
val value = when (arguments[1]) {
is JNIV8Undefined -> "undefined"
null -> "null"
else -> arguments[1].toString()
null -> "null"
else -> arguments[1].toString()
}
preferences.edit().putString(key, value).apply()

Expand All @@ -113,26 +113,27 @@ class BGJSModuleLocalStorage private constructor(applicationContext: Context) :
preferences.registerOnSharedPreferenceChangeListener(listener)
}

fun getItem(key: String) : String {
fun getItem(key: String): String {
return preferences.getString(key, "") ?: ""
}

companion object {
const val SHARED_PREFS_LOCALSTORAGE = "localStorage"
private const val SHARED_PREFS_INSERT_ORDER = "insertOrder"
private const val INSERT_ORDER_KEY = "insert_order"
@Volatile private var instance: BGJSModuleLocalStorage? = null
@Volatile
private var instance: BGJSModuleLocalStorage? = null

@JvmStatic
fun getInstance(ctx : Context) : BGJSModuleLocalStorage {
fun getInstance(ctx: Context): BGJSModuleLocalStorage {
val i = instance
if(i != null) {
if (i != null) {
return i
}

return synchronized(this) {
val i2 = instance
if(i2 != null) {
if (i2 != null) {
i2
} else {
val created = BGJSModuleLocalStorage(ctx)
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/ag/boersego/bgjs/modules/BGJSModulePlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import java.util.*
class BGJSModulePlatform(applicationContext: Context, v8Engine: V8Engine, val appVersion: String) : JNIV8Module("platform") {
private var isTablet = applicationContext.resources.getBoolean(R.bool.isTablet)
private val intentFilter = IntentFilter().apply {
addAction(Intent.ACTION_LOCALE_CHANGED)
addAction(Intent.ACTION_TIMEZONE_CHANGED)
addAction(ACTION_LOCALE_CHANGED)
}

private lateinit var eventBus: JNIV8GenericObject

private var localeChangedReciever = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
when (intent?.action) {
Intent.ACTION_LOCALE_CHANGED -> eventBus.callV8Method("dispatch", "platform:locale", Locale.getDefault().toString())
ACTION_LOCALE_CHANGED -> eventBus.callV8Method("dispatch", "platform:locale", Locale.getDefault().toString())
Intent.ACTION_TIMEZONE_CHANGED -> eventBus.callV8Method("dispatch", "platform:timeZone", TimeZone.getDefault().id)
}
}
Expand Down Expand Up @@ -56,7 +56,6 @@ class BGJSModulePlatform(applicationContext: Context, v8Engine: V8Engine, val ap
}

companion object {
private val TAG = BGJSModulePlatform::class.java.simpleName
const val ACTION_LOCALE_CHANGED = "actionLocaleChanged"
}

}

0 comments on commit aae56d3

Please sign in to comment.