Skip to content

Commit

Permalink
mac demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jehoochen committed May 16, 2017
1 parent 0225646 commit ab35976
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 161 deletions.
1 change: 1 addition & 0 deletions samples/Mac/Bussiness/CommandID.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
static const int kSayHello = 1;
static const int kConvLst = 2;
static const int kSendMsg = 3;
static const int kPushMessageCmdId = 10001;

#endif /* CommandID_h */
2 changes: 2 additions & 0 deletions samples/Mac/Bussiness/NetworkDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@


#import "UINotifyDelegate.h"
#import "PushNotifyDelegate.h"

@class CGITask;

@protocol NetworkDelegate <NSObject>

@required - (void)addPushObserver:(id<PushNotifyDelegate>)observer withCmdId:(int)cmdId;
@required - (void)addObserver:(id<UINotifyDelegate>)observer forKey:(NSString *)key;
@required - (void)addCGITasks:(CGITask*)cgiTask forKey:(NSString *)key;

Expand Down
2 changes: 1 addition & 1 deletion samples/Mac/Bussiness/NetworkService.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
- (void)makesureLongLinkConnect;
- (void)destoryMars;


- (void)addPushObserver:(id<PushNotifyDelegate>)observer withCmdId:(int)cmdId;
- (int)startTask:(CGITask *)task ForUI:(id<UINotifyDelegate>)delegateUI;
- (void)stopTask:(NSInteger)taskID;

Expand Down
5 changes: 5 additions & 0 deletions samples/Mac/Bussiness/NetworkService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ - (void)OnConnectionStatusChange:(int32_t)status longConnStatus:(int32_t)longCon
[_delegate OnConnectionStatusChange:status longConnStatus:longConnStatus];
}

- (void)addPushObserver:(id<PushNotifyDelegate>)observer withCmdId:(int)cmdId {
[_delegate addPushObserver:observer withCmdId:cmdId];
}


#pragma mark NetworkStatusDelegate
-(void) ReachabilityChange:(UInt32)uiFlags {

Expand Down
18 changes: 18 additions & 0 deletions samples/Mac/Bussiness/PushNotifyDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// PushNotifyDelegate.h
// MacDemo
//
// Created by chenzihao on 17/05/15.
// Copyright © 2017年 chenzihao. All rights reserved.
//

#ifndef PushNotifyDelegate_h
#define PushNotifyDelegate_h

@protocol PushNotifyDelegate <NSObject>

@required -(void)notifyPushMessage:(NSData*)pushData withCmdId:(int)cmdId;

@end

#endif /* PushNotifyDelegate_h */
2 changes: 1 addition & 1 deletion samples/Mac/CoreUI/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NetworkService sharedInstance] setCallBack];
[[NetworkService sharedInstance] setClientVersion:200];
[[NetworkService sharedInstance] createMars];
[[NetworkService sharedInstance] setLongLinkAddress:@"localhost" port:8081];
[[NetworkService sharedInstance] setLongLinkAddress:@"www.marsopen.cn" port:8081];
[[NetworkService sharedInstance] setShortLinkPort:8080];

[[NetworkService sharedInstance] reportEvent_OnForground:YES];
Expand Down
132 changes: 70 additions & 62 deletions samples/Mac/CoreUI/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions samples/Mac/CoreUI/DemoEntryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
//

#import <Cocoa/Cocoa.h>
#import "Main.pb.h"

@interface DemoEntryController : NSViewController


-(void)setConversation:(Conversation*)conversation;
@end
33 changes: 32 additions & 1 deletion samples/Mac/CoreUI/DemoEntryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
//

#import "DemoEntryController.h"
#import "TopicViewController.h"
#import "MessagesController.h"

@interface DemoEntryController ()
@interface DemoEntryController () {
NSTabViewController* _tabviewController;
MessagesController* _messageController;
TopicViewController* _topicController;
}

@end

Expand All @@ -30,5 +36,30 @@ - (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
}
-(void)prepareForSegue:(NSStoryboardSegue *)segue sender:(id)sender {
if(![segue.destinationController isKindOfClass:[NSTabViewController class]])return;
_tabviewController = segue.destinationController;
for(NSViewController* childController in _tabviewController.childViewControllers) {
if([childController isKindOfClass:[MessagesController class]]) {
_messageController = (MessagesController*)childController;
if(_messageController)[_messageController setHostController:self];
}
else if([childController isKindOfClass:[TopicViewController class]]) {
_topicController = (TopicViewController*)childController;
if(_topicController)[_topicController setHostController:self];
}
}
_tabviewController.selectedTabViewItemIndex = 0;
[_tabviewController removeChildViewControllerAtIndex:2];
}

-(void)setConversation:(Conversation*)conversation {
if(!_tabviewController || !_messageController || !_topicController)
return;
[_tabviewController removeChildViewControllerAtIndex:1];
[_topicController setConversation:conversation];
[_tabviewController addChildViewController:_topicController];
_tabviewController.selectedTabViewItemIndex = 1;

}
@end
12 changes: 7 additions & 5 deletions samples/Mac/CoreUI/MessagesController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Tencent is pleased to support the open source community by making Mars available.
// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.

// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
Expand All @@ -14,8 +14,8 @@
// MessagesController.h
// mactest
//
// Created by caoshaokun on 16/11/28.
// Copyright © 2016年 caoshaokun. All rights reserved.
// Created by chenzihao on 17/05/15.
// Copyright © 2017年 chenzihao. All rights reserved.
//

