new timers
top alert update function
This commit is contained in:
parent
1bb0eda96a
commit
b371cf5e83
@ -21,14 +21,17 @@ public extension MVMCoreUITopAlertView {
|
|||||||
NotificationCenter.default.addObserver(self, selector: #selector(viewControllerChanged(notification:)), name: NSNotification.Name(rawValue: MVMCoreNotificationViewControllerChanged), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(viewControllerChanged(notification:)), name: NSNotification.Name(rawValue: MVMCoreNotificationViewControllerChanged), object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func getDelegateObject() -> MVMCoreUIDelegateObject {
|
||||||
|
// TODO: Top alert view is current delegate. Should move to current view controller eventually?
|
||||||
|
return MVMCoreUIDelegateObject.create(withDelegateForAll: self)
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks for new top alert json
|
/// Checks for new top alert json
|
||||||
@objc func responseJSONUpdated(notification: Notification) {
|
@objc func responseJSONUpdated(notification: Notification) {
|
||||||
guard let responseJSON = (notification.userInfo?[String(describing: MVMCoreLoadObject.self)] as? MVMCoreLoadObject)?.responseJSON,
|
guard let responseJSON = (notification.userInfo?[String(describing: MVMCoreLoadObject.self)] as? MVMCoreLoadObject)?.responseJSON,
|
||||||
let json = responseJSON.optionalDictionaryForKey("TopNotification") else { return }
|
let json = responseJSON.optionalDictionaryForKey("TopNotification"),
|
||||||
|
let model = decodeTopNotification(with: json, delegateObject: getDelegateObject()) else { return }
|
||||||
// TODO: Top alert view is current delegate. Should move to current view controller eventually?
|
showTopAlert(with: model)
|
||||||
let delegateObject = MVMCoreUIDelegateObject.create(withDelegateForAll: self)
|
|
||||||
showTopAlert(with: json, delegateObject: delegateObject)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When a detail page changes, check top alerts.
|
/// When a detail page changes, check top alerts.
|
||||||
@ -37,24 +40,47 @@ public extension MVMCoreUITopAlertView {
|
|||||||
MVMCoreAlertHandler.shared()?.checkPagesDependency(for: controller.pageType)
|
MVMCoreAlertHandler.shared()?.checkPagesDependency(for: controller.pageType)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shows the top alert with the json payload.
|
func decodeTopNotification(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) -> TopNotificationModel? {
|
||||||
func showTopAlert(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) {
|
|
||||||
do {
|
do {
|
||||||
let model = try TopNotificationModel.decode(json: json, delegateObject: delegateObject)
|
return try TopNotificationModel.decode(json: json, delegateObject: delegateObject)
|
||||||
showTopAlert(with: model, delegateObject: delegateObject)
|
|
||||||
} catch {
|
} catch {
|
||||||
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "\(self)") {
|
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "\(self)") {
|
||||||
MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
|
MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shows the top alert with the model.
|
/// Shows the top alert with the model.
|
||||||
func showTopAlert(with model: TopNotificationModel, delegateObject: MVMCoreUIDelegateObject?) {
|
func showTopAlert(with model: TopNotificationModel) {
|
||||||
let object = model.createTopAlertObject()
|
let object = model.createTopAlertObject()
|
||||||
MVMCoreAlertHandler.shared()?.showTopAlert(with: object)
|
MVMCoreAlertHandler.shared()?.showTopAlert(with: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func updateMolecule(with topAlertObject: MVMCoreTopAlertObject) {
|
||||||
|
guard topAlertObject.type == self.topAlertObject?.type else { return }
|
||||||
|
let delegateObject = getDelegateObject()
|
||||||
|
guard let newJson = topAlertObject.json,
|
||||||
|
let newModel = decodeTopNotification(with: newJson, delegateObject: delegateObject),
|
||||||
|
let newModelName = MoleculeObjectMapping.shared()?.getMoleculeClass(newModel.molecule)?.nameForReuse(with: newModel.molecule, delegateObject),
|
||||||
|
let currentJson = self.topAlertObject?.json,
|
||||||
|
let currentModel = decodeTopNotification(with: currentJson, delegateObject: delegateObject),
|
||||||
|
let currentModelName = MoleculeObjectMapping.shared()?.getMoleculeClass(currentModel.molecule)?.nameForReuse(with: currentModel.molecule, delegateObject),
|
||||||
|
newModelName == currentModelName,
|
||||||
|
let molecule = currentAlert as? MoleculeViewProtocol else { return /* Something is not right, revisit */}
|
||||||
|
// Update molecule
|
||||||
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||||
|
molecule.reset()
|
||||||
|
molecule.set(with: newModel.molecule, delegateObject, nil)
|
||||||
|
(molecule as? MVMCoreViewProtocol)?.updateView(self.bounds.width)
|
||||||
|
|
||||||
|
// Update status bar.
|
||||||
|
guard let statusBarDelegate = molecule as? StatusBarUI else { return }
|
||||||
|
let statusBarUI = statusBarDelegate.getStatusBarUI()
|
||||||
|
self.setStatusBarColor(statusBarUI.color, statusBarStyle: statusBarUI.style)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the top alert molecule to use and status bar color legacy style.
|
/// Returns the top alert molecule to use and status bar color legacy style.
|
||||||
@objc func molecule(for topAlertObject: MVMCoreTopAlertObject, statusBarColor: AutoreleasingUnsafeMutablePointer<UIColor?>?, statusBarStyle: UnsafeMutablePointer<UIStatusBarStyle>?) -> UIView? {
|
@objc func molecule(for topAlertObject: MVMCoreTopAlertObject, statusBarColor: AutoreleasingUnsafeMutablePointer<UIColor?>?, statusBarStyle: UnsafeMutablePointer<UIStatusBarStyle>?) -> UIView? {
|
||||||
do {
|
do {
|
||||||
|
|||||||
@ -27,6 +27,9 @@
|
|||||||
// Current top alert object
|
// Current top alert object
|
||||||
@property (strong, nullable, nonatomic) MVMCoreTopAlertObject *topAlertObject;
|
@property (strong, nullable, nonatomic) MVMCoreTopAlertObject *topAlertObject;
|
||||||
|
|
||||||
|
/// Current top alert view.
|
||||||
|
@property (weak, nullable, nonatomic, readonly) UIView *currentAlert;
|
||||||
|
|
||||||
// Returns the top alert view
|
// Returns the top alert view
|
||||||
+ (nullable instancetype)sharedGlobal;
|
+ (nullable instancetype)sharedGlobal;
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
|||||||
@property (strong, nonatomic) NSLayoutConstraint *statusBarBottomConstraint;
|
@property (strong, nonatomic) NSLayoutConstraint *statusBarBottomConstraint;
|
||||||
|
|
||||||
@property (weak, nonatomic) UIView *alertView;
|
@property (weak, nonatomic) UIView *alertView;
|
||||||
@property (weak, nonatomic) UIView *currentAlert;
|
@property (weak, nullable, nonatomic, readwrite) UIView *currentAlert;
|
||||||
@property (strong, nonatomic) NSLayoutConstraint *height;
|
@property (strong, nonatomic) NSLayoutConstraint *height;
|
||||||
|
|
||||||
@property (weak, nonatomic) MVMCoreUITopAlertExpandableView *topAlertClearspotView;
|
@property (weak, nonatomic) MVMCoreUITopAlertExpandableView *topAlertClearspotView;
|
||||||
@ -181,6 +181,10 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed.";
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateTopAlertWith:(MVMCoreTopAlertObject *)topAlertObject {
|
||||||
|
[self updateMoleculeWith:topAlertObject];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style {
|
- (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style {
|
||||||
self.statusBarView.backgroundColor = statusBarColor;
|
self.statusBarView.backgroundColor = statusBarColor;
|
||||||
self.statusBarStyle = style;
|
self.statusBarStyle = style;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user