Skip to content

Commit

Permalink
add pin/unpin actions to the gear button menu
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed May 24, 2022
1 parent 2a60992 commit 5570fd3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
51 changes: 29 additions & 22 deletions IRCCloud/Classes/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -3683,6 +3683,8 @@ -(IBAction)settingsButtonPressed:(id)sender {
[self actionSheetActionClicked:a.title];
};

[self _addPinAction:alert buffer:self->_buffer];

if([self->_buffer.type isEqualToString:@"console"]) {
Server *s = [[ServersDataSource sharedInstance] getServer:self->_buffer.cid];
if([s.status isEqualToString:@"disconnected"]) {
Expand Down Expand Up @@ -4281,33 +4283,43 @@ -(void)bufferLongPressed:(int)bid rect:(CGRect)rect {
[alert addAction:[UIAlertAction actionWithTitle:@"Reorder Connections" style:UIAlertActionStyleDefault handler:^(UIAlertAction *alert) {
[self _reorder];
}]];

if(!self->_selectedBuffer.archived && ([self->_selectedBuffer.type isEqualToString:@"channel"] || [self->_selectedBuffer.type isEqualToString:@"conversation"])) {

[alert addAction:[UIAlertAction actionWithTitle:@"Reorder Pins" style:UIAlertActionStyleDefault handler:^(UIAlertAction *alert) {
PinReorderViewController *pvc = [[PinReorderViewController alloc] initWithStyle:UITableViewStylePlain];
[self.slidingViewController resetTopView];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:pvc];
[nc.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone])
nc.modalPresentationStyle = UIModalPresentationFormSheet;
else
nc.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:nc animated:YES completion:nil];
}]];

[self _addPinAction:alert buffer:self->_selectedBuffer];

[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
alert.popoverPresentationController.sourceRect = rect;
alert.popoverPresentationController.sourceView = self->_buffersView.tableView;
[self presentViewController:alert animated:YES completion:nil];
}

-(void)_addPinAction:(UIAlertController *)alert buffer:(Buffer *)buffer {
if(!buffer.archived && ([buffer.type isEqualToString:@"channel"] || [buffer.type isEqualToString:@"conversation"])) {
BOOL pinned = NO;

NSDictionary *prefs = [[NetworkConnection sharedInstance] prefs];

if([[prefs objectForKey:@"pinnedBuffers"] isKindOfClass:NSArray.class] && [(NSArray *)[prefs objectForKey:@"pinnedBuffers"] count] > 0) {
for(NSNumber *n in [prefs objectForKey:@"pinnedBuffers"]) {
if(n.intValue == self->_selectedBuffer.bid) {
if(n.intValue == buffer.bid) {
pinned = YES;
break;
}
}
}

if(pinned) {
[alert addAction:[UIAlertAction actionWithTitle:@"Reorder Pins" style:UIAlertActionStyleDefault handler:^(UIAlertAction *alert) {
PinReorderViewController *pvc = [[PinReorderViewController alloc] initWithStyle:UITableViewStylePlain];
[self.slidingViewController resetTopView];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:pvc];
[nc.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone])
nc.modalPresentationStyle = UIModalPresentationFormSheet;
else
nc.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:nc animated:YES completion:nil];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Remove Pin" style:UIAlertActionStyleDefault handler:^(UIAlertAction *alert) {
NSMutableDictionary *mutablePrefs = prefs.mutableCopy;
NSMutableArray *pinnedBuffers;
Expand All @@ -4316,7 +4328,7 @@ -(void)bufferLongPressed:(int)bid rect:(CGRect)rect {
} else {
pinnedBuffers = [[NSMutableArray alloc] init];
}
[pinnedBuffers removeObject:@(self->_selectedBuffer.bid)];
[pinnedBuffers removeObject:@(buffer.bid)];
[mutablePrefs setObject:pinnedBuffers forKey:@"pinnedBuffers"];
SBJson5Writer *writer = [[SBJson5Writer alloc] init];
NSString *json = [writer stringWithObject:mutablePrefs];
Expand All @@ -4330,15 +4342,15 @@ -(void)bufferLongPressed:(int)bid rect:(CGRect)rect {
}];
}]];
} else {
[alert addAction:[UIAlertAction actionWithTitle:[self->_selectedBuffer.type isEqualToString:@"channel"]?@"Pin Channel":@"Pin Conversation" style:UIAlertActionStyleDefault handler:^(UIAlertAction *alert) {
[alert addAction:[UIAlertAction actionWithTitle:[buffer.type isEqualToString:@"channel"]?@"Pin Channel":@"Pin Conversation" style:UIAlertActionStyleDefault handler:^(UIAlertAction *alert) {
NSMutableDictionary *mutablePrefs = prefs.mutableCopy;
NSMutableArray *pinnedBuffers;
if([[prefs objectForKey:@"pinnedBuffers"] isKindOfClass:NSArray.class] && [(NSArray *)[prefs objectForKey:@"pinnedBuffers"] count] > 0) {
pinnedBuffers = ((NSArray *)[prefs objectForKey:@"pinnedBuffers"]).mutableCopy;
} else {
pinnedBuffers = [[NSMutableArray alloc] init];
}
[pinnedBuffers addObject:@(self->_selectedBuffer.bid)];
[pinnedBuffers addObject:@(buffer.bid)];
[mutablePrefs setObject:pinnedBuffers forKey:@"pinnedBuffers"];
SBJson5Writer *writer = [[SBJson5Writer alloc] init];
NSString *json = [writer stringWithObject:mutablePrefs];
Expand All @@ -4353,11 +4365,6 @@ -(void)bufferLongPressed:(int)bid rect:(CGRect)rect {
}]];
}
}

[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
alert.popoverPresentationController.sourceRect = rect;
alert.popoverPresentationController.sourceView = self->_buffersView.tableView;
[self presentViewController:alert animated:YES completion:nil];
}

-(void)spamSelected:(int)cid {
Expand Down
2 changes: 1 addition & 1 deletion build-scripts/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
256
258

0 comments on commit 5570fd3

Please sign in to comment.