package capacitor.plugin.appsflyer.sdk import android.os.Bundle import android.util.Log import com.getcapacitor.JSObject import org.json.JSONException object AFHelpers { fun jsonToMap(json: JSObject?): Map? { var newMap: MutableMap? = null json?.run { newMap = HashMap() val iterator: Iterator<*> = keys() while (iterator.hasNext()) { val key = iterator.next() as String newMap!![key] = get(key) } } return newMap } fun jsonToStringMap(json: JSObject?): Map? { var newMap: MutableMap? = null json?.run { newMap = HashMap() try { val iterator: Iterator<*> = keys() while (iterator.hasNext()) { val key = iterator.next() as String newMap!![key] = get(key) as String } } catch (e: JSONException) { afLogger(e.message) return null } } return newMap } fun jsonToBundle(json: JSObject?): Bundle? { val bundle = Bundle() json?.run { val iterator: Iterator<*> = keys() while (iterator.hasNext()) { val key = iterator.next() as String val value = get(key) as String bundle.putString(key, value) } } return bundle } fun mapToJson(map: Map?): JSObject? { map?.run { val json = JSObject() for ((k, v) in map) { json.put(k, v) } return json } return null } private fun afLogger(message: String?) { if (!message.isNullOrEmpty()) Log.d(TAG, message) } }