2017-02-17 08:41:24 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "CountryPickerViewController.h"
|
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
2017-07-21 09:28:17 +00:00
|
|
|
@interface CountryPickerViewController ()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change.
|
|
|
|
*/
|
|
|
|
id kRiotDesignValuesDidChangeThemeNotificationObserver;
|
2017-08-14 11:09:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
The fake top view displayed in case of vertical bounce.
|
|
|
|
*/
|
|
|
|
UIView *topview;
|
2017-07-21 09:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-02-17 08:41:24 +00:00
|
|
|
@implementation CountryPickerViewController
|
|
|
|
|
|
|
|
- (void)finalizeInit
|
|
|
|
{
|
|
|
|
[super finalizeInit];
|
|
|
|
|
|
|
|
// Setup `MXKViewControllerHandling` properties
|
|
|
|
self.enableBarTintColorStatusChange = NO;
|
|
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
// Hide line separators of empty cells
|
|
|
|
self.tableView.tableFooterView = [[UIView alloc] init];
|
2017-08-11 14:56:09 +00:00
|
|
|
// Note: UISearchDisplayController is deprecated in iOS 8.
|
|
|
|
// MXKCountryPickerViewController should use UISearchController to manage the presentation of a search bar and display search results.
|
|
|
|
self.searchDisplayController.searchResultsTableView.tableFooterView = [[UIView alloc] init];
|
2017-08-14 11:09:11 +00:00
|
|
|
|
|
|
|
// Add a top view which will be displayed in case of vertical bounce.
|
|
|
|
CGFloat height = self.tableView.frame.size.height;
|
|
|
|
topview = [[UIView alloc] initWithFrame:CGRectMake(0,-height,self.tableView.frame.size.width,height)];
|
|
|
|
topview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
|
|
|
[self.tableView addSubview:topview];
|
2017-02-17 08:41:24 +00:00
|
|
|
|
2017-07-21 09:28:17 +00:00
|
|
|
// Observe user interface theme change.
|
|
|
|
kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
|
|
|
|
}];
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)userInterfaceThemeDidChange
|
|
|
|
{
|
|
|
|
self.defaultBarTintColor = kRiotSecondaryBgColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
self.barTitleColor = kRiotPrimaryTextColor;
|
|
|
|
|
|
|
|
self.searchBar.barStyle = kRiotDesignSearchBarStyle;
|
|
|
|
self.searchBar.tintColor = kRiotDesignSearchBarTintColor;
|
|
|
|
|
|
|
|
// Use the primary bg color for the table view in plain style.
|
|
|
|
self.tableView.backgroundColor = kRiotPrimaryBgColor;
|
2017-08-14 11:09:11 +00:00
|
|
|
topview.backgroundColor = kRiotPrimaryBgColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
self.searchDisplayController.searchResultsTableView.backgroundColor = self.tableView.backgroundColor;
|
|
|
|
|
|
|
|
if (self.tableView.dataSource)
|
|
|
|
{
|
|
|
|
[self.tableView reloadData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle
|
|
|
|
{
|
|
|
|
return kRiotDesignStatusBarStyle;
|
2017-07-21 09:28:17 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 15:22:34 +00:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
// Screen tracking (via Google Analytics)
|
|
|
|
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
|
|
|
|
if (tracker)
|
|
|
|
{
|
|
|
|
[tracker set:kGAIScreenName value:@"CountryPicker"];
|
|
|
|
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 09:28:17 +00:00
|
|
|
- (void)destroy
|
|
|
|
{
|
|
|
|
[super destroy];
|
|
|
|
|
2017-08-14 11:09:11 +00:00
|
|
|
[topview removeFromSuperview];
|
|
|
|
topview = nil;
|
|
|
|
|
2017-07-21 09:28:17 +00:00
|
|
|
if (kRiotDesignValuesDidChangeThemeNotificationObserver)
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver];
|
|
|
|
kRiotDesignValuesDidChangeThemeNotificationObserver = nil;
|
|
|
|
}
|
2017-02-17 08:41:24 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 14:56:09 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
|
|
|
|
{
|
|
|
|
cell.textLabel.textColor = kRiotPrimaryTextColor;
|
|
|
|
cell.detailTextLabel.textColor = kRiotSecondaryTextColor;
|
|
|
|
cell.backgroundColor = kRiotPrimaryBgColor;
|
|
|
|
|
|
|
|
// Update the selected background view
|
|
|
|
if (kRiotSelectedBgColor)
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = [[UIView alloc] init];
|
|
|
|
cell.selectedBackgroundView.backgroundColor = kRiotSelectedBgColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tableView.style == UITableViewStylePlain)
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView.backgroundColor = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 08:41:24 +00:00
|
|
|
@end
|