3535#import " EACodeReleaseViewController.h"
3636#import " Ease_2FA.h"
3737
38+ #import " Project_RootViewController.h"
39+ #import " MyTask_RootViewController.h"
40+ #import " Tweet_RootViewController.h"
41+ #import " Message_RootViewController.h"
42+ #import " Me_RootViewController.h"
43+ #import " ProjectViewController.h"
44+ #import " EACodeReleaseListViewController.h"
45+ #import " EACodeBranchListViewController.h"
46+ #import " MRPRListViewController.h"
47+ #import " ProjectSettingViewController.h"
48+ #import " CodeListViewController.h"
49+ #import " FileListViewController.h"
50+
3851#import " UnReadManager.h"
3952
4053typedef NS_ENUM (NSInteger , AnalyseMethodType) {
@@ -56,6 +69,7 @@ - (void)dismissModalVC{
5669#pragma mark - BaseViewController
5770
5871@interface BaseViewController ()
72+ @property (nonatomic ,strong ) NSUserActivity *userActivity;
5973
6074@end
6175
@@ -78,6 +92,7 @@ - (void)viewWillDisappear:(BOOL)animated
7892 [super viewWillDisappear: animated];
7993
8094 [MobClick endLogPageView: [NSString stringWithUTF8String: object_getClassName (self )]];
95+ [_userActivity resignCurrent ];
8196}
8297
8398- (void )viewDidLoad {
@@ -91,6 +106,151 @@ - (void)viewDidLoad{
91106 }
92107}
93108
109+ - (void )viewDidAppear : (BOOL )animated {
110+ [super viewDidAppear: animated];
111+ // Handoff
112+ [self p_setupUserActivity ];
113+ }
114+
115+ - (void )p_setupUserActivity {
116+ NSString *webStr = nil ;
117+
118+ // 主 Tab
119+ if ([self isKindOfClass: Project_RootViewController.class]) {// Project
120+ webStr = @" /user/projects" ;
121+ }else if ([self isKindOfClass: MyTask_RootViewController.class]){// Task
122+ webStr = [NSString stringWithFormat: @" /user/tasks?owner=%@ &status=1" , [Login curLoginUser ].id ];
123+ }else if ([self isKindOfClass: Tweet_RootViewController.class]){// Tweet
124+ Tweet_RootViewControllerType type = ((Tweet_RootViewController *)self).type ;
125+ webStr = [NSString stringWithFormat: @" /pp%@ " , (type == Tweet_RootViewControllerTypeHot? @" /hot" :
126+ type == Tweet_RootViewControllerTypeFriend? @" /friends" :
127+ @" " )];
128+ }else if ([self isKindOfClass: Message_RootViewController.class]){// Message
129+ webStr = @" /user/messages/basic" ;
130+ }else if ([self isKindOfClass: Me_RootViewController.class]){// User
131+ webStr = @" /user/account" ;
132+
133+ // Project
134+ }else if ([self isKindOfClass: NProjectViewController.class]){
135+ Project *curPro = ((NProjectViewController *)self).myProject ;
136+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ " , curPro.owner_user_name, curPro.name];
137+ }else if ([self isKindOfClass: ProjectViewController.class]){
138+ Project *curPro = ((ProjectViewController *)self).myProject ;
139+ ProjectViewType type = ((ProjectViewController *)self).curType ;
140+ NSString *sufStr = (type == ProjectViewTypeTasks? @" /tasks" :
141+ type == ProjectViewTypeFiles? @" /attachment" :
142+ type == ProjectViewTypeTopics? @" /topics" :
143+ type == ProjectViewTypeCodes? @" /git" :
144+ type == ProjectViewTypeMembers? @" /setting/member" :
145+ type == ProjectViewTypeActivities? @" " :@" " );
146+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@%@ " , curPro.owner_user_name, curPro.name, sufStr];
147+ }else if ([self isKindOfClass: EACodeBranchListViewController.class]){
148+ Project *curPro = ((EACodeBranchListViewController *)self).myProject ;
149+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /git/branches" , curPro.owner_user_name, curPro.name];
150+ }else if ([self isKindOfClass: EACodeReleaseListViewController.class]){
151+ Project *curPro = ((EACodeReleaseListViewController *)self).myProject ;
152+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /git/releases" , curPro.owner_user_name, curPro.name];
153+ }else if ([self isKindOfClass: MRPRListViewController.class]){
154+ Project *curPro = ((MRPRListViewController *)self).curProject ;
155+ BOOL isMR = ((MRPRListViewController *)self).isMR ;
156+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /git/%@ " , curPro.owner_user_name, curPro.name, isMR? @" merges" : @" pulls/open" ];
157+ }else if ([self isKindOfClass: UserOrProjectTweetsViewController.class]){
158+ Tweets *curTweets = ((UserOrProjectTweetsViewController *)self).curTweets ;
159+ if (curTweets.tweetType == TweetTypeProject) {
160+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /setting/notice" , curTweets.curPro.owner_user_name, curTweets.curPro.name];
161+ }else if (curTweets.tweetType == TweetTypeUserSingle){
162+ webStr = [NSString stringWithFormat: @" /u/%@ /bubble" , curTweets.curUser.global_key];
163+ }
164+ }else if ([self isKindOfClass: ProjectSettingViewController.class]){
165+ Project *curPro = ((ProjectSettingViewController *)self).project ;
166+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /setting" , curPro.owner_user_name, curPro.name];
167+
168+ // Task
169+ }else if ([self isKindOfClass: EditTaskViewController.class]){
170+ Task *curTask = ((EditTaskViewController *)self).myTask ;
171+ NSString *project_path = curTask.backend_project_path .copy ;
172+ project_path = [[project_path stringByReplacingOccurrencesOfString: @" /user/" withString: @" /u/" ] stringByReplacingOccurrencesOfString: @" /project/" withString: @" /p/" ];
173+ webStr = [NSString stringWithFormat: @" %@ /task/%@ " , project_path, curTask.id ];
174+
175+ // Tweet
176+ }else if ([self isKindOfClass: TweetDetailViewController.class]){
177+ Tweet *curTweet = ((TweetDetailViewController *)self).curTweet ;
178+ if (curTweet.isProjectTweet ) {
179+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /setting/notice/%@ " , curTweet.project.owner_user_name, curTweet.project.name, curTweet.id ];
180+ }else {
181+ webStr = [NSString stringWithFormat: @" /u/%@ /pp/%@ " , curTweet.user_global_key ?: curTweet.owner.global_key, curTweet.id ];
182+ }
183+
184+ // Message
185+ }else if ([self isKindOfClass: ConversationViewController.class]){
186+ PrivateMessages *curPriMs = ((ConversationViewController *)self).myPriMsgs ;
187+ webStr = [NSString stringWithFormat: @" /user/messages/history/%@ " , curPriMs.curFriend.global_key];
188+
189+ // User
190+ }else if ([self isKindOfClass: UserInfoViewController.class]){
191+ User *curU = ((UserInfoViewController *)self).curUser ;
192+ webStr = [NSString stringWithFormat: @" /u/%@ " , curU.global_key];
193+
194+ // Topic/File/MR/Code/Wiki/Release
195+ }else if ([self isKindOfClass: TopicDetailViewController.class]){
196+ ProjectTopic *curTopic = ((TopicDetailViewController *)self).curTopic ;
197+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /topic/%@ " , curTopic.project.owner_user_name, curTopic.project.name, curTopic.id ];
198+ }else if ([self isKindOfClass: FileViewController.class]){
199+ ProjectFile *curFile = ((FileViewController *)self).curFile ;
200+ if (curFile.project_owner_name && curFile.project_name ) {
201+ webStr = curFile.owner_preview ;
202+ }else if (curFile.owner_preview ){
203+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /attachment/default/preview/%@ " , curFile.project_owner_name, curFile.project_name, curFile.file_id];
204+ }
205+ }else if ([self isKindOfClass: MRDetailViewController.class] || [self isKindOfClass: PRDetailViewController.class]){
206+ MRPR *curMRPR = [self valueForKey: @" curMRPR" ];
207+ webStr = curMRPR.path ;
208+ }else if ([self isKindOfClass: CodeViewController.class]){
209+ Project *curPro = ((CodeViewController *) self).myProject ;
210+ CodeFile *curCF = ((CodeViewController *) self).myCodeFile ;
211+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /git/blob/%@ /%@ " , curPro.owner_user_name, curPro.name, curCF.ref, curCF.path];
212+ }else if ([self isKindOfClass: WikiViewController.class]){
213+ WikiViewController *vc = (WikiViewController *)self;
214+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /wiki" , vc.myProject.owner_user_name, vc.myProject.name];
215+ if (vc.iid ) {
216+ webStr = [webStr stringByAppendingFormat: @" /%@ " , vc.iid];
217+ if (vc.version .integerValue > 0 ) {
218+ webStr = [webStr stringByAppendingFormat: @" ?version=%@ " , vc.version];
219+ }
220+ }
221+ }else if ([self isKindOfClass: EACodeReleaseViewController.class]){
222+ EACodeRelease *curR = ((EACodeReleaseViewController *)self).curRelease ;
223+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /git/releases/%@ " , curR.project.owner_user_name, curR.project.name, curR.tag_name];
224+
225+ // CodeList/FileList/Webview
226+ }else if ([self isKindOfClass: CodeListViewController.class]){
227+ Project *curPro = ((CodeListViewController *) self).myProject ;
228+ CodeTree *curCT = ((CodeListViewController *) self).myCodeTree ;
229+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /git/tree/%@ /%@ " , curPro.owner_user_name, curPro.name, curCT.ref, curCT.path];
230+ }else if ([self isKindOfClass: FileListViewController.class]){
231+ Project *curPro = ((FileListViewController *) self).curProject ;
232+ ProjectFolder *curPF = ((FileListViewController *) self).curFolder ;
233+ webStr = [NSString stringWithFormat: @" /u/%@ /p/%@ /attachment/%@ " , curPro.owner_user_name, curPro.name, curPF.file_id];
234+ }else if ([self isKindOfClass: WebViewController.class]){
235+ webStr = ((WebViewController *)self).request .URL .absoluteString ;
236+ }
237+
238+ if (webStr) {
239+ NSURL *webURL = nil ;
240+ if (![webStr hasPrefix: @" http" ]) {
241+ webURL = [NSURL URLWithString: webStr relativeToURL: [NSURL URLWithString: [NSObject baseURLStr ]]];
242+ }else {
243+ webURL = [NSURL URLWithString: webStr];
244+ }
245+ if (!_userActivity) {
246+ _userActivity = [[NSUserActivity alloc ]initWithActivityType:@" com.alex.handoffdemo" ];
247+ _userActivity.title = @" CODING" ;
248+ }
249+ [_userActivity setWebpageURL: webURL];
250+ [_userActivity becomeCurrent ];
251+ }
252+ }
253+
94254- (void )tabBarItemClicked {
95255 DebugLog (@" \n tabBarItemClicked : %@ " , NSStringFromClass ([self class ]));
96256}
@@ -275,7 +435,12 @@ + (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr analyseMethod:(An
275435 }
276436 if (!analyseVC) {
277437 TopicDetailViewController *vc = [[TopicDetailViewController alloc ] init ];
278- vc.curTopic = [ProjectTopic topicWithId: [NSNumber numberWithInteger: topic_id.integerValue]];
438+ ProjectTopic *curTopic = [ProjectTopic topicWithId: [NSNumber numberWithInteger: topic_id.integerValue]];
439+ Project *curPro = [[Project alloc ] init ];
440+ curPro.owner_user_name = matchedCaptures[1 ];
441+ curPro.name = matchedCaptures[2 ];
442+ curTopic.project = curPro;
443+ vc.curTopic = curTopic;
279444 analyseVC = vc;
280445 }
281446 }else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex: taskRegexStr]).count > 0 ){
0 commit comments