Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 38 additions & 100 deletions android/src/main/kotlin/com/airship/flutter/AirshipPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,8 @@ class AirshipPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
"push#setUserNotificationsEnabled" -> result.resolve(scope, call) { proxy.push.setUserNotificationsEnabled(call.booleanArg()) }
"push#enableUserNotifications" -> result.resolve(scope, call) {
val enableArgs = call.jsonArgs().let {
try {
EnableUserNotificationsArgs.fromJson(it)
} catch (e: Exception) {
null
}
EnableUserNotificationsArgs.fromJson(it)
}

proxy.push.enableUserPushNotifications(enableArgs)
}
"push#isUserNotificationsEnabled" -> result.resolve(scope, call) { proxy.push.isUserNotificationsEnabled() }
Expand Down Expand Up @@ -251,145 +246,88 @@ class AirshipPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

// Live Activities
"liveUpdate#start" -> result.resolve(scope, call) {
try {
val args = call.jsonArgs()
Log.d("AirshipPlugin", "Received args for liveUpdate#start: $args")
val args = call.jsonArgs()
Log.d("AirshipPlugin", "Received args for liveUpdate#start: $args")

val startRequest = LiveUpdateRequest.Start.fromJson(args)
val startRequest = LiveUpdateRequest.Start.fromJson(args)

Log.d("AirshipPlugin", "Created LiveUpdateRequest.Start: $startRequest")
Log.d("AirshipPlugin", "Created LiveUpdateRequest.Start: $startRequest")

proxy.liveUpdateManager.start(startRequest)
Log.d("AirshipPlugin", "LiveUpdate start method called successfully")
proxy.liveUpdateManager.start(startRequest)
Log.d("AirshipPlugin", "LiveUpdate start method called successfully")

null // Return null as the start function doesn't return anything
} catch (e: Exception) {
throw e
}
null // Return null as the start function doesn't return anything
}

"liveUpdate#update" -> result.resolve(scope, call) {
try {
val args = call.jsonArgs()
Log.d("AirshipPlugin", "Received args for liveUpdate#update: $args")

val updateRequest = LiveUpdateRequest.Update.fromJson(args)

proxy.liveUpdateManager.update(updateRequest)
Log.d("AirshipPlugin", "LiveUpdate update method called successfully")
null
} catch (e: Exception) {
Log.e("AirshipPlugin", "Error processing liveUpdate#update request", e)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we log exceptions somewhere else?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will reject it at the flutter level to let them log it as its a usage error and not a plugin error

throw e
}
val args = call.jsonArgs()
Log.d("AirshipPlugin", "Received args for liveUpdate#update: $args")

val updateRequest = LiveUpdateRequest.Update.fromJson(args)

proxy.liveUpdateManager.update(updateRequest)
Log.d("AirshipPlugin", "LiveUpdate update method called successfully")
null
}

"liveUpdate#list" -> result.resolve(scope, call) {
val args = call.jsonArgs()
Log.d("AirshipPlugin", "Received args for liveUpdate#list: $args")

val listRequest = LiveUpdateRequest.List.fromJson(args)

scope.launch {
try {
proxy.liveUpdateManager.list(listRequest)
Log.d("AirshipPlugin", "LiveUpdate list method completed successfully")
} catch (e: Exception) {
Log.e("AirshipPlugin", "Error listing LiveUpdates", e)
}
}
proxy.liveUpdateManager.list(listRequest)
Log.d("AirshipPlugin", "LiveUpdate list method completed successfully")
}

"liveUpdate#listAll" -> result.resolve(scope, call) {
try {
proxy.liveUpdateManager.listAll()
Log.d("AirshipPlugin", "LiveUpdate listAll method completed successfully")
} catch (e: Exception) {
Log.e("AirshipPlugin", "Error listing all LiveUpdates", e)
}
proxy.liveUpdateManager.listAll()
Log.d("AirshipPlugin", "LiveUpdate listAll method completed successfully")
}

