Skip to content

Commit

Permalink
Fixes #354 - Added the BKRSettings class.
Browse files Browse the repository at this point in the history
commit 720ca7cc62bb99c84673a2ff6bf20dd1ee842f86
Author: Pieter Claerhout <pieter@yellowduck.be>
Date:   Wed Nov 5 14:27:22 2014 +0100

    Converted all define statements to the BKRSettings class.

commit 79ca3c7eaa15b1f7a4fb703258f8880289621f26
Author: Pieter Claerhout <pieter@yellowduck.be>
Date:   Tue Nov 4 16:27:23 2014 +0100

    Added a settings file.
  • Loading branch information
pieterclaerhout committed Nov 5, 2014
1 parent b253f07 commit 4bb09eb
Show file tree
Hide file tree
Showing 19 changed files with 636 additions and 510 deletions.
14 changes: 10 additions & 4 deletions Baker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
BFAB78D317B2A67E00E91ADE /* BakerAnalyticsEvents.m in Sources */ = {isa = PBXBuildFile; fileRef = BFAB78D217B2A67E00E91ADE /* BakerAnalyticsEvents.m */; };
C649F0981A090B6000B02548 /* BKRShelfHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = C649F0971A090B6000B02548 /* BKRShelfHeaderView.m */; };
C649F09B1A0912F500B02548 /* UIScreen+BakerExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = C649F09A1A0912F500B02548 /* UIScreen+BakerExtensions.m */; };
C649F09D1A0926CD00B02548 /* settings.plist in Resources */ = {isa = PBXBuildFile; fileRef = C649F09C1A0926CD00B02548 /* settings.plist */; };
C649F0A31A0927F300B02548 /* BKRSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = C649F0A21A0927F300B02548 /* BKRSettings.m */; };
C66857A01A07D38300776443 /* NSString+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = C668579D1A07D38300776443 /* NSString+Extensions.m */; };
C66857A11A07D38300776443 /* UIColor+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = C668579F1A07D38300776443 /* UIColor+Extensions.m */; };
C66857A41A07DDBE00776443 /* NSObject+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = C66857A31A07DDBE00776443 /* NSObject+Extensions.m */; };
Expand All @@ -77,7 +79,6 @@
AB246A3016C5BC6E00715E25 /* NSMutableURLRequest+WebServiceClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableURLRequest+WebServiceClient.m"; sourceTree = "<group>"; };
AB26004F16011D9D00E9AA66 /* BakerBookStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BakerBookStatus.h; sourceTree = "<group>"; };
AB26005016011D9D00E9AA66 /* BakerBookStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BakerBookStatus.m; sourceTree = "<group>"; };
AB379313161759A900B4C1A3 /* Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = "<group>"; };
AB40042A15B4B83000D87E2A /* BakerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BakerViewController.h; sourceTree = "<group>"; };
AB40042B15B4B83000D87E2A /* BakerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BakerViewController.m; sourceTree = "<group>"; };
AB40043315B4B83000D87E2A /* IndexViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -148,7 +149,9 @@
C649F0971A090B6000B02548 /* BKRShelfHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BKRShelfHeaderView.m; sourceTree = "<group>"; };
C649F0991A0912F500B02548 /* UIScreen+BakerExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScreen+BakerExtensions.h"; sourceTree = "<group>"; };
C649F09A1A0912F500B02548 /* UIScreen+BakerExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScreen+BakerExtensions.m"; sourceTree = "<group>"; };
C668579B1A07D27C00776443 /* UIConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIConstants.h; sourceTree = "<group>"; };
C649F09C1A0926CD00B02548 /* settings.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = settings.plist; sourceTree = "<group>"; };
C649F0A11A0927F300B02548 /* BKRSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BKRSettings.h; sourceTree = "<group>"; };
C649F0A21A0927F300B02548 /* BKRSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BKRSettings.m; sourceTree = "<group>"; };
C668579C1A07D38300776443 /* NSString+Extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Extensions.h"; sourceTree = "<group>"; };
C668579D1A07D38300776443 /* NSString+Extensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Extensions.m"; sourceTree = "<group>"; };
C668579E1A07D38300776443 /* UIColor+Extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+Extensions.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -208,7 +211,6 @@
AB40042E15B4B83000D87E2A /* img */,
AB40043715B4B83000D87E2A /* lib */,
AB40045015B4B83000D87E2A /* ui */,
C668579B1A07D27C00776443 /* UIConstants.h */,
9F8FC1C215C55E8C0065F0A3 /* BakerBook.h */,
9F8FC1C315C55E8C0065F0A3 /* BakerBook.m */,
AB26004F16011D9D00E9AA66 /* BakerBookStatus.h */,
Expand Down Expand Up @@ -288,7 +290,6 @@
BF0785EA1794AF4000EB988E /* info */,
9F58D85E15D6743C0027902C /* img */,
9FF7957E15B4C4F600899E51 /* lib */,
AB379313161759A900B4C1A3 /* Constants.h */,
ABD7D45D1616FC5B008B13B5 /* BakerIssue.h */,
ABD7D45E1616FC5B008B13B5 /* BakerIssue.m */,
ABC270CF1616F3CB00AD97E9 /* IssuesManager.h */,
Expand Down Expand Up @@ -354,8 +355,11 @@
ABAFB59115AB9A2E002FA498 /* Baker */ = {
isa = PBXGroup;
children = (
C649F09C1A0926CD00B02548 /* settings.plist */,
ABAFB59A15AB9A2E002FA498 /* AppDelegate.h */,
ABAFB59B15AB9A2E002FA498 /* AppDelegate.m */,
C649F0A11A0927F300B02548 /* BKRSettings.h */,
C649F0A21A0927F300B02548 /* BKRSettings.m */,
BFAB78D117B2A67E00E91ADE /* BakerAnalyticsEvents.h */,
BFAB78D217B2A67E00E91ADE /* BakerAnalyticsEvents.m */,
ABAFB59215AB9A2E002FA498 /* Supporting Files */,
Expand Down Expand Up @@ -428,6 +432,7 @@
BF78D1B0180C8F070093DFBC /* BakerAssets.xcassets in Resources */,
20CC551D16AD346900DEFB5C /* Localizable.strings in Resources */,
BF0785EB1794AF4000EB988E /* info in Resources */,
C649F09D1A0926CD00B02548 /* settings.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -458,6 +463,7 @@
AB40047715B4B83000D87E2A /* PageTitleLabel.m in Sources */,
9FF795A715B4C57E00899E51 /* ShelfViewController.m in Sources */,
9F8FC1C415C55E8C0065F0A3 /* BakerBook.m in Sources */,
C649F0A31A0927F300B02548 /* BKRSettings.m in Sources */,
9F58D85115D66E870027902C /* UICustomNavigationBar.m in Sources */,
9F58D85215D66E870027902C /* UICustomNavigationController.m in Sources */,
AB26005116011D9D00E9AA66 /* BakerBookStatus.m in Sources */,
Expand Down
63 changes: 39 additions & 24 deletions Baker/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import "Constants.h"
#import "UIConstants.h"

#import "AppDelegate.h"
#import "UICustomNavigationController.h"
#import "UICustomNavigationBar.h"
Expand All @@ -41,6 +38,7 @@
#import "UIColor+Extensions.h"
#import "Utils.h"

#import "BKRSettings.h"
#import "BakerViewController.h"
#import "BakerAnalyticsEvents.h"

Expand All @@ -57,11 +55,11 @@ + (void)initialize {

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

#ifdef BAKER_NEWSSTAND
[self configureNewsstandApp:application options:launchOptions];
#else
[self configureStandAloneApp:application options:launchOptions];
#endif
if ([BKRSettings sharedSettings].isNewsstand) {
[self configureNewsstandApp:application options:launchOptions];
} else {
[self configureStandAloneApp:application options:launchOptions];
}

self.rootNavigationController = [[UICustomNavigationController alloc] initWithRootViewController:self.rootViewController];

Expand Down Expand Up @@ -136,7 +134,7 @@ - (void)configureStandAloneApp:(UIApplication*)application options:(NSDictionary

- (void)configureNavigationBar {
UICustomNavigationBar *navigationBar = (UICustomNavigationBar*)self.rootNavigationController.navigationBar;
navigationBar.tintColor = [UIColor colorWithHexString:ISSUES_ACTION_BUTTON_BACKGROUND_COLOR];
navigationBar.tintColor = [UIColor colorWithHexString:[BKRSettings sharedSettings].issuesActionBackgroundColor];
navigationBar.barTintColor = [UIColor colorWithHexString:@"ffffff"];
navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor colorWithHexString:@"000000"]};
[navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation-bar-bg"] forBarMetrics:UIBarMetricsDefault];
Expand All @@ -154,7 +152,11 @@ - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotifi
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
#ifdef BAKER_NEWSSTAND

if (![BKRSettings sharedSettings].isNewsstand) {
return;
}

NSString *apnsToken = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
apnsToken = [apnsToken stringByReplacingOccurrencesOfString:@" " withString:@""];

Expand All @@ -166,29 +168,41 @@ - (void)application:(UIApplication*)application didRegisterForRemoteNotification

BakerAPI *api = [BakerAPI sharedInstance];
[api postAPNSToken:apnsToken];
#endif

}

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
#ifdef BAKER_NEWSSTAND

if (![BKRSettings sharedSettings].isNewsstand) {
return;
}

NSDictionary *aps = userInfo[@"aps"];
if (aps && aps[@"content-available"]) {
[self applicationWillHandleNewsstandNotificationOfContent:userInfo[@"content-name"]];
}
#endif

}

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult result))handler {
#ifdef BAKER_NEWSSTAND

if (![BKRSettings sharedSettings].isNewsstand) {
return;
}

NSDictionary *aps = userInfo[@"aps"];
if (aps && aps[@"content-available"]) {
[self applicationWillHandleNewsstandNotificationOfContent:userInfo[@"content-name"]];
}
#endif

}

