Skip to content

Commit

Permalink
Merge in completion handler fix, now playing implementation
Browse files Browse the repository at this point in the history
From remote-tracking branch 'icapps/bugfix/oguzhnatly#17-completion-handler-not-finished'

MR in the main repo:   oguzhnatly#26
icapps source branch:  https://github.com/icapps/flutter_carplay/tree/bugfix/%2317-completion-handler-not-finished,
  • Loading branch information
jaysephjw committed Aug 18, 2024
2 parents ac91bee + 410218f commit bf4714e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
45 changes: 38 additions & 7 deletions ios/Classes/SwiftFlutterCarplayPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SwiftFlutterCarplayPlugin: NSObject, FlutterPlugin {
private static var streamHandler: FCPStreamHandlerPlugin?
private(set) static var registrar: FlutterPluginRegistrar?
private static var objcRootTemplate: FCPRootTemplate?
private static var templateStack: [FCPRootTemplate] = []
private static var _rootTemplate: CPTemplate?
public static var animated: Bool = false
private var objcPresentTemplate: FCPPresentTemplate?
Expand Down Expand Up @@ -43,6 +44,8 @@ public class SwiftFlutterCarplayPlugin: NSObject, FlutterPlugin {
result(false)
return
}

SwiftFlutterCarplayPlugin.templateStack = []
var rootTemplate: FCPRootTemplate?
switch args["runtimeType"] as! String {
case String(describing: FCPTabBarTemplate.self):
Expand Down Expand Up @@ -156,6 +159,7 @@ public class SwiftFlutterCarplayPlugin: NSObject, FlutterPlugin {
return
}
for _ in 1...(args["count"] as! Int) {
SwiftFlutterCarplayPlugin.templateStack.removeLast()
FlutterCarPlaySceneDelegate.pop(animated: args["animated"] as! Bool)
}
result(true)
Expand All @@ -174,7 +178,13 @@ public class SwiftFlutterCarplayPlugin: NSObject, FlutterPlugin {
result(false)
return
}
FlutterCarPlaySceneDelegate.push(template: CPNowPlayingTemplate.shared, animated: animated)
//<<<<<<< HEAD
// FlutterCarPlaySceneDelegate.push(template: CPNowPlayingTemplate.shared, animated: animated)
//=======
let template = FCPSharedNowPlayingTemplate()
SwiftFlutterCarplayPlugin.templateStack.append(template)
FlutterCarPlaySceneDelegate.push(template: template.get, animated: animated)
//>>>>>>> icapps/bugfix/#17-completion-handler-not-finished
result(true)
break
case FCPChannelTypes.pushTemplate:
Expand All @@ -186,17 +196,25 @@ public class SwiftFlutterCarplayPlugin: NSObject, FlutterPlugin {
let animated = args["animated"] as! Bool
switch args["runtimeType"] as! String {
case String(describing: FCPGridTemplate.self):
pushTemplate = FCPGridTemplate(obj: args["template"] as! [String : Any]).get
let template = FCPGridTemplate(obj: args["template"] as! [String : Any])
SwiftFlutterCarplayPlugin.templateStack.append(template)
pushTemplate = template.get
break
case String(describing: FCPPointOfInterestTemplate.self):
pushTemplate = FCPPointOfInterestTemplate(obj: args["template"] as! [String : Any]).get
let template = FCPPointOfInterestTemplate(obj: args["template"] as! [String : Any])
SwiftFlutterCarplayPlugin.templateStack.append(template)
pushTemplate = template.get
break
case String(describing: FCPInformationTemplate.self):
pushTemplate = FCPInformationTemplate(obj: args["template"] as! [String : Any]).get
let template = FCPInformationTemplate(obj: args["template"] as! [String : Any])
SwiftFlutterCarplayPlugin.templateStack.append(template)
pushTemplate = template.get
break

case String(describing: FCPListTemplate.self):
pushTemplate = FCPListTemplate(obj: args["template"] as! [String : Any], templateType: FCPListTemplateTypes.DEFAULT).get
let template = FCPListTemplate(obj: args["template"] as! [String : Any], templateType: FCPListTemplateTypes.DEFAULT)
SwiftFlutterCarplayPlugin.templateStack.append(template)
pushTemplate = template.get
break
default:
result(false)
Expand All @@ -210,6 +228,7 @@ public class SwiftFlutterCarplayPlugin: NSObject, FlutterPlugin {
result(false)
return
}
SwiftFlutterCarplayPlugin.templateStack = []
FlutterCarPlaySceneDelegate.popToRootTemplate(animated: animated)
self.objcPresentTemplate = nil
result(true)
Expand All @@ -236,17 +255,29 @@ public class SwiftFlutterCarplayPlugin: NSObject, FlutterPlugin {
var templates: [FCPListTemplate] = []
if (objcRootTemplateType.elementsEqual(String(describing: FCPListTemplate.self))) {
templates.append(SwiftFlutterCarplayPlugin.objcRootTemplate as! FCPListTemplate)
NSLog("FCP: FCPListTemplate")
} else if (objcRootTemplateType.elementsEqual(String(describing: FCPTabBarTemplate.self))) {
templates = (SwiftFlutterCarplayPlugin.objcRootTemplate as! FCPTabBarTemplate).getTemplates()
NSLog("FCP: FCPTabBarTemplate")
} else {
NSLog("FCP: No Template")
return
}
l1: for t in templates {
for t in templateStack {
if (t is FCPListTemplate) {
guard let template = t as? FCPListTemplate else {
break;
}
templates.append(template)
}
}

for t in templates {
for s in t.getSections() {
for i in s.getItems() {
if (i.elementId == elementId) {
actionWhenFound(i)
break l1
return
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions ios/Classes/models/FCPSharedNowPlayingTemplate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// FCPSharedNowPlaying.swift
// flutter_carplay
//
// Created by Koen Van Looveren on 16/09/2022.
//

import CarPlay

@available(iOS 14.0, *)
class FCPSharedNowPlayingTemplate {
var get: CPNowPlayingTemplate {
return CPNowPlayingTemplate.shared
}
}

@available(iOS 14.0, *)
extension FCPSharedNowPlayingTemplate: FCPRootTemplate { }
4 changes: 2 additions & 2 deletions lib/carplay_worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FlutterCarplay {
static final FlutterCarPlayController _carPlayController =
FlutterCarPlayController();

/// CarPlay main bridge as a listener from CarPlay and native side.
/// CarPlay main bridge as a listenSer from CarPlay and native side.
late final StreamSubscription<dynamic>? _eventBroadcast;

/// Current CarPlay and mobile app connection status.
Expand Down Expand Up @@ -289,7 +289,7 @@ class FlutterCarplay {
}
}

/// Navigate to the shared instance of the NowPlaying Template
/// Navigate to the shared instance of the NowPlaying Template
///
/// - If animated is true, CarPlay animates the transition between templates.
static Future<bool> showSharedNowPlaying({
Expand Down

0 comments on commit bf4714e

Please sign in to comment.