"liveUpdate#end" -> result.resolve(scope, call) {
try {
val args = call.jsonArgs()
Log.d("AirshipPlugin", "Received args for liveUpdate#end: $args")

val endRequest = LiveUpdateRequest.End.fromJson(args)

proxy.liveUpdateManager.end(endRequest)
Log.d("AirshipPlugin", "LiveUpdate end method called successfully")
null
} catch (e: Exception) {
Log.e("AirshipPlugin", "Error processing liveUpdate#end request", e)
throw e
}
val args = call.jsonArgs()
Log.d("AirshipPlugin", "Received args for liveUpdate#end: $args")

val endRequest = LiveUpdateRequest.End.fromJson(args)

proxy.liveUpdateManager.end(endRequest)
Log.d("AirshipPlugin", "LiveUpdate end method called successfully")
null
}

"liveUpdate#clearAll" -> result.resolve(scope, call) {
try {
proxy.liveUpdateManager.clearAll()
Log.d("AirshipPlugin", "LiveUpdate clearAll method called successfully")
null
} catch (e: Exception) {
Log.e("AirshipPlugin", "Error processing liveUpdate#clearAll request", e)
throw e
}
proxy.liveUpdateManager.clearAll()
Log.d("AirshipPlugin", "LiveUpdate clearAll method called successfully")
null
}

// Feature Flag
"featureFlagManager#flag" -> result.resolve(scope, call) {
val args = call.jsonArgs().requireMap()
val flagName = args.get("flagName")?.requireString()
val flagName = requireNotNull(args.get("flagName")?.requireString())
val useResultCache = args.get("useResultCache")?.getBoolean(false) ?: false
try {
if (flagName == null) {
throw Exception("Missing flagName")
}

proxy.featureFlagManager.flag(flagName, useResultCache)
} catch (e: Exception) {
result.error("ERROR", "Failed to get flag", e.localizedMessage)
}
proxy.featureFlagManager.flag(flagName, useResultCache)
}

"featureFlagManager#trackInteraction" -> result.resolve(scope, call) {
val parsedFlag = FeatureFlagProxy(JsonValue.wrap(call.stringArg().toMap()))
proxy.featureFlagManager.trackInteraction(parsedFlag)
}

"featureFlagManager#resultCacheGetFlag" -> result.resolve(scope, call) {
scope.launch {
try {
proxy.featureFlagManager.resultCache.flag(call.stringArg())
} catch (e: Exception) {
result.error("ERROR", "Failed to get flag", e.localizedMessage)
}
}
"featureFlagManager#resultCacheRemoveFlag" -> result.resolve(scope, call) {
proxy.featureFlagManager.resultCache.removeCachedFlag(call.stringArg())
}

"featureFlagManager#resultCacheSetFlag"-> result.resolve(scope, call) {
val args = call.jsonArgs().requireMap()
val flag = FeatureFlagProxy(JsonValue.wrap(args.get("flag")?.requireString()?.toMap()))
val ttl = args.get("ttl")?.getLong(0)
val miliseconds = ttl?.milliseconds ?: throw Exception("Missing ttl")

scope.launch {
try {
proxy.featureFlagManager.resultCache.cache(flag, miliseconds)
} catch (e: Exception) {
result.error("ERROR", "Failed to set flag", e.localizedMessage)
}
}
val milliseconds = requireNotNull(ttl?.milliseconds)
proxy.featureFlagManager.resultCache.cache(flag, milliseconds)
}

"featureFlagManager#resultCacheRemoveFlag" -> result.resolve(scope, call) {
scope.launch {
try {
proxy.featureFlagManager.resultCache.removeCachedFlag(call.stringArg())
} catch (e: Exception) {
result.error("ERROR", "Failed to remove cached flag", e.localizedMessage)
}
}
proxy.featureFlagManager.resultCache.removeCachedFlag(call.stringArg())
}

else -> result.notImplemented()
Expand Down