diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 7ccd22a4784..6f1ee6536b1 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -3230,7 +3230,7 @@ public class com/facebook/react/modules/devloading/DevLoadingModule : com/facebo public fun showMessage (Ljava/lang/String;Ljava/lang/Double;Ljava/lang/Double;)V } -public class com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule : com/facebook/fbreact/specs/NativeDevToolsSettingsManagerSpec { +public final class com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule : com/facebook/fbreact/specs/NativeDevToolsSettingsManagerSpec { public fun (Lcom/facebook/react/bridge/ReactApplicationContext;)V public fun getConsolePatchSettings ()Ljava/lang/String; public fun getProfilingSettings ()Ljava/lang/String; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule.java deleted file mode 100644 index 00e56e2ad36..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.modules.devtoolssettings; - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import androidx.annotation.Nullable; -import com.facebook.fbreact.specs.NativeDevToolsSettingsManagerSpec; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.module.annotations.ReactModule; - -@ReactModule(name = NativeDevToolsSettingsManagerSpec.NAME) -public class DevToolsSettingsManagerModule extends NativeDevToolsSettingsManagerSpec { - private static final String SHARED_PREFERENCES_PREFIX = "ReactNative__DevToolsSettings"; - private static final String KEY_CONSOLE_PATCH_SETTINGS = "ConsolePatchSettings"; - private static final String KEY_PROFILING_SETTINGS = "ProfilingSettings"; - - private final SharedPreferences mSharedPreferences; - - public DevToolsSettingsManagerModule(ReactApplicationContext reactContext) { - super(reactContext); - mSharedPreferences = - reactContext.getSharedPreferences(SHARED_PREFERENCES_PREFIX, Context.MODE_PRIVATE); - } - - @Override - public @Nullable String getConsolePatchSettings() { - return mSharedPreferences.getString(KEY_CONSOLE_PATCH_SETTINGS, null); - } - - @Override - public void setConsolePatchSettings(String newSettings) { - Editor editor = mSharedPreferences.edit(); - editor.putString(KEY_CONSOLE_PATCH_SETTINGS, newSettings); - editor.apply(); - } - - @Override - public @Nullable String getProfilingSettings() { - return mSharedPreferences.getString(KEY_PROFILING_SETTINGS, null); - } - - @Override - public void setProfilingSettings(String newSettings) { - mSharedPreferences.edit().putString(KEY_PROFILING_SETTINGS, newSettings).apply(); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule.kt new file mode 100644 index 00000000000..4b1305fe066 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/devtoolssettings/DevToolsSettingsManagerModule.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.modules.devtoolssettings + +import android.content.Context +import android.content.SharedPreferences +import com.facebook.fbreact.specs.NativeDevToolsSettingsManagerSpec +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.module.annotations.ReactModule + +@ReactModule(name = NativeDevToolsSettingsManagerSpec.NAME) +public class DevToolsSettingsManagerModule(reactContext: ReactApplicationContext) : + NativeDevToolsSettingsManagerSpec(reactContext) { + + private val sharedPreferences: SharedPreferences = + reactContext.getSharedPreferences(SHARED_PREFERENCES_PREFIX, Context.MODE_PRIVATE) + + public override fun getConsolePatchSettings(): String? = + sharedPreferences.getString(KEY_CONSOLE_PATCH_SETTINGS, null) + + public override fun setConsolePatchSettings(newSettings: String?): Unit = + sharedPreferences.edit().putString(KEY_CONSOLE_PATCH_SETTINGS, newSettings).apply() + + public override fun getProfilingSettings(): String? = + sharedPreferences.getString(KEY_PROFILING_SETTINGS, null) + + public override fun setProfilingSettings(newSettings: String?): Unit = + sharedPreferences.edit().putString(KEY_PROFILING_SETTINGS, newSettings).apply() + + private companion object { + private const val SHARED_PREFERENCES_PREFIX = "ReactNative__DevToolsSettings" + private const val KEY_CONSOLE_PATCH_SETTINGS = "ConsolePatchSettings" + private const val KEY_PROFILING_SETTINGS = "ProfilingSettings" + } +}