- (void)applicationWillHandleNewsstandNotificationOfContent:(NSString*)contentName {
#ifdef BAKER_NEWSSTAND

if (![BKRSettings sharedSettings].isNewsstand) {
return;
}

IssuesManager *issuesManager = [IssuesManager sharedInstance];
PurchasesManager *purchasesManager = [PurchasesManager sharedInstance];
__block BakerIssue *targetIssue = nil;
Expand Down Expand Up @@ -219,7 +233,7 @@ - (void)applicationWillHandleNewsstandNotificationOfContent:(NSString*)contentNa
}
}];
}];
#endif

}

#pragma mark - Application Lifecycle
Expand All @@ -229,17 +243,18 @@ - (void)applicationWillResignActive:(UIApplication*)application {
}

- (void)applicationDidEnterBackground:(UIApplication*)application {
#ifdef BAKER_NEWSSTAND
// Everything that happened while the application was opened can be considered as "seen"
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
#endif
[self resetApplicationBadge];
}

- (void)applicationDidBecomeActive:(UIApplication*)application {
#ifdef BAKER_NEWSSTAND
// Opening the application means all new items can be considered as "seen".
[self resetApplicationBadge];
}

- (void)resetApplicationBadge {
if (![BKRSettings sharedSettings].isNewsstand) {
return;
}
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
#endif
}

