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