forked from ChatSecure/ChatSecure-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OTRQRCodeActivity.m
80 lines (65 loc) · 2.19 KB
/
OTRQRCodeActivity.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// QRCodeActivity.m
// Off the Record
//
// Created by David on 5/30/13.
// Copyright (c) 2013 Chris Ballinger. All rights reserved.
//
#import "OTRQRCodeActivity.h"
#import "UIImage+ChatSecure.h"
#import "UIActivity+ChatSecure.h"
#import "OTRLanguageManager.h"
@import OTRAssets;
NSString *const kOTRActivityTypeQRCode = @"OTRActivityTypeQRCode";
@interface OTRQRCodeActivity()
@property (nonatomic, copy, readonly) NSString *qrString;
@end
@implementation OTRQRCodeActivity
-(NSString *)activityTitle
{
return QR_CODE_STRING;
}
-(NSString *)activityType
{
return kOTRActivityTypeQRCode;
}
-(UIImage *)activityImage
{
return [UIImage otr_imageWithImage:[UIImage imageNamed:@"chatsecure_qrcode.png" inBundle:[OTRAssets resourcesBundle] compatibleWithTraitCollection:nil] scaledToSize:[UIActivity otr_defaultImageSize]];
}
-(BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
BOOL canPerformActivity = NO;
if (activityItems.count == 1) {
id activityItem = activityItems[0];
if ([activityItem isKindOfClass:[NSString class]] || [activityItem isKindOfClass:[NSURL class]]) {
canPerformActivity = YES;
}
}
return canPerformActivity;
}
- (void)prepareWithActivityItems:(NSArray *)activityItems {
id activityItem = activityItems[0];
if ([activityItem isKindOfClass:[NSString class]]) {
_qrString = activityItem;
} else if ([activityItem isKindOfClass:[NSURL class]]) {
NSURL *url = activityItem;
_qrString = url.absoluteString;
}
}
-(UIViewController *)activityViewController
{
OTRQRCodeViewController * QRCodeViewController = [[OTRQRCodeViewController alloc] initWithQRString:self.qrString];
QRCodeViewController.delegate = self;
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:QRCodeViewController];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
navController.modalPresentationStyle = UIModalPresentationFormSheet;
}
return navController;
}
#pragma mark OTRQRCodeViewControllerDelegate
-(void)didDismissQRCodeViewController:(OTRQRCodeViewController*)qrCodeViewController
{
[self activityDidFinish:YES];
}
@end