@end
113 changes: 113 additions & 0 deletions Baker/BKRSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//
// BKRSettings.h
// Baker
//
// ==========================================================================================
//
// Copyright (c) 2014, Pieter Claerhout
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// Neither the name of the Baker Framework nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <Foundation/Foundation.h>

@interface BKRSettings : NSObject

// Timeout for most network requests (in seconds)
@property (nonatomic, readonly) NSTimeInterval requestTimeout;

@property (nonatomic, readonly) BOOL isNewsstand;

// ----------------------------------------------------------------------------------------------------
// Mandatory - This constant defines where the JSON file containing all the publications is located.
// For more information on this file, see: https://github.com/Simbul/baker/wiki/Newsstand-shelf-JSON
// E.g. @"http://example.com/shelf.json"
@property (nonatomic, readonly) NSString *newsstandManifestUrl;

// ----------------------------------------------------------------------------------------------------
// Optional - This constant specifies the URL to ping back when a user purchases an issue or a subscription.
// For more information, see: https://github.com/Simbul/baker/wiki/Baker-Server-API
// E.g. @"http://example.com/purchased"
@property (nonatomic, readonly) NSString *purchaseConfirmationUrl;

// ----------------------------------------------------------------------------------------------------
// Optional - This constant specifies a URL that will be used to retrieve the list of purchased issues.
// For more information, see: https://github.com/Simbul/baker/wiki/Baker-Server-API
// E.g. @"http://example.com/purchases"
@property (nonatomic, readonly) NSString *purchasesUrl;

