Commit 01183e21 authored by jzhang's avatar jzhang

no message

parent a9ae7b9c
......@@ -15,7 +15,6 @@
692EC423284C8D6F0043E3EA /* spanish.json in Resources */ = {isa = PBXBuildFile; fileRef = 692EC41F284C8D6F0043E3EA /* spanish.json */; };
694B85BC2848EB4C009BEDE1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 694B85BB2848EB4C009BEDE1 /* AppDelegate.swift */; };
694B85BE2848EB4C009BEDE1 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 694B85BD2848EB4C009BEDE1 /* SceneDelegate.swift */; };
694B85C02848EB4C009BEDE1 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 694B85BF2848EB4C009BEDE1 /* ViewController.swift */; };
694B85C32848EB4C009BEDE1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 694B85C12848EB4C009BEDE1 /* Main.storyboard */; };
694B85C52848EB4E009BEDE1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 694B85C42848EB4E009BEDE1 /* Assets.xcassets */; };
694B85C82848EB4E009BEDE1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 694B85C62848EB4E009BEDE1 /* LaunchScreen.storyboard */; };
......@@ -59,6 +58,7 @@
EA8F430528EF3DCA00983014 /* ZJTableViewManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA8F42F728EF3DCA00983014 /* ZJTableViewManager.swift */; };
EA8F430628EF3DCA00983014 /* ZJExpandTreeCellItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA8F42F928EF3DCA00983014 /* ZJExpandTreeCellItem.swift */; };
EA8F430828EF3DCA00983014 /* Popover.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA8F42FD28EF3DCA00983014 /* Popover.swift */; };
EAB6F1C228F0449E0005FF33 /* BaseLandingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB6F1C128F0449E0005FF33 /* BaseLandingVC.swift */; };
EAD8102728E207A4002A86C9 /* MyTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD8102628E207A4002A86C9 /* MyTools.swift */; };
EAD8102D28E20A54002A86C9 /* PermissionAlertVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD8102C28E20A54002A86C9 /* PermissionAlertVC.swift */; };
/* End PBXBuildFile section */
......@@ -95,7 +95,6 @@
694B85B82848EB4C009BEDE1 /* BreastFeedingDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BreastFeedingDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
694B85BB2848EB4C009BEDE1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
694B85BD2848EB4C009BEDE1 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
694B85BF2848EB4C009BEDE1 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
694B85C22848EB4C009BEDE1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
694B85C42848EB4E009BEDE1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
694B85C72848EB4E009BEDE1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
......@@ -131,6 +130,7 @@
EA8F42F728EF3DCA00983014 /* ZJTableViewManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZJTableViewManager.swift; sourceTree = "<group>"; };
EA8F42F928EF3DCA00983014 /* ZJExpandTreeCellItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZJExpandTreeCellItem.swift; sourceTree = "<group>"; };
EA8F42FD28EF3DCA00983014 /* Popover.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Popover.swift; sourceTree = "<group>"; };
EAB6F1C128F0449E0005FF33 /* BaseLandingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseLandingVC.swift; sourceTree = "<group>"; };
EAD8102628E207A4002A86C9 /* MyTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyTools.swift; sourceTree = "<group>"; };
EAD8102C28E20A54002A86C9 /* PermissionAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionAlertVC.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -193,7 +193,6 @@
EAFC261B28E2144600F802FE /* ViewController */,
694B85BB2848EB4C009BEDE1 /* AppDelegate.swift */,
694B85BD2848EB4C009BEDE1 /* SceneDelegate.swift */,
694B85BF2848EB4C009BEDE1 /* ViewController.swift */,
692EC419284C81700043E3EA /* ViewModel.swift */,
EA14360628E0CA3100FFBE72 /* LanguageCell.swift */,
EA14360728E0CA3100FFBE72 /* LanguageCell.xib */,
......@@ -317,6 +316,7 @@
children = (
EA14360428E0BF1900FFBE72 /* DemoViewController.swift */,
EA8F42CE28EEA85200983014 /* CradleHoldLandingVC.swift */,
EAB6F1C128F0449E0005FF33 /* BaseLandingVC.swift */,
EA8F42D028EEA87A00983014 /* SideLyingLandingVC.swift */,
EAD8102C28E20A54002A86C9 /* PermissionAlertVC.swift */,
697B07EC284F2E5C0051FC23 /* CompleteVC.swift */,
......@@ -406,7 +406,6 @@
EA8F430628EF3DCA00983014 /* ZJExpandTreeCellItem.swift in Sources */,
EA8F42C528EE998000983014 /* StringModel.swift in Sources */,
EA8F430428EF3DCA00983014 /* ZJTableViewItem.swift in Sources */,
694B85C02848EB4C009BEDE1 /* ViewController.swift in Sources */,
EA8F42D128EEA87A00983014 /* SideLyingLandingVC.swift in Sources */,
694B85BC2848EB4C009BEDE1 /* AppDelegate.swift in Sources */,
EA8F42C328EE998000983014 /* StringLyingGestureIntroduce.swift in Sources */,
......@@ -416,6 +415,7 @@
EA8F430128EF3DCA00983014 /* ZJDefaultCell.swift in Sources */,
EA8F42CF28EEA85200983014 /* CradleHoldLandingVC.swift in Sources */,
EA14360528E0BF1900FFBE72 /* DemoViewController.swift in Sources */,
EAB6F1C228F0449E0005FF33 /* BaseLandingVC.swift in Sources */,
692EC41A284C81700043E3EA /* ViewModel.swift in Sources */,
EA8F430528EF3DCA00983014 /* ZJTableViewManager.swift in Sources */,
EA8F430828EF3DCA00983014 /* Popover.swift in Sources */,
......@@ -484,6 +484,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_BITCODE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
......@@ -544,6 +545,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_BITCODE = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
......
......@@ -892,6 +892,7 @@
</state>
<connections>
<action selector="okAction:" destination="kbc-T2-Z4j" eventType="touchUpInside" id="ukf-Bw-3lq"/>
<action selector="startAction:" destination="2ZC-tX-YAa" eventType="touchUpInside" id="20l-lQ-8mF"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="a0G-Ge-cAP">
......@@ -1182,6 +1183,7 @@
</state>
<connections>
<action selector="okAction:" destination="kbc-T2-Z4j" eventType="touchUpInside" id="fHv-G0-4fD"/>
<action selector="startAction:" destination="ny1-NH-dmJ" eventType="touchUpInside" id="gjm-mt-6yv"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mpe-0M-8jL">
......
//
// ViewController.swift
// BreastFeedingDemo
//
// Created by Jay Zhang on 2022/6/2.
//
import AVFoundation
import Flutter
import UIKit
class ViewController: UIViewController {
@IBOutlet var titleL: UILabel!
@IBOutlet var stepL1: UILabel!
@IBOutlet var stepL2: UILabel!
@IBOutlet var stepL3: UILabel!
@IBOutlet var startBtn: UIButton!
@IBOutlet var panelV: UIStackView!
@IBOutlet var popupView: UIView!
@IBOutlet var switchBtn: UIButton!
@IBOutlet var permisionPopupV: UIView!
@IBOutlet var permissionTitle: UILabel!
@IBOutlet var permissionText: UILabel!
@IBOutlet var permissionOKBtn: UIButton!
@IBOutlet var permissionPanel: UIView!
var methodChannel: FlutterMethodChannel?
lazy var vm: ViewModel = .init()
var isFirstLoad: Bool = true
fileprivate func updateUI() {
// titleL.text = vm.landingPageTitle
// stepL1.text = vm.landingPageStep1
// stepL2.text = vm.landingPageStep2
// stepL3.text = vm.landingPageStep3
//
// permissionText.text = vm.cameraText1
// permissionTitle.text = vm.cameraText
// permissionOKBtn.setTitle(vm.cameraButtonText, for: .normal)
// startBtn.setTitle(vm.landingPageStart, for: .normal)
panelV.layer.cornerRadius = 8
permissionPanel.layer.cornerRadius = 8
permissionPanel.clipsToBounds = true
panelV.clipsToBounds = true
}
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .light
UIApplication.shared.isIdleTimerDisabled = true
navigationController?.setNavigationBarHidden(true, animated: false)
updateUI()
popupView.isHidden = true
if let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine {
methodChannel = FlutterMethodChannel(name: "com.wmdigit.breastcoachai.native",
binaryMessenger: flutterEngine.binaryMessenger)
methodChannel?.setMethodCallHandler { [weak self]
(call: FlutterMethodCall, result: @escaping FlutterResult) in
if let strongSelf = self {
switch call.method {
case "init":
result(strongSelf.vm.flutterArguments)
case "teachingEnd":
strongSelf.methodChannel?.invokeMethod("dispose", arguments: nil)
// ["totalDuration": 3, "reasonText": Concern about my personal privacy, "status": incomplete, "incompleteReasonCode": 2]
let argument: [String: Any] = try! JSONSerialization.jsonObject(with: (call.arguments as! String).data(using: .utf8)!) as! [String: Any]
// let totalDuration: Int = argument["totalDuration"] as! Int
// let reasonText: String = argument["reasonText"] as! String
// let incompleteReasonCode: Int = argument["incompleteReasonCode"] as! Int
let status: String = argument["status"] as! String
if status == "incomplete" {
// strongSelf.showError(reasonText)
} else if status == "complete" {
strongSelf.toCompleteVC()
return
}
strongSelf.navigationController?.popViewController(animated: true)
default:
// Unrecognized method name
print("Unrecognized method name: \(call.method)")
}
}
}
}
}
func checkCameraPermission() -> Bool? {
let cameraAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
switch cameraAuthorizationStatus {
case .notDetermined:
return nil
case .authorized:
return true
default:
permisionPopupV.isHidden = false
return false
}
}
func showError(_ text: String?) {
let alertVC = UIAlertController(title: text, message: nil, preferredStyle: .alert)
alertVC.addAction(UIAlertAction(title: "OK", style: .cancel))
navigationController?.pushViewController(alertVC, animated: true)
}
func toCompleteVC() {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "CompleteVC") as! CompleteVC
// vc.vm = vm
navigationController?.pushViewController(vc, animated: true)
}
@IBAction func toSetting(_: Any) {
if let appSettingsURL = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(appSettingsURL)
}
}
@IBAction func tapStart(_: Any) {
if checkCameraPermission() == false {
return
}
if !isFirstLoad {
methodChannel?.invokeMethod("reload", arguments: nil)
}
isFirstLoad = false
if let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine {
let scanVC = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
scanVC.modalPresentationStyle = .overFullScreen
navigationController?.pushViewController(scanVC, animated: true)
}
}
/// 选择语言
@IBAction func showPanel(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
popupView.isHidden = !sender.isSelected
//
(panelV.viewWithTag(1000) as! UIButton).isSelected = false
(panelV.viewWithTag(1001) as! UIButton).isSelected = false
(panelV.viewWithTag(1002) as! UIButton).isSelected = false
// switch vm.language {
// case .english:
// (panelV.viewWithTag(1000) as! UIButton).isSelected = true
// case .français:
// (panelV.viewWithTag(1001) as! UIButton).isSelected = true
// case .español:
// (panelV.viewWithTag(1002) as! UIButton).isSelected = true
// }
}
@IBAction func dismissPermissimPanel(_: Any) {
permisionPopupV.isHidden = true
}
// @IBAction func selectLanguage(_ sender: UIButton) {
// switch sender.tag {
// case 1000:
// vm.language = .english
// case 1001:
// vm.language = .français
// case 1002:
// vm.language = .español
// default:
// break
// }
//
// switchBtn.isSelected = false
// popupView.isHidden = true
//
// updateUI()
// }
}
//
// BaseLandingVC.swift
// BreastFeedingDemo
//
// Created by Jie Zhang on 2022/10/7.
//
import AVFoundation
import Flutter
import UIKit
class BaseLandingVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
viewModel.teachingEndHandler = { [weak self] in
self?.navigationController?.popViewController(animated: true)
}
viewModel.completeHandler = { [weak self] in
self?.toCompleteVC()
}
// Do any additional setup after loading the view.
}
/// 检查权限
/// - Returns: 是否有相机权限
func checkCameraPermission() -> Bool? {
let cameraAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
switch cameraAuthorizationStatus {
case .notDetermined:
return nil
case .authorized:
return true
default:
showPermissionChalenge()
return false
}
}
/// 提示权限问题
func showPermissionChalenge() {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "PermissionAlertVC") as! PermissionAlertVC
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true)
}
func toCompleteVC() {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "CompleteVC") as! CompleteVC
navigationController?.pushViewController(vc, animated: true)
}
func showFlutterScreen() {
if let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine {
let scanVC = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
scanVC.modalPresentationStyle = .overFullScreen
navigationController?.pushViewController(scanVC, animated: true)
}
}
@IBAction func startAction(_: Any) {
if checkCameraPermission() == false {
return
}
if !viewModel.isFirstLoad {
viewModel.methodChannel?.invokeMethod("reload", arguments: nil)
}
viewModel.isFirstLoad = false
showFlutterScreen()
}
}
......@@ -7,7 +7,7 @@
import UIKit
class CradleHoldLandingVC: UIViewController {
class CradleHoldLandingVC: BaseLandingVC {
@IBOutlet weak var titleL: UILabel!
@IBOutlet weak var subtitleL: UILabel!
......@@ -22,7 +22,7 @@ class CradleHoldLandingVC: UIViewController {
super.viewDidLoad()
setupUI()
}
@IBAction func back(_ sender: Any) {
navigationController?.popViewController(animated: true)
}
......@@ -34,7 +34,7 @@ class CradleHoldLandingVC: UIViewController {
text2L.text = getString().sittingGestureIntroduce.suggestedText2
text3L.text = getString().sittingGestureIntroduce.suggestedText3
text4L.text = getString().sittingGestureIntroduce.suggestedText4
startBtn.setTitle(getString().homeButtonText, for: .normal)
}
}
......@@ -7,9 +7,7 @@
import AVFoundation
import Flutter
//import Popover
import UIKit
//import ZJTableViewManager
class DemoViewController: UIViewController {
fileprivate var popover: Popover!
......@@ -26,8 +24,6 @@ class DemoViewController: UIViewController {
@IBOutlet weak var lyingTitleL: UILabel!
@IBOutlet weak var lyingSubtitleL: UILabel!
@IBOutlet weak var topConstraint: NSLayoutConstraint!
var methodChannel: FlutterMethodChannel?
var isFirstLoad: Bool = true
override func viewDidLoad() {
super.viewDidLoad()
......@@ -37,7 +33,6 @@ class DemoViewController: UIViewController {
scrollView.automaticallyAdjustsScrollIndicatorInsets = false
scrollView.contentInsetAdjustmentBehavior = .never
updateUI()
flutterInitialize()
}
override func viewDidAppear(_ animated: Bool) {
......@@ -64,71 +59,6 @@ class DemoViewController: UIViewController {
updateUI()
}
/// 提示权限问题
fileprivate func showPermissionChalenge() {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "PermissionAlertVC") as! PermissionAlertVC
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true)
}
/// 检查权限
/// - Returns: 是否有相机权限
fileprivate func checkCameraPermission() -> Bool? {
let cameraAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
switch cameraAuthorizationStatus {
case .notDetermined:
return nil
case .authorized:
return true
default:
showPermissionChalenge()
return false
}
}
fileprivate func flutterInitialize() {
if let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine {
methodChannel = FlutterMethodChannel(name: "com.wmdigit.breastcoachai.native",
binaryMessenger: flutterEngine.binaryMessenger)
methodChannel?.setMethodCallHandler { [weak self]
(call: FlutterMethodCall, result: @escaping FlutterResult) in
if let strongSelf = self {
switch call.method {
case "init":
result(viewModel.flutterArguments)
case "teachingEnd":
strongSelf.methodChannel?.invokeMethod("dispose", arguments: nil)
// ["totalDuration": 3, "reasonText": Concern about my personal privacy, "status": incomplete, "incompleteReasonCode": 2]
let argument: [String: Any] = try! JSONSerialization.jsonObject(with: (call.arguments as! String).data(using: .utf8)!) as! [String: Any]
// let totalDuration: Int = argument["totalDuration"] as! Int
// let reasonText: String = argument["reasonText"] as! String
// let incompleteReasonCode: Int = argument["incompleteReasonCode"] as! Int
let status: String = argument["status"] as! String
if status == "incomplete" {
// strongSelf.showError(reasonText)
} else if status == "complete" {
strongSelf.toCompleteVC()
return
}
strongSelf.navigationController?.popViewController(animated: true)
default:
// Unrecognized method name
print("Unrecognized method name: \(call.method)")
}
}
}
}
}
func toCompleteVC() {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "CompleteVC") as! CompleteVC
navigationController?.pushViewController(vc, animated: true)
}
func toSideLyingLandingVC() {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "SideLyingLandingVC") as! SideLyingLandingVC
......@@ -142,35 +72,14 @@ class DemoViewController: UIViewController {
}
@IBAction func sideLyingAction(_ sender: Any) {
if checkCameraPermission() == false {
return
}
if !isFirstLoad {
methodChannel?.invokeMethod("reload", arguments: nil)
}
isFirstLoad = false
viewModel.posture = .lying
toSideLyingLandingVC()
}
@IBAction func cradleHold(_: Any) {
if checkCameraPermission() == false {
return
}
if !isFirstLoad {
methodChannel?.invokeMethod("reload", arguments: nil)
}
isFirstLoad = false
viewModel.posture = .cradle
toCradleHoldLandingVC()
// if let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine {
// let scanVC = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
// scanVC.modalPresentationStyle = .overFullScreen
// navigationController?.pushViewController(scanVC, animated: true)
// }
}
}
......
......@@ -7,7 +7,7 @@
import UIKit
class SideLyingLandingVC: UIViewController {
class SideLyingLandingVC: BaseLandingVC {
@IBOutlet weak var titleL: UILabel!
@IBOutlet weak var subtitleL: UILabel!
......@@ -28,6 +28,7 @@ class SideLyingLandingVC: UIViewController {
@IBAction func back(_ sender: Any) {
navigationController?.popViewController(animated: true)
}
fileprivate func setupUI() {
titleL.text = getString().lyingGestureIntroduce.title
subtitleL.text = getString().lyingGestureIntroduce.subTitle
......
......@@ -6,8 +6,13 @@
//
import Foundation
import Flutter
class ViewModel {
enum Posture: Int {
case cradle = 0
case lying = 1
}
/// 语言枚举,enum代表语言包文件名,rawValue代表语言选项
enum Language: String, CaseIterable {
case english = "English"
......@@ -24,8 +29,11 @@ class ViewModel {
setupText()
}
}
var posture: Posture = .cradle
var string: StringModel!
var isFirstLoad: Bool = true
var languagePack: [String: Any] {
let languageFile = "\(language)".appending(".json")
......@@ -38,6 +46,7 @@ class ViewModel {
var flutterArguments: String {
let arguments: [String: Any] = [
"lying": posture.rawValue,
"languagePack": languagePack,
"env": env,
"apiKey": apiKey,
......@@ -48,10 +57,48 @@ class ViewModel {
let str = String(data: data!, encoding: String.Encoding.utf8)
return str!
}
var methodChannel: FlutterMethodChannel!
var completeHandler: (()->())?
var teachingEndHandler: (()->())?
init() {
language = .english
setupText()
methodChannel = setupFlutter()
}
func setupFlutter() -> FlutterMethodChannel {
let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine
let methodChannel = FlutterMethodChannel(name: "com.wmdigit.breastcoachai.native",
binaryMessenger: flutterEngine!.binaryMessenger)
methodChannel.setMethodCallHandler { [weak self]
(call: FlutterMethodCall, result: @escaping FlutterResult) in
if let strongSelf = self {
switch call.method {
case "init":
result(viewModel.flutterArguments)
case "teachingEnd":
strongSelf.methodChannel.invokeMethod("dispose", arguments: nil)
// ["totalDuration": 3, "reasonText": Concern about my personal privacy, "status": incomplete, "incompleteReasonCode": 2]
let argument: [String: Any] = try! JSONSerialization.jsonObject(with: (call.arguments as! String).data(using: .utf8)!) as! [String: Any]
let status: String = argument["status"] as! String
if status == "incomplete" {
// strongSelf.showError(reasonText)
} else if status == "complete" {
strongSelf.completeHandler?()
// strongSelf.toCompleteVC()
return
}
strongSelf.teachingEndHandler?()
default:
// Unrecognized method name
print("Unrecognized method name: \(call.method)")
}
}
}
return methodChannel
}
fileprivate func setupText() {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment