From 2cba42118b0600a01f20fdc5165311547a7d5f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=A9=E8=BE=BA=E7=BE=85=E3=82=A8=E3=83=AB=E3=83=8D?= =?UTF-8?q?=E3=82=B9=E3=83=88?= Date: Thu, 14 Nov 2013 16:31:21 +0900 Subject: [PATCH] Add Adjust Levels subspec --- LumberjackConsole.podspec | 18 +- Source/Adjust Levels/PTEAdjustLevelsCell.xib | 321 ++++++++++++++++++ .../Adjust Levels/PTEAdjustLevelsTableView.h | 37 ++ .../Adjust Levels/PTEAdjustLevelsTableView.m | 270 +++++++++++++++ 4 files changed, 643 insertions(+), 3 deletions(-) create mode 100644 Source/Adjust Levels/PTEAdjustLevelsCell.xib create mode 100644 Source/Adjust Levels/PTEAdjustLevelsTableView.h create mode 100644 Source/Adjust Levels/PTEAdjustLevelsTableView.m diff --git a/LumberjackConsole.podspec b/LumberjackConsole.podspec index 4f5561d..206835d 100644 --- a/LumberjackConsole.podspec +++ b/LumberjackConsole.podspec @@ -1,12 +1,14 @@ Pod::Spec.new do |s| + s.name = "LumberjackConsole" s.version = "1.0.0" s.summary = "On-device CocoaLumberjack console with support for search, filters and more." s.homepage = "http://ptez.github.io/LumberjackConsole" + s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' } - s.author = { "PTEz" => "", "Ernesto Rivera" => "rivera_ernesto@cyberagent.co.jp" } + s.author = { "Ernesto Rivera" => "rivera_ernesto@cyberagent.co.jp" } s.screenshots = [ "https://raw.github.com/wiki/CyberAgent/iOS-NBUCore/images/Dashboard.png", "https://raw.github.com/wiki/CyberAgent/iOS-NBUCore/images/Dashboard_minimized.png", "https://raw.github.com/wiki/CyberAgent/iOS-NBUCore/images/Dashboard_filter.png" ] @@ -14,11 +16,21 @@ Pod::Spec.new do |s| s.platform = :ios s.requires_arc = true - s.source_files = 'Source/*.{h,m}' - s.resources = 'Source/*.{xib}' s.preserve_paths = "README.*", "NOTICE", "*.xcconfig" s.dependency 'NBUCore', '>= 2.0.0' s.dependency 'CocoaLumberjack', '>= 1.6.3' + + s.subspec 'Base' do |sub| + sub.source_files = 'Source/*.{h,m}' + sub.resources = 'Source/*.{xib}' + end + + s.subspec 'AdjustLevels' do |sub| + s.dependency 'LumberjackConsole/Base' + sub.source_files = 'Source/Adjust Levels/*.{h,m}' + sub.resources = 'Source/Adjust Levels/*.{xib}' + end + end diff --git a/Source/Adjust Levels/PTEAdjustLevelsCell.xib b/Source/Adjust Levels/PTEAdjustLevelsCell.xib new file mode 100644 index 0000000..a2ef468 --- /dev/null +++ b/Source/Adjust Levels/PTEAdjustLevelsCell.xib @@ -0,0 +1,321 @@ + + + + 1280 + 13A598 + 4511 + 1265 + 695.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 3745 + + + IBProxyObject + IBUILabel + IBUIStepper + IBUITableViewCell + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 292 + + + + 256 + + + + 274 + {{15, 10}, {168, 38}} + + + + _NS:9 + {251, 251} + NO + YES + 7 + NO + IBCocoaTouchFramework + Label + + 1 + MC45MDE5NjA3OTAyIDAuOTAxOTYwNzkwMiAwLjkwMTk2MDc5MDIAA + + + 0 + + 2 + 17 + + + HelveticaNeue-Bold + 17 + 16 + + NO + + + + 289 + {{206, 23}, {94, 27}} + + + + _NS:9 + {750, 750} + NO + YES + IBCocoaTouchFramework + 0 + 0 + NO + 5 + + + + 289 + {{206, 8}, {94, 14}} + + + + _NS:9 + {251, 251} + NO + YES + 7 + NO + IBCocoaTouchFramework + Label + + 1 + MSAwIDAAA + + + 0 + 1 + + 1 + 13 + + + HelveticaNeue + 13 + 16 + + NO + + + {320, 57} + + + + _NS:12 + + 3 + MCAwAA + + NO + YES + 4 + YES + IBCocoaTouchFramework + + + {320, 58} + + + + _NS:9 + + IBCocoaTouchFramework + 0 + 15 + + PTEAdjustLevelsCell + + + + + NO + + + + nameLabel + + + + WBx-cE-hvJ + + + + levelLabel + + + + yUy-pA-ipu + + + + levelStepper + + + + 0el-08-lyR + + + + stepperValueChanged: + + + 13 + + m9q-N8-LTq + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + QxI-yo-nEs + + + + + + + + + + Gxy-Rj-k4Q + + + + + uyn-fJ-YO8 + + + + + aoD-YL-Qc0 + + + + + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + PTEAdjustLevelsCell + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + + + + + PTEAdjustLevelsCell + UITableViewCell + + UILabel + UIStepper + UILabel + + + + levelLabel + UILabel + + + levelStepper + UIStepper + + + nameLabel + UILabel + + + + IBProjectSource + ./Classes/PTEAdjustLevelsCell.h + + + + PTEAdjustLevelsTableView + UITableView + + stepperValueChanged: + UIStepper + + + stepperValueChanged: + + stepperValueChanged: + UIStepper + + + + IBProjectSource + ./Classes/PTEAdjustLevelsTableView.h + + + + + 0 + IBCocoaTouchFramework + YES + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES + 3 + 3745 + + diff --git a/Source/Adjust Levels/PTEAdjustLevelsTableView.h b/Source/Adjust Levels/PTEAdjustLevelsTableView.h new file mode 100644 index 0000000..a9864a1 --- /dev/null +++ b/Source/Adjust Levels/PTEAdjustLevelsTableView.h @@ -0,0 +1,37 @@ +// +// PTEAdjustLevelsTableView.h +// LumberjackConsole +// +// Created by Ernesto Rivera on 2013/10/09. +// Copyright (c) 2013. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// 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. +// + +/** + */ +@interface PTEAdjustLevelsTableView : UITableView + +@end + + +/** + */ +@interface PTEAdjustLevelsCell : UITableViewCell + +@property (weak, nonatomic) IBOutlet UILabel * nameLabel; +@property (weak, nonatomic) IBOutlet UILabel * levelLabel; +@property (weak, nonatomic) IBOutlet UIStepper * levelStepper; + +@end + diff --git a/Source/Adjust Levels/PTEAdjustLevelsTableView.m b/Source/Adjust Levels/PTEAdjustLevelsTableView.m new file mode 100644 index 0000000..a084566 --- /dev/null +++ b/Source/Adjust Levels/PTEAdjustLevelsTableView.m @@ -0,0 +1,270 @@ +// +// PTEAdjustLevelsTableView.m +// LumberjackConsole +// +// Created by Ernesto Rivera on 2013/10/09. +// Copyright (c) 2013. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// 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. +// + +#ifdef COCOAPODS_POD_AVAILABLE_NBULog + +#import "PTEAdjustLevelsTableView.h" +#import + +// Class extension +@interface PTEAdjustLevelsTableView () + +@end + +@implementation PTEAdjustLevelsTableView +{ + NSArray * _orderedContexts; +} + +- (void)awakeFromNib +{ + [super awakeFromNib]; + + // Init + _orderedContexts = [NBULog orderedRegisteredContexts]; + [self restoreLogLevels]; + [self registerNib:[UINib nibWithNibName:@"PTEAdjustLevelsCell" + bundle:nil] forCellReuseIdentifier:@"PTEAdjustLevelsCell"]; + self.dataSource = self; +} + +#pragma mark - Save/load levels + +- (void)saveLogLevels +{ + NSMutableArray * contextLevels = [NSMutableArray array]; + + // Save each context level + NSMutableDictionary * moduleLevels; + for (NBULogContextDescription * context in _orderedContexts) + { + // And each module level + moduleLevels = [NSMutableDictionary dictionary]; + for (NSNumber * module in context.orderedModules) + { + moduleLevels[module.description] = @(context.contextLevelForModule(module.intValue)); + } + + [contextLevels addObject:@{@"context" : @(context.logContext), + @"contextLevel" : @(context.contextLevel()), + @"modules" : moduleLevels}]; + } + + [[NSUserDefaults standardUserDefaults] setObject:contextLevels + forKey:@"PTEAdjustLevels"]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + +- (void)restoreLogLevels +{ + NSArray * contextLevels = [[NSUserDefaults standardUserDefaults] objectForKey:@"PTEAdjustLevels"]; + + // Restore each context level + int logContext; + NBULogContextDescription * context; + NSDictionary * moduleLevels; + for (NSDictionary * contextDictionary in contextLevels) + { + logContext = ((NSNumber *)contextDictionary[@"context"]).intValue; + + // Get the context description + context = nil; + for (context in _orderedContexts) + { + if (context.logContext == logContext) + break; + } + + if (!context) + continue; + + // And each module level + moduleLevels = contextDictionary[@"modules"]; + for (NSString * module in moduleLevels) + { + context.setContextLevelForModule(module.intValue, ((NSNumber *)moduleLevels[module]).intValue); + } + } +} + +#pragma mark - Actions + +- (IBAction)stepperValueChanged:(UIStepper *)sender +{ + NSIndexPath * indexPath = [self indexPathForRowAtPoint:[self convertPoint:sender.frame.origin + fromView:sender.superview]]; + NBULogContextDescription * context = _orderedContexts[indexPath.section]; + + // Get the log level + int logLevel; + switch ((int)sender.value) + { + case 5: + logLevel = LOG_LEVEL_VERBOSE; + break; + case 4: + logLevel = LOG_LEVEL_DEBUG; + break; + case 3: + logLevel = LOG_LEVEL_INFO; + break; + case 2: + logLevel = LOG_LEVEL_WARN; + break; + case 1: + logLevel = LOG_LEVEL_ERROR; + break; + case 0: + default: + logLevel = LOG_LEVEL_OFF; + break; + } + + // Context cell + if (indexPath.row == 0) + { + context.setContextLevel(logLevel); + } + + // Module cell + else + { + NSNumber * module = context.orderedModules[indexPath.row - 1]; + context.setContextLevelForModule(module.intValue, logLevel); + } + + [self reloadData]; + [self saveLogLevels]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return _orderedContexts.count; +} + +- (NSInteger)tableView:(UITableView *)tableView + numberOfRowsInSection:(NSInteger)section +{ + NBULogContextDescription * context = _orderedContexts[section]; + return context.modulesAndNames.count + 1; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + NBULogContextDescription * context = _orderedContexts[indexPath.section]; + PTEAdjustLevelsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PTEAdjustLevelsCell"]; + + // Context cell + if (indexPath.row == 0) + { + cell.nameLabel.text = context.name; + cell.nameLabel.font = [UIFont boldSystemFontOfSize:17.0]; + cell.nameLabel.frame = CGRectMake(15.0, + 10.0, + cell.nameLabel.frame.size.width, + cell.nameLabel.frame.size.height); + [self configureLevelLabel:cell.levelLabel + andStepper:cell.levelStepper + forLevel:context.contextLevel()]; + } + + // Module cell + else + { + NSNumber * module = context.orderedModules[indexPath.row - 1]; + + cell.nameLabel.text = context.modulesAndNames[module]; + cell.nameLabel.font = [UIFont systemFontOfSize:17.0]; + cell.nameLabel.frame = CGRectMake(30.0, + 10.0, + cell.nameLabel.frame.size.width, + cell.nameLabel.frame.size.height); + [self configureLevelLabel:cell.levelLabel + andStepper:cell.levelStepper + forLevel:context.contextLevelForModule(module.intValue)]; + } + + return cell; +} + +- (void)configureLevelLabel:(UILabel *)label + andStepper:(UIStepper *)stepper + forLevel:(int)level +{ + switch (level) + { + case LOG_LEVEL_ERROR: + { + label.text = @"Error level"; + label.textColor = [UIColor redColor]; + stepper.value = 1; + break; + } + case LOG_LEVEL_WARN: + { + label.text = @"Warning level"; + label.textColor = [UIColor orangeColor]; + stepper.value = 2; + break; + } + case LOG_LEVEL_INFO: + { + label.text = @"Info level"; + label.textColor = [UIColor greenColor]; + stepper.value = 3; + break; + } + case LOG_LEVEL_DEBUG: + { + label.text = @"Debug level"; + label.textColor = [UIColor whiteColor]; + stepper.value = 4; + break; + } + case LOG_LEVEL_VERBOSE: + { + label.text = @"Verbose level"; + label.textColor = [UIColor lightGrayColor]; + stepper.value = 5; + break; + } + case LOG_LEVEL_OFF: + default: + { + label.text = @"Logging off"; + label.textColor = [UIColor grayColor]; + stepper.value = 0; + break; + } + } +} + +@end + + +@implementation PTEAdjustLevelsCell + +@end + +#endif +