From d1f60ba79c2f599f8c7d01ec818bfc8ac5bf2037 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 16 Jul 2020 16:45:36 -0400 Subject: [PATCH 1/6] action sheet stuff --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 8 +++ .../ActionHandling/MVMCoreActionHandler.m | 32 +++++++++ .../MVMCore/Constants/MVMCoreJSONConstants.h | 1 + .../MVMCore/Constants/MVMCoreJSONConstants.m | 1 + .../Models/ActionType/ActionAlertModel.swift | 57 +++++++++++++++ .../Models/ActionType/ActionBackModel.swift | 11 ++- .../Models/ActionType/ActionCallModel.swift | 9 ++- .../Models/ActionType/ActionCancelModel.swift | 9 ++- .../ActionType/ActionModelProtocol.swift | 1 - .../ActionType/ActionOpenPageModel.swift | 9 ++- .../ActionType/ActionOpenUrlModel.swift | 9 ++- .../Models/ActionType/ActionPopupModel.swift | 9 ++- .../ActionPreviousSubmitModel.swift | 9 ++- .../ActionType/ActionRestartModel.swift | 9 ++- .../ActionType/ActionSettingModel.swift | 9 ++- .../Models/ActionType/ActionShareModel.swift | 1 - .../Models/ActionType/ActionSheetModel.swift | 70 +++++++++++++++++++ MVMCore/MVMCore/Models/ModelMapping.swift | 2 + 18 files changed, 244 insertions(+), 12 deletions(-) create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionSheetModel.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index f1a3230..c4f8ac4 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -30,6 +30,8 @@ 01F2A04E23A82CF500D954D8 /* ActionPopupModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */; }; 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05123A8325100D954D8 /* ModelMapping.swift */; }; 0A42538F23F3414800554656 /* Codable+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A42538E23F3414800554656 /* Codable+Helpers.swift */; }; + 0A6173B724C09315005FB46A /* ActionSheetModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6173B624C09315005FB46A /* ActionSheetModel.swift */; }; + 0AD93AA424C0CD8300E56A97 /* ActionAlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AD93AA324C0CD8300E56A97 /* ActionAlertModel.swift */; }; 0AFF597A23FC6E60005C24E8 /* ActionShareModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AFF597923FC6E60005C24E8 /* ActionShareModel.swift */; }; 30349BF11FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */; }; @@ -180,6 +182,8 @@ 0A11030B20864F94008ADD90 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; 0A11030C20864F9A008ADD90 /* es-MX */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-MX"; path = "es-MX.lproj/Localizable.strings"; sourceTree = ""; }; 0A42538E23F3414800554656 /* Codable+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Codable+Helpers.swift"; sourceTree = ""; }; + 0A6173B624C09315005FB46A /* ActionSheetModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionSheetModel.swift; sourceTree = ""; }; + 0AD93AA324C0CD8300E56A97 /* ActionAlertModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionAlertModel.swift; sourceTree = ""; }; 0AFF597923FC6E60005C24E8 /* ActionShareModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionShareModel.swift; sourceTree = ""; }; 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreSessionTimeHandler.h; sourceTree = ""; }; 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreSessionTimeHandler.m; sourceTree = ""; }; @@ -466,6 +470,8 @@ 94C014D2242119E6005811A9 /* ActionPreviousSubmitModel.swift */, 94C014D424211AF0005811A9 /* ActionCancelModel.swift */, 94C014D824212360005811A9 /* ActionSettingModel.swift */, + 0A6173B624C09315005FB46A /* ActionSheetModel.swift */, + 0AD93AA324C0CD8300E56A97 /* ActionAlertModel.swift */, ); path = ActionType; sourceTree = ""; @@ -923,6 +929,7 @@ AFED77A31FCCA29400BAE689 /* MVMCoreViewControllerNibMappingObject.m in Sources */, 8876D5EB1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.m in Sources */, AFBB96A41FBA3A9A0008D868 /* MVMCoreTopAlertObject.m in Sources */, + 0A6173B724C09315005FB46A /* ActionSheetModel.swift in Sources */, 01F2A03923A812DD00D954D8 /* ActionOpenUrlModel.swift in Sources */, AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */, AFBB969C1FBA3A9A0008D868 /* MVMCoreAlertHandler.m in Sources */, @@ -948,6 +955,7 @@ AF43A6FF1FBE3252008E9347 /* Reachability.m in Sources */, 01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */, AFBB96921FBA3A9A0008D868 /* MVMCoreNavigationOperation.m in Sources */, + 0AD93AA424C0CD8300E56A97 /* ActionAlertModel.swift in Sources */, AFBB96611FBA3A570008D868 /* MVMCoreLoadObject.m in Sources */, 946EE1B4237B619D0036751F /* Encoder.swift in Sources */, AFBB96941FBA3A9A0008D868 /* MVMCorePresentAnimationOperation.m in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 7867991..2d1c51e 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -71,6 +71,9 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeShare]) { [self shareAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + } else if ([actionType isEqualToString:KeyActionTypeActionSheet]) { + [self actionSheetAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + } else if ([actionType isEqualToString:KeyActionTypePreviousSubmit]) { [self previousSubmitAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; @@ -197,6 +200,35 @@ NSString * const KeyActionTypeOpen = @"openPage"; } } +- (void)actionSheetAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { + + NSArray *actions = [actionInformation array:@"actions"]; + NSString *title = [actionInformation string:@"title"]; + NSString *message = [actionInformation string:@"message"]; + BOOL isGreedy = [actionInformation boolForKey:@"isGreedy"]; + + NSMutableArray *alertActions = [NSMutableArray array]; + + [actions enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + + NSDictionary *actionDict = [actions objectAtIndex:idx]; + NSString *actionTitle = [actionDict string:@"title"]; + + UIAlertAction *alertAction = [UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:obj additionalData:nil delegateObject:nil]; + }]; + + [alertActions addObject:alertAction]; + }]; + + [[MVMCoreAlertHandler sharedAlertHandler] showAlertWithTitle:title + message:message + actions:alertActions + alertStyle:UIAlertControllerStyleActionSheet + isGreedy:isGreedy + alertDelegate:nil]; +} + - (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { // Invalidates the session before restarting. diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index 902ee78..8410270 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -31,6 +31,7 @@ extern NSString * const KeyMessage; extern NSString * const KeyActionTypeRestart; extern NSString * const KeyActionTypeBack; extern NSString * const KeyActionTypeShare; +extern NSString * const KeyActionTypeActionSheet; extern NSString * const KeyShareType; extern NSString * const KeyShareText; extern NSString * const KeyActionTypeCall; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index 019f879..7f38e20 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -33,6 +33,7 @@ NSString * const KeyMessage = @"message"; NSString * const KeyActionTypeRestart = @"restart"; NSString * const KeyActionTypeBack = @"back"; NSString * const KeyActionTypeShare = @"share"; +NSString * const KeyActionTypeActionSheet = @"actionSheet"; NSString * const KeyActionTypeCall = @"call"; NSString * const KeyActionTypePreviousSubmit = @"previousSubmit"; NSString * const KeyActionTypePopup = @"popup"; diff --git a/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift new file mode 100644 index 0000000..762a646 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift @@ -0,0 +1,57 @@ +// +// ActionAlertModel.swift +// MVMCore +// +// Created by Kevin Christiano on 7/16/20. +// Copyright © 2020 myverizon. All rights reserved. +// + + +@objcMembers public class ActionAlertModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public static var identifier: String = "actionAlert" + public var actionType: String = ActionAlertModel.identifier + public var extraParameters: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? + public var title: String? + public var action: ActionModelProtocol + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + + private enum CodingKeys: String, CodingKey { + case actionType + case action + case title + } + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + public init(action: ActionAlertModel, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { + self.extraParameters = extraParameters + self.analyticsData = analyticsData + self.action = action + } + + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + action = try typeContainer.decodeModel(codingKey: .action) + title = try typeContainer.decodeIfPresent(String.self, forKey: .title) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeModel(action, forKey: .action) + try container.encodeIfPresent(title, forKey: .title) + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/ActionBackModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionBackModel.swift index cb8b643..3ecdfe4 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionBackModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionBackModel.swift @@ -1,19 +1,26 @@ // -// File.swift +// ActionBackModel.swift // MVMCore // // Created by Suresh, Kamlesh on 1/15/20. // Copyright © 2020 myverizon. All rights reserved. // -import Foundation @objcMembers public class ActionBackModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "back" public var actionType: String = ActionBackModel.identifier public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.extraParameters = extraParameters self.analyticsData = analyticsData diff --git a/MVMCore/MVMCore/Models/ActionType/ActionCallModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionCallModel.swift index 75ce450..e5dba2b 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionCallModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionCallModel.swift @@ -6,9 +6,12 @@ // Copyright © 2019 myverizon. All rights reserved. // -import Foundation @objcMembers public class ActionCallModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "call" public var actionType: String = ActionCallModel.identifier // TODO: decode into phone number once action handler is re-written @@ -16,6 +19,10 @@ import Foundation public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(callNumber: String, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.callNumber = callNumber self.extraParameters = extraParameters diff --git a/MVMCore/MVMCore/Models/ActionType/ActionCancelModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionCancelModel.swift index 0b1b675..8a77c11 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionCancelModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionCancelModel.swift @@ -6,14 +6,21 @@ // Copyright © 2020 myverizon. All rights reserved. // -import UIKit @objcMembers public class ActionCancelModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "cancel" public var actionType: String = ActionCancelModel.identifier public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.extraParameters = extraParameters self.analyticsData = analyticsData diff --git a/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift index 70c3150..a5d3229 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift @@ -6,7 +6,6 @@ // Copyright © 2019 myverizon. All rights reserved. // -import Foundation public protocol ActionModelProtocol: ModelProtocol { diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift index 7478e3a..94b7a3d 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift @@ -6,9 +6,12 @@ // Copyright © 2019 Suresh, Kamlesh. All rights reserved. // -import Foundation @objcMembers open class ActionOpenPageModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "openPage" public var actionType: String = ActionOpenPageModel.identifier public var pageType: String @@ -17,6 +20,10 @@ import Foundation public var presentationStyle: String? public var tabBarIndex: Int? + //-------------------------------------------------- + // MARK: - Initialzier + //-------------------------------------------------- + public init(pageType: String, presentationStyle: String? = nil, extraParameters: JSONValueDictionary? = nil, analyticsData: JSONValueDictionary? = nil, tabBarIndex: Int? = nil) { self.pageType = pageType self.presentationStyle = presentationStyle diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift index df86873..274b7a4 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift @@ -6,9 +6,12 @@ // Copyright © 2019 myverizon. All rights reserved. // -import Foundation @objcMembers public class ActionOpenUrlModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "openURL" public var actionType: String = ActionOpenUrlModel.identifier // TODO: decode into url once action handler is re-written @@ -27,6 +30,10 @@ import Foundation public var dontShowProgress: Bool? public var headerParameters: JSONValueDictionary? + //-------------------------------------------------- + // MARK: - Initialzier + //-------------------------------------------------- + public init(browserUrl: String) { self.browserUrl = browserUrl } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionPopupModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionPopupModel.swift index 9c5ee17..8cdbd83 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionPopupModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionPopupModel.swift @@ -6,15 +6,22 @@ // Copyright © 2019 myverizon. All rights reserved. // -import Foundation @objcMembers public class ActionPopupModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "popup" public var actionType: String = ActionPopupModel.identifier public var pageType: String public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(pageType: String, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.pageType = pageType self.extraParameters = extraParameters diff --git a/MVMCore/MVMCore/Models/ActionType/ActionPreviousSubmitModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionPreviousSubmitModel.swift index f64b5ba..506f056 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionPreviousSubmitModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionPreviousSubmitModel.swift @@ -6,14 +6,21 @@ // Copyright © 2020 myverizon. All rights reserved. // -import UIKit @objcMembers public class ActionPreviousSubmitModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "previousSubmit" public var actionType: String = ActionPreviousSubmitModel.identifier public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + //-------------------------------------------------- + // MARK: - Initialzier + //-------------------------------------------------- + public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.extraParameters = extraParameters self.analyticsData = analyticsData diff --git a/MVMCore/MVMCore/Models/ActionType/ActionRestartModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionRestartModel.swift index fe9c09d..da785ac 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionRestartModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionRestartModel.swift @@ -6,9 +6,12 @@ // Copyright © 2020 myverizon. All rights reserved. // -import UIKit @objcMembers public class ActionRestartModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "restart" public var actionType: String = ActionRestartModel.identifier public var extraParameters: JSONValueDictionary? @@ -17,6 +20,10 @@ import UIKit ///Optional pageType, if pageType is nil, will start with pageType launchApp public var pageType: String? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(_ pageType: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.pageType = pageType self.extraParameters = extraParameters diff --git a/MVMCore/MVMCore/Models/ActionType/ActionSettingModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionSettingModel.swift index 5986e47..96e95d3 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionSettingModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionSettingModel.swift @@ -6,14 +6,21 @@ // Copyright © 2020 myverizon. All rights reserved. // -import UIKit @objcMembers public class ActionSettingModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "openSettings" public var actionType: String = ActionSettingModel.identifier public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.extraParameters = extraParameters self.analyticsData = analyticsData diff --git a/MVMCore/MVMCore/Models/ActionType/ActionShareModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionShareModel.swift index 7dc327f..893c638 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionShareModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionShareModel.swift @@ -6,7 +6,6 @@ // Copyright © 2020 myverizon. All rights reserved. // -import UIKit @objcMembers public class ActionShareModel: ActionModelProtocol { //-------------------------------------------------- diff --git a/MVMCore/MVMCore/Models/ActionType/ActionSheetModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionSheetModel.swift new file mode 100644 index 0000000..1c20e9f --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionSheetModel.swift @@ -0,0 +1,70 @@ +// +// ActionSheetModel.swift +// MVMCore +// +// Created by Kevin Christiano on 7/16/20. +// Copyright © 2020 myverizon. All rights reserved. +// + + +@objcMembers public class ActionSheetModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public static var identifier: String = "actionSheet" + public var actionType: String = ActionSheetModel.identifier + public var extraParameters: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? + public var actions: [ActionModelProtocol] + public var title: String? + public var message: String? + public var isGreedy = false + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil, _ actions: [ActionModelProtocol]) { + self.extraParameters = extraParameters + self.analyticsData = analyticsData + self.actions = actions + } + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + + private enum CodingKeys: String, CodingKey { + case actionType + case actions + case title + case message + case greedy + } + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + actions = try typeContainer.decodeModels(codingKey: .actions) +// actions = try typeContainer.decode([ActionAlertModel].self, forKey: .actions) + title = try typeContainer.decodeIfPresent(String.self, forKey: .title) + message = try typeContainer.decodeIfPresent(String.self, forKey: .message) + + if let isGreedy = try typeContainer.decodeIfPresent(Bool.self, forKey: .greedy) { + self.isGreedy = isGreedy + } + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeModels(actions, forKey: .actions) + try container.encodeIfPresent(title, forKey: .title) + try container.encodeIfPresent(message, forKey: .message) + try container.encode(isGreedy, forKey: .greedy) + try container.encode(actionType, forKey: .actionType) + } +} diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 87cf215..7cf8dd2 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -21,5 +21,7 @@ import Foundation try? ModelRegistry.register(ActionPreviousSubmitModel.self) try? ModelRegistry.register(ActionCancelModel.self) try? ModelRegistry.register(ActionSettingModel.self) + try? ModelRegistry.register(ActionAlertModel.self) + try? ModelRegistry.register(ActionSheetModel.self) } } From 2daf72e1c8a0ed76971c415cf91f595d26aeaeac Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 16 Jul 2020 17:07:04 -0400 Subject: [PATCH 2/6] sae --- .../Models/ActionType/AlertModel.swift | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index 6b4c634..e85e7c2 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -10,21 +10,38 @@ import UIKit public class AlertButtonModel: Codable { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public var title: String public var action: ActionModelProtocol public var style: UIAlertAction.Style = .default + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(_ title: String,_ action: ActionModelProtocol,_ style: UIAlertAction.Style = .default) { self.title = title self.action = action self.style = style } + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { case title case action case style } + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) title = try typeContainer.decode(String.self, forKey: .title) @@ -44,21 +61,38 @@ public class AlertButtonModel: Codable { } public class AlertModel: Codable { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public var title: String public var message: String public var alertActions: [AlertButtonModel] + + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public init(_ title: String,_ message: String,_ alertActions: [AlertButtonModel]) { self.title = title self.message = message self.alertActions = alertActions } + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { case title case message case alertActions } + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) title = try typeContainer.decode(String.self, forKey: .title) From 0b7b73ba09f975d09204a602ec5a059f29e22b07 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 17 Jul 2020 14:33:57 -0400 Subject: [PATCH 3/6] opening alert action to allow for action sheet. --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 18 +++-- .../ActionHandling/MVMCoreActionHandler.m | 47 +++---------- .../MVMCoreAlertObject+Swift.swift | 30 ++++---- .../MVMCore/Constants/MVMCoreJSONConstants.h | 1 - .../MVMCore/Constants/MVMCoreJSONConstants.m | 1 - .../Models/ActionType/ActionSheetModel.swift | 70 ------------------- .../UIAlertActionStyle+Codable.swift | 7 +- .../UIAlertControllerStyle+Extension.swift | 37 ++++++++++ .../Models/ActionType/AlertModel.swift | 7 ++ MVMCore/MVMCore/Models/ModelMapping.swift | 1 - 10 files changed, 89 insertions(+), 130 deletions(-) delete mode 100644 MVMCore/MVMCore/Models/ActionType/ActionSheetModel.swift rename MVMCore/MVMCore/Models/ActionType/{ => Alert Extensions}/UIAlertActionStyle+Codable.swift (90%) create mode 100644 MVMCore/MVMCore/Models/ActionType/Alert Extensions/UIAlertControllerStyle+Extension.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 0e10622..5bbffe9 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -34,7 +34,7 @@ 01F2A04E23A82CF500D954D8 /* ActionPopupModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */; }; 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05123A8325100D954D8 /* ModelMapping.swift */; }; 0A42538F23F3414800554656 /* Codable+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A42538E23F3414800554656 /* Codable+Helpers.swift */; }; - 0A6173B724C09315005FB46A /* ActionSheetModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6173B624C09315005FB46A /* ActionSheetModel.swift */; }; + 0A62624824C1DFDC00C316B9 /* UIAlertControllerStyle+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A62624724C1DFDC00C316B9 /* UIAlertControllerStyle+Extension.swift */; }; 0AFF597A23FC6E60005C24E8 /* ActionShareModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AFF597923FC6E60005C24E8 /* ActionShareModel.swift */; }; 30349BF11FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */; }; @@ -189,7 +189,7 @@ 0A11030B20864F94008ADD90 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; 0A11030C20864F9A008ADD90 /* es-MX */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-MX"; path = "es-MX.lproj/Localizable.strings"; sourceTree = ""; }; 0A42538E23F3414800554656 /* Codable+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Codable+Helpers.swift"; sourceTree = ""; }; - 0A6173B624C09315005FB46A /* ActionSheetModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionSheetModel.swift; sourceTree = ""; }; + 0A62624724C1DFDC00C316B9 /* UIAlertControllerStyle+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertControllerStyle+Extension.swift"; sourceTree = ""; }; 0AFF597923FC6E60005C24E8 /* ActionShareModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionShareModel.swift; sourceTree = ""; }; 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreSessionTimeHandler.h; sourceTree = ""; }; 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreSessionTimeHandler.m; sourceTree = ""; }; @@ -346,6 +346,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 0A62624624C1DFB700C316B9 /* Alert Extensions */ = { + isa = PBXGroup; + children = ( + 0184D3FC24BE54A300A05369 /* UIAlertActionStyle+Codable.swift */, + 0A62624724C1DFDC00C316B9 /* UIAlertControllerStyle+Extension.swift */, + ); + path = "Alert Extensions"; + sourceTree = ""; + }; 8876D5BF1FB50A9E00EB2E3D = { isa = PBXGroup; children = ( @@ -465,11 +474,11 @@ 946EE1B6237B66630036751F /* ActionType */ = { isa = PBXGroup; children = ( + 0A62624624C1DFB700C316B9 /* Alert Extensions */, 01F2A03523A80A7300D954D8 /* ActionModelProtocol.swift */, 946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */, 01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */, 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */, - 0184D3FC24BE54A300A05369 /* UIAlertActionStyle+Codable.swift */, 01F2A04B23A82B1B00D954D8 /* ActionCallModel.swift */, 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */, 01C851D023CF97FE0021F976 /* ActionBackModel.swift */, @@ -479,7 +488,6 @@ 94C014D424211AF0005811A9 /* ActionCancelModel.swift */, 94C014D824212360005811A9 /* ActionSettingModel.swift */, 0184D3FE24BE554A00A05369 /* AlertModel.swift */, - 0A6173B624C09315005FB46A /* ActionSheetModel.swift */, ); path = ActionType; sourceTree = ""; @@ -936,13 +944,13 @@ AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, AFBB96581FBA3A570008D868 /* FreeBeeAuthObject.m in Sources */, 01F2A04E23A82CF500D954D8 /* ActionPopupModel.swift in Sources */, + 0A62624824C1DFDC00C316B9 /* UIAlertControllerStyle+Extension.swift in Sources */, AF43A5781FBA5B7C008E9347 /* MVMCoreJSONConstants.m in Sources */, AFBB96691FBA3A570008D868 /* MVMCoreRequestParameters.m in Sources */, AFED77A31FCCA29400BAE689 /* MVMCoreViewControllerNibMappingObject.m in Sources */, 8876D5EB1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.m in Sources */, 0184D3DB24B7D5A600A05369 /* ActionAlertModel.swift in Sources */, AFBB96A41FBA3A9A0008D868 /* MVMCoreTopAlertObject.m in Sources */, - 0A6173B724C09315005FB46A /* ActionSheetModel.swift in Sources */, 01F2A03923A812DD00D954D8 /* ActionOpenUrlModel.swift in Sources */, AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */, AFBB969C1FBA3A9A0008D868 /* MVMCoreAlertHandler.m in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 1f0685b..5642bd6 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -70,10 +70,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeShare]) { [self shareAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeActionSheet]) { - [self actionSheetAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - + } else if ([actionType isEqualToString:KeyActionTypePreviousSubmit]) { [self previousSubmitAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; @@ -203,35 +200,6 @@ NSString * const KeyActionTypeOpen = @"openPage"; } } -- (void)actionSheetAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - - NSArray *actions = [actionInformation array:@"actions"]; - NSString *title = [actionInformation string:@"title"]; - NSString *message = [actionInformation string:@"message"]; - BOOL isGreedy = [actionInformation boolForKey:@"isGreedy"]; - - NSMutableArray *alertActions = [NSMutableArray array]; - - [actions enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - - NSDictionary *actionDict = [actions objectAtIndex:idx]; - NSString *actionTitle = [actionDict string:@"title"]; - - UIAlertAction *alertAction = [UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { - [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:obj additionalData:nil delegateObject:nil]; - }]; - - [alertActions addObject:alertAction]; - }]; - - [[MVMCoreAlertHandler sharedAlertHandler] showAlertWithTitle:title - message:message - actions:alertActions - alertStyle:UIAlertControllerStyleActionSheet - isGreedy:isGreedy - alertDelegate:nil]; -} - - (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { // Invalidates the session before restarting. @@ -346,21 +314,26 @@ NSString * const KeyActionTypeOpen = @"openPage"; } - (void)showAlert:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - + MVMCoreErrorObject *error = nil; MVMCoreAlertObject *alertObject = [MVMCoreAlertObject alertObjectWithAction:actionInformation additionalData:additionalData delegateObject:delegateObject error:&error]; if ([delegateObject.actionDelegate respondsToSelector:@selector(willShowPopupWithAlertObject:alertJson:)]) { [delegateObject.actionDelegate willShowPopupWithAlertObject:alertObject alertJson:actionInformation]; } - + + NSDictionary *alertDictionary = [actionInformation dict:@"alert"]; + NSNumber *style = [alertDictionary optionalNumberForKey:@"style"]; + if ([style isEqual:@0]) { + alertObject.alertStyle = UIAlertControllerStyleActionSheet; + } + if (alertObject) { [[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:alertObject]; } else { - [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; + [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; } } - - (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { return NO; } diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index d15ed80..b5cd66f 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -6,32 +6,34 @@ // Copyright © 2020 myverizon. All rights reserved. // -import UIKit public extension MVMCoreAlertObject { - - @objc static func alertObjectWith(action actionJson: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> MVMCoreAlertObject? { - + + @objc static func alertObjectWith(action actionJson: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> MVMCoreAlertObject? { + guard let alertJson = actionJson?.optionalDictionaryForKey("alert"), (alertJson.optionalStringForKey(KeyTitle) != nil || alertJson.optionalStringForKey(KeyMessage) != nil), - let actionsList = alertJson.optionalArrayForKey("alertActions") as? [[AnyHashable : Any]] else { + let actionsList = alertJson.optionalArrayForKey("alertActions") as? [[AnyHashable: Any]] + else { error?.pointee = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: ErrorCode.popupFailed.rawValue, domain: ErrorDomainNative, location: String(describing: self)) - return nil + return nil } - + var actionsForAlert: [UIAlertAction] = [] + for actionJson in actionsList { let style = UIAlertAction.Style(rawValue: actionJson.stringForkey("style")) - let alertAction = UIAlertAction(title: actionJson.optionalStringForKey(KeyTitle), style: style) { (action) in - MVMCoreActionHandler.shared()?.handleAction(with: actionJson.optionalDictionaryForKey("action"), additionalData: additionalData, delegateObject: delegateObject) + let alertAction = UIAlertAction(title: actionJson.optionalStringForKey(KeyTitle), style: style) { action in + MVMCoreActionHandler.shared()?.handleAction(with: actionJson.optionalDictionaryForKey("action"), + additionalData: additionalData, + delegateObject: delegateObject) } actionsForAlert.append(alertAction) } - let alert = MVMCoreAlertObject(popupAlertWithTitle: alertJson.optionalStringForKey(KeyTitle), - message: alertJson.optionalStringForKey(KeyMessage), - actions: actionsForAlert, - isGreedy: false) - return alert + return MVMCoreAlertObject(popupAlertWithTitle: alertJson.optionalStringForKey(KeyTitle), + message: alertJson.optionalStringForKey(KeyMessage), + actions: actionsForAlert, + isGreedy: false) } } diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index eeb167d..697374c 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -31,7 +31,6 @@ extern NSString * const KeyMessage; extern NSString * const KeyActionTypeRestart; extern NSString * const KeyActionTypeBack; extern NSString * const KeyActionTypeShare; -extern NSString * const KeyActionTypeActionSheet; extern NSString * const KeyShareType; extern NSString * const KeyShareText; extern NSString * const KeyActionTypeCall; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index fd34761..c283fd6 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -33,7 +33,6 @@ NSString * const KeyMessage = @"message"; NSString * const KeyActionTypeRestart = @"restart"; NSString * const KeyActionTypeBack = @"back"; NSString * const KeyActionTypeShare = @"share"; -NSString * const KeyActionTypeActionSheet = @"actionSheet"; NSString * const KeyActionTypeCall = @"call"; NSString * const KeyActionTypePreviousSubmit = @"previousSubmit"; NSString * const KeyActionTypePopup = @"popup"; diff --git a/MVMCore/MVMCore/Models/ActionType/ActionSheetModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionSheetModel.swift deleted file mode 100644 index 1c20e9f..0000000 --- a/MVMCore/MVMCore/Models/ActionType/ActionSheetModel.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// ActionSheetModel.swift -// MVMCore -// -// Created by Kevin Christiano on 7/16/20. -// Copyright © 2020 myverizon. All rights reserved. -// - - -@objcMembers public class ActionSheetModel: ActionModelProtocol { - //-------------------------------------------------- - // MARK: - Properties - //-------------------------------------------------- - - public static var identifier: String = "actionSheet" - public var actionType: String = ActionSheetModel.identifier - public var extraParameters: JSONValueDictionary? - public var analyticsData: JSONValueDictionary? - public var actions: [ActionModelProtocol] - public var title: String? - public var message: String? - public var isGreedy = false - - //-------------------------------------------------- - // MARK: - Initializer - //-------------------------------------------------- - - public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil, _ actions: [ActionModelProtocol]) { - self.extraParameters = extraParameters - self.analyticsData = analyticsData - self.actions = actions - } - - //-------------------------------------------------- - // MARK: - Keys - //-------------------------------------------------- - - private enum CodingKeys: String, CodingKey { - case actionType - case actions - case title - case message - case greedy - } - - //-------------------------------------------------- - // MARK: - Initializer - //-------------------------------------------------- - - required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - actions = try typeContainer.decodeModels(codingKey: .actions) -// actions = try typeContainer.decode([ActionAlertModel].self, forKey: .actions) - title = try typeContainer.decodeIfPresent(String.self, forKey: .title) - message = try typeContainer.decodeIfPresent(String.self, forKey: .message) - - if let isGreedy = try typeContainer.decodeIfPresent(Bool.self, forKey: .greedy) { - self.isGreedy = isGreedy - } - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeModels(actions, forKey: .actions) - try container.encodeIfPresent(title, forKey: .title) - try container.encodeIfPresent(message, forKey: .message) - try container.encode(isGreedy, forKey: .greedy) - try container.encode(actionType, forKey: .actionType) - } -} diff --git a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift b/MVMCore/MVMCore/Models/ActionType/Alert Extensions/UIAlertActionStyle+Codable.swift similarity index 90% rename from MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift rename to MVMCore/MVMCore/Models/ActionType/Alert Extensions/UIAlertActionStyle+Codable.swift index bb3f5bd..266a305 100644 --- a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift +++ b/MVMCore/MVMCore/Models/ActionType/Alert Extensions/UIAlertActionStyle+Codable.swift @@ -6,7 +6,6 @@ // Copyright © 2020 myverizon. All rights reserved. // -import UIKit extension UIAlertAction.Style: Codable { @@ -14,10 +13,13 @@ extension UIAlertAction.Style: Codable { switch rawValue { case "default": self = .default + case "cancel": self = .cancel + case "destructive": self = .destructive + default: self = .default } @@ -27,10 +29,13 @@ extension UIAlertAction.Style: Codable { switch self { case .default: return "default" + case .cancel: return "cancel" + case .destructive: return "destructive" + @unknown default: return "default" } diff --git a/MVMCore/MVMCore/Models/ActionType/Alert Extensions/UIAlertControllerStyle+Extension.swift b/MVMCore/MVMCore/Models/ActionType/Alert Extensions/UIAlertControllerStyle+Extension.swift new file mode 100644 index 0000000..1de084a --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/Alert Extensions/UIAlertControllerStyle+Extension.swift @@ -0,0 +1,37 @@ +// +// UIAlertControllerStyle+Extension.swift +// MVMCore +// +// Created by Kevin Christiano on 7/17/20. +// Copyright © 2020 myverizon. All rights reserved. +// + + +extension UIAlertController.Style: Codable { + + init(rawValue: String) { + switch rawValue { + case "alert": + self = .alert + + case "actionSheet": + self = .actionSheet + + default: + self = .alert + } + } + + var rawValueString: String { + switch self { + case .alert: + return "alert" + + case .actionSheet: + return "actionSheet" + + @unknown default: + return "alert" + } + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index e85e7c2..f636d99 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -67,6 +67,7 @@ public class AlertModel: Codable { public var title: String public var message: String + public var style: UIAlertController.Style = .alert public var alertActions: [AlertButtonModel] //-------------------------------------------------- @@ -87,6 +88,7 @@ public class AlertModel: Codable { case title case message case alertActions + case style } //-------------------------------------------------- @@ -98,6 +100,10 @@ public class AlertModel: Codable { title = try typeContainer.decode(String.self, forKey: .title) message = try typeContainer.decode(String.self, forKey: .message) alertActions = try typeContainer.decode([AlertButtonModel].self, forKey: .alertActions) + + if let style = try? typeContainer.decodeIfPresent(String.self, forKey: .style) { + self.style = UIAlertController.Style(rawValue: style) + } } open func encode(to encoder: Encoder) throws { @@ -105,5 +111,6 @@ public class AlertModel: Codable { try container.encode(title, forKey: .title) try container.encode(message, forKey: .message) try container.encode(alertActions, forKey: .alertActions) + try container.encode(style, forKey: .style) } } diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 7cf8dd2..66fdab0 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -22,6 +22,5 @@ import Foundation try? ModelRegistry.register(ActionCancelModel.self) try? ModelRegistry.register(ActionSettingModel.self) try? ModelRegistry.register(ActionAlertModel.self) - try? ModelRegistry.register(ActionSheetModel.self) } } From 85f37ddfe046df4e535013cbe40b1fa95f10c0dc Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 17 Jul 2020 16:40:03 -0400 Subject: [PATCH 4/6] no ? --- MVMCore/MVMCore/Models/ActionType/AlertModel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index f636d99..3d299a3 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -46,7 +46,7 @@ public class AlertButtonModel: Codable { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) title = try typeContainer.decode(String.self, forKey: .title) - if let style = try? typeContainer.decodeIfPresent(String.self, forKey: .style) { + if let style = try typeContainer.decodeIfPresent(String.self, forKey: .style) { self.style = UIAlertAction.Style(rawValue: style) } action = try typeContainer.decodeModel(codingKey: .action) @@ -101,7 +101,7 @@ public class AlertModel: Codable { message = try typeContainer.decode(String.self, forKey: .message) alertActions = try typeContainer.decode([AlertButtonModel].self, forKey: .alertActions) - if let style = try? typeContainer.decodeIfPresent(String.self, forKey: .style) { + if let style = try typeContainer.decodeIfPresent(String.self, forKey: .style) { self.style = UIAlertController.Style(rawValue: style) } } From bc9c28aa3fd1801f9167462e1cc93359e7e68113 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 20 Jul 2020 12:09:12 -0400 Subject: [PATCH 5/6] changes --- .../MVMCore/ActionHandling/MVMCoreActionHandler.m | 6 ------ .../AlertHandling/MVMCoreAlertObject+Swift.swift | 15 ++++++++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 5642bd6..2aee69b 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -321,12 +321,6 @@ NSString * const KeyActionTypeOpen = @"openPage"; [delegateObject.actionDelegate willShowPopupWithAlertObject:alertObject alertJson:actionInformation]; } - NSDictionary *alertDictionary = [actionInformation dict:@"alert"]; - NSNumber *style = [alertDictionary optionalNumberForKey:@"style"]; - if ([style isEqual:@0]) { - alertObject.alertStyle = UIAlertControllerStyleActionSheet; - } - if (alertObject) { [[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:alertObject]; } else { diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index b5cd66f..1e65c97 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -30,10 +30,15 @@ public extension MVMCoreAlertObject { } actionsForAlert.append(alertAction) } - - return MVMCoreAlertObject(popupAlertWithTitle: alertJson.optionalStringForKey(KeyTitle), - message: alertJson.optionalStringForKey(KeyMessage), - actions: actionsForAlert, - isGreedy: false) + + let alertObject = MVMCoreAlertObject(popupAlertWithTitle: alertJson.optionalStringForKey(KeyTitle), + message: alertJson.optionalStringForKey(KeyMessage), + actions: actionsForAlert, + isGreedy: false) + + let alertStyle = alertJson.int32ForKey("style") + alertObject?.alertStyle = alertStyle == 0 ? .actionSheet : .alert + + return alertObject } } From d4ab61f923bbfe0045d89001432c30ffb12c4680 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 20 Jul 2020 13:57:06 -0400 Subject: [PATCH 6/6] less confusing --- MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift | 5 +++-- MVMCore/MVMCore/Models/ActionType/AlertModel.swift | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index 1e65c97..162dd2d 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -36,8 +36,9 @@ public extension MVMCoreAlertObject { actions: actionsForAlert, isGreedy: false) - let alertStyle = alertJson.int32ForKey("style") - alertObject?.alertStyle = alertStyle == 0 ? .actionSheet : .alert + if let alertStyle = alertJson.optionalStringForKey("style") { + alertObject?.alertStyle = UIAlertController.Style(rawValue: alertStyle) + } return alertObject } diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index 3d299a3..866bfb3 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -111,6 +111,6 @@ public class AlertModel: Codable { try container.encode(title, forKey: .title) try container.encode(message, forKey: .message) try container.encode(alertActions, forKey: .alertActions) - try container.encode(style, forKey: .style) + try container.encode(style.rawValueString, forKey: .style) } }