Pigeon: Integrated showCastDialog API in Android and iOS

This commit is contained in:
gianlucaparadise 2021-11-01 16:39:11 +01:00
parent f7f5cc679a
commit 3768c925b2
4 changed files with 18 additions and 25 deletions

View file

@ -153,22 +153,8 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
//endregion
override fun onMethodCall(call: MethodCall, result: Result) {
val method = call.method
val arguments = call.arguments
when (method) {
MethodNames.showCastDialog -> {
val context = applicationContext
val activity = this.activity
if (context == null || activity == null) {
Log.d(TAG, "onMethodCall - missing context")
return
}
CastDialogOpener.showCastDialog(context, activity)
}
else -> result.notImplemented()
}
Log.d(TAG, "onMethodCall - ${call.method} not implemented")
result.notImplemented()
}
private inner class MyApi : HostApis.CastApi {
@ -176,6 +162,16 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
mMessageCastingChannel?.sendMessage(mCastSession, message)
}
override fun showCastDialog() {
val context = applicationContext
val activity = activity
if (context == null || activity == null) {
Log.d(TAG, "showCastDialog - missing context")
return
}
CastDialogOpener.showCastDialog(context, activity)
}
}
private inner class NamespaceResult(val oldSession: CastSession?, val newSession: CastSession?) : Result {

View file

@ -2,7 +2,6 @@ package com.gianlucaparadise.flutter_cast_framework
object MethodNames {
const val onCastStateChanged = "CastContext.onCastStateChanged"
const val showCastDialog = "showCastDialog"
// region SessionManager
const val onSessionStarting = "SessionManager.onSessionStarting"

View file

@ -9,8 +9,7 @@ import Foundation
enum MethodNames : String {
case onCastStateChanged = "CastContext.onCastStateChanged"
case showCastDialog = "showCastDialog"
// region SessionManager
case onSessionStarting = "SessionManager.onSessionStarting"
case onSessionStarted = "SessionManager.onSessionStarted"

View file

@ -111,12 +111,7 @@ public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessio
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case MethodNames.showCastDialog.rawValue:
castContext.presentCastDialog()
default:
print("Method [\(call.method)] is not implemented.")
}
print("Method [\(call.method)] is not implemented.")
}
deinit {
@ -129,6 +124,10 @@ public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessio
MessageCastingChannel.sendMessage(allCastingChannels: self.castingChannels, castMessage: message)
}
public func showCastDialogWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
castContext.presentCastDialog()
}
// MARK: - GCKSessionManagerListener
// onSessionSuspended