Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature - Alternate Text for sharers #242

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Classes/Example/ExampleShareImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ - (void)loadView
- (void)share
{
SHKItem *item = [SHKItem image:imageView.image title:@"San Francisco"];
[item setAlternateText:@"Golden Gate Bridge #SanFrancisco" toShareOn:@"Twitter"];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

[actionSheet showFromToolbar:self.navigationController.toolbar];
Expand Down
1 change: 1 addition & 0 deletions Classes/Example/ExampleShareLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- (void)share
{
SHKItem *item = [SHKItem URL:webView.request.URL title:[webView pageTitle]];
[item setAlternateText:[NSString stringWithFormat:@"%@ #channel",[webView pageTitle]] toShareOn:@"Twitter"];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
[actionSheet showFromToolbar:self.navigationController.toolbar];
}
Expand Down
2 changes: 2 additions & 0 deletions Classes/Example/ExampleShareText.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ - (void)share


SHKItem *item = [SHKItem text:text];
[item setAlternateText:[item.text stringByAppendingString:@" #ShareKit"] toShareOn:@"Twitter"];
[item setAlternateText:[item.text stringByAppendingString:@" <br/><br/>Alternate text for Email Action"] toShareOn:@"Email"];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

[actionSheet showFromToolbar:self.navigationController.toolbar];
Expand Down
3 changes: 3 additions & 0 deletions Classes/ShareKit/Core/Base Sharer Classes/SHKSharer.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ - (id)init
{
self.shareDelegate = self;
self.item = [[[SHKItem alloc] init] autorelease];
self.item.currentOwner = self;

if ([self respondsToSelector:@selector(modalPresentationStyle)])
self.modalPresentationStyle = [SHK modalPresentationStyle];
Expand All @@ -187,6 +188,8 @@ + (id)shareItem:(SHKItem *)i
// Create controller and set share options
SHKSharer *controller = [[self alloc] init];
controller.item = i;
controller.item.currentOwner = controller;


// share and/or show UI
[controller share];
Expand Down
5 changes: 5 additions & 0 deletions Classes/ShareKit/Core/SHKItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef enum

@private
NSMutableDictionary *custom;
NSObject *currentOwner;
}

@property (nonatomic) SHKShareType shareType;
Expand All @@ -71,11 +72,15 @@ typedef enum
@property (nonatomic, retain) NSString *mimeType;
@property (nonatomic, retain) NSString *filename;

@property (assign) NSObject *currentOwner;

+ (SHKItem *)URL:(NSURL *)url title:(NSString *)title;
+ (SHKItem *)image:(UIImage *)image title:(NSString *)title;
+ (SHKItem *)text:(NSString *)text;
+ (SHKItem *)file:(NSData *)data filename:(NSString *)filename mimeType:(NSString *)mimeType title:(NSString *)title;

- (void)setAlternateText:(NSString *)alternateText toShareOn:(NSString *)sharer;

- (void)setCustomValue:(NSString *)value forKey:(NSString *)key;
- (NSString *)customValueForKey:(NSString *)key;
- (BOOL)customBoolForSwitchKey:(NSString *)key;
Expand Down
18 changes: 17 additions & 1 deletion Classes/ShareKit/Core/SHKItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//

#import "SHKItem.h"
#import "SHKSharer.h"
#import "SHK.h"


Expand All @@ -37,7 +38,7 @@ @interface SHKItem()
@implementation SHKItem

@synthesize shareType;
@synthesize URL, image, title, text, tags, data, mimeType, filename;
@synthesize URL, image, title, text, tags, data, mimeType, filename, currentOwner;
@synthesize custom;

- (void)dealloc
Expand Down Expand Up @@ -135,6 +136,21 @@ - (BOOL)customBoolForSwitchKey:(NSString *)key
return [[custom objectForKey:key] isEqualToString:SHKFormFieldSwitchOn];
}

#pragma mark -

//Special getter for convenience in sharers
//It "magically" gets alternate text set for particular sharer
- (NSString *)text {
NSString *sharerTitle = [(SHKSharer *)currentOwner sharerTitle];
NSString *alternateText = [self customValueForKey:[NSString stringWithFormat:@"alternateTextFor%@",sharerTitle]];
return (alternateText == nil) ? text : alternateText;
}

//Adds ability to add custom text for each sharer by name
- (void)setAlternateText:(NSString *)alternateText toShareOn:(NSString *)sharer {
[self setCustomValue:alternateText forKey:[NSString stringWithFormat:@"alternateTextFor%@",sharer]];
}


#pragma mark -

Expand Down
1 change: 1 addition & 0 deletions Classes/ShareKit/Core/SHKOfflineSharer.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ - (void)share
// create sharer
self.sharer = [[NSClassFromString(sharerId) alloc] init];
sharer.item = item;
sharer.item.currentOwner = sharer;
sharer.quiet = YES;
sharer.shareDelegate = self;

Expand Down
9 changes: 9 additions & 0 deletions Classes/ShareKit/SHKConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@
#define SHKSharedWithSignature 0


//Evernote settings
#define SHKEvernoteUserStoreURL @""
#define SHKEvernoteConsumerKey @""
#define SHKEvernoteSecretKey @""
#define SHKEvernoteNetStoreURLBase @""



/*
UI Configuration : Basic
Expand Down Expand Up @@ -118,6 +125,8 @@
// Append 'Shared With 'Signature to Email (and related forms)
#define SHKSharedWithSignature 0



/*
UI Configuration : Advanced
------
Expand Down