Skip to content

Commit edf5990

Browse files
refactor: remove deprecated APIs and improve serialization handling
1 parent d76066a commit edf5990

7 files changed

Lines changed: 38 additions & 53 deletions

File tree

android/src/main/java/com/mendix/mendixnative/MendixApplication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.mendix.mendixnative.react.splash.MendixSplashScreenPresenter;
66

77
import java.util.List;
8-
import java.util.Map;
98

109
public interface MendixApplication extends ReactApplication {
1110
boolean getUseDeveloperSupport();

android/src/main/java/com/mendix/mendixnative/MendixInitializer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.mendix.mendixnative
22

33
import android.app.Activity
44
import com.facebook.react.ReactHost
5-
import com.facebook.react.devsupport.DevSupportManagerBase
65
import com.facebook.react.modules.network.OkHttpClientProvider
76
import com.mendix.mendixnative.config.AppPreferences
87
import com.mendix.mendixnative.react.*

android/src/main/java/com/mendix/mendixnative/activity/MendixReactActivity.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package com.mendix.mendixnative.activity
22

3+
import android.os.Build
34
import android.os.Bundle
45
import android.view.KeyEvent
56
import com.facebook.react.ReactActivity
67
import com.facebook.react.ReactActivityDelegate
7-
import com.facebook.react.bridge.ReactContext
88
import com.facebook.react.devsupport.interfaces.DevSupportManager
99
import com.mendix.mendixnative.DevAppMenuHandler
1010
import com.mendix.mendixnative.MendixApplication
1111
import com.mendix.mendixnative.MendixInitializer
1212
import com.mendix.mendixnative.react.MendixApp
1313
import com.mendix.mendixnative.react.splash.MendixSplashScreenPresenter
1414
import com.mendix.mendixnative.util.MendixBackwardsCompatUtility
15+
import java.io.Serializable
1516

1617
open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScreenHandler {
1718

@@ -24,7 +25,7 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
2425

2526
override fun onCreate(savedInstanceState: Bundle?) {
2627
mendixApp = mendixApp
27-
?: intent.getSerializableExtra(MENDIX_APP_INTENT_KEY) as? MendixApp
28+
?: getSerializableData(MENDIX_APP_INTENT_KEY, MendixApp::class.java)
2829
?: throw IllegalStateException("MendixApp configuration can't be null")
2930
val mendixApplication = application as? MendixApplication
3031
?: throw ClassCastException("Application needs to implement MendixApplication")
@@ -36,6 +37,19 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
3637
super.onCreate(null)
3738
}
3839

40+
inline fun <reified T : Serializable> getSerializableData(key: String?, clazz: Class<T>): T? {
41+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
42+
intent.getSerializableExtra<T?>(key, clazz)
43+
} else {
44+
@Suppress("DEPRECATION")
45+
val data = intent.getSerializableExtra(key)
46+
if (data is T) {
47+
return data
48+
}
49+
return null
50+
}
51+
}
52+
3953
override fun onDestroy() {
4054
mendixInitializer.onDestroy()
4155
super.onDestroy()
@@ -46,12 +60,9 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
4660
}
4761

4862
override fun showDevAppMenu() {
49-
currentDevSupportManager?.showDevOptionsDialog();
63+
currentDevSupportManager?.showDevOptionsDialog()
5064
}
5165

52-
private val currentReactContext: ReactContext?
53-
get() = reactHost.currentReactContext
54-
5566
val currentDevSupportManager: DevSupportManager?
5667
get() = reactHost.devSupportManager
5768

android/src/main/java/com/mendix/mendixnative/fragment/MendixReactFragment.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mendix.mendixnative.fragment
22

33
import android.content.Intent
4+
import android.os.Build
45
import android.os.Bundle
56
import android.view.KeyEvent
67
import com.facebook.react.devsupport.interfaces.DevSupportManager
@@ -9,6 +10,7 @@ import com.mendix.mendixnative.MendixInitializer
910
import com.mendix.mendixnative.activity.LaunchScreenHandler
1011
import com.mendix.mendixnative.react.MendixApp
1112
import com.mendix.mendixnative.util.MendixDoubleTapRecognizer
13+
import java.io.Serializable
1214

1315
/**
1416
* Class used for Sample apps
@@ -54,7 +56,7 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
5456
}
5557

5658
if (mendixApp == null) {
57-
mendixApp = requireArguments().getSerializable(ARG_MENDIX_APP) as MendixApp?
59+
mendixApp = getSerializableData(ARG_MENDIX_APP, MendixApp::class.java)
5860
?: throw IllegalArgumentException("Mendix app is required")
5961
}
6062

@@ -73,6 +75,19 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
7375
super.onCreate(savedInstanceState)
7476
}
7577

78+
inline fun <reified T : Serializable> getSerializableData(key: String?, clazz: Class<T>): T? {
79+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
80+
requireArguments().getSerializable<T?>(key, clazz)
81+
} else {
82+
@Suppress("DEPRECATION")
83+
val data = requireArguments().getSerializable(key)
84+
if (data is T) {
85+
return data
86+
}
87+
return null
88+
}
89+
}
90+
7691
fun onNewIntent(intent: Intent) {
7792
reactHost?.currentReactContext?.let {
7893
it.onNewIntent(it.currentActivity, intent)
@@ -100,7 +115,7 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
100115

101116
override fun showDevAppMenu() {
102117
activity?.let {
103-
currentDevSupportManager?.showDevOptionsDialog();
118+
currentDevSupportManager?.showDevOptionsDialog()
104119
}
105120
}
106121

android/src/main/java/com/mendix/mendixnative/react/ClearData.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ fun clearDataWithReactContext(applicationContext: Application, reactHost: ReactH
4848
deleteAppDatabaseAsync(reactContext, object : BooleanCallback {
4949
var fired = false
5050

51-
override fun invoke(success: Boolean) {
51+
override fun invoke(res: Boolean) {
5252
if (fired) return
5353

5454
fired = true
5555

56-
if (!success) {
56+
if (!res) {
5757
reportError("database")
5858
}
5959

@@ -62,7 +62,7 @@ fun clearDataWithReactContext(applicationContext: Application, reactHost: ReactH
6262
}
6363

6464
clearSecureStorage(reactContext?.applicationContext)
65-
if (!success) {
65+
if (!res) {
6666
reportError("encrypted storage")
6767
}
6868

android/src/main/java/com/mendix/mendixnative/react/cookie/NativeCookieModule.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package com.mendix.mendixnative.react.cookie
22

33
import com.facebook.react.bridge.Promise
44
import com.facebook.react.bridge.ReactApplicationContext
5-
import com.facebook.react.bridge.WritableMap
6-
import com.facebook.react.bridge.WritableNativeMap
75
import com.facebook.react.modules.network.ForwardingCookieHandler
86

97
class NativeCookieModule(val reactContext: ReactApplicationContext) {
108
fun clearAll(promise: Promise) {
11-
ForwardingCookieHandler(reactContext).clearCookies {
9+
ForwardingCookieHandler().clearCookies {
1210
promise.resolve(null)
1311
}
1412
}

android/src/main/java/com/mendix/mendixnative/util/MendixBackwardsCompatUtility.kt

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)