Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Grechuhin <i.grechuhin@gmail.com>2017-01-27 15:39:48 +0300
committerSergey Yershov <syershov@maps.me>2017-01-27 15:58:31 +0300
commit5af5ab1abcde91acfd5ca1aaf4296122b355df73 (patch)
tree702b29b13024ff2aa818772225ef271cee127075
parent48e6542541eeb2676ef0df64a942e48909aba511 (diff)
[themes] [ios] Refactored theme settings.beta-594
-rw-r--r--iphone/Maps/Classes/MapsAppDelegate.h5
-rw-r--r--iphone/Maps/Classes/MapsAppDelegate.mm27
-rw-r--r--iphone/Maps/Core/Routing/MWMRouter.mm4
-rw-r--r--iphone/Maps/Core/Settings/MWMSettings.h6
-rw-r--r--iphone/Maps/Core/Settings/MWMSettings.mm38
-rw-r--r--iphone/Maps/Maps.xcodeproj/project.pbxproj16
-rw-r--r--iphone/Maps/UI/Appearance/Theme.swift7
-rw-r--r--iphone/Maps/UI/Settings/MWMNightModeController.mm53
-rw-r--r--iphone/Maps/UI/Settings/MWMSettingsViewController.mm12
9 files changed, 92 insertions, 76 deletions
diff --git a/iphone/Maps/Classes/MapsAppDelegate.h b/iphone/Maps/Classes/MapsAppDelegate.h
index 86a2ece033..f1e51196fe 100644
--- a/iphone/Maps/Classes/MapsAppDelegate.h
+++ b/iphone/Maps/Classes/MapsAppDelegate.h
@@ -47,10 +47,9 @@ typedef NS_ENUM(NSUInteger, MWMRoutingPlaneMode) {
- (void)enableDownloadIndicator;
- (void)showMap;
-- (void)startMapStyleChecker;
-- (void)stopMapStyleChecker;
++ (void)startMapStyleChecker;
++ (void)stopMapStyleChecker;
- (void)showAlertIfRequired;
-+ (void)setAutoNightModeOff:(BOOL)off;
+ (void)resetToDefaultMapStyle;
+ (void)changeMapStyleIfNedeed;
diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm
index c248858dcb..465405ff84 100644
--- a/iphone/Maps/Classes/MapsAppDelegate.mm
+++ b/iphone/Maps/Classes/MapsAppDelegate.mm
@@ -290,10 +290,10 @@ using namespace osm_auth_ios;
[self updateApplicationIconBadgeNumber];
}
-- (void)determineMapStyle
++ (void)determineMapStyle
{
auto & f = GetFramework();
- if ([MWMSettings autoNightModeEnabled])
+ if ([MWMSettings theme] == MWMThemeAuto)
{
f.SetMapStyle(MapStyleClear);
[UIColor setNightMode:NO];
@@ -304,26 +304,19 @@ using namespace osm_auth_ios;
}
}
-+ (void)setAutoNightModeOff:(BOOL)off
++ (void)startMapStyleChecker
{
- [MWMSettings setAutoNightModeEnabled:!off];
- if (!off)
- [MapsAppDelegate.theApp stopMapStyleChecker];
-}
-
-- (void)startMapStyleChecker
-{
- if (![MWMSettings autoNightModeEnabled])
+ if ([MWMSettings theme] != MWMThemeAuto)
return;
- self.mapStyleSwitchTimer =
+ MapsAppDelegate.theApp.mapStyleSwitchTimer =
[NSTimer scheduledTimerWithTimeInterval:(30 * 60)
- target:[MapsAppDelegate class]
+ target:self
selector:@selector(changeMapStyleIfNedeed)
userInfo:nil
repeats:YES];
}
-- (void)stopMapStyleChecker { [self.mapStyleSwitchTimer invalidate]; }
++ (void)stopMapStyleChecker { [MapsAppDelegate.theApp.mapStyleSwitchTimer invalidate]; }
+ (void)resetToDefaultMapStyle
{
MapsAppDelegate * app = MapsAppDelegate.theApp;
@@ -335,12 +328,12 @@ using namespace osm_auth_ios;
[UIColor setNightMode:NO];
[static_cast<id<MWMController>>(app.mapViewController.navigationController.topViewController)
mwm_refreshUI];
- [app stopMapStyleChecker];
+ [self stopMapStyleChecker];
}
+ (void)changeMapStyleIfNedeed
{
- if (![MWMSettings autoNightModeEnabled])
+ if ([MWMSettings theme] != MWMThemeAuto)
return;
auto & f = GetFramework();
CLLocation * lastLocation = [MWMLocationManager lastLocation];
@@ -400,7 +393,7 @@ using namespace osm_auth_ios;
[HttpThread setDownloadIndicatorProtocol:self];
InitLocalizedStrings();
- [self determineMapStyle];
+ [[self class] determineMapStyle];
GetFramework().EnterForeground();
diff --git a/iphone/Maps/Core/Routing/MWMRouter.mm b/iphone/Maps/Core/Routing/MWMRouter.mm
index da5419872d..86b8de883d 100644
--- a/iphone/Maps/Core/Routing/MWMRouter.mm
+++ b/iphone/Maps/Core/Routing/MWMRouter.mm
@@ -222,7 +222,7 @@ bool isMarkerPoint(MWMRoutePoint const & point) { return point.IsValid() && !poi
app.routingPlaneMode = MWMRoutingPlaneModeNone;
[MWMRouterSavedState store];
[MapsAppDelegate changeMapStyleIfNedeed];
- [app startMapStyleChecker];
+ [MapsAppDelegate startMapStyleChecker];
}
else
{
@@ -271,7 +271,7 @@ bool isMarkerPoint(MWMRoutePoint const & point) { return point.IsValid() && !poi
MapsAppDelegate * app = [MapsAppDelegate theApp];
app.routingPlaneMode = MWMRoutingPlaneModeNone;
[MWMRouterSavedState remove];
- if ([MWMSettings autoNightModeEnabled])
+ if ([MWMSettings theme] == MWMThemeAuto)
[MapsAppDelegate resetToDefaultMapStyle];
[app showAlertIfRequired];
}
diff --git a/iphone/Maps/Core/Settings/MWMSettings.h b/iphone/Maps/Core/Settings/MWMSettings.h
index 9f81d3ab22..dd55bb9007 100644
--- a/iphone/Maps/Core/Settings/MWMSettings.h
+++ b/iphone/Maps/Core/Settings/MWMSettings.h
@@ -1,3 +1,5 @@
+#import "SwiftBridge.h"
+
#include "platform/measurement_utils.hpp"
@interface MWMSettings : NSObject
@@ -23,8 +25,8 @@
+ (BOOL)statisticsEnabled;
+ (void)setStatisticsEnabled:(BOOL)statisticsEnabled;
-+ (BOOL)autoNightModeEnabled;
-+ (void)setAutoNightModeEnabled:(BOOL)autoNightModeEnabled;
++ (MWMTheme)theme;
++ (void)setTheme:(MWMTheme)theme;
+ (BOOL)routingDisclaimerApproved;
+ (void)setRoutingDisclaimerApproved;
diff --git a/iphone/Maps/Core/Settings/MWMSettings.mm b/iphone/Maps/Core/Settings/MWMSettings.mm
index 19b366ddd5..d2cc4cc980 100644
--- a/iphone/Maps/Core/Settings/MWMSettings.mm
+++ b/iphone/Maps/Core/Settings/MWMSettings.mm
@@ -1,5 +1,6 @@
#import "MWMSettings.h"
#import "MWMMapViewControlsManager.h"
+#import "MapsAppDelegate.h"
#import "3party/Alohalytics/src/alohalytics_objc.h"
@@ -118,16 +119,41 @@ NSString * const kSpotlightLocaleLanguageId = @"SpotlightLocaleLanguageId";
settings::Set(kStatisticsEnabledSettingsKey, static_cast<bool>(statisticsEnabled));
}
-+ (BOOL)autoNightModeEnabled
++ (MWMTheme)theme
{
- return ![[NSUserDefaults standardUserDefaults] boolForKey:kUDAutoNightModeOff];
+ if (![[NSUserDefaults standardUserDefaults] boolForKey:kUDAutoNightModeOff])
+ return MWMThemeAuto;
+ if (GetFramework().GetMapStyle() == MapStyleDark)
+ return MWMThemeNight;
+ return MWMThemeDay;
}
-+ (void)setAutoNightModeEnabled:(BOOL)autoNightModeEnabled
++ (void)setTheme:(MWMTheme)theme
{
- NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
- [ud setBool:!autoNightModeEnabled forKey:kUDAutoNightModeOff];
- [ud synchronize];
+ if ([self theme] == theme)
+ return;
+ auto ud = [NSUserDefaults standardUserDefaults];
+ auto & f = GetFramework();
+ switch (theme)
+ {
+ case MWMThemeDay:
+ [ud setBool:YES forKey:kUDAutoNightModeOff];
+ f.SetMapStyle(MapStyleClear);
+ [UIColor setNightMode:NO];
+ break;
+ case MWMThemeNight:
+ [ud setBool:YES forKey:kUDAutoNightModeOff];
+ f.SetMapStyle(MapStyleDark);
+ [UIColor setNightMode:YES];
+ break;
+ case MWMThemeAuto:
+ [ud setBool:NO forKey:kUDAutoNightModeOff];
+ f.SetMapStyle(MapStyleClear);
+ [UIColor setNightMode:NO];
+ [MapsAppDelegate stopMapStyleChecker];
+ [MapsAppDelegate changeMapStyleIfNedeed];
+ break;
+ }
}
+ (BOOL)routingDisclaimerApproved
diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj
index dfd225dde6..65c90a403f 100644
--- a/iphone/Maps/Maps.xcodeproj/project.pbxproj
+++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj
@@ -193,6 +193,9 @@
34570A3B1B13222600E6D4FD /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 34570A3A1B13222600E6D4FD /* libz.dylib */; settings = {ATTRIBUTES = (Required, ); }; };
34570A3D1B13223000E6D4FD /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 34570A3C1B13223000E6D4FD /* libsqlite3.dylib */; settings = {ATTRIBUTES = (Required, ); }; };
34570A3F1B13225500E6D4FD /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34570A3E1B13225500E6D4FD /* Accounts.framework */; settings = {ATTRIBUTES = (Required, ); }; };
+ 34574A621E3B5B620061E839 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34574A611E3B5B620061E839 /* Theme.swift */; };
+ 34574A631E3B5B620061E839 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34574A611E3B5B620061E839 /* Theme.swift */; };
+ 34574A641E3B5B620061E839 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34574A611E3B5B620061E839 /* Theme.swift */; };
3462258E1DDC5DBA001E8752 /* MWMSearchNoResultsAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3462258D1DDC5DBA001E8752 /* MWMSearchNoResultsAlert.mm */; };
3462258F1DDC5DBA001E8752 /* MWMSearchNoResultsAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3462258D1DDC5DBA001E8752 /* MWMSearchNoResultsAlert.mm */; };
346225911DDC5FBA001E8752 /* MWMSearchNoResultsAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 346225901DDC5FBA001E8752 /* MWMSearchNoResultsAlert.xib */; };
@@ -1509,6 +1512,7 @@
34570A3A1B13222600E6D4FD /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
34570A3C1B13223000E6D4FD /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
34570A3E1B13225500E6D4FD /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; };
+ 34574A611E3B5B620061E839 /* Theme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
3462258C1DDC5DB9001E8752 /* MWMSearchNoResultsAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMSearchNoResultsAlert.h; sourceTree = "<group>"; };
3462258D1DDC5DBA001E8752 /* MWMSearchNoResultsAlert.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMSearchNoResultsAlert.mm; sourceTree = "<group>"; };
346225901DDC5FBA001E8752 /* MWMSearchNoResultsAlert.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMSearchNoResultsAlert.xib; sourceTree = "<group>"; };
@@ -2705,6 +2709,14 @@
path = Categories;
sourceTree = "<group>";
};
+ 34574A601E3B5B2A0061E839 /* Appearance */ = {
+ isa = PBXGroup;
+ children = (
+ 34574A611E3B5B620061E839 /* Theme.swift */,
+ );
+ path = Appearance;
+ sourceTree = "<group>";
+ };
345C34661CE9D32500BB2224 /* SideButtons */ = {
isa = PBXGroup;
children = (
@@ -3278,6 +3290,7 @@
F6E2FBFB1E097B9F0083EBEC /* UI */ = {
isa = PBXGroup;
children = (
+ 34574A601E3B5B2A0061E839 /* Appearance */,
349D1AC21E2E325B004A2006 /* BottomMenu */,
F6E2FBFC1E097B9F0083EBEC /* Downloader */,
F6E2FC291E097B9F0083EBEC /* EditBookmark */,
@@ -4833,6 +4846,7 @@
F6E2FEC31E097BA00083EBEC /* MWMSearchFilterPresentationController.mm in Sources */,
340475731E081A4600C92850 /* MWMStorage.mm in Sources */,
F6E2FD851E097BA00083EBEC /* MWMBaseMapDownloaderViewController.mm in Sources */,
+ 34574A621E3B5B620061E839 /* Theme.swift in Sources */,
34ABA6241C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */,
34943BBA1E2626B200B14F84 /* WelcomePageController.swift in Sources */,
F6E2FEE11E097BA00083EBEC /* MWMSearchManager.mm in Sources */,
@@ -5088,6 +5102,7 @@
F6E2FEC41E097BA00083EBEC /* MWMSearchFilterPresentationController.mm in Sources */,
34ABA6251C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */,
F6E2FD861E097BA00083EBEC /* MWMBaseMapDownloaderViewController.mm in Sources */,
+ 34574A631E3B5B620061E839 /* Theme.swift in Sources */,
F6E2FEE21E097BA00083EBEC /* MWMSearchManager.mm in Sources */,
F6E2FE221E097BA00083EBEC /* MWMOpeningHoursEditorViewController.mm in Sources */,
34943BBB1E2626B200B14F84 /* WelcomePageController.swift in Sources */,
@@ -5343,6 +5358,7 @@
F6E2FEC51E097BA00083EBEC /* MWMSearchFilterPresentationController.mm in Sources */,
F6E2FD871E097BA00083EBEC /* MWMBaseMapDownloaderViewController.mm in Sources */,
F6E2FEE31E097BA00083EBEC /* MWMSearchManager.mm in Sources */,
+ 34574A641E3B5B620061E839 /* Theme.swift in Sources */,
34943BBC1E2626B200B14F84 /* WelcomePageController.swift in Sources */,
F6E2FE231E097BA00083EBEC /* MWMOpeningHoursEditorViewController.mm in Sources */,
34D3AFE31E376F7E004100F9 /* UITableView+Updates.swift in Sources */,
diff --git a/iphone/Maps/UI/Appearance/Theme.swift b/iphone/Maps/UI/Appearance/Theme.swift
new file mode 100644
index 0000000000..bb0e4bbc8c
--- /dev/null
+++ b/iphone/Maps/UI/Appearance/Theme.swift
@@ -0,0 +1,7 @@
+@objc(MWMTheme)
+enum Theme: Int {
+
+ case day
+ case night
+ case auto
+}
diff --git a/iphone/Maps/UI/Settings/MWMNightModeController.mm b/iphone/Maps/UI/Settings/MWMNightModeController.mm
index a8251509ac..149f0ff0e7 100644
--- a/iphone/Maps/UI/Settings/MWMNightModeController.mm
+++ b/iphone/Maps/UI/Settings/MWMNightModeController.mm
@@ -21,26 +21,15 @@
{
[super viewDidLoad];
self.title = L(@"pref_map_style_title");
- if ([MWMSettings autoNightModeEnabled])
+ SettingsTableViewSelectableCell * selectedCell = nil;
+ switch ([MWMSettings theme])
{
- self.autoSwitch.accessoryType = UITableViewCellAccessoryCheckmark;
- _selectedCell = self.autoSwitch;
- return;
- }
-
- switch (GetFramework().GetMapStyle())
- {
- case MapStyleDark:
- self.on.accessoryType = UITableViewCellAccessoryCheckmark;
- _selectedCell = self.on;
- break;
- case MapStyleClear:
- self.off.accessoryType = UITableViewCellAccessoryCheckmark;
- _selectedCell = self.off;
- break;
- case MapStyleMerged:
- case MapStyleCount: break;
+ case MWMThemeDay: selectedCell = self.off; break;
+ case MWMThemeNight: selectedCell = self.on; break;
+ case MWMThemeAuto: selectedCell = self.autoSwitch; break;
}
+ selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
+ self.selectedCell = selectedCell;
}
- (void)setSelectedCell:(SettingsTableViewSelectableCell *)cell
@@ -48,42 +37,26 @@
if ([_selectedCell isEqual:cell])
return;
+ BOOL const isNightMode = [UIColor isNightMode];
_selectedCell = cell;
- auto & f = GetFramework();
- auto const style = f.GetMapStyle();
NSString * statValue = nil;
if ([cell isEqual:self.on])
{
- [MapsAppDelegate setAutoNightModeOff:YES];
- if (style == MapStyleDark)
- return;
- f.SetMapStyle(MapStyleDark);
- [UIColor setNightMode:YES];
- [self mwm_refreshUI];
+ [MWMSettings setTheme:MWMThemeNight];
statValue = kStatOn;
}
else if ([cell isEqual:self.off])
{
- [MapsAppDelegate setAutoNightModeOff:YES];
- if (style == MapStyleClear)
- return;
- f.SetMapStyle(MapStyleClear);
- [UIColor setNightMode:NO];
- [self mwm_refreshUI];
+ [MWMSettings setTheme:MWMThemeDay];
statValue = kStatOff;
}
else if ([cell isEqual:self.autoSwitch])
{
- [MapsAppDelegate setAutoNightModeOff:NO];
- [MapsAppDelegate changeMapStyleIfNedeed];
- if (style == MapStyleClear)
- return;
- [UIColor setNightMode:NO];
- f.SetMapStyle(MapStyleClear);
- [self mwm_refreshUI];
+ [MWMSettings setTheme:MWMThemeAuto];
statValue = kStatValue;
}
-
+ if (isNightMode != [UIColor isNightMode])
+ [self mwm_refreshUI];
[Statistics logEvent:kStatNightMode withParameters:@{kStatValue : statValue}];
}
diff --git a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm
index 9f0b810dd9..5154d56e4f 100644
--- a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm
+++ b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm
@@ -141,12 +141,12 @@ extern NSString * const kAlohalyticsTapEventKey;
- (void)configNavigationSection
{
NSString * nightMode = nil;
- if ([MWMSettings autoNightModeEnabled])
- nightMode = L(@"pref_map_style_auto");
- else if (GetFramework().GetMapStyle() == MapStyleDark)
- nightMode = L(@"pref_map_style_night");
- else
- nightMode = L(@"pref_map_style_default");
+ switch ([MWMSettings theme])
+ {
+ case MWMThemeDay: nightMode = L(@"pref_map_style_default"); break;
+ case MWMThemeNight: nightMode = L(@"pref_map_style_night"); break;
+ case MWMThemeAuto: nightMode = L(@"pref_map_style_auto"); break;
+ }
[self.nightModeCell configWithTitle:L(@"pref_map_style_title") info:nightMode];
bool _ = true, on = true;