#import <Cocoa/Cocoa.h>
Expand All @@ -24,9 +24,11 @@

#import "NetworkDelegate.h"
#import "UINotifyDelegate.h"
#import "MessagesDelegate.h"

@interface MessagesController : NSTableView<UINotifyDelegate, NSTableViewDelegate, NSTableViewDataSource> {
NSArray<Conversation*> * converSations;
@interface MessagesController : NSViewController<MessagesDelegate> {
}

-(void)setHostController:(NSViewController*)controller;
-(void)setConversation:(Conversation*)conversation;
@end
109 changes: 27 additions & 82 deletions samples/Mac/CoreUI/MessagesController.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Tencent is pleased to support the open source community by making Mars available.
// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.

// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
Expand All @@ -14,98 +14,43 @@
// MessagesController.m
// mactest
//
// Created by caoshaokun on 16/11/28.
// Copyright © 2016年 caoshaokun. All rights reserved.
// Created by chenzihao on 17/05/15.
// Copyright © 2017年 chenzihao. All rights reserved.
//

#import "MessagesController.h"

#import "TopicViewController.h"
#import "LogUtil.h"

#import "CommandID.h"
#import "CGITask.h"
#import "NetworkService.h"

@implementation MessagesController

- (id)initWithCoder:(NSCoder *)coder {
if (self = [super initWithCoder:coder]) {
self->converSations = [[NSArray alloc] init];
self.dataSource = self;
self.delegate = self;
[self setDoubleAction:NSSelectorFromString(@"doubleClick:")];
}

CGITask *convlstCGI = [[CGITask alloc] initAll:ChannelType_ShortConn AndCmdId:kConvLst AndCGIUri:@"/mars/getconvlist" AndHost:@"www.marsopen.cn"];
[[NetworkService sharedInstance] startTask:convlstCGI ForUI:self];

return self;
}

- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
}

- (NSInteger)numberOfRows {
return [self->converSations count];
}

- (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row {
NSTableCellView *cellView = [tableView makeViewWithIdentifier:@"message" owner:self];

cellView.textField.stringValue = self->converSations[row].notice;

return cellView;
#import "MessagesTableView.h"
#import "DemoEntryController.h"
@interface MessagesController() {
DemoEntryController* _hostController;
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [self->converSations count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
{
return [self->converSations objectAtIndex:row];
}

- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
return NO;
}
@end
@implementation MessagesController

- (void) doubleClick: (id)sender
{
NSInteger rowNumber = [self clickedRow];
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
MessagesTableView* view = (MessagesTableView*)[self findSubView:[self view] class:[MessagesTableView class]];
view.messagesDelegate = self;

}

- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row
{
return YES;
}

- (NSData*)requestSendData {

ConversationListRequest* convlstRequest = [[[[ConversationListRequest builder] setType:0] setAccessToken:@"123456"] build];
NSData* data = [convlstRequest data];

return data;
-(NSView*)findSubView:(NSView*)view class:(Class)class {
for(NSView* subView in view.subviews) {
if([subView isKindOfClass:class])
return subView;
NSView* findView = [self findSubView:subView class:class];
if(findView != nil)
return findView;
}
return nil;
}

- (int)onPostDecode:(NSData*)responseData {
ConversationListResponse *convlstResponse = [ConversationListResponse parseFromData:responseData];
self->converSations = convlstResponse.list;
LOG_INFO(kModuleViewController, @"recv conversation list, size: %lu", (unsigned long)[self->converSations count]);

return [self->converSations count] > 0 ? 0 : -1;

-(void)setHostController:(NSViewController*)controller {
_hostController = (DemoEntryController*)controller;
}

- (int)onTaskEnd:(uint32_t)tid errType:(uint32_t)errtype errCode:(uint32_t)errcode {
dispatch_async(dispatch_get_main_queue(), ^{
[self reloadData];
});
return 0;
-(void)setConversation:(Conversation*)conversation {
[_hostController setConversation:conversation];
}

@end
28 changes: 28 additions & 0 deletions samples/Mac/CoreUI/MessagesDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Tencent is pleased to support the open source community by making Mars available.
// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.

// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://opensource.org/licenses/MIT

// Unless required by applicable law or agreed to in writing, software distributed under the License is
// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions and
// limitations under the License.

//
// MessagesDelegate.h
// mactest
//
// Created by chenzihao on 17/05/15.
// Copyright © 2017年 chenzihao. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#import "Main.pb.h"


@protocol MessagesDelegate
-(void)setConversation:(Conversation*)conversation;
@end
35 changes: 35 additions & 0 deletions samples/Mac/CoreUI/MessagesTableView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Tencent is pleased to support the open source community by making Mars available.
// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.

// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://opensource.org/licenses/MIT

// Unless required by applicable law or agreed to in writing, software distributed under the License is
// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions and
// limitations under the License.

//
// MessagesTableView.h
// mactest
//
// Created by caoshaokun on 16/11/28.
// Copyright © 2016年 caoshaokun. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#import "Main.pb.h"

#import "NetworkDelegate.h"
#import "UINotifyDelegate.h"
#import "MessagesDelegate.h"

@interface MessagesTableView : NSTableView<UINotifyDelegate, NSTableViewDelegate, NSTableViewDataSource> {
NSArray<Conversation*> * converSations;
}

@property (nullable, weak) id <MessagesDelegate> messagesDelegate;

@end
Loading

0 comments on commit ab35976

Please sign in to comment.