Skip to content

Commit

Permalink
mapfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
overtake committed May 22, 2015
1 parent 9b6c8dd commit 47fbc6f
Show file tree
Hide file tree
Showing 25 changed files with 299 additions and 44 deletions.
3 changes: 3 additions & 0 deletions TGShare/ShareViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@

@interface ShareViewController : NSViewController

+(void)loadContacts;
+(void)close;

@end
29 changes: 23 additions & 6 deletions TGShare/ShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ @implementation TGSSearchRowView

-(instancetype)initWithFrame:(NSRect)frameRect {
if(self = [super initWithFrame:frameRect]) {
_searchField = [[TMSearchTextField alloc] initWithFrame:NSMakeRect(5, 5, NSWidth(frameRect) - 10 , NSHeight(frameRect) - 10)];
_searchField = [[TMSearchTextField alloc] initWithFrame:NSMakeRect(5, 5, NSWidth(frameRect) - 20 , 30)];

[_searchField setCenterByView:self];

[self addSubview:_searchField];

Expand Down Expand Up @@ -91,17 +93,19 @@ - (NSString *)nibName {
return @"ShareViewController";
}

static ShareViewController *shareViewController;

- (void)loadView {
[super loadView];


shareViewController = self;

_isLoaded = NO;

_contacts = [[NSMutableArray alloc] init];
_items = [[NSMutableArray alloc] init];

_searchRowView = [[TGSSearchRowView alloc] initWithFrame:NSMakeRect(0, 0, NSWidth(self.view.bounds), 40)];
_searchRowView = [[TGSSearchRowView alloc] initWithFrame:NSMakeRect(0, 0, NSWidth(self.view.bounds), 60)];

_searchRowView.searchField.delegate = self;

Expand All @@ -122,7 +126,7 @@ - (void)loadView {

[_cancelButton setTitleColor:LINK_COLOR forControlState:BTRControlStateNormal];

[_cancelButton setTitle:@"Cancel" forControlState:BTRControlStateNormal];
[_cancelButton setTitle:NSLocalizedString(@"Cancel", nil) forControlState:BTRControlStateNormal];


weak();
Expand All @@ -143,7 +147,7 @@ - (void)loadView {

[_sendButton setTitleColor:LINK_COLOR forControlState:BTRControlStateNormal];

[_sendButton setTitle:@"Send" forControlState:BTRControlStateNormal];
[_sendButton setTitle:NSLocalizedString(@"Share", nil) forControlState:BTRControlStateNormal];

[_sendButton addBlock:^(BTRControlEvents events) {

Expand Down Expand Up @@ -229,6 +233,19 @@ -(void)searchFieldTextChange:(NSString *)searchString {

}




+(void)loadContacts {
[shareViewController loadContacts];
}

+(void)close {

NSError *cancelError = [NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil];
[shareViewController.extensionContext cancelRequestWithError:cancelError];
}

-(void)loadContacts {

[TGS_RPCRequest sendRequest:[TLAPI_contacts_getContacts createWithN_hash:@""] successHandler:^(id request, id response) {
Expand Down Expand Up @@ -360,7 +377,7 @@ - (IBAction)send:(id)sender {


- (CGFloat)rowHeight:(NSUInteger)row item:(TMRowItem *) item {
return row == 0 ? 40 : 50;
return row == 0 ? 60 : 50;
}
- (BOOL)isGroupRow:(NSUInteger)row item:(TMRowItem *) item {
return NO;
Expand Down
2 changes: 2 additions & 0 deletions TGShare/TGSAppManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@

+(void)initializeContacts;

+(NSUserDefaults *)standartUserDefaults;

@end
15 changes: 14 additions & 1 deletion TGShare/TGSAppManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "TGSAppManager.h"
#import "TGSNoAuthModalView.h"
#import "TGSEnterPasscodeView.h"
#import "ShareViewController.h"
@implementation TGSAppManager


Expand Down Expand Up @@ -51,7 +52,19 @@ +(void)hidePasslock {
}

+(void)initializeContacts {

[ShareViewController loadContacts];
}


+(NSUserDefaults *)standartUserDefaults {

static NSUserDefaults *instance;

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[NSUserDefaults alloc] initWithSuiteName:@"group.ru.keepcoder.Telegram"];
});

return instance;
}
@end
24 changes: 24 additions & 0 deletions TGShare/TGSEnterPasscodeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
#import "TGSAppManager.h"
#import "NSStringCategory.h"
#import "TGS_MTNetwork.h"
#import "TGImageView.h"
#import "TGSImageObject.h"
@interface TGSEnterPasscodeView ()
@property (nonatomic,strong) NSSecureTextField *secureField;
@property (nonatomic,strong) BTRButton *enterButton;
@property (nonatomic,strong) TGImageView *avatar;
@end

@implementation TGSEnterPasscodeView
Expand All @@ -31,6 +34,25 @@ -(instancetype)initWithFrame:(NSRect)frameRect {



_avatar = [[TGImageView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];


[_avatar setCenterByView:self];

[_avatar setFrameOrigin:NSMakePoint(NSMinX(_avatar.frame), NSMinY(_avatar.frame) + 50)];

[self addSubview:_avatar];

TLUser *user = [ClassStore deserialize:[[TGSAppManager standartUserDefaults] objectForKey:@"selfUser"]];

TGSImageObject *imageObject = [[TGSImageObject alloc] initWithLocation:user.photo.photo_small];

imageObject.imageSize = NSMakeSize(100, 100);

_avatar.object = imageObject;



self.backgroundColor = [NSColor whiteColor];

self.secureField = [[BTRSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 30)];
Expand Down Expand Up @@ -76,6 +98,8 @@ -(instancetype)initWithFrame:(NSRect)frameRect {

[self.secureField setCenterByView:self];

[self.secureField setFrameOrigin:NSMakePoint(NSMinX(_secureField.frame), NSMinY(_secureField.frame) - 30)];


[self addSubview:self.secureField];

Expand Down
31 changes: 31 additions & 0 deletions TGShare/TGSNoAuthModalView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
//

#import "TGSNoAuthModalView.h"
#import "BTRButton.h"
#import "ShareViewController.h"
@interface TGSNoAuthModalView ()
@property (nonatomic,strong) BTRButton *cancelButton;
@end

@implementation TGSNoAuthModalView

Expand All @@ -33,6 +38,32 @@ -(instancetype)initWithFrame:(NSRect)frameRect {
[textField setCenterByView:self];

[self addSubview:textField];


_cancelButton = [[BTRButton alloc] initWithFrame:NSMakeRect(0, 0, NSWidth(self.frame), 50)];

_cancelButton.layer.backgroundColor = [NSColor whiteColor].CGColor;

[_cancelButton setTitleColor:LINK_COLOR forControlState:BTRControlStateNormal];

[_cancelButton setTitle:NSLocalizedString(@"Cancel", nil) forControlState:BTRControlStateNormal];


[_cancelButton addBlock:^(BTRControlEvents events) {
[ShareViewController close];
} forControlEvents:BTRControlEventClick];


TMView *topSeparator = [[TMView alloc] initWithFrame:NSMakeRect(0, 49, NSWidth(self.frame), DIALOG_BORDER_WIDTH)];

topSeparator.backgroundColor = DIALOG_BORDER_COLOR;



[self addSubview:_cancelButton];

[self addSubview:topSeparator];

}

return self;
Expand Down
1 change: 1 addition & 0 deletions TGShare/TGS_ConversationRowItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


@property (nonatomic,strong,readonly) NSAttributedString *name;

@property (nonatomic,assign,readonly) NSSize nameSize;

@property (nonatomic,strong,readonly) TGSImageObject *imageObject;
Expand Down
54 changes: 52 additions & 2 deletions TGShare/TGS_ConversationRowItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#import "TGS_ConversationRowItem.h"
#import "NSAttributedStringCategory.h"
#import "TMAttributedString.h"
#import "TGS_MTNetwork.h"
#import "TGDateUtils.h"
@implementation TGS_ConversationRowItem

-(id)initWithConversation:(TLDialog *)conversation user:(TLUser *)user {
if(self = [super init]) {
_conversation = conversation;
_user = user;


[self configure];
}

Expand All @@ -39,8 +39,17 @@ -(void)configure {

[attr appendString:_user ? [NSString stringWithFormat:@"%@ %@",_user.first_name, _user.last_name] : _chat.title withColor:NSColorFromRGB(0x000000)];


[attr setFont:TGSystemFont(15) forRange:attr.range];

[attr appendString:@"\n"];

NSString *lastSeen = [self lastSeen];

NSRange range = [attr appendString:lastSeen withColor:[lastSeen isEqualToString:@"online"] ? LINK_COLOR : GRAY_TEXT_COLOR];

[attr setFont:TGSystemFont(13) forRange:range];

_name = attr;

NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
Expand All @@ -56,6 +65,47 @@ -(void)configure {
}


- (NSString *)lastSeen {

if(_chat)
{
return [NSString stringWithFormat:NSLocalizedString(_chat.participants_count > 1 ? @"Group.membersCount" : @"Group.memberCount", nil),_chat.participants_count];
}

if(_user.n_id == 777000) {
return NSLocalizedString(@"Service notifications", nil);
}

int lastSeenTime = [_user.status isKindOfClass:[TL_userStatusEmpty class]] ? - 1 : (_user.status.expires ? _user.status.expires : _user.status.was_online);

if([[TGS_MTNetwork instance] getTime] < lastSeenTime)
return NSLocalizedString(@"Account.Online", nil);

int time = lastSeenTime;
if(time == -1)
return NSLocalizedString(@"LastSeen.longTimeAgo", nil);

if(time == 0) {

if(_user.status.class == [TL_userStatusRecently class]) {
return NSLocalizedString(@"LastSeen.Recently", nil);
}
if(_user.status.class == [TL_userStatusLastWeek class]) {
return NSLocalizedString(@"LastSeen.Weekly", nil);
}
if(_user.status.class == [TL_userStatusLastMonth class]) {
return NSLocalizedString(@"LastSeen.Monthly", nil);
}

return NSLocalizedString(@"LastSeen.longTimeAgo", nil);
}


time -= [[TGS_MTNetwork instance] getTime] - [[NSDate date] timeIntervalSince1970];

return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Time.last_seen", nil), [TGDateUtils stringForRelativeLastSeen:time]];
}

-(NSUInteger)hash {
return _user ? _user.n_id : _chat.n_id;
}
Expand Down
12 changes: 7 additions & 5 deletions TGShare/TGS_ConversationRowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (void)drawRect:(NSRect)dirtyRect {

[DIALOG_BORDER_COLOR set];

NSRectFill(NSMakeRect(80, 0, NSWidth(dirtyRect) - 85, DIALOG_BORDER_WIDTH));
NSRectFill(NSMakeRect(60, 0, NSWidth(dirtyRect) - 60, DIALOG_BORDER_WIDTH));

}

Expand All @@ -40,19 +40,19 @@ -(instancetype)initWithFrame:(NSRect)frameRect {
[_nameField setEditable:NO];
[[_nameField cell] setLineBreakMode:NSLineBreakByTruncatingTail];

[_nameField setFrameOrigin:NSMakePoint(80, 17)];
[_nameField setFrameSize:NSMakeSize(NSWidth(frameRect) - 85, 20)];
[_nameField setFrameOrigin:NSMakePoint(60, 17)];
[_nameField setFrameSize:NSMakeSize(NSWidth(frameRect) - 85, 40)];

[self addSubview:_nameField];


_imageView = [[TGImageView alloc] initWithFrame:NSMakeRect(30, 5, 0, 0)];
_imageView = [[TGImageView alloc] initWithFrame:NSMakeRect(10, 5, 0, 0)];

[self addSubview:_imageView];



_selectButton = [[BTRButton alloc] initWithFrame:NSMakeRect(5, roundf((NSHeight(frameRect) - image_ComposeCheckActive().size.height )/ 2), image_ComposeCheckActive().size.width, image_ComposeCheckActive().size.height)];
_selectButton = [[BTRButton alloc] initWithFrame:NSMakeRect(NSWidth(frameRect) - image_ComposeCheckActive().size.width - 10, roundf((NSHeight(frameRect) - image_ComposeCheckActive().size.height )/ 2), image_ComposeCheckActive().size.width, image_ComposeCheckActive().size.height)];

weak();

Expand Down Expand Up @@ -114,6 +114,8 @@ -(void)redrawRow {
[_nameField setAttributedStringValue:item.name];

[_imageView setFrameSize:item.imageObject.imageSize];

[_nameField setCenteredYByView:self];

_imageView.object = item.imageObject;

Expand Down
4 changes: 2 additions & 2 deletions TGShare/TGS_MTNetwork.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ - (instancetype)init

[TGSAppManager initializeContacts];

if(![self isAuth]) {
// if(![self isAuth]) {
[TGSAppManager hidePasslock];
[TGSAppManager showNoAuthView];
}
// }
}


Expand Down
4 changes: 4 additions & 0 deletions TGShare/TGShare.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>group.ru.keepcoder.Telegram</string>
</array>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
Expand Down
Loading

0 comments on commit 47fbc6f

Please sign in to comment.