[ios] feat: add the outdoor style button into the layers selection

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2023-12-01 15:42:01 +04:00 committed by Roman Tsisyk
parent 2d7030153b
commit 35736074f2
6 changed files with 139 additions and 15 deletions

View file

@ -30,14 +30,23 @@
auto &f = GetFramework();
auto const style = f.GetMapStyle();
auto const isOutdoor = ^BOOL(MapStyle style) {
switch (style) {
case MapStyleOutdoorsClear:
case MapStyleOutdoorsDark:
return YES;
default:
return NO;
}
}(style);
auto const newStyle = ^MapStyle(MWMTheme theme) {
switch (theme) {
case MWMThemeDay:
return MapStyleClear;
return isOutdoor ? MapStyleOutdoorsClear : MapStyleClear;
case MWMThemeVehicleDay:
return MapStyleVehicleClear;
case MWMThemeNight:
return MapStyleDark;
return isOutdoor ? MapStyleOutdoorsDark : MapStyleDark;
case MWMThemeVehicleNight:
return MapStyleVehicleDark;
case MWMThemeAuto:

View file

@ -24,6 +24,11 @@ typedef NS_ENUM(NSUInteger, MWMMapOverlayIsolinesState) {
MWMMapOverlayIsolinesStateNoData,
} NS_SWIFT_NAME(MapOverlayTransitState);
typedef NS_ENUM(NSUInteger, MWMMapOverlayOutdoorState) {
MWMMapOverlayOutdoorStateDisabled,
MWMMapOverlayOutdoorStateEnabled,
} NS_SWIFT_NAME(MapOverlayOutdoorState);
NS_SWIFT_NAME(MapOverlayManagerObserver)
@protocol MWMMapOverlayManagerObserver <NSObject>
@ -31,6 +36,7 @@ NS_SWIFT_NAME(MapOverlayManagerObserver)
- (void)onTrafficStateUpdated;
- (void)onTransitStateUpdated;
- (void)onIsoLinesStateUpdated;
- (void)onOutdoorStateUpdated;
@end
@ -43,14 +49,17 @@ NS_SWIFT_NAME(MapOverlayManager)
+ (MWMMapOverlayTrafficState)trafficState;
+ (MWMMapOverlayTransitState)transitState;
+ (MWMMapOverlayIsolinesState)isolinesState;
+ (MWMMapOverlayOutdoorState)outdoorState;
+ (BOOL)trafficEnabled;
+ (BOOL)transitEnabled;
+ (BOOL)isoLinesEnabled;
+ (BOOL)isolinesVisible;
+ (BOOL)outdoorEnabled;
+ (void)setTrafficEnabled:(BOOL)enable;
+ (void)setTransitEnabled:(BOOL)enable;
+ (void)setIsoLinesEnabled:(BOOL)enable;
+ (void)setOutdoorEnabled:(BOOL)enable;
@end

View file

@ -3,6 +3,7 @@
#include "Framework.h"
static NSString *kGuidesWasShown = @"guidesWasShown";
static NSString *didChangeOutdoorMapStyle = @"didChangeOutdoorMapStyle";
@interface MWMMapOverlayManager ()
@ -48,6 +49,13 @@ static NSString *kGuidesWasShown = @"guidesWasShown";
}
}
});
[NSNotificationCenter.defaultCenter addObserverForName:didChangeOutdoorMapStyle object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) {
for (id<MWMMapOverlayManagerObserver> observer in self.observers) {
if ([observer respondsToSelector:@selector(onOutdoorStateUpdated)]) {
[observer onOutdoorStateUpdated];
}
}
}];
}
return self;
}
@ -109,6 +117,16 @@ static NSString *kGuidesWasShown = @"guidesWasShown";
}
}
+ (MWMMapOverlayOutdoorState)outdoorState {
switch (GetFramework().GetMapStyle()) {
case MapStyleOutdoorsClear:
case MapStyleOutdoorsDark:
return MWMMapOverlayOutdoorStateEnabled;
default:
return MWMMapOverlayOutdoorStateDisabled;
}
}
+ (BOOL)trafficEnabled {
return self.trafficState != MWMMapOverlayTrafficStateDisabled;
}
@ -125,6 +143,10 @@ static NSString *kGuidesWasShown = @"guidesWasShown";
return GetFramework().GetIsolinesManager().IsVisible();
}
+ (BOOL)outdoorEnabled {
return self.outdoorState != MWMMapOverlayOutdoorStateDisabled;
}
+ (void)setTrafficEnabled:(BOOL)enable {
if (enable) {
[self setTransitEnabled:false];
@ -140,6 +162,7 @@ static NSString *kGuidesWasShown = @"guidesWasShown";
if (enable) {
[self setTrafficEnabled:!enable];
[self setIsoLinesEnabled:false];
[self setOutdoorEnabled:false];
}
auto &f = GetFramework();
@ -158,4 +181,30 @@ static NSString *kGuidesWasShown = @"guidesWasShown";
f.SaveIsolinesEnabled(enable);
}
+ (void)setOutdoorEnabled:(BOOL)enable {
if (enable) {
[self setTransitEnabled:false];
[self setTrafficEnabled:false];
}
auto &f = GetFramework();
switch (f.GetMapStyle()) {
case MapStyleClear:
case MapStyleVehicleClear:
case MapStyleOutdoorsClear:
f.SetMapStyle(enable ? MapStyleOutdoorsClear : MapStyleClear);
break;
case MapStyleDark:
case MapStyleVehicleDark:
case MapStyleOutdoorsDark:
f.SetMapStyle(enable ? MapStyleOutdoorsDark : MapStyleDark);
break;
default:
break;
}
// TODO: - Observing for the selected/deselected state of the Outdoor style should be implemented not by NSNotificationCenter but the same way as for IsoLines with 'GetFramework().GetIsolinesManager().SetStateListener'.
[NSNotificationCenter.defaultCenter postNotificationName:didChangeOutdoorMapStyle object:nil];
}
@end

View file

@ -161,18 +161,25 @@ NSArray<UIImage *> *imagesWithName(NSString *name) {
} else if ([MWMMapOverlayManager isoLinesEnabled]) {
btn.imageName = @"btn_isoMap_on";
[self handleIsolinesState:[MWMMapOverlayManager isolinesState]];
} else if ([MWMMapOverlayManager outdoorEnabled]) {
btn.imageName = @"btn_isoMap_on";
} else {
btn.imageName = @"btn_layers";
}
}
- (IBAction)buttonTouchUpInside {
if ([MWMMapOverlayManager trafficEnabled]) {
BOOL needsToDisableMapLayer =
[MWMMapOverlayManager trafficEnabled] ||
[MWMMapOverlayManager transitEnabled] ||
[MWMMapOverlayManager isoLinesEnabled] ||
[MWMMapOverlayManager outdoorEnabled];
if (needsToDisableMapLayer) {
[MWMMapOverlayManager setTrafficEnabled:NO];
} else if ([MWMMapOverlayManager transitEnabled]) {
[MWMMapOverlayManager setTransitEnabled:NO];
} else if ([MWMMapOverlayManager isoLinesEnabled]) {
[MWMMapOverlayManager setIsoLinesEnabled:NO];
[MWMMapOverlayManager setOutdoorEnabled:NO];
} else {
MWMMapViewControlsManager.manager.menuState = MWMBottomMenuStateLayers;
}
@ -197,5 +204,8 @@ NSArray<UIImage *> *imagesWithName(NSString *name) {
- (void)onIsoLinesStateUpdated {
[self applyTheme];
}
- (void)onOutdoorStateUpdated {
[self applyTheme];
}
@end

View file

@ -16,7 +16,12 @@ class BottomMenuLayersCell: UITableViewCell {
updateIsoLinesButton()
}
}
@IBOutlet private var outdoorButton: BottomMenuLayerButton! {
didSet {
updateOutdoorButton()
}
}
var onClose: (()->())?
override func awakeFromNib() {
@ -48,6 +53,11 @@ class BottomMenuLayersCell: UITableViewCell {
let enabled = MapOverlayManager.isoLinesEnabled()
isoLinesButton.setStyleAndApply(enabled ? "MenuButtonEnabled" : "MenuButtonDisabled")
}
private func updateOutdoorButton() {
let enabled = MapOverlayManager.outdoorEnabled()
outdoorButton.setStyleAndApply(enabled ? "MenuButtonEnabled" : "MenuButtonDisabled")
}
@IBAction func onCloseButtonPressed(_ sender: Any) {
onClose?()
@ -67,6 +77,11 @@ class BottomMenuLayersCell: UITableViewCell {
let enable = !MapOverlayManager.isoLinesEnabled()
MapOverlayManager.setIsoLinesEnabled(enable)
}
@IBAction func onOutdoorButton(_ sender: Any) {
let enable = !MapOverlayManager.outdoorEnabled()
MapOverlayManager.setOutdoorEnabled(enable)
}
}
extension BottomMenuLayersCell: MapOverlayManagerObserver {
@ -81,4 +96,8 @@ extension BottomMenuLayersCell: MapOverlayManagerObserver {
func onIsoLinesStateUpdated() {
updateIsoLinesButton()
}
func onOutdoorStateUpdated() {
updateOutdoorButton()
}
}

View file

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="ipad9_7" orientation="landscape" layout="fullscreen" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="165" id="KGk-i7-Jjw" customClass="BottomMenuLayersCell" customModule="OMaps" customModuleProvider="target">
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="165" id="KGk-i7-Jjw" customClass="BottomMenuLayersCell" customModule="Organic_Maps" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="340" height="165"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" ambiguous="YES" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
@ -20,8 +20,8 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="W1i-v6-zbz">
<rect key="frame" x="0.0" y="0.0" width="340" height="50"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Map Layers" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Vuk-dn-n2c">
<rect key="frame" x="16" y="13" width="108" height="24"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Map Layers" textAlignment="natural" lineBreakMode="clip" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Vuk-dn-n2c">
<rect key="frame" x="16" y="13" width="543" height="24"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
@ -48,8 +48,10 @@
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="00h-1i-skR"/>
<constraint firstItem="2xW-dK-D9y" firstAttribute="leading" secondItem="Vuk-dn-n2c" secondAttribute="trailing" constant="8" id="4PG-Fm-yqS"/>
<constraint firstItem="Vuk-dn-n2c" firstAttribute="centerY" secondItem="W1i-v6-zbz" secondAttribute="centerY" id="4du-pr-7hv"/>
<constraint firstAttribute="height" constant="45" id="Ez1-s5-1EO"/>
<constraint firstItem="Vuk-dn-n2c" firstAttribute="centerX" secondItem="W1i-v6-zbz" secondAttribute="centerX" id="XEG-CK-41Y"/>
<constraint firstItem="Vuk-dn-n2c" firstAttribute="leading" secondItem="W1i-v6-zbz" secondAttribute="leading" constant="16" id="kSJ-Wa-nYA"/>
<constraint firstAttribute="trailing" secondItem="2xW-dK-D9y" secondAttribute="trailing" constant="16" id="kae-50-2nG"/>
<constraint firstItem="2xW-dK-D9y" firstAttribute="centerY" secondItem="Vuk-dn-n2c" secondAttribute="centerY" id="wCu-O0-cz8"/>
@ -58,6 +60,7 @@
<mask key="constraints">
<exclude reference="00h-1i-skR"/>
<exclude reference="Ez1-s5-1EO"/>
<exclude reference="XEG-CK-41Y"/>
</mask>
</variation>
<variation key="heightClass=compact">
@ -70,12 +73,36 @@
<include reference="00h-1i-skR"/>
</mask>
</variation>
<variation key="heightClass=regular-widthClass=regular">
<mask key="constraints">
<include reference="XEG-CK-41Y"/>
<exclude reference="kSJ-Wa-nYA"/>
<exclude reference="4PG-Fm-yqS"/>
</mask>
</variation>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="sRd-zd-xSl">
<rect key="frame" x="16" y="58" width="308" height="64"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="edA-Mo-3Vx" customClass="BottomMenuLayerButton" customModule="OMaps" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="154" height="64"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="g13-pK-Eig" userLabel="Outdoor Button" customClass="BottomMenuLayerButton" customModule="Organic_Maps" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="102.5" height="64"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="image" keyPath="image" value="btn_menu_isomaps"/>
<userDefinedRuntimeAttribute type="number" keyPath="spacing">
<real key="value" value="10"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="numberOfLines">
<integer key="value" value="2"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="title" value="Outdoor"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="onOutdoorButton:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="UQ2-jj-fPc"/>
</connections>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="edA-Mo-3Vx" customClass="BottomMenuLayerButton" customModule="Organic_Maps" customModuleProvider="target">
<rect key="frame" x="102.5" y="0.0" width="103" height="64"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="image" keyPath="image" value="btn_menu_isomaps"/>
@ -91,8 +118,8 @@
<action selector="onIsoLinesButton:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="3LS-C2-2Mc"/>
</connections>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4US-fZ-cyg" customClass="BottomMenuLayerButton" customModule="OMaps" customModuleProvider="target">
<rect key="frame" x="154" y="0.0" width="154" height="64"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4US-fZ-cyg" customClass="BottomMenuLayerButton" customModule="Organic_Maps" customModuleProvider="target">
<rect key="frame" x="205.5" y="0.0" width="102.5" height="64"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="image" keyPath="image" value="btn_menu_subway"/>
@ -163,6 +190,7 @@
</constraints>
<connections>
<outlet property="isoLinesButton" destination="edA-Mo-3Vx" id="qoC-8w-EqY"/>
<outlet property="outdoorButton" destination="g13-pK-Eig" id="ib1-aw-Qv9"/>
<outlet property="subwayButton" destination="4US-fZ-cyg" id="eQB-HR-Wgl"/>
</connections>
<point key="canvasLocation" x="137.6953125" y="201.953125"/>