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 //endregion
override fun onMethodCall(call: MethodCall, result: Result) { override fun onMethodCall(call: MethodCall, result: Result) {
val method = call.method Log.d(TAG, "onMethodCall - ${call.method} not implemented")
val arguments = call.arguments result.notImplemented()
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()
}
} }
private inner class MyApi : HostApis.CastApi { private inner class MyApi : HostApis.CastApi {
@ -176,6 +162,16 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
mMessageCastingChannel?.sendMessage(mCastSession, message) 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 { 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 { object MethodNames {
const val onCastStateChanged = "CastContext.onCastStateChanged" const val onCastStateChanged = "CastContext.onCastStateChanged"
const val showCastDialog = "showCastDialog"
// region SessionManager // region SessionManager
const val onSessionStarting = "SessionManager.onSessionStarting" const val onSessionStarting = "SessionManager.onSessionStarting"

View file

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

View file

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