Skip to content

Commit

Permalink
Remove webview from about view
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Mar 3, 2014
1 parent ad5d3ee commit 6bc2bcc
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 109 deletions.
9 changes: 3 additions & 6 deletions Off the Record/OTRAboutViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
// along with ChatSecure. If not, see <http://www.gnu.org/licenses/>.

#import <UIKit/UIKit.h>
#import <Twitter/Twitter.h>
#import <MessageUI/MessageUI.h>

@interface OTRAboutViewController : UIViewController <UIWebViewDelegate, UIActionSheetDelegate>
@interface OTRAboutViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain) UIImageView *imageView;
@property (strong, nonatomic) UILabel *versionLabel;
@property (nonatomic, retain) UIWebView *aboutTextView;
@property (nonatomic, retain) NSURL *lastActionLink;
@property (nonatomic,strong) UIScrollView * scrollView;
@property (nonatomic, retain) UITableView *aboutTableView;

@end
174 changes: 87 additions & 87 deletions Off the Record/OTRAboutViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,29 @@
#import "OTRAboutViewController.h"
#import "Strings.h"
#import "OTRAppDelegate.h"
#import "UIActionSheet+Blocks.h"

#define ACTIONSHEET_SHARE_TAG 2
#define ACTIONSHEET_LINK_TAG 1
static NSString *const kDefaultCellReuseIdentifier = @"kDefaultCellReuseIdentifier";

@interface OTRAboutViewController(Private)
- (NSArray*) buttonTitlesForShareButton;
@interface OTRAboutTableCellData : NSObject
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSURL *url;
+ (instancetype) cellDataWithTitle:(NSString*)title url:(NSURL*)url;
@end
@implementation OTRAboutTableCellData
+ (instancetype) cellDataWithTitle:(NSString *)title url:(NSURL *)url {
OTRAboutTableCellData *cellData = [[OTRAboutTableCellData alloc] init];
cellData.title = title;
cellData.url = url;
return cellData;
}
@end

@implementation OTRAboutViewController
@synthesize versionLabel, aboutTextView,lastActionLink, imageView;
@synthesize scrollView;
@interface OTRAboutViewController()
@property (nonatomic, strong) NSArray *cellData;
@end

@implementation OTRAboutViewController

- (id)init {
if (self = [super init]) {
Expand All @@ -43,85 +54,62 @@ - (id)init {
return self;
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}


#pragma mark - View lifecycle


- (void) loadView
{
[super loadView];
- (void) setupVersionLabel {
self.versionLabel = [[UILabel alloc] init];
NSString *version = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"];
self.versionLabel.text = [NSString stringWithFormat:@"%@ %@", VERSION_STRING, version];
self.versionLabel.textAlignment = NSTextAlignmentCenter;
self.versionLabel.frame = CGRectMake(0, 0, self.view.frame.size.width, 30);
}

- (void) setupImageView {
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chatsecure_banner.png"]];

self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:self.imageView];
}

- (void) setupTableView {
self.aboutTableView = [[UITableView alloc] init];
self.aboutTableView.delegate = self;
self.aboutTableView.dataSource = self;
[self.aboutTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kDefaultCellReuseIdentifier];
self.aboutTableView.scrollEnabled = NO;
self.aboutTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;

[self.view addSubview:self.aboutTableView];
}


- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// Do any additional setup after loading the view from its nib.
NSString *aboutString = [NSString stringWithFormat:@"%@: libotr, libgcrypt, libgpg-error, LibOrange, XMPPFramework, MBProgressHUD, Appirater, SSKeychain, AFNetowork, Hockey SDK, UserVoice.<br><a href=\"https://chatsecure.org/\">%@</a><br><a href=\"https://github.com/chrisballinger/Off-the-Record-iOS\">%@</a><br><a href=\"https://www.transifex.com/projects/p/chatsecure\">%@</a>", ATTRIBUTION_STRING, PROJECT_HOMEPAGE_STRING, SOURCE_STRING, CONTRIBUTE_TRANSLATION_STRING];

self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

aboutTextView = [[UIWebView alloc] init];
aboutTextView.delegate = self;
[aboutTextView loadHTMLString:aboutString baseURL:[NSURL URLWithString:@"/"]];

aboutTextView.userInteractionEnabled = YES;
if([aboutTextView respondsToSelector:@selector(scrollView)]) {
aboutTextView.scrollView.scrollEnabled = NO;
// Fixes frame problems on iOS 7
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController.view setBackgroundColor:[UIColor whiteColor]];
}
OTRAboutTableCellData *homepageData = [OTRAboutTableCellData cellDataWithTitle:PROJECT_HOMEPAGE_STRING url:[NSURL URLWithString:@"https://chatsecure.org"]];
OTRAboutTableCellData *sourceData = [OTRAboutTableCellData cellDataWithTitle:SOURCE_STRING url:[NSURL URLWithString:@"https://github.com/chrisballinger/Off-the-Record-iOS"]];
OTRAboutTableCellData *translateData = [OTRAboutTableCellData cellDataWithTitle:CONTRIBUTE_TRANSLATION_STRING url:[NSURL URLWithString:@"https://www.transifex.com/projects/p/chatsecure"]];
self.cellData = @[homepageData, sourceData, translateData];
self.view.backgroundColor = [UIColor whiteColor];

NSString *version = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"];
versionLabel.text = [NSString stringWithFormat:@"%@ %@", VERSION_STRING, version];

[scrollView addSubview:aboutTextView];
[scrollView addSubview:imageView];
[scrollView addSubview:versionLabel];

[self.view addSubview:scrollView];
[self setupVersionLabel];
[self setupImageView];
[self setupTableView];
}

- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

CGFloat imageViewFrameWidth = imageView.image.size.width;
CGFloat imageViewFrameHeight = imageView.image.size.height;
imageView.frame = CGRectMake(self.view.frame.size.width/2 - imageViewFrameWidth/2, 20, imageViewFrameWidth, imageViewFrameHeight);
imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;

CGSize versionLabelSize = [[versionLabel text]sizeWithFont:[versionLabel font]];
versionLabel.frame = CGRectMake(floorf(self.view.frame.size.width/2 - versionLabelSize.width/2), self.view.frame.size.height-versionLabelSize.height-20, versionLabelSize.width, versionLabelSize.height);
versionLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;

CGFloat aboutTextViewFrameWidth = self.view.frame.size.width-40;
CGFloat aboutTextViewFrameYOrigin = imageView.frame.origin.y + imageViewFrameHeight + 10;
aboutTextView.frame = CGRectMake(self.view.frame.size.width/2-aboutTextViewFrameWidth/2, aboutTextViewFrameYOrigin, aboutTextViewFrameWidth, versionLabel.frame.origin.y - aboutTextViewFrameYOrigin);
aboutTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;

scrollView.contentSize = CGSizeMake(self.view.frame.size.width, versionLabel.frame.origin.y+versionLabelSize.height);
CGFloat padding = 10.0f;
self.imageView.frame = CGRectMake(padding, padding, self.view.frame.size.width - padding*2, 100);
self.aboutTableView.frame = CGRectMake(0, self.imageView.frame.origin.y + self.imageView.frame.size.height + padding, self.view.frame.size.width, self.view.frame.size.height - self.imageView.frame.size.height - padding * 2);
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.versionLabel = nil;
self.aboutTextView = nil;
self.imageView = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
Expand All @@ -133,28 +121,40 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.absoluteString isEqualToString:@"file:///"]) {
return YES;
}
if ([[UIApplication sharedApplication] canOpenURL:request.URL])
{
self.lastActionLink = request.URL;
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:[[request.URL absoluteURL] description] delegate:self cancelButtonTitle:CANCEL_STRING destructiveButtonTitle:nil otherButtonTitles:OPEN_IN_SAFARI_STRING, nil];
action.tag = ACTIONSHEET_LINK_TAG;
[OTR_APP_DELEGATE presentActionSheet:action inView:self.view];
}
return NO;
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _cellData.count;
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == ACTIONSHEET_LINK_TAG) {
if (buttonIndex != actionSheet.cancelButtonIndex)
{
[[UIApplication sharedApplication] openURL:[lastActionLink absoluteURL]];
}
}
- (UIView*) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return self.versionLabel;
}

- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return self.versionLabel.frame.size.height;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kDefaultCellReuseIdentifier forIndexPath:indexPath];
OTRAboutTableCellData *cellData = [self.cellData objectAtIndex:indexPath.row];
cell.textLabel.text = cellData.title;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
OTRAboutTableCellData *cellData = [self.cellData objectAtIndex:indexPath.row];
NSURL *url = cellData.url;
RIButtonItem *cancelButton = [RIButtonItem itemWithLabel:CANCEL_STRING];
RIButtonItem *safariButton = [RIButtonItem itemWithLabel:OPEN_IN_SAFARI_STRING action:^{
[[UIApplication sharedApplication] openURL:url];
}];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:url.absoluteString cancelButtonItem:cancelButton destructiveButtonItem:nil otherButtonItems:safariButton, nil];
[OTR_APP_DELEGATE presentActionSheet:actionSheet inView:self.view];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
7 changes: 0 additions & 7 deletions Off the Record/OTRQRCodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ - (void) viewDidLoad {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:DONE_STRING style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonPressed:)];
}

