react-native-firework-sdk 1.2.4 → 1.3.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -180,7 +180,6 @@ dependencies {
180
180
  // noinspection GradleDynamicVersion
181
181
  api 'com.facebook.react:react-native:+'
182
182
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
183
- implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.6"
184
183
  implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
185
184
  // required to avoid crash on Android 12 API 31
186
185
  implementation 'androidx.work:work-runtime-ktx:2.7.0'
@@ -189,6 +188,8 @@ dependencies {
189
188
  implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
190
189
  // react-native 0.61.3
191
190
  implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
191
+
192
+ implementation "com.google.code.gson:gson:2.9.0"
192
193
  }
193
194
 
194
195
  configurations.all {
@@ -1,7 +1,7 @@
1
1
  package com.fireworksdk.bridge.models
2
2
 
3
3
  import android.os.Parcelable
4
- import com.fasterxml.jackson.annotation.JsonProperty
4
+ import com.google.gson.annotations.SerializedName
5
5
  import kotlinx.android.parcel.Parcelize
6
6
 
7
7
  @Parcelize
@@ -10,10 +10,10 @@ data class FWVideoPlaybackDetails(
10
10
  val badge: String?,
11
11
  val caption: String?,
12
12
  val duration: Long?,
13
- @field:JsonProperty("has_cta")
13
+ @SerializedName("has_cta")
14
14
  val hasCta: Boolean?,
15
15
  val height: Int?,
16
16
  val width: Int?,
17
- @field:JsonProperty("video_id")
17
+ @SerializedName("video_id")
18
18
  val videoId: String?
19
19
  ) : Parcelable
@@ -10,12 +10,12 @@ import com.facebook.react.uimanager.annotations.ReactProp
10
10
  import com.fireworksdk.bridge.constants.FWCommandConstant
11
11
  import com.fireworksdk.bridge.models.FWVideoFeedConfigModel
12
12
  import com.fireworksdk.bridge.models.FWVideoPlayerConfigModel
13
- import com.fireworksdk.bridge.utils.FWJsonUtils
14
13
  import com.facebook.react.common.MapBuilder
15
14
  import com.fireworksdk.bridge.components.videofeed.FWVideoFeed
16
15
  import com.fireworksdk.bridge.models.FWFeedViewEventName
17
16
  import com.fireworksdk.bridge.models.FWVideoFeedItemDetailsModel
18
17
  import com.fireworksdk.bridge.reactnative.utils.FWEventUtils
18
+ import com.fireworksdk.bridge.utils.FWGsonUtil
19
19
  import com.fireworksdk.bridge.utils.FWLogUtils
20
20
  import com.loopnow.fireworklibrary.models.OnPlaylistGroupItemClickedListener
21
21
  import com.loopnow.fireworklibrary.models.VideoContentStatus
@@ -158,14 +158,14 @@ class FWVideoFeedManager : SimpleViewManager<FWVideoFeed>() {
158
158
  @ReactProp(name = "videoFeedConfiguration")
159
159
  fun setVideoFeedConfig(view: FWVideoFeed, config: ReadableMap?) {
160
160
  val configMap = config?.toHashMap()
161
- val videoFeedConfigModel = FWJsonUtils.fromMap(configMap, FWVideoFeedConfigModel::class.java)
161
+ val videoFeedConfigModel = FWGsonUtil.fromObject(configMap, FWVideoFeedConfigModel::class.java)
162
162
  view.setVideoFeedConfigProps(videoFeedConfigModel)
163
163
  }
164
164
 
165
165
  @ReactProp(name = "videoPlayerConfiguration")
166
166
  fun setVideoPlayerConfig(view: FWVideoFeed, config: ReadableMap?) {
167
167
  val configMap = config?.toHashMap()
168
- val videoPlayerConfigModel = FWJsonUtils.fromMap(configMap, FWVideoPlayerConfigModel::class.java)
168
+ val videoPlayerConfigModel = FWGsonUtil.fromObject(configMap, FWVideoPlayerConfigModel::class.java)
169
169
  view.setVideoPlayerConfigProps(videoPlayerConfigModel)
170
170
  }
171
171
 
@@ -2,17 +2,16 @@ package com.fireworksdk.bridge.reactnative.module
2
2
 
3
3
  import android.app.Activity
4
4
  import com.facebook.react.bridge.*
5
- import com.fasterxml.jackson.core.type.TypeReference
6
- import com.loopnow.fireworklibrary.baya.Baya
7
- import com.loopnow.fireworklibrary.baya.UpdateCartStatus
8
- import com.fireworksdk.bridge.reactnative.models.FWVideoShoppingInterface
9
5
  import com.fireworksdk.bridge.models.FWVideoShoppingProduct
6
+ import com.fireworksdk.bridge.reactnative.models.FWVideoShoppingInterface
10
7
  import com.fireworksdk.bridge.reactnative.utils.FWEventUtils
11
- import com.fireworksdk.bridge.utils.FWJsonUtils
8
+ import com.fireworksdk.bridge.utils.FWGsonUtil
12
9
  import com.fireworksdk.bridge.utils.FWLogUtils
10
+ import com.google.gson.reflect.TypeToken
11
+ import com.loopnow.fireworklibrary.baya.Baya
12
+ import com.loopnow.fireworklibrary.baya.UpdateCartStatus
13
13
  import com.loopnow.fireworklibrary.data.Product
14
14
  import com.loopnow.fireworklibrary.utils.Util
15
- import kotlin.collections.HashMap
16
15
 
17
16
 
18
17
  class FWVideoShoppingModule(
@@ -37,7 +36,10 @@ class FWVideoShoppingModule(
37
36
  }
38
37
 
39
38
  val configArrayList = productArray?.toArrayList()
40
- val videoShoppingProducts = FWJsonUtils.fromJson(FWJsonUtils.toJson(configArrayList), object : TypeReference<List<FWVideoShoppingProduct>?>() {})
39
+ val configArrayListJsonString = FWGsonUtil.toJson(configArrayList)
40
+
41
+ val listOfMyClassObject = object : TypeToken<List<FWVideoShoppingProduct>?>() {}.type
42
+ val videoShoppingProducts: List<FWVideoShoppingProduct>? = FWGsonUtil.fromJson(configArrayListJsonString, listOfMyClassObject)
41
43
  if (videoShoppingProducts.isNullOrEmpty()) {
42
44
  return
43
45
  }
@@ -66,7 +66,7 @@ class FireworkSDKModule(
66
66
 
67
67
  // set configuration
68
68
  val configMap = config?.toHashMap()
69
- val videoPlayerContentConfigModel = FWJsonUtils.fromMap(configMap, FWVideoPlayerConfigModel::class.java)
69
+ val videoPlayerContentConfigModel = FWGsonUtil.fromObject(configMap, FWVideoPlayerConfigModel::class.java)
70
70
  FWVideoPlayerUtils.setVideoPlayerConfig(videoPlayerContentConfigModel)
71
71
 
72
72
  // open player
@@ -94,7 +94,7 @@ class FireworkSDKModule(
94
94
  @ReactMethod
95
95
  override fun setAdBadgeConfiguration(config: ReadableMap?, promise: Promise) {
96
96
  val configMap = config?.toHashMap()
97
- val adBadgeConfigModel = FWJsonUtils.fromMap(configMap, FWAdBadgeConfigModel::class.java)
97
+ val adBadgeConfigModel = FWGsonUtil.fromObject(configMap, FWAdBadgeConfigModel::class.java)
98
98
  FWVideoPlayerUtils.setAdBadgeConfig(adBadgeConfigModel)
99
99
  promise.resolve(Arguments.createMap())
100
100
  }
@@ -198,7 +198,7 @@ class FireworkSDKModule(
198
198
  }
199
199
  FwSDK.addVideoEventListener(object: FwSDK.VideoEventListener {
200
200
  override fun event(event: String, jsonObject: JSONObject) {
201
- val videoPlaybackDetails = FWJsonUtils.fromJson(jsonObject.toString(), FWVideoPlaybackDetails::class.java)
201
+ val videoPlaybackDetails = FWGsonUtil.fromJson(jsonObject.toString(), FWVideoPlaybackDetails::class.java)
202
202
 
203
203
  when (event) {
204
204
  VideoEvent.videoImpression -> {
@@ -1,16 +1,19 @@
1
1
  package com.fireworksdk.bridge.reactnative.utils
2
2
 
3
3
  import com.facebook.react.bridge.*
4
- import com.fireworksdk.bridge.utils.FWJsonUtils
4
+ import com.fireworksdk.bridge.utils.FWGsonUtil
5
5
  import org.json.JSONArray
6
6
  import org.json.JSONException
7
7
  import org.json.JSONObject
8
8
 
9
9
 
10
- inline fun <reified T : Any> T.asMap(): WritableMap {
11
- val jsonString = FWJsonUtils.toJson(this)
10
+ inline fun <reified T : Any?> T.asMap(): WritableMap? {
11
+ val jsonString = FWGsonUtil.toJson(this)
12
+ if (jsonString.isNullOrBlank()) {
13
+ return null
14
+ }
12
15
  val jsonObject = JSONObject(jsonString)
13
- return FWDataUtils.convertJsonObjectToWritableMap(jsonObject)?: Arguments.createMap()
16
+ return FWDataUtils.convertJsonObjectToWritableMap(jsonObject)
14
17
  }
15
18
 
16
19
  object FWDataUtils {
@@ -9,7 +9,6 @@ import com.fireworksdk.bridge.reactnative.FWInitializationProvider
9
9
  import com.fireworksdk.bridge.reactnative.module.FireworkSDKModule
10
10
  import com.fireworksdk.bridge.reactnative.pages.FWContainerActivity
11
11
  import com.fireworksdk.bridge.utils.FWDateUtils
12
- import com.fireworksdk.bridge.utils.FWJsonUtils
13
12
  import com.fireworksdk.bridge.utils.FWLogUtils
14
13
  import com.loopnow.fireworklibrary.data.Product
15
14
  import java.util.*
@@ -73,8 +72,8 @@ object FWEventUtils {
73
72
  contentMap.putString("playlist", info.playlist)
74
73
  contentMap.putString("channel", info.channel)
75
74
 
76
- val dynamicContentParametersMap = Arguments.createMap()
77
75
  if (!info.dynamicContentParameters.isNullOrEmpty()) {
76
+ val dynamicContentParametersMap = Arguments.createMap()
78
77
  for (key in info.dynamicContentParameters.keys) {
79
78
  val value = info.dynamicContentParameters[key]
80
79
  val array = Arguments.createArray()
@@ -85,15 +84,10 @@ object FWEventUtils {
85
84
  }
86
85
  dynamicContentParametersMap.putArray(key, array)
87
86
  }
87
+ contentMap.putMap("dynamicContentParameters", dynamicContentParametersMap)
88
88
  }
89
- contentMap.putMap("dynamicContentParameters", dynamicContentParametersMap)
90
89
 
91
90
  eventMap.putMap("info", contentMap)
92
- // sendLogMessageEvent(reactContext, "[Android] Receive sendVideoFeedClickEvent event before: $info")
93
- // val jsonString = FWJsonUtils.toJson(info)
94
- // sendLogMessageEvent(reactContext, "[Android] Receive sendVideoFeedClickEvent event before2: $jsonString")
95
- // eventMap.putMap("info", info.asMap())
96
- // sendLogMessageEvent(reactContext, "[Android] Receive sendVideoFeedClickEvent event after: $eventMap")
97
91
 
98
92
  sendEvent(reactContext, FWEventName.VideoFeedClick.rawValue, eventMap)
99
93
  }
@@ -0,0 +1,38 @@
1
+ package com.fireworksdk.bridge.utils
2
+
3
+ import com.google.gson.Gson
4
+ import java.lang.reflect.Type
5
+
6
+ object FWGsonUtil {
7
+
8
+ private val gson by lazy {
9
+ Gson()
10
+ }
11
+
12
+ fun toJson(ts: Any?): String? {
13
+ return gson.toJson(ts)
14
+ }
15
+
16
+ fun <T> fromJson(json: String?, type: Class<T>): T? {
17
+ if (json.isNullOrBlank()) {
18
+ return null
19
+ }
20
+ return gson.fromJson(json, type)
21
+ }
22
+
23
+ fun <T> fromJson(json: String?, type: Type): T? {
24
+ if (json.isNullOrBlank()) {
25
+ return null
26
+ }
27
+ return gson.fromJson(json, type)
28
+ }
29
+
30
+ fun <T> fromObject(o: Any?, type: Class<T>): T? {
31
+ if (o == null) {
32
+ return null
33
+ }
34
+ val jsonString = toJson(o)
35
+ return gson.fromJson(jsonString, type)
36
+ }
37
+
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-firework-sdk",
3
- "version": "1.2.4",
3
+ "version": "1.3.0-beta.2",
4
4
  "description": "Firework React Native SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,85 +0,0 @@
1
- package com.fireworksdk.bridge.utils
2
-
3
- import android.os.Looper
4
- import com.fasterxml.jackson.annotation.JsonInclude
5
- import com.fasterxml.jackson.core.type.TypeReference
6
- import com.fasterxml.jackson.databind.DeserializationFeature
7
- import com.fasterxml.jackson.databind.ObjectMapper
8
- import com.fasterxml.jackson.databind.SerializationFeature
9
- import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
10
- import java.util.*
11
-
12
- object FWJsonUtils {
13
- val mapper: ObjectMapper by lazy {
14
- jacksonObjectMapper()
15
- // .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
16
- .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
17
- .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
18
- .setSerializationInclusion(JsonInclude.Include.NON_NULL)
19
- .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
20
- .configure(SerializationFeature.WRITE_DATES_WITH_ZONE_ID, true)
21
- .setTimeZone(TimeZone.getDefault())
22
- }
23
-
24
- private fun logJsonError(e: Exception) {
25
- val loggedError = RuntimeException("Json Read Error!", e)
26
- if (Looper.myLooper() != Looper.getMainLooper()) {
27
- throw loggedError
28
- }
29
- }
30
-
31
- @JvmStatic
32
- fun <T> fromMap(map: Map<*, *>?, cls: Class<T>): T? {
33
- if (map.isNullOrEmpty()) {
34
- return null
35
- }
36
- try {
37
- return mapper.convertValue(map, cls)
38
- } catch (e: Exception) {
39
- e.printStackTrace()
40
- logJsonError(e)
41
- }
42
- return null
43
- }
44
-
45
- @JvmStatic
46
- fun <T> fromJson(json: String?, cls: Class<T>): T? {
47
- if (json.isNullOrBlank()) {
48
- return null
49
- }
50
- try {
51
- return mapper.readValue(json, cls)
52
- } catch (e: Exception) {
53
- e.printStackTrace()
54
- logJsonError(e)
55
- }
56
- return null
57
- }
58
-
59
- @JvmStatic
60
- fun <T> fromJson(json: String?, type: TypeReference<T>): T? {
61
- if (json.isNullOrBlank()) {
62
- return null
63
- }
64
- try {
65
- return mapper.readValue(json, type)
66
- } catch (e: Exception) {
67
- e.printStackTrace()
68
- logJsonError(e)
69
- }
70
- return null
71
- }
72
-
73
- @JvmStatic
74
- fun toJson(obj: Any?): String? {
75
- if (obj == null) {
76
- return null
77
- }
78
- try {
79
- return mapper.writeValueAsString(obj)
80
- } catch (e: Exception) {
81
- e.printStackTrace()
82
- }
83
- return null
84
- }
85
- }