Skip to content

Commit

Permalink
Dark mode support. Bump version to 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
romaxin committed Jan 20, 2020
1 parent 367e6b6 commit d8bfc5d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
4 changes: 2 additions & 2 deletions IQCoreDataBrowser.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "IQCoreDataBrowser"
s.version = "1.0.2"
s.version = "1.1.0"
s.summary = "Fast visualization of CoreData context content"
s.homepage = "https://github.com/InQBarna/iq-core-data-browser"
s.author = { "David Romacho" => "[email protected]", "Sergi Hernanz" => "[email protected]" }
Expand All @@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.7'

s.source = { :git => "https://github.com/InQBarna/iq-core-data-browser/iq-core-data-browser.git", :tag => "1.0.2" }
s.source = { :git => "https://github.com/InQBarna/iq-core-data-browser/iq-core-data-browser.git", :tag => "1.1.0" }
s.source_files = 'IQCoreDataBrowser/*.{h,m}'

s.requires_arc = true
Expand Down
69 changes: 51 additions & 18 deletions IQCoreDataBrowser/IQCoreDataBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ - (void)viewDidLoad
{
[super viewDidLoad];

self.tableView.tableFooterView = [[UIView alloc] init];

if(self.mode != IQCoreDataBrowserModeObjectList) {
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.frame.size.width, 44.0f)];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Expand All @@ -72,7 +74,6 @@ - (void)viewDidLoad
self.tableView.tableHeaderView = searchBar;
self.searchBar = searchBar;
}

[self reloadTableView];
}

Expand All @@ -87,6 +88,11 @@ - (void)viewDidAppear:(BOOL)animated {
}
}

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange: previousTraitCollection];
[self reloadTableView];
}

#pragma mark -
#pragma mark IQCoreDataBrowser methods

Expand Down Expand Up @@ -380,15 +386,15 @@ - (void)reloadTableView
}
}

- (NSAttributedString*)highlightText:text
- (NSAttributedString*)highlightText:text color:(UIColor*)textColor
{
NSMutableAttributedString *result = [[NSMutableAttributedString alloc] initWithString:text
attributes:@{NSForegroundColorAttributeName : [UIColor blackColor]}];
attributes:@{NSForegroundColorAttributeName : textColor}];

if(self.searchBar.text) {
NSRange range = [text rangeOfString:self.searchBar.text options:NSCaseInsensitiveSearch];
if(range.location != NSNotFound) {
[result addAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor]} range:range];
[result addAttributes:@{NSForegroundColorAttributeName : self.view.tintColor} range:range];
}
}

Expand All @@ -398,7 +404,8 @@ - (NSAttributedString*)highlightText:text
- (void)configureCell:(UITableViewCell*)cell forEntity:(NSEntityDescription*)entityDescription
{
// Set title
cell.textLabel.attributedText = [self highlightText:entityDescription.name];
cell.textLabel.textColor = self.textColor;
cell.textLabel.attributedText = [self highlightText:entityDescription.name color:self.textColor];

// Set detail
NSFetchRequest *fr = [NSFetchRequest fetchRequestWithEntityName:entityDescription.name];
Expand All @@ -411,22 +418,23 @@ - (void)configureCell:(UITableViewCell*)cell forEntity:(NSEntityDescription*)ent
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
cell.detailTextLabel.textColor = self.detailTextColor;
} else {
cell.detailTextLabel.text = @"Error";
cell.accessoryType = UITableViewCellAccessoryNone;
cell.detailTextLabel.textColor = [UIColor redColor];
cell.detailTextLabel.textColor = self.view.tintColor;
}
}

- (void)configureCell:(UITableViewCell*)cell forObject:(NSManagedObject*)object
{
// Set title
cell.textLabel.attributedText = [self highlightText:[self titleForObject:object]];
cell.textLabel.textColor = self.textColor;
cell.textLabel.attributedText = [self highlightText:[self titleForObject:object] color:self.textColor];

// Set detail
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
cell.detailTextLabel.attributedText = [self highlightText:[self detailForObject:object]];
cell.detailTextLabel.textColor = self.detailTextColor;
cell.detailTextLabel.attributedText = [self highlightText:[self detailForObject:object] color:self.detailTextColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

Expand All @@ -436,14 +444,15 @@ - (void)configureCell:(UITableViewCell*)cell forAttribute:(NSAttributeDescriptio
NSString *title = [NSString stringWithFormat:@"%@ (%@)",
attribute.name,
[self.class nameForAttributeType:attribute.attributeType]];
cell.textLabel.attributedText = [self highlightText:title];

cell.textLabel.textColor = self.textColor;
cell.textLabel.attributedText = [self highlightText:title color:self.textColor];

cell.detailTextLabel.textColor = self.detailTextColor;

if(value) {
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
NSString *valueString = [[value description] stringByReplacingOccurrencesOfString:@"\n" withString:@" "]; // value as single line
cell.detailTextLabel.attributedText = [self highlightText:valueString];
cell.detailTextLabel.attributedText = [self highlightText:valueString color:self.detailTextColor];
} else {
cell.detailTextLabel.textColor = [UIColor orangeColor];
cell.detailTextLabel.text = @"nil";
}

Expand All @@ -452,7 +461,8 @@ - (void)configureCell:(UITableViewCell*)cell forAttribute:(NSAttributeDescriptio

- (void)configureCell:(UITableViewCell*)cell forRelationship:(NSRelationshipDescription*)r
{
cell.textLabel.attributedText = [self highlightText:r.name];
cell.textLabel.textColor = self.textColor;
cell.textLabel.attributedText = [self highlightText:r.name color:self.textColor];

id value = [self.object valueForKey:r.name];

Expand All @@ -478,7 +488,7 @@ - (void)configureCell:(UITableViewCell*)cell forRelationship:(NSRelationshipDesc
cell.accessoryType = UITableViewCellAccessoryNone;
if(!value) {
detail = [detail stringByAppendingString:@", nil"];
cell.detailTextLabel.textColor = [UIColor orangeColor];
cell.detailTextLabel.textColor = self.detailTextColor;
} else {

if(r.toMany) {
Expand All @@ -489,7 +499,7 @@ - (void)configureCell:(UITableViewCell*)cell forRelationship:(NSRelationshipDesc
} else {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
cell.detailTextLabel.textColor = self.detailTextColor;
}
cell.detailTextLabel.text = detail;
}
Expand Down Expand Up @@ -609,6 +619,29 @@ - (void)dismiss {
[self dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)isDarkModeEnabled {
if (@available(iOS 13.0, *)) {
switch (UITraitCollection.currentTraitCollection.userInterfaceStyle) {
case UIUserInterfaceStyleDark:
return true;
default:
return false;
}
return false;
} else {
return false;
}

}

- (UIColor*)textColor {
return self.isDarkModeEnabled ? [UIColor whiteColor] : [UIColor blackColor];
}

- (UIColor*)detailTextColor {
return self.isDarkModeEnabled ? [UIColor lightGrayColor] : [UIColor darkGrayColor];
}

#pragma mark -
#pragma mark UITableViewDataSource methods

Expand Down

0 comments on commit d8bfc5d

Please sign in to comment.