Permalink
Browse files

Changed iOS SDK 4.2

  • Loading branch information...
1 parent eb9b70a commit f4cbafde7f4eb134d147d6402ec695b81b33fdf3 @kishikawakatsumi committed Nov 14, 2010
@@ -10,7 +10,7 @@
@class MyBookmarkAPI;
-@interface AddBookmarkViewController : UIViewController {
+@interface AddBookmarkViewController : UIViewController<UITextFieldDelegate> {
UILabel *titleLabel;
UILabel *URLLabel;
UITextField *commentField;
@@ -32,15 +32,15 @@ - (void)loadView {
self.view = contentView;
[contentView release];
- titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 8.0f, 300.0f, 44.0f)];
+ titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 4.0f, 300.0f, 44.0f)];
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont boldSystemFontOfSize:14.0f];
titleLabel.numberOfLines = 2;
[contentView addSubview:titleLabel];
[titleLabel release];
- URLLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 52.0f, 300.0f, 40.0f)];
+ URLLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 48.0f, 300.0f, 40.0f)];
URLLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
URLLabel.backgroundColor = [UIColor clearColor];
URLLabel.font = [UIFont systemFontOfSize:12.0f];
@@ -50,13 +50,22 @@ - (void)loadView {
[contentView addSubview:URLLabel];
[URLLabel release];
- commentField = [[UITextField alloc] initWithFrame:CGRectMake(10.0f, 102.0f, 300.0f, 31.0f)];
- commentField.borderStyle = UITextBorderStyleBezel;
+ commentField = [[UITextField alloc] initWithFrame:CGRectMake(10.0f, 86.0f, 300.0f, 29.0f)];
+ commentField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+ commentField.delegate = self;
+ commentField.borderStyle = UITextBorderStyleLine;
+ commentField.adjustsFontSizeToFitWidth = NO;
+ commentField.clearButtonMode = UITextFieldViewModeWhileEditing;
+ commentField.clearsOnBeginEditing = NO;
+ commentField.enablesReturnKeyAutomatically = YES;
+ commentField.returnKeyType = UIReturnKeyDone;
+ commentField.placeholder = NSLocalizedString(@"Comment", nil);
[contentView addSubview:commentField];
[commentField release];
- UIButton *addButton = [UIButton buttonWithType:111];
- addButton.frame = CGRectMake(200.0f, 153.0f, 114.0f, 40.0f);
+ UIButton *addButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+ addButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
+ addButton.frame = CGRectMake(200.0f, 140.0f, 110.0f, 36.0f);
[addButton setTitle:NSLocalizedString(@"Add", nil) forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(addBookmark:) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:addButton];
@@ -81,14 +90,20 @@ - (void)loadView {
- (void)viewDidLoad {
[super viewDidLoad];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ self.title = NSLocalizedString(@"Add MyBookmark", nil);
+
+ if (&UIApplicationDidEnterBackgroundNotification) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ }
titleLabel.text = self.pageTitle;
URLLabel.text = self.pageURL;
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(dismiss:)];
[self.navigationItem setRightBarButtonItem:closeButton animated:NO];
[closeButton release];
+
+ [commentField becomeFirstResponder];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
@@ -110,6 +125,8 @@ - (void)viewDidUnload {
- (void)addBookmark:(id)sender {
[[NetworkActivityManager sharedInstance] pushActivity:NSStringFromClass([self class])];
+ [commentField resignFirstResponder];
+
[UIView beginAnimations:nil context:nil];
blockView.alpha = 1.0f;
[UIView commitAnimations];
@@ -170,4 +187,11 @@ - (void)applicationDidEnterBackground:(NSNotification *)note {
alert = nil;
}
+#pragma mark -
+
+- (BOOL)textFieldShouldReturn:(UITextField *)textField {
+ [textField resignFirstResponder];
+ return YES;
+}
+
@end
@@ -108,7 +108,9 @@ - (void)loadView {
- (void)viewDidLoad {
[super viewDidLoad];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ if (&UIApplicationDidEnterBackgroundNotification) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ }
self.title = NSLocalizedString(@"BacknumberTitle", nil);
@@ -156,17 +158,6 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
#pragma mark -
- (void)loadNextData {
- if (![[InternetReachability sharedInstance] isReachableInternet]) {
- alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"AppName", nil)
- message:NSLocalizedString(@"No internet connection.", nil)
- delegate:self
- cancelButtonTitle:nil
- otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
- [alert show];
- [alert release];
- return;
- }
-
[[NetworkActivityManager sharedInstance] pushActivity:NSStringFromClass([self class])];
dotImageView.hidden = YES;
[activityIndicator startAnimating];
@@ -333,7 +324,7 @@ - (void)parser:(DiaryFeedParser *)parser encounteredError:(NSError *)error {
[alert release];
}
-- (void)parserFinished:(DiaryFeedParser *)parser {
+- (void)parserFinished:(DiaryFeedParser *)p {
if ([[parser.diaries objectForKey:@"entries"] count] < 20) {
hasMoreData = NO;
dotImageView.hidden = NO;
@@ -361,7 +352,7 @@ - (void)diaryUploader:(DiaryUploader *)uploader uploadFinished:(id)responseData
[[NetworkActivityManager sharedInstance] popActivity:NSStringFromClass([self class])];
}
-- (void)diaryUploader:(DiaryUploader *)uploader uploadFailed:(NSError *)error {
+- (void)diaryUploader:(DiaryUploader *)diaryUploader uploadFailed:(NSError *)error {
self.uploader = nil;
[UIView beginAnimations:nil context:nil];
@@ -42,6 +42,8 @@ UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
NSInteger statusCode;
BOOL initialized;
+
+ NSString *insertText;
}
@property (nonatomic, retain) Diary *editingDiary;
@@ -50,5 +52,6 @@ UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
@property (nonatomic, retain) NSString *diaryTextForEdit;
@property (nonatomic, retain) NSMutableData *receivedData;
@property (nonatomic, assign) BOOL isDraft;
+@property (nonatomic, retain) NSString *insertText;
@end
@@ -16,7 +16,6 @@
#import "FotolifeUploader.h"
#import "UserSettings.h"
#import "NetworkActivityManager.h"
-#import "NSData+Base64.h"
#import <QuartzCore/QuartzCore.h>
#import <objc/runtime.h>
@@ -37,12 +36,14 @@ - (void)enableUserInteraction;
- (void)disableUserInteraction;
- (void)saveTemporaryDiary;
- (void)loadTemporaryDiary;
+- (void)insertSyntax:(NSString *)syntax;
@end
@implementation DiaryViewController
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ [[NetworkActivityManager sharedInstance] popActivity:NSStringFromClass([self class])];
self.editingDiary = nil;
self.editURI = nil;
self.titleTextForEdit = nil;
@@ -154,7 +155,9 @@ - (void)loadView {
- (void)viewDidLoad {
[super viewDidLoad];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ if (&UIApplicationDidEnterBackgroundNotification) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ }
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
@@ -205,6 +208,11 @@ - (void)viewDidLoad {
[self loadTemporaryDiary];
titleField.text = self.editingDiary.titleText;
bodyTextView.text = self.editingDiary.diaryText;
+
+ if (self.insertText) {
+ [self insertSyntax:self.insertText];
+ self.insertText = nil;
+ }
}
clearButton.enabled = [titleField.text length] > 0 || [bodyTextView.text length] > 0;
@@ -230,6 +238,8 @@ - (void)viewDidUnload {
[super viewDidUnload];
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ bodyTextView = nil;
+
blockView = nil;
indicatorView = nil;
messageLabel = nil;
@@ -376,6 +386,10 @@ - (void)uploadImage:(UIImage *)image title:(NSString *)title {
}
- (void)insertSyntax:(NSString *)syntax {
+ if (!bodyTextView) {
+ self.insertText = syntax;
+ return;
+ }
id newText = [NSMutableString stringWithString:bodyTextView.text];
if ([newText length] == 0) {
newText = syntax;
@@ -450,7 +464,7 @@ - (void)hatenaSyntaxViewController:(HatenaSyntaxViewController *)controller didS
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
- UIImage *originalImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
+ UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
if (pickerController.sourceType == UIImagePickerControllerSourceTypeCamera) {
[picker dismissModalViewControllerAnimated:YES];
@@ -466,7 +480,6 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
[picker pushViewController:controller animated:YES];
[controller release];
}
-
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
@@ -678,7 +691,6 @@ - (void)diaryUploader:(DiaryUploader *)uploader uploadFinished:(id)responseData
}
- (void)diaryUploader:(DiaryUploader *)uploader uploadFailed:(NSError *)error {
- NSLog(@"%s", __func__);
[self enableUserInteraction];
[[NetworkActivityManager sharedInstance] popActivity:NSStringFromClass([self class])];
@@ -747,6 +759,10 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
- (void)applicationDidEnterBackground:(NSNotification *)note {
[alert dismissWithClickedButtonIndex:0 animated:NO];
alert = nil;
+
+ if (self.modalViewController) {
+ [self.modalViewController dismissModalViewControllerAnimated:NO];
+ }
}
@end
@@ -51,7 +51,7 @@ - (NSMutableURLRequest *)makeRequestWithURI:(NSString *)URI method:(NSString *)m
NSString *password = settings.password;
NSURL *webServiceURL = [NSURL URLWithString:URI];
- NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:webServiceURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:20.0];
+ NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:webServiceURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
NSString *credentials = [self makeCredentialsWithUsername:username password:password];
@@ -41,7 +41,7 @@ - (id)init {
- (id)initWithURL:(NSURL *)URL {
if (self = [super init]) {
identifier = [[URL absoluteString] retain];
- self.request = [NSURLRequest requestWithURL:URL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:20.0];
+ self.request = [NSURLRequest requestWithURL:URL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
[self commonInit];
}
@@ -18,7 +18,7 @@ @implementation HatenaTouchAppDelegate
#pragma mark -
#pragma mark Application lifecycle
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window makeKeyAndVisible];
[window addSubview:navigationController.view];
@@ -121,7 +121,9 @@ - (void)loadView {
- (void)viewDidLoad {
[super viewDidLoad];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ if (&UIApplicationDidEnterBackgroundNotification) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ }
self.title = NSLocalizedString(@"HotEntry", nil);
@@ -160,17 +162,6 @@ - (void)viewDidUnload {
#pragma mark -
- (void)cateoryChanged:(id)sender {
- if (![[InternetReachability sharedInstance] isReachableInternet]) {
- alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"AppName", nil)
- message:NSLocalizedString(@"No internet connection.", nil)
- delegate:self
- cancelButtonTitle:nil
- otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
- [alert show];
- [alert release];
- return;
- }
-
UISegmentedControl *control = (UISegmentedControl *)sender;
NSInteger index = control.selectedSegmentIndex;
@@ -20,4 +20,4 @@
@protocol ImagePreviewViewControllerDelegate
- (void)imagePreviewControllerDidFinishPickingMedia:(ImagePreviewViewController *)controller;
- (void)imagePreviewControllerDidCancel:(ImagePreviewViewController *)controller;
-@end
+@end
@@ -37,15 +37,15 @@ - (void)dealloc {
- (void)reachabilityChanged:(NSNotification *)note {
Reachability *reachability = [note object];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
-// if (netStatus == NotReachable) {
-// alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"AppName", nil)
-// message:NSLocalizedString(@"No internet connection.", nil)
-// delegate:self
-// cancelButtonTitle:nil
-// otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
-// [alert show];
-// [alert release];
-// }
+ if (netStatus == NotReachable) {
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"AppName", nil)
+ message:NSLocalizedString(@"No internet connection.", nil)
+ delegate:self
+ cancelButtonTitle:nil
+ otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
+ [alert show];
+ [alert release];
+ }
}
- (BOOL)isReachableInternet {
@@ -94,7 +94,9 @@ - (void)loadView {
- (void)viewDidLoad {
[super viewDidLoad];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ if (&UIApplicationDidEnterBackgroundNotification) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ }
self.title = NSLocalizedString(@"MyBookmark", nil);
@@ -142,17 +144,6 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
#pragma mark -
- (void)loadNextData {
- if (![[InternetReachability sharedInstance] isReachableInternet]) {
- alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"AppName", nil)
- message:NSLocalizedString(@"No internet connection.", nil)
- delegate:self
- cancelButtonTitle:nil
- otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
- [alert show];
- [alert release];
- return;
- }
-
[[NetworkActivityManager sharedInstance] pushActivity:NSStringFromClass([self class])];
dotImageView.hidden = YES;
[activityIndicator startAnimating];
@@ -328,7 +319,7 @@ - (void)parser:(MyBookmarkFeedParser *)parser encounteredError:(NSError *)error
[alert release];
}
-- (void)parserFinished:(MyBookmarkFeedParser *)parser {
+- (void)parserFinished:(MyBookmarkFeedParser *)p {
if ([[parser.bookmarks objectForKey:@"entries"] count] < 20) {
hasMoreData = NO;
dotImageView.hidden = NO;
Oops, something went wrong.

0 comments on commit f4cbafd

Please sign in to comment.