Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

Commit

Permalink
Default images
Browse files Browse the repository at this point in the history
  • Loading branch information
leonspok committed Jan 29, 2017
1 parent cfae2f4 commit e3e7387
Show file tree
Hide file tree
Showing 15 changed files with 648 additions and 30 deletions.
20 changes: 20 additions & 0 deletions Irvue Screensaver.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
E379652D1DEF0AD900C27AC7 /* NSScreen+MaxScaleFactor.m in Sources */ = {isa = PBXBuildFile; fileRef = E379652A1DEF0AD900C27AC7 /* NSScreen+MaxScaleFactor.m */; };
E3B4C0401DF04A2E00747C26 /* ConfigureSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = E3B4C03F1DF04A2E00747C26 /* ConfigureSheet.xib */; };
E3B4C0411DF04A2E00747C26 /* ConfigureSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = E3B4C03F1DF04A2E00747C26 /* ConfigureSheet.xib */; };
E3E940221E3E495A00094B83 /* TTOfflineChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = E3E940201E3E495A00094B83 /* TTOfflineChecker.h */; };
E3E940231E3E495A00094B83 /* TTOfflineChecker.m in Sources */ = {isa = PBXBuildFile; fileRef = E3E940211E3E495A00094B83 /* TTOfflineChecker.m */; };
E3E940241E3E495A00094B83 /* TTOfflineChecker.m in Sources */ = {isa = PBXBuildFile; fileRef = E3E940211E3E495A00094B83 /* TTOfflineChecker.m */; };
E3E940271E3E49BA00094B83 /* Reachability.h in Headers */ = {isa = PBXBuildFile; fileRef = E3E940251E3E49BA00094B83 /* Reachability.h */; };
E3E940281E3E49BA00094B83 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = E3E940261E3E49BA00094B83 /* Reachability.m */; };
E3E940291E3E49BA00094B83 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = E3E940261E3E49BA00094B83 /* Reachability.m */; };
E3FBA54B1DEEE9CD00CF2932 /* Irvue_ScreensaverView.h in Headers */ = {isa = PBXBuildFile; fileRef = E3FBA54A1DEEE9CD00CF2932 /* Irvue_ScreensaverView.h */; };
E3FBA54D1DEEE9CD00CF2932 /* Irvue_ScreensaverView.m in Sources */ = {isa = PBXBuildFile; fileRef = E3FBA54C1DEEE9CD00CF2932 /* Irvue_ScreensaverView.m */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -124,6 +130,10 @@
E37965291DEF0AD900C27AC7 /* NSScreen+MaxScaleFactor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSScreen+MaxScaleFactor.h"; sourceTree = "<group>"; };
E379652A1DEF0AD900C27AC7 /* NSScreen+MaxScaleFactor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSScreen+MaxScaleFactor.m"; sourceTree = "<group>"; };
E3B4C03F1DF04A2E00747C26 /* ConfigureSheet.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ConfigureSheet.xib; sourceTree = "<group>"; };
E3E940201E3E495A00094B83 /* TTOfflineChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTOfflineChecker.h; sourceTree = "<group>"; };
E3E940211E3E495A00094B83 /* TTOfflineChecker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTOfflineChecker.m; sourceTree = "<group>"; };
E3E940251E3E49BA00094B83 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
E3E940261E3E49BA00094B83 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };
E3F6104B1DF97313009A0CF9 /* UnsplashCredentials.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UnsplashCredentials.h; sourceTree = "<group>"; };
E3FBA5471DEEE9CD00CF2932 /* Irvue Screensaver.saver */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Irvue Screensaver.saver"; sourceTree = BUILT_PRODUCTS_DIR; };
E3FBA54A1DEEE9CD00CF2932 /* Irvue_ScreensaverView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Irvue_ScreensaverView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,6 +179,10 @@
E37964EF1DEEED3F00C27AC7 /* Commons */ = {
isa = PBXGroup;
children = (
E3E940251E3E49BA00094B83 /* Reachability.h */,
E3E940261E3E49BA00094B83 /* Reachability.m */,
E3E940201E3E495A00094B83 /* TTOfflineChecker.h */,
E3E940211E3E495A00094B83 /* TTOfflineChecker.m */,
E37964BB1DEEED3A00C27AC7 /* NSDictionary+NSURL.h */,
E37964BC1DEEED3A00C27AC7 /* NSDictionary+NSURL.m */,
E37964BD1DEEED3A00C27AC7 /* NSString+MD5.h */,
Expand Down Expand Up @@ -278,7 +292,9 @@
E37964E91DEEED3A00C27AC7 /* NSImage+Effects.h in Headers */,
E37964E51DEEED3A00C27AC7 /* LPImageDownloadManager.h in Headers */,
E37964A41DEEEC9600C27AC7 /* IVPhoto.h in Headers */,
E3E940221E3E495A00094B83 /* TTOfflineChecker.h in Headers */,
E37964DE1DEEED3A00C27AC7 /* NSImage+Luminance.h in Headers */,
E3E940271E3E49BA00094B83 /* Reachability.h in Headers */,
E37964A61DEEEC9600C27AC7 /* IVPhotoLocation.h in Headers */,
E37964ED1DEEED3A00C27AC7 /* NSCharacterSet+QueryParams.h in Headers */,
E3FBA54B1DEEE9CD00CF2932 /* Irvue_ScreensaverView.h in Headers */,
Expand Down Expand Up @@ -400,8 +416,10 @@
E37965221DEF098900C27AC7 /* LPUnsplashPhotoView.m in Sources */,
E37965101DEEFE1000C27AC7 /* NSString+MD5.m in Sources */,
E37965111DEEFE1000C27AC7 /* NSArray+Utilities.m in Sources */,
E3E940291E3E49BA00094B83 /* Reachability.m in Sources */,
E37965121DEEFE1000C27AC7 /* NSSet+Utilities.m in Sources */,
E37965131DEEFE1000C27AC7 /* NSImage+Luminance.m in Sources */,
E3E940241E3E495A00094B83 /* TTOfflineChecker.m in Sources */,
E37965151DEEFE1000C27AC7 /* LPImageDownloadManager.m in Sources */,
E37965161DEEFE1000C27AC7 /* NSBezierPath+CGPath.m in Sources */,
E37965171DEEFE1000C27AC7 /* NSImage+Effects.m in Sources */,
Expand Down Expand Up @@ -431,7 +449,9 @@
E37964E61DEEED3A00C27AC7 /* LPImageDownloadManager.m in Sources */,
E37964D91DEEED3A00C27AC7 /* NSString+MD5.m in Sources */,
E37964A51DEEEC9600C27AC7 /* IVPhoto.m in Sources */,
E3E940231E3E495A00094B83 /* TTOfflineChecker.m in Sources */,
E37965211DEF098900C27AC7 /* LPUnsplashPhotoView.m in Sources */,
E3E940281E3E49BA00094B83 /* Reachability.m in Sources */,
E37964AF1DEEEC9600C27AC7 /* IVCollection.m in Sources */,
E37964DF1DEEED3A00C27AC7 /* NSImage+Luminance.m in Sources */,
E37964B41DEEECAE00C27AC7 /* LPUnsplashAPI.m in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Irvue Screensaver/IVPhoto.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@

- (NSURL *)imageURLForSize:(NSSize)size;


@property (nonatomic, readonly, getter=isPlaceholder) BOOL placeholder;
+ (instancetype)placeholderPhoto;

@end
17 changes: 17 additions & 0 deletions Irvue Screensaver/IVPhoto.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#import "NSDictionary+NSURL.h"
#import "LPUnsplashAPI.h"

@interface IVPhoto()
@property (nonatomic, readwrite) BOOL placeholder;
@end

@implementation IVPhoto

- (id)initWithCoder:(NSCoder *)aDecoder {
Expand Down Expand Up @@ -143,4 +147,17 @@ - (NSURL *)imageURLForSize:(NSSize)size {
return url;
}

#pragma mark Placeholder

+ (instancetype)placeholderPhoto {
IVPhoto *photo = [IVPhoto new];
photo.uid = @"YadCgbsLHcE";
photo.placeholder = YES;
IVUser *user = [IVUser new];
user.username = @"willpower";
user.name = @"William Stitt";
photo.author = user;
return photo;
}

@end
4 changes: 2 additions & 2 deletions Irvue Screensaver/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.4</string>
<string>1.0.5</string>
<key>CFBundleVersion</key>
<string>1040</string>
<string>1050</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 Leonspok. All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
17 changes: 16 additions & 1 deletion Irvue Screensaver/Irvue_ScreensaverView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "LPUnsplashPhotoView.h"
#import "NSArray+Utilities.h"
#import "NSString+MD5.h"
#import "TTOfflineChecker.h"

typedef enum {
SwitchDirectionLeft = 0,
Expand Down Expand Up @@ -68,7 +69,14 @@ - (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
[self.containerView.layer setBackgroundColor:[NSColor blackColor].CGColor];
[self addSubview:self.containerView];

[self changeImage];
if ([self cachedPhotosFromSource:self.source].count == 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self replaceCurrentPhotoViewWith:[[LPUnsplashPhotoView alloc] initWithPhoto:[IVPhoto placeholderPhoto]] animated:YES];
[self changeImage];
});
} else {
[self changeImage];
}

[self setAnimationTimeInterval:1/30.0];
}
Expand Down Expand Up @@ -255,6 +263,13 @@ - (void)saveToCachePhotos:(NSArray<IVPhoto *> *)photos fromSource:(PhotosSource)
#pragma mark Animations

- (void)changeImage {
if ([[TTOfflineChecker defaultChecker] isOffline]) {
dispatch_async(dispatch_get_main_queue(), ^{
changeImageTimer = [NSTimer scheduledTimerWithTimeInterval:self.updateInterval target:self selector:@selector(changeImage) userInfo:nil repeats:YES];
});
return;
}

[changeImageTimer invalidate];
changeImageTimer = nil;
[self getNextImageSuccess:^(IVPhoto *photo) {
Expand Down
74 changes: 47 additions & 27 deletions Irvue Screensaver/LPUnsplashPhotoView.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,10 @@ - (void)setupCompletion:(void (^)(BOOL))completion {
}
};

NSURL *imageURL = [self.photo imageURLForSize:[NSScreen maxScreenResolution]];
if ([[LPImageDownloadManager defaultManager] hasImageForURL:[imageURL absoluteString]]) {
photoImage = [[LPImageDownloadManager defaultManager] getImageForURL:[imageURL absoluteString]];
if (photoImage) {
[self.photoImageView setImage:photoImage];
[self setNeedsLayout:YES];
imageLoaded = 1;
} else {
imageLoaded = -1;
}
completionBlock();
} else {
[[LPImageDownloadManager defaultManager] getImageForURL:[imageURL absoluteString] completion:^(NSImage *image) {
photoImage = image;
if (![self.photo isPlaceholder]) {
NSURL *imageURL = [self.photo imageURLForSize:[NSScreen maxScreenResolution]];
if ([[LPImageDownloadManager defaultManager] hasImageForURL:[imageURL absoluteString]]) {
photoImage = [[LPImageDownloadManager defaultManager] getImageForURL:[imageURL absoluteString]];
if (photoImage) {
[self.photoImageView setImage:photoImage];
[self setNeedsLayout:YES];
Expand All @@ -140,7 +130,29 @@ - (void)setupCompletion:(void (^)(BOOL))completion {
imageLoaded = -1;
}
completionBlock();
}];
} else {
[[LPImageDownloadManager defaultManager] getImageForURL:[imageURL absoluteString] completion:^(NSImage *image) {
photoImage = image;
if (photoImage) {
[self.photoImageView setImage:photoImage];
[self setNeedsLayout:YES];
imageLoaded = 1;
} else {
imageLoaded = -1;
}
completionBlock();
}];
}
} else {
photoImage = [NSImage imageNamed:@"placeholder"];
if (photoImage) {
[self.photoImageView setImage:photoImage];
[self setNeedsLayout:YES];
imageLoaded = 1;
} else {
imageLoaded = -1;
}
completionBlock();
}

NSURL *authorImageURL = self.photo.author.largeProfileImage;
Expand All @@ -151,20 +163,28 @@ - (void)setupCompletion:(void (^)(BOOL))completion {
authorImageURL = self.photo.author.smallProfileImage;
}

if ([[LPImageDownloadManager defaultManager] hasImageForURL:[authorImageURL absoluteString] size:TTImageSize300px rounded:YES]) {
[self.avatarImageView setImage:[[LPImageDownloadManager defaultManager] getImageForURL:[authorImageURL absoluteString] size:TTImageSize300px rounded:YES]];
if (authorImageURL) {
if ([[LPImageDownloadManager defaultManager] hasImageForURL:[authorImageURL absoluteString] size:TTImageSize300px rounded:YES]) {
[self.avatarImageView setImage:[[LPImageDownloadManager defaultManager] getImageForURL:[authorImageURL absoluteString] size:TTImageSize300px rounded:YES]];
avatarLoaded = 1;
completionBlock();
} else {
[[LPImageDownloadManager defaultManager] getImageForURL:[authorImageURL absoluteString] size:TTImageSize300px rounded:YES completion:^(NSImage *image) {
if (image) {
[self.avatarImageView setImage:image];
avatarLoaded = 1;
} else {
avatarLoaded = -1;
}
completionBlock();
}];
}
} else {
if ([self.photo isPlaceholder]) {
[self.avatarImageView setImage:[[NSImage imageNamed:@"placeholderProfileImage"] resizeWithAspectFillToSize:NSMakeSize(300, 300) rounded:YES]];
}
avatarLoaded = 1;
completionBlock();
} else {
[[LPImageDownloadManager defaultManager] getImageForURL:[authorImageURL absoluteString] size:TTImageSize300px rounded:YES completion:^(NSImage *image) {
if (image) {
[self.avatarImageView setImage:image];
avatarLoaded = 1;
} else {
avatarLoaded = -1;
}
completionBlock();
}];
}
}

Expand Down
100 changes: 100 additions & 0 deletions Irvue Screensaver/Reachability.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
File: Reachability.h
Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
Version: 3.5
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/

#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <netinet/in.h>


typedef enum : NSInteger {
NotReachable = 0,
ReachableViaWiFi,
ReachableViaWWAN
} NetworkStatus;


extern NSString *kReachabilityChangedNotification;


@interface Reachability : NSObject

/*!
* Use to check the reachability of a given host name.
*/
+ (instancetype)reachabilityWithHostName:(NSString *)hostName;

/*!
* Use to check the reachability of a given IP address.
*/
+ (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress;

/*!
* Checks whether the default route is available. Should be used by applications that do not connect to a particular host.
*/
+ (instancetype)reachabilityForInternetConnection;

/*!
* Checks whether a local WiFi connection is available.
*/
+ (instancetype)reachabilityForLocalWiFi;

/*!
* Start listening for reachability notifications on the current run loop.
*/
- (BOOL)startNotifier;
- (void)stopNotifier;

- (NetworkStatus)currentReachabilityStatus;

/*!
* WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand.
*/
- (BOOL)connectionRequired;

@end


Loading

0 comments on commit e3e7387

Please sign in to comment.