mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 00:52:43 +02:00
Merge MatrixKit develop with commit hash: b85b736313bec0592bd1cabc68035d97f5331137
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
@import Foundation;
|
||||
|
||||
#import "MXKErrorPresentation.h"
|
||||
|
||||
/**
|
||||
`MXKErrorAlertPresentation` is a concrete implementation of `MXKErrorPresentation` using UIAlertViewController. Display error alert from a view controller.
|
||||
*/
|
||||
@interface MXKErrorAlertPresentation : NSObject<MXKErrorPresentation>
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "MXKErrorAlertPresentation.h"
|
||||
|
||||
#import "MXKErrorPresentableBuilder.h"
|
||||
#import "NSBundle+MatrixKit.h"
|
||||
|
||||
#import "MXKSwiftHeader.h"
|
||||
|
||||
@interface MXKErrorAlertPresentation()
|
||||
|
||||
@property (nonatomic, strong) MXKErrorPresentableBuilder *errorPresentableBuidler;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - Implementation
|
||||
|
||||
@implementation MXKErrorAlertPresentation
|
||||
|
||||
#pragma mark - Setup & Teardown
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_errorPresentableBuidler = [[MXKErrorPresentableBuilder alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - MXKErrorPresentation
|
||||
|
||||
- (void)presentErrorFromViewController:(UIViewController*)viewController
|
||||
title:(NSString*)title
|
||||
message:(NSString*)message
|
||||
animated:(BOOL)animated
|
||||
handler:(void (^)(void))handler
|
||||
{
|
||||
|
||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
|
||||
|
||||
[alert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok]
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction * _Nonnull action) {
|
||||
if (handler)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
}]];
|
||||
|
||||
[viewController presentViewController:alert animated:animated completion:nil];
|
||||
}
|
||||
|
||||
- (void)presentErrorFromViewController:(UIViewController*)viewController
|
||||
forError:(NSError*)error
|
||||
animated:(BOOL)animated
|
||||
handler:(void (^)(void))handler
|
||||
{
|
||||
id <MXKErrorPresentable> errorPresentable = [self.errorPresentableBuidler errorPresentableFromError:error];
|
||||
|
||||
if (errorPresentable)
|
||||
{
|
||||
[self presentErrorFromViewController:viewController
|
||||
forErrorPresentable:errorPresentable
|
||||
animated:animated
|
||||
handler:handler];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)presentGenericErrorFromViewController:(UIViewController*)viewController
|
||||
animated:(BOOL)animated
|
||||
handler:(void (^)(void))handler
|
||||
{
|
||||
id <MXKErrorPresentable> errorPresentable = [self.errorPresentableBuidler commonErrorPresentable];
|
||||
|
||||
[self presentErrorFromViewController:viewController
|
||||
forErrorPresentable:errorPresentable
|
||||
animated:animated
|
||||
handler:handler];
|
||||
}
|
||||
|
||||
- (void)presentErrorFromViewController:(UIViewController*)viewController
|
||||
forErrorPresentable:(id<MXKErrorPresentable>)errorPresentable
|
||||
animated:(BOOL)animated
|
||||
handler:(void (^)(void))handler
|
||||
{
|
||||
[self presentErrorFromViewController:viewController
|
||||
title:errorPresentable.title
|
||||
message:errorPresentable.message
|
||||
animated:animated
|
||||
handler:handler];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
`MXKErrorPresentable` describe an error to display on screen.
|
||||
*/
|
||||
@protocol MXKErrorPresentable
|
||||
|
||||
@required
|
||||
|
||||
@property (strong, nonatomic, readonly) NSString *title;
|
||||
@property (strong, nonatomic, readonly) NSString *message;
|
||||
|
||||
- (id)initWithTitle:(NSString*)title message:(NSString*)message;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
@import Foundation;
|
||||
|
||||
#import "MXKErrorPresentable.h"
|
||||
|
||||
/**
|
||||
`MXKErrorPresentableBuilder` enable to create error to present on screen.
|
||||
*/
|
||||
@interface MXKErrorPresentableBuilder : NSObject
|
||||
|
||||
/**
|
||||
Build a displayable error from a NSError.
|
||||
|
||||
@param error an NSError.
|
||||
@return Return nil in case of network request cancellation error otherwise return a presentable error from NSError informations.
|
||||
*/
|
||||
- (id <MXKErrorPresentable>)errorPresentableFromError:(NSError*)error;
|
||||
|
||||
/**
|
||||
Build a common displayable error. Generic error message to present as fallback when error explanation can't be user friendly.
|
||||
|
||||
@return Common default error.
|
||||
*/
|
||||
- (id <MXKErrorPresentable>)commonErrorPresentable;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "MXKErrorPresentableBuilder.h"
|
||||
|
||||
#import "NSBundle+MatrixKit.h"
|
||||
#import "MXKErrorViewModel.h"
|
||||
|
||||
#import "MXKSwiftHeader.h"
|
||||
|
||||
@implementation MXKErrorPresentableBuilder
|
||||
|
||||
- (id <MXKErrorPresentable>)errorPresentableFromError:(NSError*)error
|
||||
{
|
||||
// Ignore nil error or connection cancellation error
|
||||
if (!error || ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled))
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *title = [error.userInfo valueForKey:NSLocalizedFailureReasonErrorKey];
|
||||
NSString *message = [error.userInfo valueForKey:NSLocalizedDescriptionKey];
|
||||
|
||||
if (!title)
|
||||
{
|
||||
title = [MatrixKitL10n error];
|
||||
}
|
||||
|
||||
if (!message)
|
||||
{
|
||||
message = [MatrixKitL10n errorCommonMessage];
|
||||
}
|
||||
|
||||
return [[MXKErrorViewModel alloc] initWithTitle:title message:message];
|
||||
}
|
||||
|
||||
- (id <MXKErrorPresentable>)commonErrorPresentable
|
||||
{
|
||||
return [[MXKErrorViewModel alloc] initWithTitle:[MatrixKitL10n error]
|
||||
message:[MatrixKitL10n errorCommonMessage]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
@import Foundation;
|
||||
@import UIKit;
|
||||
|
||||
#import "MXKErrorPresentable.h"
|
||||
|
||||
/**
|
||||
`MXKErrorPresentation` describe an error display handler for presenting error from a view controller.
|
||||
*/
|
||||
@protocol MXKErrorPresentation
|
||||
|
||||
- (void)presentErrorFromViewController:(UIViewController*)viewController
|
||||
title:(NSString*)title
|
||||
message:(NSString*)message
|
||||
animated:(BOOL)animated
|
||||
handler:(void (^)(void))handler;
|
||||
|
||||
- (void)presentErrorFromViewController:(UIViewController*)viewController
|
||||
forError:(NSError*)error
|
||||
animated:(BOOL)animated
|
||||
handler:(void (^)(void))handler;
|
||||
|
||||
- (void)presentGenericErrorFromViewController:(UIViewController*)viewController
|
||||
animated:(BOOL)animated
|
||||
handler:(void (^)(void))handler;
|
||||
|
||||
@required
|
||||
|
||||
- (void)presentErrorFromViewController:(UIViewController*)viewController
|
||||
forErrorPresentable:(id<MXKErrorPresentable>)errorPresentable
|
||||
animated:(BOOL)animated
|
||||
handler:(void (^)(void))handler;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
@import Foundation;
|
||||
|
||||
#import "MXKErrorPresentable.h"
|
||||
|
||||
/**
|
||||
`MXKErrorViewModel` is a concrete implementation of `MXKErrorPresentable`
|
||||
*/
|
||||
@interface MXKErrorViewModel : NSObject<MXKErrorPresentable>
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "MXKErrorViewModel.h"
|
||||
|
||||
@interface MXKErrorViewModel()
|
||||
|
||||
@property (strong, nonatomic) NSString *title;
|
||||
@property (strong, nonatomic) NSString *message;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MXKErrorViewModel
|
||||
|
||||
- (id)initWithTitle:(NSString*)title message:(NSString*)message
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_title = title;
|
||||
_message = message;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user