Permalink
Browse files

adding InAppTwitter which goes to the users twitter account in the ap…

…p, or website if the app is not installed
  • Loading branch information...
1 parent 65d938c commit c9c6d49dce9f201c908617d5d07fda9eb17c702a @kgn committed Jan 21, 2013
@@ -86,7 +86,7 @@ - (void)setUIValues{
if(textFieldFrame.origin.x < InAppSettingsCellTextFieldMinX){
textFieldFrame.origin.x = InAppSettingsCellTextFieldMinX;
}
- textFieldFrame.origin.y = (CGFloat)round((self.contentView.frame.size.height*0.5f)-(titleSize.height*0.5f))-InAppSettingsOffsetY;
+ textFieldFrame.origin.y = (CGFloat)round(CGRectGetMidY(self.contentView.bounds)-(titleSize.height*0.5f));
textFieldFrame.size.width = (CGFloat)round((CGRectGetWidth(self.bounds)-(InAppSettingsTotalTablePadding+InAppSettingsCellPadding))-textFieldFrame.origin.x);
textFieldFrame.size.height = titleSize.height;
self.textField.frame = textFieldFrame;
@@ -34,7 +34,8 @@ - (void)setUIValues{
[self setTitle];
- if([self.setting valueForKey:InAppSettingsSpecifierInAppURL]){
+ if([self.setting valueForKey:InAppSettingsSpecifierInAppURL] ||
+ [self.setting valueForKey:InAppSettingsSpecifierInAppTwitter]){
[self setDisclosure:YES];
self.canSelectCell = YES;
}
@@ -68,7 +68,7 @@ - (void)layoutSubviews{
CGRect titleFrame = self.titleLabel.frame;
titleFrame.size = titleSize;
titleFrame.origin.x = InAppSettingsCellPadding;
- titleFrame.origin.y = (CGFloat)round(CGRectGetMidY(self.contentView.bounds)-(titleSize.height*0.5f))-InAppSettingsOffsetY;
+ titleFrame.origin.y = (CGFloat)round(CGRectGetMidY(self.contentView.bounds)-(titleSize.height*0.5f));
self.titleLabel.frame = titleFrame;
// detail view
@@ -88,7 +88,7 @@ - (void)layoutSubviews{
valueFrame.origin.x = titleRightSide;
}
}
- valueFrame.origin.y = (CGFloat)round(CGRectGetMidY(self.contentView.bounds)-(valueSize.height*0.5f))-InAppSettingsOffsetY;
+ valueFrame.origin.y = (CGFloat)round(CGRectGetMidY(self.contentView.bounds)-(valueSize.height*0.5f));
valueFrame.size.width = CGRectGetWidth(self.contentView.bounds)-valueFrame.origin.x-InAppSettingsCellPadding;
//if the width is less then 0 just hide the label
@@ -12,10 +12,10 @@
#import "InAppSettingsSpecifier.h"
#import "InAppSettingsConstants.h"
-#define InAppSettingsNotification InAppSettingsNotificationName
-
extern NSString *const InAppSettingsViewControllerDelegateWillDismissedNotification;
extern NSString *const InAppSettingsViewControllerDelegateDidDismissedNotification;
+extern NSString *const InAppSettingsValueChangeNotification;
+extern NSString *const InAppSettingsTapNotification;
@interface InAppSettings : NSObject
@@ -11,6 +11,8 @@
NSString *const InAppSettingsViewControllerDelegateWillDismissedNotification = @"InAppSettingsViewControllerDelegateWillDismissedNotification";
NSString *const InAppSettingsViewControllerDelegateDidDismissedNotification = @"InAppSettingsViewControllerDelegateDidDismissedNotification";
+NSString *const InAppSettingsValueChangeNotification = @"InAppSettingsValueChangeNotification";
+NSString *const InAppSettingsTapNotification = @"InAppSettingsTapNotification";
@implementation InAppSettings
@@ -228,7 +230,18 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
childPane.title = [setting localizedTitle];
[self.navigationController pushViewController:childPane animated:YES];
}else if([setting isType:InAppSettingsPSTitleValueSpecifier]){
- InAppSettingsOpenUrl([NSURL URLWithString:[setting valueForKey:InAppSettingsSpecifierInAppURL]]);
+ NSString *InAppURL = [setting valueForKey:InAppSettingsSpecifierInAppURL];
+ NSString *InAppTwitter = [setting valueForKey:InAppSettingsSpecifierInAppTwitter];
+ if(InAppURL){
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:InAppURL]];
+ }else if(InAppTwitter){
+ if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter:"]]){
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"twitter://user?screen_name=%@", InAppTwitter]]];
+ }else{
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://twitter.com/%@", InAppTwitter]]];
+ }
+ }
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
@@ -10,9 +10,7 @@
#define InAppSettingsRootFile @"Root"
#define InAppSettingsProjectName @"InAppSettings"
-#define InAppSettingsNotificationName @"InAppSettingsNotification"
-#define InAppSettingsOffsetY 1.0f
#define InAppSettingsFontSize 17.0f
#define InAppSettingsCellPadding 9.0f
#define InAppSettingsTablePadding 10.0f
@@ -31,7 +29,6 @@
#define InAppSettingsBlue [UIColor colorWithRed:0.22f green:0.33f blue:0.53f alpha:1.0f];
#define InAppSettingsFooterBlue [UIColor colorWithRed:0.36f green:0.39f blue:0.45f alpha:1.0f]
-#define InAppSettingsOpenUrl(url) [[UIApplication sharedApplication] openURL:url];
#define InAppSettingsBundlePath [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"]
#define InAppSettingsFullPlistPath(file) \
[InAppSettingsBundlePath stringByAppendingPathComponent:[file stringByAppendingPathExtension:@"plist"]]
@@ -61,8 +58,10 @@
#define InAppSettingsSpecifierMinimumValue @"MinimumValue"
#define InAppSettingsSpecifierMaximumValue @"MaximumValue"
#define InAppSettingsSpecifierInAppURL @"InAppURL"
+#define InAppSettingsSpecifierInAppTwitter @"InAppTwitter"
#define InAppSettingsSpecifierInAppTitle @"InAppTitle"
#define InAppSettingsSpecifierInAppMultiType @"InAppMultiType"
+#define InAppSettingsSpecifierTap @"InAppTap"
// test what cell init code should be used
#define InAppSettingsUseNewCells __IPHONE_3_0 && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0
@@ -22,29 +22,23 @@ - (void)loadFile:(NSString *)file{
NSDictionary *settingsDictionary = [[NSDictionary alloc] initWithContentsOfFile:InAppSettingsFullPlistPath(file)];
NSArray *preferenceSpecifiers = [settingsDictionary objectForKey:InAppSettingsPreferenceSpecifiers];
NSString *stringsTable = [settingsDictionary objectForKey:InAppSettingsStringsTable];
-
- for(NSDictionary *eachSetting in preferenceSpecifiers){
- @autoreleasepool{
- InAppSettingsSpecifier *setting = [[InAppSettingsSpecifier alloc] initWithDictionary:eachSetting andStringsTable:stringsTable];
- if([setting isValid]){
- if([setting isType:InAppSettingsPSChildPaneSpecifier]){
- [self loadFile:[setting valueForKey:InAppSettingsSpecifierFile]];
- }else if([setting hasKey]){
- if([setting valueForKey:InAppSettingsSpecifierDefaultValue]){
- [self.values
- setObject:[setting valueForKey:InAppSettingsSpecifierDefaultValue]
- forKey:[setting getKey]];
- }
+ [preferenceSpecifiers enumerateObjectsUsingBlock:^(NSDictionary *setting, NSUInteger idx, BOOL *stop) {
+ InAppSettingsSpecifier *settingsSpecifier = [[InAppSettingsSpecifier alloc] initWithDictionary:setting andStringsTable:stringsTable];
+ if([settingsSpecifier isValid]){
+ if([settingsSpecifier isType:InAppSettingsPSChildPaneSpecifier]){
+ [self loadFile:[settingsSpecifier valueForKey:InAppSettingsSpecifierFile]];
+ }else if([settingsSpecifier hasKey]){
+ if([settingsSpecifier valueForKey:InAppSettingsSpecifierDefaultValue]){
+ [self.values setObject:[settingsSpecifier valueForKey:InAppSettingsSpecifierDefaultValue] forKey:[settingsSpecifier getKey]];
}
}
}
- }
+ }];
}
}
- (id)init{
- self = [super init];
- if (self != nil) {
+ if((self = [super init])){
self.files = [[NSMutableArray alloc] init];
self.values = [[NSMutableDictionary alloc] init];
[self loadFile:InAppSettingsRootFile];
@@ -60,8 +54,7 @@ - (id)init{
@implementation InAppSettingsReader
- (id)initWithFile:(NSString *)inputFile{
- self = [super init];
- if(self != nil){
+ if((self = [super init])){
self.file = inputFile;
//load plist
@@ -74,24 +67,22 @@ - (id)initWithFile:(NSString *)inputFile{
self.settings = [[NSMutableArray alloc] init];
//load the data
- @autoreleasepool {
- for(NSDictionary *eachSetting in preferenceSpecifiers){
- InAppSettingsSpecifier *setting = [[InAppSettingsSpecifier alloc] initWithDictionary:eachSetting andStringsTable:stringsTable];
- if([setting isValid]){
- if([setting isType:InAppSettingsPSGroupSpecifier]){
- [self.headersAndFooters addObject:@[[setting localizedTitle], [setting localizedFooterText]]];
+ [preferenceSpecifiers enumerateObjectsUsingBlock:^(NSDictionary *setting, NSUInteger idx, BOOL *stop) {
+ InAppSettingsSpecifier *settingsSpecifier = [[InAppSettingsSpecifier alloc] initWithDictionary:setting andStringsTable:stringsTable];
+ if([settingsSpecifier isValid]){
+ if([settingsSpecifier isType:InAppSettingsPSGroupSpecifier]){
+ [self.headersAndFooters addObject:@[[settingsSpecifier localizedTitle], [settingsSpecifier localizedFooterText]]];
+ [self.settings addObject:[NSMutableArray array]];
+ }else{
+ //if there are no settings make an initial container
+ if([self.settings count] < 1){
+ [self.headersAndFooters addObject:@[@"", @""]];
[self.settings addObject:[NSMutableArray array]];
- }else{
- //if there are no settings make an initial container
- if([self.settings count] < 1){
- [self.headersAndFooters addObject:@[@"", @""]];
- [self.settings addObject:[NSMutableArray array]];
- }
- [[self.settings lastObject] addObject:setting];
}
+ [[self.settings lastObject] addObject:settingsSpecifier];
}
}
- }
+ }];
}
return self;
}
@@ -56,8 +56,7 @@ - (id)getValue{
- (void)setValue:(id)newValue{
NSString *key = [self getKey];
[[NSUserDefaults standardUserDefaults] setObject:newValue forKey:key];
-
- NSNotification *notification = [NSNotification notificationWithName:InAppSettingsNotificationName object:key];
+ NSNotification *notification = [NSNotification notificationWithName:InAppSettingsValueChangeNotification object:key];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}

0 comments on commit c9c6d49

Please sign in to comment.