2014-01-06 17:55:14 -08:00
//
// OSKOmnifocusActivity . m
// Overshare
//
// Created by Jared Sinclair on 10 / 20 / 13.
// Copyright ( c ) 2013 Overshare Kit . All rights reserved .
//
# import "OSKOmnifocusActivity.h"
# import "OSKShareableContentItem.h"
static NSString * OSKOmnifocusActivity_BaseURL = @ "omnifocus://" ;
static NSString * OSKOmnifocusActivity_AddEntryWithNoteURL = @ "/add?name=%@¬e=%@" ;
@ implementation OSKOmnifocusActivity
- ( instancetype ) initWithContentItem : ( OSKShareableContentItem * ) item {
self = [ super initWithContentItem : item ] ;
if ( self ) {
//
}
return self ;
}
2014-02-27 16:54:25 -08:00
# pragma mark - OSKURLSchemeActivity
- ( BOOL ) targetApplicationSupportsXCallbackURL {
return NO ;
}
2014-01-06 17:55:14 -08:00
# pragma mark - Methods for OSKActivity Subclasses
+ ( NSString * ) supportedContentItemType {
return OSKShareableContentItemType_ToDoListEntry ;
}
+ ( BOOL ) isAvailable {
return [ [ UIApplication sharedApplication ] canOpenURL : [ NSURL URLWithString : OSKOmnifocusActivity_BaseURL ] ] ;
}
+ ( NSString * ) activityType {
return OSKActivityType_URLScheme _Omnifocus ;
}
+ ( NSString * ) activityName {
return @ "OmniFocus" ;
}
+ ( UIImage * ) iconForIdiom : ( UIUserInterfaceIdiom ) idiom {
UIImage * image = nil ;
if ( idiom = = UIUserInterfaceIdiomPhone ) {
image = [ UIImage imageNamed : @ "Omnifocus-Icon-60.png" ] ;
} else {
image = [ UIImage imageNamed : @ "Omnifocus-Icon-72.png" ] ;
}
return image ;
}
+ ( UIImage * ) settingsIcon {
return [ self iconForIdiom : UIUserInterfaceIdiomPhone ] ;
}
+ ( OSKAuthenticationMethod ) authenticationMethod {
return OSKAuthenticationMethod_None ;
}
+ ( BOOL ) requiresApplicationCredential {
return NO ;
}
2014-02-27 16:54:25 -08:00
+ ( OSKPublishingMethod ) publishingMethod {
return OSKPublishingMethod_URLScheme ;
2014-01-06 17:55:14 -08:00
}
- ( BOOL ) isReadyToPerform {
return [ ( OSKToDoListEntryContentItem * ) self . contentItem title ] . length > 0 ;
}
- ( void ) performActivity : ( OSKActivityCompletionHandler ) completion {
2014-09-17 16:58:44 -07:00
2014-01-06 17:55:14 -08:00
NSString * title = [ self toDoListItem ] . title ;
NSString * notes = [ self toDoListItem ] . notes ;
title = ( title . length ) ? title : @ "New entry" ;
notes = ( notes . length ) ? notes : @ " " ;
NSString * fullQuery = [ NSString stringWithFormat : OSKOmnifocusActivity_AddEntryWithNoteURL , title , notes ] ;
NSString * encodedQuery = [ fullQuery stringByAddingPercentEncodingWithAllowedCharacters : [ NSCharacterSet URLQueryAllowedCharacterSet ] ] ;
2014-09-17 16:58:44 -07:00
NSURL * URL = nil ;
if ( encodedQuery . length ) {
NSString * fullURL = [ NSString stringWithFormat : @ "%@%@" , OSKOmnifocusActivity_BaseURL , encodedQuery ] ;
URL = [ NSURL URLWithString : fullURL ] ;
}
2014-01-06 17:55:14 -08:00
if ( URL ) {
[ [ UIApplication sharedApplication ] openURL : URL ] ;
if ( completion ) {
completion ( self , YES , nil ) ;
}
} else {
NSError * error = [ NSError errorWithDomain : @ "OSKOmnifocusActivity" code : 400 userInfo : @ { NSLocalizedFailureReasonErrorKey : @ "Invalid URL, unable to send new entry to Omnifocus." } ] ;
if ( completion ) {
completion ( self , NO , error ) ;
}
}
}
+ ( BOOL ) canPerformViaOperation {
return NO ;
}
- ( OSKActivityOperation * ) operationForActivityWithCompletion : ( OSKActivityCompletionHandler ) completion {
return nil ;
}
# pragma mark - Convenience
- ( OSKToDoListEntryContentItem * ) toDoListItem {
return ( OSKToDoListEntryContentItem * ) self . contentItem ;
}
@ end