mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Handling default preferences.
This commit is contained in:
parent
dbd7531ef8
commit
7debd48b3d
9 changed files with 89 additions and 46 deletions
|
@ -951,7 +951,6 @@ def unread_story_hashes(request):
|
|||
story_hashes = UserSubscription.story_hashes(user.pk, feed_ids=feed_ids,
|
||||
order=order, read_filter=read_filter,
|
||||
include_timestamps=include_timestamps)
|
||||
|
||||
logging.user(request, "~FYLoading ~FCunread story hashes~FY: ~SB%s feeds~SN (%s story hashes)" %
|
||||
(len(feed_ids), len(story_hashes)))
|
||||
return dict(unread_feed_story_hashes=story_hashes)
|
||||
|
|
|
@ -242,6 +242,7 @@
|
|||
|
||||
+ (NewsBlurAppDelegate*) sharedAppDelegate;
|
||||
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
|
||||
- (void)registerDefaultsFromSettingsBundle;
|
||||
|
||||
- (void)showFirstTimeUser;
|
||||
- (void)showLogin;
|
||||
|
|
|
@ -159,6 +159,7 @@
|
|||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
NSString *currentiPhoneVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
|
||||
[self registerDefaultsFromSettingsBundle];
|
||||
|
||||
self.navigationController.delegate = self;
|
||||
self.navigationController.viewControllers = [NSArray arrayWithObject:self.feedsViewController];
|
||||
|
@ -212,6 +213,27 @@
|
|||
return YES;
|
||||
}
|
||||
|
||||
- (void)registerDefaultsFromSettingsBundle {
|
||||
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
|
||||
if(!settingsBundle) {
|
||||
NSLog(@"Could not find Settings.bundle");
|
||||
return;
|
||||
}
|
||||
|
||||
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]];
|
||||
NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
|
||||
|
||||
NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
|
||||
for(NSDictionary *prefSpecification in preferences) {
|
||||
NSString *key = [prefSpecification objectForKey:@"Key"];
|
||||
if (key && [[prefSpecification allKeys] containsObject:@"DefaultValue"]) {
|
||||
[defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
|
||||
}
|
||||
}
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
|
||||
}
|
||||
|
||||
- (void)showSplashView {
|
||||
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
||||
splashView = [[UIImageView alloc] init];
|
||||
|
@ -2244,6 +2266,8 @@
|
|||
OfflineFetchStories *operationFetchStories = [[OfflineFetchStories alloc] init];
|
||||
|
||||
[offlineQueue addOperation:operationFetchStories];
|
||||
|
||||
NSLog(@"Done start offline fetch stories");
|
||||
}
|
||||
|
||||
- (void)startOfflineFetchImages {
|
||||
|
|
|
@ -1809,7 +1809,7 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
}
|
||||
|
||||
- (void)hideNotifier {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC),
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC),
|
||||
dispatch_get_main_queue(), ^{
|
||||
[self.notifier hide];
|
||||
});
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
@synthesize appDelegate;
|
||||
|
||||
- (void)main {
|
||||
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
||||
|
||||
while (YES) {
|
||||
BOOL fetched = [self fetchImages];
|
||||
NSLog(@"Fetched: %d", fetched);
|
||||
|
@ -33,7 +35,6 @@
|
|||
}
|
||||
|
||||
NSLog(@"Fetching images...");
|
||||
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
||||
NSArray *urls = [self uncachedImageUrls];
|
||||
|
||||
imageDownloadOperationQueue = [[ASINetworkQueue alloc] init];
|
||||
|
@ -43,6 +44,8 @@
|
|||
|
||||
if (![[[NSUserDefaults standardUserDefaults]
|
||||
objectForKey:@"offline_image_download"] boolValue] ||
|
||||
![[[NSUserDefaults standardUserDefaults]
|
||||
objectForKey:@"offline_allowed"] boolValue] ||
|
||||
[urls count] == 0) {
|
||||
NSLog(@"Finished caching images. %d total", appDelegate.totalUncachedImagesCount);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
@ -131,32 +134,36 @@
|
|||
[request clearDelegatesAndCancel];
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *storyHash = [[request userInfo] objectForKey:@"story_hash"];
|
||||
|
||||
if ([request responseStatusCode] == 200) {
|
||||
NSData *responseData = [request responseData];
|
||||
NSString *md5Url = [Utilities md5:[[request originalURL] absoluteString]];
|
||||
NSLog(@"Storing image: %@ (%d bytes - %d in queue)", storyHash, [responseData length], [imageDownloadOperationQueue requestsCount]);
|
||||
if ([responseData length] <= 43) {
|
||||
NSLog(@" ---> Image url: %@", [request url]);
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
|
||||
(unsigned long)NULL), ^{
|
||||
|
||||
NSString *storyHash = [[request userInfo] objectForKey:@"story_hash"];
|
||||
|
||||
if ([request responseStatusCode] == 200) {
|
||||
NSData *responseData = [request responseData];
|
||||
NSString *md5Url = [Utilities md5:[[request originalURL] absoluteString]];
|
||||
NSLog(@"Storing image: %@ (%d bytes - %d in queue)", storyHash, [responseData length], [imageDownloadOperationQueue requestsCount]);
|
||||
if ([responseData length] <= 43) {
|
||||
NSLog(@" ---> Image url: %@", [request url]);
|
||||
}
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
NSString *cacheDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"story_images"];
|
||||
NSString *fullPath = [cacheDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", md5Url]];
|
||||
|
||||
[fileManager createFileAtPath:fullPath contents:responseData attributes:nil];
|
||||
} else {
|
||||
NSLog(@"Failed to fetch: %@ / %@", [[request originalURL] absoluteString], storyHash);
|
||||
}
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
NSString *cacheDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"story_images"];
|
||||
NSString *fullPath = [cacheDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", md5Url]];
|
||||
|
||||
[fileManager createFileAtPath:fullPath contents:responseData attributes:nil];
|
||||
} else {
|
||||
NSLog(@"Failed to fetch: %@ / %@", [[request originalURL] absoluteString], storyHash);
|
||||
}
|
||||
|
||||
[appDelegate.database inDatabase:^(FMDatabase *db) {
|
||||
[db executeUpdate:@"UPDATE cached_images SET "
|
||||
"image_cached = 1 WHERE story_hash = ?",
|
||||
storyHash];
|
||||
}];
|
||||
[appDelegate.database inDatabase:^(FMDatabase *db) {
|
||||
[db executeUpdate:@"UPDATE cached_images SET "
|
||||
"image_cached = 1 WHERE story_hash = ?",
|
||||
storyHash];
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)storeFailedImage:(ASIHTTPRequest *)request {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
@synthesize appDelegate;
|
||||
|
||||
- (void)main {
|
||||
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
||||
|
||||
while (YES) {
|
||||
BOOL fetched = [self fetchStories];
|
||||
NSLog(@"Fetched: %d", fetched);
|
||||
|
@ -31,18 +33,21 @@
|
|||
NSLog(@"FetchStories is canceled.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSLog(@"Fetching Stories...");
|
||||
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
||||
NSArray *hashes = [self unfetchedStoryHashes];
|
||||
|
||||
|
||||
if (![[[NSUserDefaults standardUserDefaults]
|
||||
objectForKey:@"offline_allowed"] boolValue]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[appDelegate.feedsViewController showDoneNotifier];
|
||||
[appDelegate.feedsViewController hideNotifier];
|
||||
});
|
||||
return NO;
|
||||
} else if ([hashes count] == 0) {
|
||||
}
|
||||
NSLog(@"Fetching Stories...");
|
||||
|
||||
NSArray *hashes = [self unfetchedStoryHashes];
|
||||
|
||||
if ([hashes count] == 0) {
|
||||
NSLog(@"Finished downloading unread stories. %d total", appDelegate.totalUnfetchedStoryCount);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (![[[NSUserDefaults standardUserDefaults]
|
||||
|
|
|
@ -9,11 +9,12 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "NewsBlurAppDelegate.h"
|
||||
#import "FMDatabaseQueue.h"
|
||||
#import "ASINetworkQueue.h"
|
||||
#import "AFJSONRequestOperation.h"
|
||||
|
||||
@interface OfflineSyncUnreads : NSOperation
|
||||
|
||||
@property (nonatomic) NewsBlurAppDelegate *appDelegate;
|
||||
@property (nonatomic) AFJSONRequestOperation *request;
|
||||
|
||||
- (void)storeUnreadHashes:(NSDictionary *)results;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
@implementation OfflineSyncUnreads
|
||||
|
||||
@synthesize appDelegate;
|
||||
@synthesize request;
|
||||
|
||||
- (void)main {
|
||||
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
||||
|
@ -25,15 +26,16 @@
|
|||
[appDelegate.feedsViewController showSyncingNotifier];
|
||||
});
|
||||
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/reader/unread_story_hashes?include_timestamps=true",
|
||||
NSURL *url = [NSURL URLWithString:[NSString
|
||||
stringWithFormat:@"%@/reader/unread_story_hashes?include_timestamps=true",
|
||||
NEWSBLUR_URL]];
|
||||
AFJSONRequestOperation *request = [AFJSONRequestOperation
|
||||
JSONRequestOperationWithRequest:[NSURLRequest requestWithURL:url]
|
||||
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
[self storeUnreadHashes:JSON];
|
||||
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
|
||||
NSLog(@"Failed fetch all story hashes.");
|
||||
}];
|
||||
request = [AFJSONRequestOperation
|
||||
JSONRequestOperationWithRequest:[NSURLRequest requestWithURL:url]
|
||||
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
[self storeUnreadHashes:JSON];
|
||||
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
|
||||
NSLog(@"Failed fetch all story hashes.");
|
||||
}];
|
||||
request.successCallbackQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
|
||||
(unsigned long)NULL);
|
||||
[request start];
|
||||
|
@ -41,7 +43,11 @@
|
|||
}
|
||||
|
||||
- (void)storeUnreadHashes:(NSDictionary *)results {
|
||||
if (self.isCancelled) return;
|
||||
if (self.isCancelled) {
|
||||
NSLog(@"Canceled storing unread hashes");
|
||||
[request cancel];
|
||||
return;
|
||||
}
|
||||
|
||||
[appDelegate.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
|
||||
NSLog(@"Storing unread story hashes...");
|
||||
|
@ -90,8 +96,8 @@
|
|||
appDelegate.totalUncachedImagesCount = 0;
|
||||
appDelegate.remainingUncachedImagesCount = 0;
|
||||
|
||||
[appDelegate startOfflineFetchStories];
|
||||
NSLog(@"Done syncing Unreads...");
|
||||
[appDelegate startOfflineFetchStories];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
// #define BACKGROUND_REFRESH_SECONDS -5
|
||||
#define BACKGROUND_REFRESH_SECONDS -10*60
|
||||
|
||||
#define NEWSBLUR_URL [NSString stringWithFormat:@"http://nb.local.com"]
|
||||
#define NEWSBLUR_HOST [NSString stringWithFormat:@"nb.local.com"]
|
||||
// #define NEWSBLUR_URL [NSString stringWithFormat:@"https://www.newsblur.com"]
|
||||
// #define NEWSBLUR_HOST [NSString stringWithFormat:@"www.newsblur.com"]
|
||||
// #define NEWSBLUR_URL [NSString stringWithFormat:@"http://nb.local.com"]
|
||||
// #define NEWSBLUR_HOST [NSString stringWithFormat:@"nb.local.com"]
|
||||
#define NEWSBLUR_URL [NSString stringWithFormat:@"https://www.newsblur.com"]
|
||||
#define NEWSBLUR_HOST [NSString stringWithFormat:@"www.newsblur.com"]
|
||||
|
||||
#define NEWSBLUR_LINK_COLOR 0x405BA8
|
||||
#define NEWSBLUR_HIGHLIGHT_COLOR 0xd2e6fd
|
||||
|
|
Loading…
Add table
Reference in a new issue