Kaynağa Gözat

Move network monitor "Clear All" button to the toolbar

Tanner Bennett 6 yıl önce
ebeveyn
işleme
f6701f8ec9

+ 24 - 5
Classes/Network/FLEXNetworkMITMViewController.m

@@ -47,11 +47,18 @@
     self.showsSearchBar = YES;
     self.showSearchBarInitially = NO;
     
-    [self addToolbarItems:@[[UIBarButtonItem
-        itemWithImage:FLEXResources.gearIcon
-        target:self
-        action:@selector(settingsButtonTapped:)
-    ]]];
+    [self addToolbarItems:@[
+        [UIBarButtonItem
+            itemWithImage:FLEXResources.gearIcon
+            target:self
+            action:@selector(settingsButtonTapped:)
+        ],
+        [[UIBarButtonItem
+          systemItem:UIBarButtonSystemItemTrash
+          target:self
+          action:@selector(trashButtonTapped:)
+        ] withTintColor:UIColor.redColor]
+    ]];
 
     [self.tableView
         registerClass:[FLEXNetworkTransactionTableViewCell class]
@@ -114,6 +121,18 @@
     [self presentViewController:nav animated:YES completion:nil];
 }
 
+- (void)trashButtonTapped:(id)sender {
+    [FLEXAlert makeSheet:^(FLEXAlert *make) {
+        make.title(@"Clear All Recorded Requests?");
+        make.message(@"This cannot be undone.");
+        
+        make.button(@"Cancel").cancelStyle();
+        make.button(@"Clear All").destructiveStyle().handler(^(NSArray *strings) {
+            [FLEXNetworkRecorder.defaultRecorder clearRecordedActivity];
+        });
+    } showFrom:self];
+}
+
 - (void)settingsViewControllerDoneTapped:(id)sender {
     [self dismissViewControllerAnimated:YES completion:nil];
 }

+ 0 - 36
Classes/Network/FLEXNetworkSettingsTableViewController.m

@@ -46,9 +46,6 @@
     self.cacheLimitCell = [self sliderCellWithTitle:cacheLimitTitle changedAction:@selector(cacheLimitAdjusted:) minimum:0.0 maximum:fiftyMega initialValue:currentCacheLimit];
     [mutableCells addObject:self.cacheLimitCell];
 
-    UITableViewCell *clearRecordedRequestsCell = [self buttonCellWithTitle:@"❌  Clear Recorded Requests" touchUpAction:@selector(clearRequestsTapped:) isDestructive:YES];
-    [mutableCells addObject:clearRecordedRequestsCell];
-
     self.cells = mutableCells;
 }
 
@@ -68,18 +65,6 @@
     self.cacheLimitCell.textLabel.text = [self titleForCacheLimitCellWithValue:sender.value];
 }
 
-- (void)clearRequestsTapped:(UIButton *)sender {
-    [FLEXAlert makeSheet:^(FLEXAlert *make) {
-        make.button(@"Cancel").cancelStyle();
-        make.button(@"Clear Recorded Requests").destructiveStyle().handler(^(NSArray *strings) {
-            [FLEXNetworkRecorder.defaultRecorder clearRecordedActivity];
-        });
-    } showFrom:self];
-
-    self.popoverPresentationController.sourceView = sender;
-    self.popoverPresentationController.sourceRect = sender.bounds;
-}
-
 
 #pragma mark - Table View Data Source
 
@@ -113,27 +98,6 @@
     return cell;
 }
 
-- (UITableViewCell *)buttonCellWithTitle:(NSString *)title touchUpAction:(SEL)action isDestructive:(BOOL)isDestructive {
-    UITableViewCell *buttonCell = [UITableViewCell new];
-    buttonCell.selectionStyle = UITableViewCellSelectionStyleNone;
-
-    UIButton *actionButton = [UIButton buttonWithType:UIButtonTypeSystem];
-    [actionButton setTitle:title forState:UIControlStateNormal];
-    if (isDestructive) {
-        actionButton.tintColor = UIColor.redColor;
-    }
-    actionButton.titleLabel.font = [[self class] cellTitleFont];
-    [actionButton addTarget:self action:@selector(clearRequestsTapped:) forControlEvents:UIControlEventTouchUpInside];
-
-    [buttonCell.contentView addSubview:actionButton];
-    actionButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-    actionButton.frame = buttonCell.contentView.frame;
-    actionButton.contentEdgeInsets = UIEdgeInsetsMake(0.0, self.tableView.separatorInset.left, 0.0, self.tableView.separatorInset.left);
-    actionButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
-
-    return buttonCell;
-}
-
 - (NSString *)titleForCacheLimitCellWithValue:(long long)cacheLimit {
     NSInteger limitInMB = round(cacheLimit / (1024 * 1024));
     return [NSString stringWithFormat:@"Cache Limit (%ld MB)", (long)limitInMB];

+ 3 - 0
Classes/Utility/Categories/UIBarButtonItem+FLEX.h

@@ -30,6 +30,9 @@
 + (instancetype)disabledItemWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style;
 + (instancetype)disabledItemWithImage:(UIImage *)image;
 
+/// @return the receiver
+- (UIBarButtonItem *)withTintColor:(UIColor *)tint;
+
 - (void)_setWidth:(CGFloat)width;
 
 @end

+ 5 - 0
Classes/Utility/Categories/UIBarButtonItem+FLEX.m

@@ -64,4 +64,9 @@
     return item;
 }
 
+- (UIBarButtonItem *)withTintColor:(UIColor *)tint {
+    self.tintColor = tint;
+    return self;
+}
+
 @end