// ----------------------------------------------------------------------------------------------------
// Optional - This constant specifies the URL to ping back when a user enables push notifications.
// For more information, see: https://github.com/Simbul/baker/wiki/Baker-Server-API
// E.g. @"http://example.com/post_apns_token"
@property (nonatomic, readonly) NSString *postApnsTokenUrl;

// ----------------------------------------------------------------------------------------------------
// Mandatory - The following two constants identify the subscriptions you set up in iTunesConnect.
// See: iTunes Connect -> Manage Your Application -> (Your application) -> Manage In App Purchases

// This constant identifies a free subscription.
// E.g. @"com.example.MyBook.subscription.free"
@property (nonatomic, readonly) NSString *freeSubscriptionProductId;

// This constant identifies one or more auto-renewable subscriptions.
@property (nonatomic, readonly) NSArray *autoRenewableSubscriptionProductIds;


// Background color for issues cover (before downloading the actual cover)
@property (nonatomic, readonly) NSString *issuesCoverBackgroundColor;

// Title for issues in the shelf
@property (nonatomic, readonly) NSString *issuesTitleFont;
@property (nonatomic, readonly) int issuesTitleFontSize;
@property (nonatomic, readonly) NSString *issuesTitleColor;

// Info text for issues in the shelf
@property (nonatomic, readonly) NSString *issuesInfoFont;
@property (nonatomic, readonly) int issuesInfoFontSize;
@property (nonatomic, readonly) NSString *issuesInfoColor;

@property (nonatomic, readonly) NSString *issuesPriceColor;

// Download/read button for issues in the shelf
@property (nonatomic, readonly) NSString *issuesActionFont;
@property (nonatomic, readonly) int issuesActionFontSize;
@property (nonatomic, readonly) NSString *issuesActionBackgroundColor;
@property (nonatomic, readonly) NSString *issuesActionButtonColor;

// Archive button for issues in the shelf
@property (nonatomic, readonly) NSString *issuesArchiveFont;
@property (nonatomic, readonly) int issuesArchiveFontSize;
@property (nonatomic, readonly) NSString *issuesArchiveBackgroundColor;
@property (nonatomic, readonly) NSString *issuesArchiveButtonColor;

// Text and spinner for issues that are being loaded in the shelf
@property (nonatomic, readonly) NSString *issuesLoadingLabelColor;
@property (nonatomic, readonly) NSString *issuesLoadingSpinnerColor;

// Progress bar for issues that are being downloaded in the shelf
@property (nonatomic, readonly) NSString *issuesProgressbarTintColor;

+ (BKRSettings*)sharedSettings;

@end
Loading

0 comments on commit 4bb09eb

Please sign in to comment.