From 537d0f11b717ebc36ffdcb2bcafc2985917a7178 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 9 Jul 2020 21:05:23 -0400 Subject: [PATCH 01/13] action alert --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 + .../ActionHandling/MVMCoreActionHandler.m | 25 +++++++ .../AlertHandling/MVMCoreAlertObject.h | 1 + .../AlertHandling/MVMCoreAlertObject.m | 38 ++++++++++ .../MVMCore/Constants/MVMCoreJSONConstants.h | 1 + .../MVMCore/Constants/MVMCoreJSONConstants.m | 1 + .../Models/ActionType/ActionAlertModel.swift | 75 +++++++++++++++++++ MVMCore/MVMCore/Models/ModelMapping.swift | 1 + .../MFHardCodedServerResponse.h | 2 +- 9 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index f1a3230..b681269 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 0184D3DB24B7D5A600A05369 /* ActionAlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */; }; 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; }; 01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBackModel.swift */; }; 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; }; @@ -169,6 +170,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionAlertModel.swift; sourceTree = ""; }; 01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = ""; }; 01C851D023CF97FE0021F976 /* ActionBackModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackModel.swift; sourceTree = ""; }; 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = ""; }; @@ -458,6 +460,7 @@ 01F2A03523A80A7300D954D8 /* ActionModelProtocol.swift */, 946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */, 01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */, + 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */, 01F2A04B23A82B1B00D954D8 /* ActionCallModel.swift */, 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */, 01C851D023CF97FE0021F976 /* ActionBackModel.swift */, @@ -922,6 +925,7 @@ 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 */, 01F2A03923A812DD00D954D8 /* ActionOpenUrlModel.swift in Sources */, AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 7867991..3515506 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -92,6 +92,9 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeCollapseNotification]) { [self collapseNotificationAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + } else if ([actionType isEqualToString:KeyActionTypeAlert]) { + [self showAlert:actionInformation additionalData:additionalData delegateObject:delegateObject]; + } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]) { // not a known action type. [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; @@ -310,6 +313,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(willShowTopAlertWithAlertObject:alertJson:)]) { + alertObject = [delegateObject.actionDelegate willShowTopAlertWithAlertObject:alertObject + alertJson:actionInformation]; + } + + if (alertObject) { + [[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:alertObject]; + } else { + [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; } @@ -475,6 +498,8 @@ NSString * const KeyActionTypeOpen = @"openPage"; [self settingsAction:actionInformation additionalData:additionalData delegate:delegate]; } else if ([actionType isEqualToString:KeyActionTypeCollapseNotification]) { [self collapseNotificationAction:actionInformation additionalData:additionalData delegate:delegate]; + } else if ([actionType isEqualToString:KeyActionTypeAlert]) { + //[self showAlert:actionInformation additionalData:additionalData delegate:delegate]; } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegate:delegate]) { // not a known action type. [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegate:delegate]; diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.h b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.h index 161e123..ed9234f 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.h @@ -68,5 +68,6 @@ typedef void (^TextFieldErrorHandler)(NSArray * _Nonnull fieldErrors); + (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error actionDelegate:(nullable NSObject *)actionDelegate __deprecated; + (nullable instancetype)alertObjectForPageType:(nullable NSString *)pageType responseInfo:(nullable NSDictionary *)responseInfo additionalData:(nullable NSDictionary *)additionalData actionDelegate:(nullable NSObject *)actionDelegate __deprecated; + (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate error:(MVMCoreErrorObject *_Nullable *_Nullable)error __deprecated; ++ (nullable instancetype)alertObjectWithAction:(nullable NSDictionary *)actionJson additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error; @end diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.m b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.m index 09c0d23..ec18111 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.m +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.m @@ -299,5 +299,43 @@ } } ++ (nullable instancetype)alertObjectWithAction:(nullable NSDictionary *)actionJson additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error { + + NSDictionary *alertJson = [actionJson dict:@"alert"]; + MVMCoreAlertObject *alert = [[MVMCoreAlertObject alloc] init]; + alert.title = [alertJson stringForKey:KeyTitle]; + alert.message = [alertJson stringForKey:KeyMessage]; + alert.type = MFAlertTypePopup; + alert.isGreedy = YES; + alert.alertStyle = UIAlertControllerStyleAlert; + + NSArray *actions = [alertJson array:@"alertActions"]; + NSMutableArray *actionsForAlert = [NSMutableArray array]; + for (NSDictionary *actionMap in actions) { + [actionsForAlert addObject:[UIAlertAction actionWithTitle:[actionMap stringForKey:KeyTitle] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:[actionMap dict:@"action"] + additionalData:additionalData + delegateObject:delegateObject]; + }]]; + } + alert.actions = actionsForAlert; + + if ((alert.title.length > 0 || alert.message.length > 0) && alert.actions.count > 0) { + return alert; + } else { + if (error) { + *error = [[MVMCoreErrorObject alloc] initWithTitle:nil messageToLog:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] + code:ErrorCodePopupFailed + domain:ErrorDomainNative + location:@""]; + } + return nil; + } +} + + + @end diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index 902ee78..697374c 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -41,6 +41,7 @@ extern NSString * const KeyActionTypeRedirect; extern NSString * const KeyActionTypeTopAlert; extern NSString * const KeyActionTypeSettings; extern NSString * const KeyActionTypeCollapseNotification; +extern NSString * const KeyActionTypeAlert; extern NSString * const KeyActionInformation; extern NSString * const KeyLinkAwayAppURL; extern NSString * const KeyLinkAwayURL; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index 019f879..c283fd6 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -41,6 +41,7 @@ NSString * const KeyActionTypeRedirect = @"switchApp"; NSString * const KeyActionTypeTopAlert = @"topAlert"; NSString * const KeyActionTypeSettings = @"openSettings"; NSString * const KeyActionTypeCollapseNotification = @"collapseNotification"; +NSString * const KeyActionTypeAlert = @"alert"; NSString * const KeyActionInformation = @"actionInformation"; NSString * const KeyLinkAwayAppURL = @"appURL"; NSString * const KeyLinkAwayURL = @"browserUrl"; diff --git a/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift new file mode 100644 index 0000000..b9220e0 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift @@ -0,0 +1,75 @@ +// +// ActionAlertModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 7/9/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class AlertButtonModel: Codable { + public var title: String + public var action: ActionModelProtocol + public init(_ title: String,_ action: ActionModelProtocol) { + self.title = title + self.action = action + } + + private enum CodingKeys: String, CodingKey { + case title + case action + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + title = try typeContainer.decode(String.self, forKey: .title) + action = try typeContainer.decodeModel(codingKey: .action) + } + + open func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(title, forKey: .title) + try container.encodeModel(action, forKey: .action) + } +} + +public class AlertModel: Codable { + public var title: String + public var message: String + public var alertActions: [AlertButtonModel] + public init(_ title: String,_ message: String,_ alertActions: [AlertButtonModel]) { + self.title = title + self.message = message + self.alertActions = alertActions + } + + private enum CodingKeys: String, CodingKey { + case title + case message + case alertActions + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + title = try typeContainer.decode(String.self, forKey: .title) + message = try typeContainer.decode(String.self, forKey: .message) + alertActions = try typeContainer.decode([AlertButtonModel].self, forKey: .alertActions) + } + + open func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(title, forKey: .title) + try container.encode(message, forKey: .message) + try container.encode(alertActions, forKey: .alertActions) + } +} + +@objcMembers public class ActionAlertModel: ActionModelProtocol { + + public static var identifier: String = "alert" + public var actionType: String = ActionAlertModel.identifier + public var alert: AlertModel + public var extraParameters: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? +} diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 87cf215..66fdab0 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -21,5 +21,6 @@ import Foundation try? ModelRegistry.register(ActionPreviousSubmitModel.self) try? ModelRegistry.register(ActionCancelModel.self) try? ModelRegistry.register(ActionSettingModel.self) + try? ModelRegistry.register(ActionAlertModel.self) } } diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 4631d332bd24b46b662c085681fd13d9c705ea9e Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 9 Jul 2020 21:09:15 -0400 Subject: [PATCH 02/13] reomve comment --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 2 -- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 3515506..93166a9 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -498,8 +498,6 @@ NSString * const KeyActionTypeOpen = @"openPage"; [self settingsAction:actionInformation additionalData:additionalData delegate:delegate]; } else if ([actionType isEqualToString:KeyActionTypeCollapseNotification]) { [self collapseNotificationAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypeAlert]) { - //[self showAlert:actionInformation additionalData:additionalData delegate:delegate]; } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegate:delegate]) { // not a known action type. [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegate:delegate]; diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From e63ba83770c3d2b9945b808de61dd59f582c89ba Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 10 Jul 2020 17:22:25 -0400 Subject: [PATCH 03/13] review fixes --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 ++ .../ActionHandling/MVMCoreActionHandler.m | 12 ++---- .../MVMCoreAlertObject+Swift.swift | 42 +++++++++++++++++++ .../AlertHandling/MVMCoreAlertObject.h | 1 - .../AlertHandling/MVMCoreAlertObject.m | 39 ----------------- .../Models/ActionType/ActionAlertModel.swift | 9 +++- .../MFHardCodedServerResponse.h | 2 +- 7 files changed, 59 insertions(+), 50 deletions(-) create mode 100644 MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index b681269..da488a1 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ /* Begin PBXBuildFile section */ 0184D3DB24B7D5A600A05369 /* ActionAlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */; }; + 0184D3E324B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0184D3E224B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift */; }; 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; }; 01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBackModel.swift */; }; 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; }; @@ -171,6 +172,7 @@ /* Begin PBXFileReference section */ 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionAlertModel.swift; sourceTree = ""; }; + 0184D3E224B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreAlertObject+Swift.swift"; sourceTree = ""; }; 01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = ""; }; 01C851D023CF97FE0021F976 /* ActionBackModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackModel.swift; sourceTree = ""; }; 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = ""; }; @@ -613,6 +615,7 @@ AFBB967F1FBA3A9A0008D868 /* MVMCoreAlertHandler.m */, AFBB96801FBA3A9A0008D868 /* MVMCoreAlertObject.h */, AFBB96811FBA3A9A0008D868 /* MVMCoreAlertObject.m */, + 0184D3E224B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift */, AFBB96821FBA3A9A0008D868 /* MVMCoreAlertOperation.h */, AFBB96831FBA3A9A0008D868 /* MVMCoreAlertOperation.m */, AFBB96841FBA3A9A0008D868 /* MVMCoreTopAlertAnimationDelegateProtocol.h */, @@ -903,6 +906,7 @@ AFBB96BA1FBA3CEC0008D868 /* MVMCoreActionHandler.m in Sources */, AFBB96ED1FBA4A260008D868 /* MFHardCodedServerResponse.m in Sources */, AF43A74D1FC6109F008E9347 /* MVMCoreSessionObject.m in Sources */, + 0184D3E324B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift in Sources */, D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */, AFBB965F1FBA3A570008D868 /* MFFreebeeOperation.m in Sources */, AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 93166a9..1de9eff 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -315,14 +315,10 @@ 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(willShowTopAlertWithAlertObject:alertJson:)]) { - alertObject = [delegateObject.actionDelegate willShowTopAlertWithAlertObject:alertObject - alertJson:actionInformation]; + 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]; } if (alertObject) { diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift new file mode 100644 index 0000000..0a0f846 --- /dev/null +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -0,0 +1,42 @@ +// +// MVMCoreAlertObject+Swift.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 7/10/20. +// 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? { + + guard let alertJson = actionJson?.optionalDictionaryForKey("alert"), + let actionsList = alertJson.optionalArrayForKey("alertActions") as? [[AnyHashable : Any]] else { + return nil + } + + var actionsForAlert:[UIAlertAction] = [] + for actionJson in actionsList { + let style = UIAlertAction.Style(rawValue: Int(actionJson.int32ForKey("style"))) ?? UIAlertAction.Style.default + let alertAction = UIAlertAction(title: actionJson.stringForkey(KeyTitle), style: style) { (action) in + MVMCoreActionHandler.shared()?.handleAction(with: actionJson.dictionaryForKey("action"), additionalData: additionalData, delegateObject: delegateObject) + } + actionsForAlert.append(alertAction) + } + + let alertTitle = alertJson.optionalStringForKey(KeyTitle) + let alertMessage = alertJson.optionalStringForKey(KeyMessage) + + if alertTitle != nil || alertMessage != nil { + let alert = MVMCoreAlertObject(popupAlertWithTitle: alertTitle, message: alertMessage, actions: actionsForAlert, isGreedy: true) + return alert + } + + if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: ErrorCode.popupFailed.rawValue, domain: ErrorDomainNative, location: String(describing: self)) { + error?.pointee = errorObject + } + return nil + } +} diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.h b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.h index ed9234f..161e123 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.h @@ -68,6 +68,5 @@ typedef void (^TextFieldErrorHandler)(NSArray * _Nonnull fieldErrors); + (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error actionDelegate:(nullable NSObject *)actionDelegate __deprecated; + (nullable instancetype)alertObjectForPageType:(nullable NSString *)pageType responseInfo:(nullable NSDictionary *)responseInfo additionalData:(nullable NSDictionary *)additionalData actionDelegate:(nullable NSObject *)actionDelegate __deprecated; + (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate error:(MVMCoreErrorObject *_Nullable *_Nullable)error __deprecated; -+ (nullable instancetype)alertObjectWithAction:(nullable NSDictionary *)actionJson additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error; @end diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.m b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.m index ec18111..c8deb7a 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.m +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject.m @@ -299,43 +299,4 @@ } } -+ (nullable instancetype)alertObjectWithAction:(nullable NSDictionary *)actionJson additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error { - - NSDictionary *alertJson = [actionJson dict:@"alert"]; - MVMCoreAlertObject *alert = [[MVMCoreAlertObject alloc] init]; - alert.title = [alertJson stringForKey:KeyTitle]; - alert.message = [alertJson stringForKey:KeyMessage]; - alert.type = MFAlertTypePopup; - alert.isGreedy = YES; - alert.alertStyle = UIAlertControllerStyleAlert; - - NSArray *actions = [alertJson array:@"alertActions"]; - NSMutableArray *actionsForAlert = [NSMutableArray array]; - for (NSDictionary *actionMap in actions) { - [actionsForAlert addObject:[UIAlertAction actionWithTitle:[actionMap stringForKey:KeyTitle] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * _Nonnull action) { - [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:[actionMap dict:@"action"] - additionalData:additionalData - delegateObject:delegateObject]; - }]]; - } - alert.actions = actionsForAlert; - - if ((alert.title.length > 0 || alert.message.length > 0) && alert.actions.count > 0) { - return alert; - } else { - if (error) { - *error = [[MVMCoreErrorObject alloc] initWithTitle:nil messageToLog:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] - code:ErrorCodePopupFailed - domain:ErrorDomainNative - location:@""]; - } - return nil; - } -} - - - - @end diff --git a/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift index b9220e0..5cdbd77 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift @@ -11,25 +11,32 @@ import UIKit public class AlertButtonModel: Codable { public var title: String public var action: ActionModelProtocol - public init(_ title: String,_ action: ActionModelProtocol) { + public var style: Int = 0 + public init(_ title: String,_ action: ActionModelProtocol,_ style: Int) { self.title = title self.action = action + self.style = style } private enum CodingKeys: String, CodingKey { case title case action + case style } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) title = try typeContainer.decode(String.self, forKey: .title) + if let style = try? typeContainer.decodeIfPresent(Int.self, forKey: .style) { + self.style = style + } action = try typeContainer.decodeModel(codingKey: .action) } open func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(title, forKey: .title) + try container.encode(style, forKey: .style) try container.encodeModel(action, forKey: .action) } } diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 749356c5580e467dafabf76323ad6bd3c47c552c Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 10 Jul 2020 17:27:29 -0400 Subject: [PATCH 04/13] flig flag --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 944f584f7edf195037fc0f705084ddb37bb998b4 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 14 Jul 2020 21:19:40 -0400 Subject: [PATCH 05/13] fixes --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 8 ++ .../ActionHandling/MVMCoreActionHandler.h | 5 +- .../ActionHandling/MVMCoreActionHandler.m | 4 +- .../MVMCoreAlertObject+Swift.swift | 25 +++---- .../Models/ActionType/ActionAlertModel.swift | 64 ---------------- .../Models/ActionType/AlertModel.swift | 73 +++++++++++++++++++ .../UIAlertActionStyle+Codable.swift | 42 +++++++++++ 7 files changed, 139 insertions(+), 82 deletions(-) create mode 100644 MVMCore/MVMCore/Models/ActionType/AlertModel.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index da488a1..46b0ab0 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ /* Begin PBXBuildFile section */ 0184D3DB24B7D5A600A05369 /* ActionAlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */; }; 0184D3E324B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0184D3E224B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift */; }; + 0184D3FD24BE54A300A05369 /* UIAlertActionStyle+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0184D3FC24BE54A300A05369 /* UIAlertActionStyle+Codable.swift */; }; + 0184D3FF24BE554A00A05369 /* AlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0184D3FE24BE554A00A05369 /* AlertModel.swift */; }; 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; }; 01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBackModel.swift */; }; 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; }; @@ -173,6 +175,8 @@ /* Begin PBXFileReference section */ 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionAlertModel.swift; sourceTree = ""; }; 0184D3E224B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreAlertObject+Swift.swift"; sourceTree = ""; }; + 0184D3FC24BE54A300A05369 /* UIAlertActionStyle+Codable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertActionStyle+Codable.swift"; sourceTree = ""; }; + 0184D3FE24BE554A00A05369 /* AlertModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertModel.swift; sourceTree = ""; }; 01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = ""; }; 01C851D023CF97FE0021F976 /* ActionBackModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackModel.swift; sourceTree = ""; }; 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = ""; }; @@ -463,6 +467,7 @@ 946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */, 01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */, 0184D3DA24B7D5A600A05369 /* ActionAlertModel.swift */, + 0184D3FC24BE54A300A05369 /* UIAlertActionStyle+Codable.swift */, 01F2A04B23A82B1B00D954D8 /* ActionCallModel.swift */, 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */, 01C851D023CF97FE0021F976 /* ActionBackModel.swift */, @@ -471,6 +476,7 @@ 94C014D2242119E6005811A9 /* ActionPreviousSubmitModel.swift */, 94C014D424211AF0005811A9 /* ActionCancelModel.swift */, 94C014D824212360005811A9 /* ActionSettingModel.swift */, + 0184D3FE24BE554A00A05369 /* AlertModel.swift */, ); path = ActionType; sourceTree = ""; @@ -898,6 +904,7 @@ 01F2A03623A80A7300D954D8 /* ActionModelProtocol.swift in Sources */, AFBB96991FBA3A9A0008D868 /* MVMCoreAlertController.m in Sources */, 881D26941FCC9D180079C521 /* MVMCoreOperation.m in Sources */, + 0184D3FD24BE54A300A05369 /* UIAlertActionStyle+Codable.swift in Sources */, AFED77A41FCCA29400BAE689 /* MVMCoreViewControllerMappingObject.m in Sources */, 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */, 01F2A04C23A82B1B00D954D8 /* ActionCallModel.swift in Sources */, @@ -920,6 +927,7 @@ 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */, D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */, 94C014D3242119E6005811A9 /* ActionPreviousSubmitModel.swift in Sources */, + 0184D3FF24BE554A00A05369 /* AlertModel.swift in Sources */, 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index 26afbe2..74b93a4 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -50,9 +50,12 @@ extern NSString * _Nonnull const KeyActionTypeOpen; // Makes the previous request, needs the delegate for this - (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Shows a popup +// Shows a popup alert by grabbing the content from the page map. - (void)popupAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; +// Shows popup alert from the alert object in the action map. The actionType of the action is 'alert' +- (void)showAlert:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; + // Shows a top alert - (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 1de9eff..807b5ac 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -315,8 +315,8 @@ 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]; + 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]; } diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index 0a0f846..37e8e98 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -13,30 +13,25 @@ public extension 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 { + error?.pointee = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: ErrorCode.popupFailed.rawValue, domain: ErrorDomainNative, location: String(describing: self)) return nil } - var actionsForAlert:[UIAlertAction] = [] + var actionsForAlert: [UIAlertAction] = [] for actionJson in actionsList { let style = UIAlertAction.Style(rawValue: Int(actionJson.int32ForKey("style"))) ?? UIAlertAction.Style.default - let alertAction = UIAlertAction(title: actionJson.stringForkey(KeyTitle), style: style) { (action) in - MVMCoreActionHandler.shared()?.handleAction(with: actionJson.dictionaryForKey("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 alertTitle = alertJson.optionalStringForKey(KeyTitle) - let alertMessage = alertJson.optionalStringForKey(KeyMessage) - - if alertTitle != nil || alertMessage != nil { - let alert = MVMCoreAlertObject(popupAlertWithTitle: alertTitle, message: alertMessage, actions: actionsForAlert, isGreedy: true) - return alert - } - - if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: ErrorCode.popupFailed.rawValue, domain: ErrorDomainNative, location: String(describing: self)) { - error?.pointee = errorObject - } - return nil + let alert = MVMCoreAlertObject(popupAlertWithTitle: alertJson.optionalStringForKey(KeyTitle), + message: alertJson.optionalStringForKey(KeyMessage), + actions: actionsForAlert, + isGreedy: true) + return alert } } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift index 5cdbd77..5893dc0 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionAlertModel.swift @@ -8,70 +8,6 @@ import UIKit -public class AlertButtonModel: Codable { - public var title: String - public var action: ActionModelProtocol - public var style: Int = 0 - public init(_ title: String,_ action: ActionModelProtocol,_ style: Int) { - self.title = title - self.action = action - self.style = style - } - - private enum CodingKeys: String, CodingKey { - case title - case action - case style - } - - required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - title = try typeContainer.decode(String.self, forKey: .title) - if let style = try? typeContainer.decodeIfPresent(Int.self, forKey: .style) { - self.style = style - } - action = try typeContainer.decodeModel(codingKey: .action) - } - - open func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(title, forKey: .title) - try container.encode(style, forKey: .style) - try container.encodeModel(action, forKey: .action) - } -} - -public class AlertModel: Codable { - public var title: String - public var message: String - public var alertActions: [AlertButtonModel] - public init(_ title: String,_ message: String,_ alertActions: [AlertButtonModel]) { - self.title = title - self.message = message - self.alertActions = alertActions - } - - private enum CodingKeys: String, CodingKey { - case title - case message - case alertActions - } - - required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - title = try typeContainer.decode(String.self, forKey: .title) - message = try typeContainer.decode(String.self, forKey: .message) - alertActions = try typeContainer.decode([AlertButtonModel].self, forKey: .alertActions) - } - - open func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(title, forKey: .title) - try container.encode(message, forKey: .message) - try container.encode(alertActions, forKey: .alertActions) - } -} - @objcMembers public class ActionAlertModel: ActionModelProtocol { public static var identifier: String = "alert" diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift new file mode 100644 index 0000000..25c12f2 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -0,0 +1,73 @@ +// +// AlertModel.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 7/14/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import UIKit + +public class AlertButtonModel: Codable { + public var title: String + public var action: ActionModelProtocol + public var style: UIAlertAction.Style = .default + public init(_ title: String,_ action: ActionModelProtocol,_ style: UIAlertAction.Style = .default) { + self.title = title + self.action = action + self.style = style + } + + private enum CodingKeys: String, CodingKey { + case title + case action + case style + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + title = try typeContainer.decode(String.self, forKey: .title) +// if let style = try? typeContainer.decodeIfPresent(UIAlertAction.Style.self, forKey: .style) { +// self.style = style +// } + action = try typeContainer.decodeModel(codingKey: .action) + } + + open func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(title, forKey: .title) + try container.encode(style, forKey: .style) + try container.encodeModel(action, forKey: .action) + } +} + +public class AlertModel: Codable { + public var title: String + public var message: String + public var alertActions: [AlertButtonModel] + public init(_ title: String,_ message: String,_ alertActions: [AlertButtonModel]) { + self.title = title + self.message = message + self.alertActions = alertActions + } + + private enum CodingKeys: String, CodingKey { + case title + case message + case alertActions + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + title = try typeContainer.decode(String.self, forKey: .title) + message = try typeContainer.decode(String.self, forKey: .message) + alertActions = try typeContainer.decode([AlertButtonModel].self, forKey: .alertActions) + } + + open func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(title, forKey: .title) + try container.encode(message, forKey: .message) + try container.encode(alertActions, forKey: .alertActions) + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift new file mode 100644 index 0000000..b2d9428 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift @@ -0,0 +1,42 @@ +// +// UIAlertActionStyle+Codable.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 7/14/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import UIKit + +enum AlertActionError: Error { + case notAnAlertAction +} + +extension UIAlertAction.Style: Codable { + public init(from decoder: Decoder) throws { + let typeContainer = try decoder.singleValueContainer() + let int = try typeContainer.decode(Int.self) + guard let alignment = UIAlertAction.Style(rawValue: int) else { + throw AlertActionError.notAnAlertAction + } + self = alignment + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(rawValueInt) + } + + var rawValueInt: Int { + switch self { + case .default: + return 0 + case .cancel: + return 1 + case .destructive: + return 2 + @unknown default: + return 0 + } + } +} From b3a2511b96c9f28d1c568008b53bd4d8aa82f007 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jul 2020 18:06:05 -0400 Subject: [PATCH 06/13] remove commented code --- MVMCore/MVMCore/Models/ActionType/AlertModel.swift | 6 +++--- .../HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index 25c12f2..5365401 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -27,9 +27,9 @@ public class AlertButtonModel: Codable { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) title = try typeContainer.decode(String.self, forKey: .title) -// if let style = try? typeContainer.decodeIfPresent(UIAlertAction.Style.self, forKey: .style) { -// self.style = style -// } + if let style = try? typeContainer.decodeIfPresent(UIAlertAction.Style.self, forKey: .style) { + self.style = style + } action = try typeContainer.decodeModel(codingKey: .action) } diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From b076ad331607d9f30024b0d1dbe6647e03b313d1 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jul 2020 19:04:29 -0400 Subject: [PATCH 07/13] fixes --- .../MVMCoreAlertObject+Swift.swift | 2 +- .../Models/ActionType/AlertModel.swift | 9 ++- .../UIAlertActionStyle+Codable.swift | 69 +++++++++++++++---- 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index 37e8e98..166ca65 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -31,7 +31,7 @@ public extension MVMCoreAlertObject { let alert = MVMCoreAlertObject(popupAlertWithTitle: alertJson.optionalStringForKey(KeyTitle), message: alertJson.optionalStringForKey(KeyMessage), actions: actionsForAlert, - isGreedy: true) + isGreedy: false) return alert } } diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index 5365401..3f002e9 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -8,6 +8,7 @@ import UIKit + public class AlertButtonModel: Codable { public var title: String public var action: ActionModelProtocol @@ -27,16 +28,18 @@ public class AlertButtonModel: Codable { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) title = try typeContainer.decode(String.self, forKey: .title) - if let style = try? typeContainer.decodeIfPresent(UIAlertAction.Style.self, forKey: .style) { - self.style = style + + if let style = try? typeContainer.decodeIfPresent(String.self, forKey: .style) { + self.style = UIAlertAction.Style.getStyle(for: style) } + action = try typeContainer.decodeModel(codingKey: .action) } open func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(title, forKey: .title) - try container.encode(style, forKey: .style) + try container.encode(UIAlertAction.Style.getStyleString(for: style), forKey: .style) try container.encodeModel(action, forKey: .action) } } diff --git a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift index b2d9428..a461e82 100644 --- a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift +++ b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift @@ -12,31 +12,72 @@ enum AlertActionError: Error { case notAnAlertAction } -extension UIAlertAction.Style: Codable { +extension UIAlertAction.Style: RawRepresentable { + public init(from decoder: Decoder) throws { let typeContainer = try decoder.singleValueContainer() let int = try typeContainer.decode(Int.self) - guard let alignment = UIAlertAction.Style(rawValue: int) else { + guard let style = UIAlertAction.Style(rawValue: int) else { throw AlertActionError.notAnAlertAction } - self = alignment + self = style } public func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() - try container.encode(rawValueInt) + try container.encode(rawValueString) } - var rawValueInt: Int { - switch self { - case .default: - return 0 - case .cancel: - return 1 - case .destructive: - return 2 - @unknown default: - return 0 + init?(rawValue: String) { + switch rawValue { + case "default": + self = .default + case "cancel": + self = .cancel + case "destructive": + self = .destructive + default: + self = .default } } + + var rawValueString: String { + switch self { + case .default: + return "default" + case .cancel: + return "cancel" + case .destructive: + return "destructive" + @unknown default: + return "default" + } + } + + public static func getStyle(for string: String) -> UIAlertAction.Style { + switch string { + case "default": + return .default + case "cancel": + return .cancel + case "destructive": + return .destructive + default: + return .default + } + } + + public static func getStyleString(for alignment: UIAlertAction.Style) -> String { + switch alignment { + case .default: + return "default" + case .cancel: + return "cancel" + case .destructive: + return "destructive" + default: + return "default" + } + } + } From 1698b21dd8c65fb743b00972435773d823b2e658 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jul 2020 19:08:26 -0400 Subject: [PATCH 08/13] extra space --- MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index 166ca65..e2cf018 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -29,7 +29,7 @@ public extension MVMCoreAlertObject { } let alert = MVMCoreAlertObject(popupAlertWithTitle: alertJson.optionalStringForKey(KeyTitle), - message: alertJson.optionalStringForKey(KeyMessage), + message: alertJson.optionalStringForKey(KeyMessage), actions: actionsForAlert, isGreedy: false) return alert From 724c1afd7c0f62a91a775ddd5819fb9c56eb3e5d Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jul 2020 19:54:37 -0400 Subject: [PATCH 09/13] fixes --- MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift | 2 +- MVMCore/MVMCore/Models/ActionType/AlertModel.swift | 3 +-- .../MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index e2cf018..46503fa 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -21,7 +21,7 @@ public extension MVMCoreAlertObject { var actionsForAlert: [UIAlertAction] = [] for actionJson in actionsList { - let style = UIAlertAction.Style(rawValue: Int(actionJson.int32ForKey("style"))) ?? UIAlertAction.Style.default + let style = UIAlertAction.Style.getStyle(for: 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) } diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index 3f002e9..b0a348d 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -28,11 +28,10 @@ public class AlertButtonModel: Codable { required public init(from decoder: Decoder) throws { 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) { self.style = UIAlertAction.Style.getStyle(for: style) } - action = try typeContainer.decodeModel(codingKey: .action) } diff --git a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift index a461e82..4957cbc 100644 --- a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift +++ b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift @@ -12,7 +12,7 @@ enum AlertActionError: Error { case notAnAlertAction } -extension UIAlertAction.Style: RawRepresentable { +extension UIAlertAction.Style: Codable { public init(from decoder: Decoder) throws { let typeContainer = try decoder.singleValueContainer() @@ -79,5 +79,4 @@ extension UIAlertAction.Style: RawRepresentable { return "default" } } - } From 52af06fd4a61a4865ca2981ed15549d8b23b9e7c Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 15 Jul 2020 20:36:34 -0400 Subject: [PATCH 10/13] remove duplicate code --- .../MVMCoreAlertObject+Swift.swift | 2 +- .../Models/ActionType/AlertModel.swift | 4 +-- .../UIAlertActionStyle+Codable.swift | 28 +------------------ 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index 46503fa..d15ed80 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -21,7 +21,7 @@ public extension MVMCoreAlertObject { var actionsForAlert: [UIAlertAction] = [] for actionJson in actionsList { - let style = UIAlertAction.Style.getStyle(for: actionJson.stringForkey("style")) + 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) } diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index b0a348d..6b4c634 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -30,7 +30,7 @@ public class AlertButtonModel: Codable { title = try typeContainer.decode(String.self, forKey: .title) if let style = try? typeContainer.decodeIfPresent(String.self, forKey: .style) { - self.style = UIAlertAction.Style.getStyle(for: style) + self.style = UIAlertAction.Style(rawValue: style) } action = try typeContainer.decodeModel(codingKey: .action) } @@ -38,7 +38,7 @@ public class AlertButtonModel: Codable { open func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(title, forKey: .title) - try container.encode(UIAlertAction.Style.getStyleString(for: style), forKey: .style) + try container.encode(style.rawValueString, forKey: .style) try container.encodeModel(action, forKey: .action) } } diff --git a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift index 4957cbc..df524ec 100644 --- a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift +++ b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift @@ -28,7 +28,7 @@ extension UIAlertAction.Style: Codable { try container.encode(rawValueString) } - init?(rawValue: String) { + init(rawValue: String) { switch rawValue { case "default": self = .default @@ -53,30 +53,4 @@ extension UIAlertAction.Style: Codable { return "default" } } - - public static func getStyle(for string: String) -> UIAlertAction.Style { - switch string { - case "default": - return .default - case "cancel": - return .cancel - case "destructive": - return .destructive - default: - return .default - } - } - - public static func getStyleString(for alignment: UIAlertAction.Style) -> String { - switch alignment { - case .default: - return "default" - case .cancel: - return "cancel" - case .destructive: - return "destructive" - default: - return "default" - } - } } From b022f09ac2b2cd0a10caeea3967a6359b30c278e Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 16 Jul 2020 09:12:28 -0400 Subject: [PATCH 11/13] remove hardcode --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 338e30c33f9a74cd77fd49019525f72cd19f1f44 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 16 Jul 2020 09:49:32 -0400 Subject: [PATCH 12/13] fix --- .../ActionType/UIAlertActionStyle+Codable.swift | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift index df524ec..bbf13b3 100644 --- a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift +++ b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift @@ -14,20 +14,6 @@ enum AlertActionError: Error { extension UIAlertAction.Style: Codable { - public init(from decoder: Decoder) throws { - let typeContainer = try decoder.singleValueContainer() - let int = try typeContainer.decode(Int.self) - guard let style = UIAlertAction.Style(rawValue: int) else { - throw AlertActionError.notAnAlertAction - } - self = style - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValueString) - } - init(rawValue: String) { switch rawValue { case "default": From c38d873447a1df4cec8ac312fbed2d18f97b8343 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 16 Jul 2020 10:00:08 -0400 Subject: [PATCH 13/13] remove unwanted code --- .../Models/ActionType/UIAlertActionStyle+Codable.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift index bbf13b3..bb3f5bd 100644 --- a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift +++ b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift @@ -8,10 +8,6 @@ import UIKit -enum AlertActionError: Error { - case notAnAlertAction -} - extension UIAlertAction.Style: Codable { init(rawValue: String) {