Permalink
Browse files

CoreSpotlight Feature Added

  • Loading branch information...
1 parent ca6f780 commit f6266fec1febac01bfba3287dd34f7b60a4f1250 @JustinFincher committed Jan 31, 2017
@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<key>CFBundleVersion</key>
- <string>875</string>
+ <string>885</string>
<key>CLKComplicationPrincipalClass</key>
<string>ComplicationController</string>
<key>CLKComplicationSupportedFamilies</key>
@@ -39,38 +39,9 @@ - (void)dealloc {
- (CLKComplicationTemplate *)getComplicationFrom:(CLKComplication *)complication
isSample:(BOOL)sampleBool
{
- NSMutableArray *weeks;
- NSData *data = [[[NSUserDefaults alloc] initWithSuiteName:JZSuiteName] objectForKey:@"GitHubContributionsArray"];
- if (data != nil)
- {
- weeks = [NSKeyedUnarchiver unarchiveObjectWithData:data];
- if (!weeks)
- {
- JZLog(@"NSUserDefaults DO NOT HAVE weeks DATA");
- }else
- {
- JZLog(@"NSUserDefaults DO HAVE weeks DATA");
- }
- }
- NSMutableArray *week = [weeks objectAtIndex:0];
- JZCommitDataModel* today;
- int todayNum = 0;
- int weekNum = 0;
- if (week)
- {
- today = [week lastObject];
- if (today)
- {
- todayNum = today.dataCount ? [today.dataCount intValue] : 0;
- }
- for (JZCommitDataModel* day in week)
- {
- if (day)
- {
- weekNum += (day.dataCount ? [today.dataCount intValue] : 0);
- }
- }
- }
+ JZCommitDataModel* today = [[JZCommitManager sharedManager] getLastDay];
+ int todayNum = [[JZCommitManager sharedManager] getDayContributionNum];
+ int weekNum = [[JZCommitManager sharedManager] getWeekContributionNum];
switch (complication.family)
{
@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<key>CFBundleVersion</key>
- <string>874</string>
+ <string>884</string>
<key>UIBackgroundModes</key>
<array/>
<key>UISupportedInterfaceOrientations</key>
@@ -31,6 +31,9 @@
0D565F9D1D85CAC5006C0324 /* JZCommitSceneView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D565F9C1D85CAC5006C0324 /* JZCommitSceneView.m */; };
0D7703FC1E1C19A00019F507 /* JZDataVisualizationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D96B1EE1E1B87A3001C1228 /* JZDataVisualizationManager.m */; };
0D7703FF1E1D52910019F507 /* JZIntroViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D7703FE1E1D52910019F507 /* JZIntroViewController.m */; };
+ 0D9044081E40D983002F9A61 /* JZAppSearchManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D9044071E40D983002F9A61 /* JZAppSearchManager.m */; };
+ 0D90440A1E40D9CA002F9A61 /* CoreSpotlight.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D9044091E40D9CA002F9A61 /* CoreSpotlight.framework */; };
+ 0D90440C1E40D9DB002F9A61 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D90440B1E40D9DB002F9A61 /* MobileCoreServices.framework */; };
0D96B1E81E1A9746001C1228 /* JZNotificationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D96B1E71E1A9746001C1228 /* JZNotificationManager.m */; };
0D96B1EB1E1A9C9A001C1228 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 0D96B1EA1E1A9C9A001C1228 /* Settings.bundle */; };
0D96B1EF1E1B87A3001C1228 /* JZDataVisualizationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D96B1EE1E1B87A3001C1228 /* JZDataVisualizationManager.m */; };
@@ -162,6 +165,10 @@
0D565F9C1D85CAC5006C0324 /* JZCommitSceneView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JZCommitSceneView.m; sourceTree = "<group>"; };
0D7703FD1E1D52910019F507 /* JZIntroViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JZIntroViewController.h; sourceTree = "<group>"; };
0D7703FE1E1D52910019F507 /* JZIntroViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JZIntroViewController.m; sourceTree = "<group>"; };
+ 0D9044061E40D983002F9A61 /* JZAppSearchManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JZAppSearchManager.h; sourceTree = "<group>"; };
+ 0D9044071E40D983002F9A61 /* JZAppSearchManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JZAppSearchManager.m; sourceTree = "<group>"; };
+ 0D9044091E40D9CA002F9A61 /* CoreSpotlight.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreSpotlight.framework; path = System/Library/Frameworks/CoreSpotlight.framework; sourceTree = SDKROOT; };
+ 0D90440B1E40D9DB002F9A61 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
0D96B1E61E1A9746001C1228 /* JZNotificationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JZNotificationManager.h; sourceTree = "<group>"; };
0D96B1E71E1A9746001C1228 /* JZNotificationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JZNotificationManager.m; sourceTree = "<group>"; };
0D96B1EA1E1A9C9A001C1228 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
@@ -234,6 +241,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 0D90440C1E40D9DB002F9A61 /* MobileCoreServices.framework in Frameworks */,
+ 0D90440A1E40D9CA002F9A61 /* CoreSpotlight.framework in Frameworks */,
0D0BA8071DF79E1100A893AB /* WatchConnectivity.framework in Frameworks */,
036F632D267B073666A2AE01 /* libPods-GitHubContributions.a in Frameworks */,
);
@@ -342,6 +351,8 @@
0D96B1EE1E1B87A3001C1228 /* JZDataVisualizationManager.m */,
0D96B1E61E1A9746001C1228 /* JZNotificationManager.h */,
0D96B1E71E1A9746001C1228 /* JZNotificationManager.m */,
+ 0D9044061E40D983002F9A61 /* JZAppSearchManager.h */,
+ 0D9044071E40D983002F9A61 /* JZAppSearchManager.m */,
);
name = Controller;
sourceTree = "<group>";
@@ -428,6 +439,8 @@
0DB556881D859A430042275E /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 0D90440B1E40D9DB002F9A61 /* MobileCoreServices.framework */,
+ 0D9044091E40D9CA002F9A61 /* CoreSpotlight.framework */,
0D10F0EA1DF9F52E00904A8B /* WatchConnectivity.framework */,
0D0BA80A1DF7AECD00A893AB /* SceneKit.framework */,
0D0BA8061DF79E1100A893AB /* WatchConnectivity.framework */,
@@ -967,6 +980,7 @@
0DEF7A481D85FE7D00761555 /* JZCommitDataModel.m in Sources */,
0D7703FF1E1D52910019F507 /* JZIntroViewController.m in Sources */,
0DEF7A471D85FE7A00761555 /* JZCommitManager.m in Sources */,
+ 0D9044081E40D983002F9A61 /* JZAppSearchManager.m in Sources */,
0D96B1EF1E1B87A3001C1228 /* JZDataVisualizationManager.m in Sources */,
0DB556711D859A120042275E /* AppDelegate.m in Sources */,
0DEF7A521D86812000761555 /* Reachability.m in Sources */,
@@ -18,6 +18,7 @@
#import <UserNotifications/UserNotifications.h>
#import "JZNotificationManager.h"
#import "JZIntroViewController.h"
+#import "JZAppSearchManager.h"
@interface AppDelegate ()<WCSessionDelegate,UNUserNotificationCenterDelegate>
@@ -64,6 +65,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
JZLog(@"UIBackgroundFetchResultNewData");
[self syncUserDefaultToWatch];
+ [[JZAppSearchManager sharedManager] updateAppSearchResult];
}
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
@@ -81,8 +83,11 @@ - (void)HandleShortcutItems
[items addObject:setUserNameItem];
}else if ([[JZCommitManager sharedManager] haveUserCommits])
{
- UIApplicationShortcutItem *shareItem = [[UIApplicationShortcutItem alloc]initWithType:@"Share" localizedTitle:@"Share"];
+ UIApplicationShortcutItem *shareItem = [[UIApplicationShortcutItem alloc]initWithType:@"Share" localizedTitle:@"Share Graph"];
[items addObject:shareItem];
+ }else
+ {
+
}
[[UIApplication sharedApplication] setShortcutItems:items];
}
@@ -183,6 +188,7 @@ -(void)application:(UIApplication *)application performFetchWithCompletionHandle
JZLog(@"UIBackgroundFetchResultNewData");
[self syncUserDefaultToWatch];
[self HandleShortcutItems];
+ [[JZAppSearchManager sharedManager] updateAppSearchResult];
completionHandler(UIBackgroundFetchResultNewData);
}
else
@@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
- <string>874</string>
+ <string>884</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
@@ -0,0 +1,16 @@
+//
+// JZAppSearchManager.h
+// GitHubContributions
+//
+// Created by Justin Fincher on 2017/1/31.
+// Copyright ยฉ 2017ๅนด JustZht. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface JZAppSearchManager : NSObject
+
++ (id)sharedManager;
+- (void)updateAppSearchResult;
+
+@end
@@ -0,0 +1,66 @@
+//
+// JZAppSearchManager.m
+// GitHubContributions
+//
+// Created by Justin Fincher on 2017/1/31.
+// Copyright ยฉ 2017ๅนด JustZht. All rights reserved.
+//
+
+#import "JZAppSearchManager.h"
+#import "JZHeader.h"
+#import <CoreSpotlight/CoreSpotlight.h>
+#import <MobileCoreServices/MobileCoreServices.h>
+#import "JZCommitManager.h"
+
+@implementation JZAppSearchManager
+
+#pragma mark Singleton Methods
+
++ (id)sharedManager {
+ static JZAppSearchManager *sharedMyManager = nil;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ sharedMyManager = [[self alloc] init];
+ });
+ return sharedMyManager;
+}
+
+- (id)init {
+ if (self = [super init])
+ {
+
+ }
+ return self;
+}
+
+- (void)dealloc {
+ // Should never be called, but just here for clarity really.
+}
+
+
+- (void)updateAppSearchResult
+{
+
+ if ([[JZCommitManager sharedManager] haveUserID] && [[JZCommitManager sharedManager] haveUserCommits])
+ {
+ NSString *userID = [[JZCommitManager sharedManager] getUserID];
+ NSInteger todayNum = [[JZCommitManager sharedManager] getDayContributionNum];
+ NSInteger weekNum = [[JZCommitManager sharedManager] getWeekContributionNum];
+
+ CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeText];
+ attributeSet.title = [NSString stringWithFormat:@"%@ 's GitHub Stats",userID];
+ attributeSet.contentDescription = [NSString stringWithFormat:@"Contributions: Today: %ld | This Week: %ld",(long)todayNum,(long)weekNum];
+ attributeSet.keywords = [NSArray arrayWithObjects:@"git",@"GitHub",@"Contributions",userID, nil];
+
+ CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:@"com.JustZht.GitHubContributions.Spotlight.Stats" domainIdentifier:@"spotlight.sample" attributeSet:attributeSet];
+
+ [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler:^(NSError *err)
+ {
+ if (err)
+ {
+ JZLog(@"%@",[err debugDescription]);
+ }
+ }];
+ }
+}
+@end
@@ -137,7 +137,13 @@ - (void)configureViews
[self keepView:self.setupLabelContainerView onPages:@[@(0)] withAttribute:IFTTTHorizontalPositionAttributeCenterX];
self.setupLabel = [[UILabel alloc] initWithFrame:CGRectZero];
- self.setupLabel.text = @"SETUP";
+ if (![[JZCommitManager sharedManager] haveUserID])
+ {
+ self.setupLabel.text = @"SETUP";
+ }else
+ {
+ self.setupLabel.text = @"SETTINGS";
+ }
self.setupLabel.userInteractionEnabled = YES;
self.setupLabel.minimumScaleFactor = 0.1;
self.setupLabel.adjustsFontSizeToFitWidth = YES;
@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<key>CFBundleVersion</key>
- <string>874</string>
+ <string>884</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
+#import "JZCommitDataModel.h"
@interface JZCommitManager : NSObject
@@ -17,5 +18,9 @@
- (NSMutableArray *)refresh;
- (BOOL)haveUserID;
+- (NSString *)getUserID;
- (BOOL)haveUserCommits;
+- (NSInteger)getWeekContributionNum;
+- (NSInteger)getDayContributionNum;
+- (JZCommitDataModel *)getLastDay;
@end
@@ -46,6 +46,16 @@ - (void)dealloc {
}
#pragma mark Helper
+- (NSString *)getUserID
+{
+ if ([self haveUserID])
+ {
+ return [[[NSUserDefaults alloc] initWithSuiteName:JZSuiteName] objectForKey:@"GitHubContributionsName"];
+ }else
+ {
+ return nil;
+ }
+}
- (BOOL)haveUserID
{
NSString *name = [[[NSUserDefaults alloc] initWithSuiteName:JZSuiteName] objectForKey:@"GitHubContributionsName"];
@@ -63,6 +73,51 @@ - (BOOL)haveUserCommits
}
return NO;
}
+- (NSInteger)getDayContributionNum
+{
+ JZCommitDataModel* today = [self getLastDay];
+ int todayNum = 0;
+ todayNum = today.dataCount ? [today.dataCount intValue] : 0;
+ return todayNum;
+}
+- (NSInteger)getWeekContributionNum
+{
+ NSMutableArray *weeks;
+ NSData *data = [[[NSUserDefaults alloc] initWithSuiteName:JZSuiteName] objectForKey:@"GitHubContributionsArray"];
+ if (data != nil)
+ {
+ weeks = [NSKeyedUnarchiver unarchiveObjectWithData:data];
+ }
+ NSMutableArray *week = [weeks objectAtIndex:0];
+ int weekNum = 0;
+ if (week)
+ {
+ for (JZCommitDataModel* day in week)
+ {
+ if (day)
+ {
+ weekNum += (day.dataCount ? [day.dataCount intValue] : 0);
+ }
+ }
+ }
+ return weekNum;
+}
+- (JZCommitDataModel *)getLastDay
+{
+ NSMutableArray *weeks;
+ NSData *data = [[[NSUserDefaults alloc] initWithSuiteName:JZSuiteName] objectForKey:@"GitHubContributionsArray"];
+ if (data != nil)
+ {
+ weeks = [NSKeyedUnarchiver unarchiveObjectWithData:data];
+ }
+ NSMutableArray *week = [weeks objectAtIndex:0];
+ JZCommitDataModel* today;
+ if (week)
+ {
+ today = [week lastObject];
+ }
+ return today;
+}
#pragma mark Web Task
- (NSMutableArray *)refresh
View
Binary file not shown.

0 comments on commit f6266fe

Please sign in to comment.