-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathArticleDetailViewController.m
More file actions
116 lines (92 loc) · 3.99 KB
/
Copy pathArticleDetailViewController.m
File metadata and controls
116 lines (92 loc) · 3.99 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// ArticleDetailViewController.m
// CernVM Co-Pilot
//
// Created by Eamon Ford on 6/18/12.
// Copyright (c) 2012 The Byte Factory. All rights reserved.
//
#import "ArticleDetailViewController.h"
#import "NSString+HTML.h"
#import "Constants.h"
@interface ArticleDetailViewController ()
@end
@implementation ArticleDetailViewController
@synthesize contentWebView, contentString;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
if (self.contentString)
[self.contentWebView loadHTMLString:self.contentString baseURL:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.contentWebView stopLoading];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return YES;
else
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)setContentForArticle:(MWFeedItem *)article
{
NSString *body = @"";
// Give "content" a higher priority, but otherwise use "summary"
if (article.content) {
body = article.content;
} else if (article.summary) {
body = article.summary;
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateStyle = NSDateFormatterMediumStyle;
NSString *dateString = [formatter stringFromDate:article.date];
if (!dateString)
dateString = @"";
NSString *link = article.link;
NSString *imgPath = [[NSBundle mainBundle] pathForResource:@"readOriginalArticle" ofType:@"png"];
NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"ArticleCSS" ofType:@"css"];
NSMutableString *htmlString = [NSMutableString stringWithFormat:@"<html><head><link rel='stylesheet' type='text/css' href='file://%@'></head><body><h1>%@</h1><h2>%@</h2>%@<p class='read'><a href='%@'><img src='file://%@' /></a></p></body></html>", cssPath, article.title, dateString, body, link, imgPath];
self.contentString = htmlString;
[self.contentWebView loadHTMLString:self.contentString baseURL:nil];
}
- (void)setContentForVideoMetadata:(NSDictionary *)videoMetadata
{
NSString *videoTag = [NSString stringWithFormat:@"<video width='100%%' controls='controls'><source src='%@' type='video/mp4' /></video>", [videoMetadata objectForKey:kVideoMetadataPropertyVideoURL]];
NSString *titleTag = [NSString stringWithFormat:@"<h1>%@</h1>", [videoMetadata objectForKey:kVideoMetadataPropertyTitle]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateStyle = NSDateFormatterMediumStyle;
NSString *dateString = [formatter stringFromDate:[videoMetadata objectForKey:kVideoMetadataPropertyDate]];
NSString *dateTag = [NSString stringWithFormat:@"<h2>%@</h2>", dateString];
NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"ArticleCSS" ofType:@"css"];
NSMutableString *htmlString = [NSMutableString stringWithFormat:@"<html><head><link rel='stylesheet' type='text/css' href='file://%@'></head><body>%@%@%@</body></html>", cssPath, videoTag, titleTag, dateTag];
self.contentString = htmlString;
[self.contentWebView loadHTMLString:self.contentString baseURL:nil];
}
- (void)setContentForTweet:(NSDictionary *)tweet
{
self.contentString = [[tweet objectForKey:@"text"] stringByLinkifyingURLs];
[self.contentWebView loadHTMLString:self.contentString baseURL:nil];
}
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
return YES;
}
@end