- (void)viewDidUnload
{
[super viewDidUnload];
self.imageView = nil;
self.instructionsLabel = nil;
}

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
Expand Down
4 changes: 2 additions & 2 deletions Off the Record/OTRSafariActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (id)initWithFrame:(CGRect)frame
-(id)initWithUrl:(NSURL *)newUrl
{

if([[[OpenInChromeController alloc]init] isChromeInstalled])
if([[OpenInChromeController sharedInstance] isChromeInstalled])
{
self = [self initWithTitle:[[newUrl absoluteURL] description] delegate:self cancelButtonTitle:CANCEL_STRING destructiveButtonTitle:nil otherButtonTitles:OPEN_IN_SAFARI_STRING,@"Open in Chrome", nil];
}
Expand All @@ -48,7 +48,7 @@ -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)
}
else
{
[[[OpenInChromeController alloc]init] openInChrome:url];
[[OpenInChromeController sharedInstance] openInChrome:url];
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions Off the Record/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define YOUR_STATUS_MESSAGE [OTRLanguageManager translatedString: @"You are: %@"]
#define PASSWORD_STRING [OTRLanguageManager translatedString: @"Password"]
#define ADVANCED_STRING [OTRLanguageManager translatedString: @"Advanced"]
#define ATTRIBUTION_STRING [OTRLanguageManager translatedString: @"ChatSecure is brought to you by many open source projects"]
#define CHAT_STATE_GONE_STRING [OTRLanguageManager translatedString: @"Gone"]
#define VERSION_STRING [OTRLanguageManager translatedString: @"Version"]
#define errSSLPeerCertUnknownString [OTRLanguageManager translatedString: @"Unknown certificate"]
Expand All @@ -34,7 +33,7 @@
#define GROUPS_STRING [OTRLanguageManager translatedString: @"Groups"]
#define NEW_CERTIFICATE_STRING [OTRLanguageManager translatedString: @"New SSL Certificate"]
#define LOGIN_STRING [OTRLanguageManager translatedString: @"Log In"]
#define CANCEL_STRING [OTRLanguageManager translatedString: @"Cancel"]
#define CHAT_STATE_PAUSED_STRING [OTRLanguageManager translatedString: @"Entered Text"]
#define REMOVE_STRING [OTRLanguageManager translatedString: @"Remove"]
#define errSSLPeerDecodeErrorString [OTRLanguageManager translatedString: @"Decoding error"]
#define iOS_SSL_ERROR_PART1_STRING [OTRLanguageManager translatedString: @"Your current iOS system version (%@) contains a serious security vulnerability. Please update to the latest version as soon as possible."]
Expand Down Expand Up @@ -207,7 +206,7 @@
#define FONT_SIZE_STRING [OTRLanguageManager translatedString: @"Font Size"]
#define SHOW_USERVOICE_STRING [OTRLanguageManager translatedString: @"Would you like to connect to UserVoice to send feedback?"]
#define SELF_SIGNED_SSL_STRING [OTRLanguageManager translatedString: @"Self Signed SSL"]
#define CHAT_STATE_PAUSED_STRING [OTRLanguageManager translatedString: @"Entered Text"]
#define CANCEL_STRING [OTRLanguageManager translatedString: @"Cancel"]
#define errSSLClosedGracefulString [OTRLanguageManager translatedString: @"Connection closed gracefully"]
#define PINNED_CERTIFICATES_DESCRIPTION_STRING [OTRLanguageManager translatedString: @"Manage saved SSL certificates"]
#define LOGIN_AUTOMATICALLY_STRING [OTRLanguageManager translatedString: @"Login Automatically"]
Expand Down
Binary file modified Off the Record/en.lproj/Localizable.strings
Binary file not shown.
4 changes: 0 additions & 4 deletions Off the Record/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
"comment": "Title for settings cell on whether or not the XMPP library should allow SSL hostname mismatch",
"string": "Hostname Mismatch"
},
"ATTRIBUTION_STRING": {
"comment": "for attribution of other projects",
"string": "ChatSecure is brought to you by many open source projects"
},
"AVAILABLE_MESSAGE_STRING": {
"comment": "Message shown in line for users that are available",
"string": "is now available"
Expand Down

0 comments on commit 6bc2bcc

Please sign in to comment.