[ios] Added download on search.

This commit is contained in:
Ilya Grechuhin 2015-07-13 15:55:49 +03:00 committed by Alex Zolotarev
parent c063b8cf6b
commit 30f952d599
26 changed files with 1116 additions and 17 deletions

View file

@ -58,3 +58,14 @@ static inline BOOL isIOSVersionLessThan(NSUInteger version)
{
return isIOSVersionLessThan([NSString stringWithFormat:@"%@", @(version)]);
}
static inline NSString * formattedSize(uint64_t size)
{
uint64_t const mb = 1024 * 1024;
NSString * sizeString;
if (size > mb)
sizeString = [NSString stringWithFormat:@"%llu %@", (size + 512 * 1024) / mb, NSLocalizedString(@"mb", nil)];
else
sizeString = [NSString stringWithFormat:@"%llu %@", (size + 1023) / 1024, NSLocalizedString(@"kb", nil)];
return [sizeString uppercaseString];
}

View file

@ -0,0 +1,38 @@
//
// MWMDownloadMapRequest.h
// Maps
//
// Created by Ilya Grechuhin on 10.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MWMCircularProgress.h"
typedef void (^MWMDownloadMapRequestDownloadCallback)(BOOL);
typedef void (^MWMDownloadMapRequestSelectCallback)();
NS_ENUM(NSUInteger, MWMDownloadMapRequestState)
{
MWMDownloadMapRequestHidden,
MWMDownloadMapRequestLocation,
MWMDownloadMapRequestUnknownLocation,
MWMDownloadMapRequestProgress
};
@interface MWMDownloadMapRequest : NSObject
@property (nonatomic, readonly) enum MWMDownloadMapRequestState state;
- (nonnull instancetype)init __attribute__((unavailable("init is not available")));
- (nonnull instancetype)initWithParentView:(nonnull UIView *)parentView delegate:(nonnull id <MWMCircularProgressDelegate>)delegate;
- (void)showForLocationWithName:(nonnull NSString *)countryName mapSize:(nonnull NSString *)mapSize mapAndRouteSize:(nonnull NSString *)mapAndRouteSize download:(nonnull MWMDownloadMapRequestDownloadCallback)download select:(nonnull MWMDownloadMapRequestSelectCallback)select;
- (void)showForUnknownLocation:(nonnull MWMDownloadMapRequestSelectCallback)select;
- (void)startDownload;
- (void)stopDownload;
- (void)downloadProgress:(CGFloat)progress countryName:(nonnull NSString *)countryName;
- (void)setDownloadFailed;
@end

View file

@ -0,0 +1,163 @@
//
// MWMDownloadMapRequest.m
// Maps
//
// Created by Ilya Grechuhin on 10.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import "Macros.h"
#import "MWMDownloadMapRequest.h"
#import "MWMDownloadMapRequestView.h"
#import "MWMCircularProgress.h"
#import "UIButton+RuntimeAttributes.h"
#import "UIColor+MapsMeColor.h"
@interface MWMDownloadMapRequest ()
@property (nonatomic) IBOutlet MWMDownloadMapRequestView * rootView;
@property (nonatomic) IBOutlet UILabel * mapTitleLabel;
@property (nonatomic) IBOutlet UIButton * downloadMapButton;
@property (nonatomic) IBOutlet UIButton * downloadRoutesButton;
@property (nonatomic) IBOutlet UILabel * undefinedLocationLabel;
@property (nonatomic) IBOutlet UIButton * selectAnotherMapButton;
@property (nonatomic) IBOutlet UIView * progressViewWrapper;
@property (nonatomic) MWMCircularProgress * progressView;
@property (copy, nonatomic) MWMDownloadMapRequestDownloadCallback downloadBlock;
@property (copy, nonatomic) MWMDownloadMapRequestSelectCallback selectBlock;
@property (copy, nonatomic) NSString * mapSize;
@property (copy, nonatomic) NSString * mapAndRouteSize;
@property (nonatomic) enum MWMDownloadMapRequestState state;
@property (nonnull, weak, nonatomic) id <MWMCircularProgressDelegate> delegate;
@end
@implementation MWMDownloadMapRequest
- (nonnull instancetype)initWithParentView:(nonnull UIView *)parentView delegate:(nonnull id <MWMCircularProgressDelegate>)delegate
{
self = [super init];
if (self)
{
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:self options:nil];
[parentView addSubview:self.rootView];
self.rootView.hidden = YES;
self.downloadRoutesButton.selected = YES;
self.delegate = delegate;
}
return self;
}
- (void)dealloc
{
[self.rootView removeFromSuperview];
}
- (void)showForLocationWithName:(nonnull NSString *)countryName mapSize:(nonnull NSString *)mapSize mapAndRouteSize:(nonnull NSString *)mapAndRouteSize download:(nonnull MWMDownloadMapRequestDownloadCallback)download select:(nonnull MWMDownloadMapRequestSelectCallback)select
{
[self stopDownload];
self.mapTitleLabel.text = countryName;
[self.downloadMapButton setTitle:[NSString stringWithFormat:@"%@ (%@)", L(@"downloader_download_map"), mapAndRouteSize] forState:UIControlStateNormal];
[self.downloadRoutesButton setTitle:L(@"search_vehicle_routes") forState:UIControlStateNormal];
[self.selectAnotherMapButton setTitle:L(@"search_select_other_map") forState:UIControlStateNormal];
[self.selectAnotherMapButton setTitleColor:[UIColor primary] forState:UIControlStateNormal];
[self.selectAnotherMapButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[self.selectAnotherMapButton setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.selectAnotherMapButton setBackgroundColor:[UIColor primary] forState:UIControlStateHighlighted];
self.mapSize = mapSize;
self.mapAndRouteSize = mapAndRouteSize;
self.downloadBlock = download;
self.selectBlock = select;
}
- (void)showForUnknownLocation:(nonnull MWMDownloadMapRequestSelectCallback)select
{
self.rootView.hidden = NO;
self.progressViewWrapper.hidden = YES;
self.mapTitleLabel.hidden = YES;
self.downloadMapButton.hidden = YES;
self.downloadRoutesButton.hidden = YES;
self.undefinedLocationLabel.hidden = NO;
[self.selectAnotherMapButton setTitle:L(@"search_select_map") forState:UIControlStateNormal];
[self.selectAnotherMapButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.selectAnotherMapButton setBackgroundColor:[UIColor primary] forState:UIControlStateNormal];
[self.selectAnotherMapButton setBackgroundColor:[UIColor primaryDark] forState:UIControlStateHighlighted];
self.selectBlock = select;
self.state = MWMDownloadMapRequestUnknownLocation;
}
#pragma mark - Process control
- (void)startDownload
{
self.progressView = [[MWMCircularProgress alloc] initWithParentView:self.progressViewWrapper delegate:self.delegate];
self.rootView.hidden = NO;
self.progressViewWrapper.hidden = NO;
self.mapTitleLabel.hidden = NO;
self.downloadMapButton.hidden = YES;
self.downloadRoutesButton.hidden = YES;
self.undefinedLocationLabel.hidden = YES;
self.selectAnotherMapButton.hidden = YES;
self.state = MWMDownloadMapRequestProgress;
}
- (void)stopDownload
{
self.rootView.hidden = NO;
self.progressViewWrapper.hidden = YES;
self.mapTitleLabel.hidden = NO;
self.downloadMapButton.hidden = NO;
self.downloadRoutesButton.hidden = NO;
self.undefinedLocationLabel.hidden = YES;
self.selectAnotherMapButton.hidden = NO;
self.state = MWMDownloadMapRequestLocation;
}
- (void)downloadProgress:(CGFloat)progress countryName:(nonnull NSString *)countryName
{
self.progressView.failed = NO;
self.progressView.progress = progress;
self.mapTitleLabel.text = countryName;
}
- (void)setDownloadFailed
{
self.progressView.failed = YES;
}
#pragma mark - Actions
- (IBAction)downloadMapTouchUpInside:(nonnull UIButton *)sender
{
self.downloadBlock(self.downloadRoutesButton.selected);
}
- (IBAction)downloadRoutesTouchUpInside:(nonnull UIButton *)sender
{
sender.selected = !sender.selected;
[self.downloadMapButton setTitle:[NSString stringWithFormat:@"%@ (%@)", L(@"downloader_download_map"), sender.selected ? self.mapAndRouteSize : self.mapSize] forState:UIControlStateNormal];
}
- (IBAction)selectMapTouchUpInside:(nonnull UIButton *)sender
{
self.selectBlock();
}
#pragma mark - Properties
- (void)setState:(enum MWMDownloadMapRequestState)state
{
_state = state;
[self.rootView layoutSubviews];
}
@end

View file

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MWMDownloadMapRequest">
<connections>
<outlet property="downloadMapButton" destination="ANW-J1-K9x" id="oE3-7R-Pyf"/>
<outlet property="downloadRoutesButton" destination="Ns9-3f-AnX" id="lxd-NO-JwR"/>
<outlet property="mapTitleLabel" destination="ldF-A5-Jo3" id="r20-cg-aHn"/>
<outlet property="progressViewWrapper" destination="Axo-F2-0Xb" id="8PW-T9-Wav"/>
<outlet property="rootView" destination="wdy-tr-47e" id="vKe-K9-3Io"/>
<outlet property="selectAnotherMapButton" destination="q7R-7R-aMD" id="StJ-Aq-Jo7"/>
<outlet property="undefinedLocationLabel" destination="0HQ-hc-mvu" id="H7G-lT-OqQ"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="wdy-tr-47e" customClass="MWMDownloadMapRequestView">
<rect key="frame" x="0.0" y="0.0" width="320" height="251"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Moscow &amp; Central" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="288" translatesAutoresizingMaskIntoConstraints="NO" id="ldF-A5-Jo3">
<rect key="frame" x="16" y="10" width="288" height="21"/>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="18"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="regular18"/>
<userDefinedRuntimeAttribute type="string" keyPath="colorName" value="blackPrimaryText"/>
</userDefinedRuntimeAttributes>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Axo-F2-0Xb" userLabel="ProgressViewWrapper">
<rect key="frame" x="144" y="55" width="32" height="32"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="32" id="CcH-aB-wPy"/>
<constraint firstAttribute="height" constant="32" id="j9b-F2-Mcs"/>
</constraints>
</view>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ANW-J1-K9x">
<rect key="frame" x="40" y="51" width="240" height="44"/>
<color key="backgroundColor" red="0.12156862745098039" green="0.59999999999999998" blue="0.32156862745098036" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="Nrd-CA-zhn"/>
<constraint firstAttribute="height" constant="44" id="tID-44-te5"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="16"/>
<state key="normal" title="Скачать карту">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="textColorName" value="whiteColor"/>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="primary"/>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="regular16"/>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="8"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundHighlightedColorName" value="primaryDark"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="downloadMapTouchUpInside:" destination="-1" eventType="touchUpInside" id="tMi-t3-4NI"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" selected="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ns9-3f-AnX">
<rect key="frame" x="40" y="115" width="240" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="24" id="FMy-No-TLl"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="14"/>
<inset key="titleEdgeInsets" minX="8" minY="0.0" maxX="0.0" maxY="0.0"/>
<state key="normal" title="Автомобильные маршруты" image="radioBtnOff">
<color key="titleColor" red="0.0" green="0.0" blue="0.0" alpha="0.54000000000000004" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="selected" image="radioBtnOn"/>
<connections>
<action selector="downloadRoutesTouchUpInside:" destination="-1" eventType="touchUpInside" id="0Zh-cL-WYE"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Ваше местоположение не определено" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="288" translatesAutoresizingMaskIntoConstraints="NO" id="0HQ-hc-mvu">
<rect key="frame" x="16" y="145" width="288" height="17"/>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="0.54000000000000004" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="regular14"/>
<userDefinedRuntimeAttribute type="string" keyPath="colorName" value="blackSecondaryText"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="unknown_current_position"/>
</userDefinedRuntimeAttributes>
</label>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="q7R-7R-aMD">
<rect key="frame" x="40" y="183" width="240" height="44"/>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="16"/>
<state key="normal" title="Выбрать другую карту">
<color key="titleColor" red="0.1215686275" green="0.59999999999999998" blue="0.32156862749999998" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="textColorName" value="primary"/>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="regular16"/>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="8"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="layer.borderColorName" value="primary"/>
<userDefinedRuntimeAttribute type="number" keyPath="layer.borderWidth">
<integer key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="textColorHighlightedName" value="whiteColor"/>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="whiteColor"/>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundHighlightedColorName" value="primary"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="selectMapTouchUpInside:" destination="-1" eventType="touchUpInside" id="RXu-BP-tNk"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="ANW-J1-K9x" firstAttribute="top" secondItem="ldF-A5-Jo3" secondAttribute="bottom" constant="20" id="8ct-NO-wGh"/>
<constraint firstAttribute="trailing" secondItem="ldF-A5-Jo3" secondAttribute="trailing" constant="16" id="KsU-Ev-FCI"/>
<constraint firstItem="q7R-7R-aMD" firstAttribute="top" secondItem="Ns9-3f-AnX" secondAttribute="bottom" constant="44" id="SM5-r0-AS2"/>
<constraint firstItem="Axo-F2-0Xb" firstAttribute="top" secondItem="ldF-A5-Jo3" secondAttribute="bottom" constant="24" id="SnX-Nf-mt9"/>
<constraint firstAttribute="bottom" secondItem="q7R-7R-aMD" secondAttribute="bottom" constant="24" id="d8R-jg-AMN"/>
<constraint firstItem="ANW-J1-K9x" firstAttribute="height" secondItem="q7R-7R-aMD" secondAttribute="height" id="eXG-Oy-6Vx"/>
<constraint firstItem="Ns9-3f-AnX" firstAttribute="centerX" secondItem="ANW-J1-K9x" secondAttribute="centerX" id="fir-kl-M8E"/>
<constraint firstItem="ANW-J1-K9x" firstAttribute="width" secondItem="q7R-7R-aMD" secondAttribute="width" id="gY4-nk-yaY"/>
<constraint firstItem="ANW-J1-K9x" firstAttribute="centerX" secondItem="q7R-7R-aMD" secondAttribute="centerX" id="gfS-3M-5zg"/>
<constraint firstItem="Ns9-3f-AnX" firstAttribute="width" secondItem="ANW-J1-K9x" secondAttribute="width" id="hQI-Kw-RlX"/>
<constraint firstItem="ldF-A5-Jo3" firstAttribute="centerX" secondItem="ANW-J1-K9x" secondAttribute="centerX" id="lWc-tH-1Oi"/>
<constraint firstItem="ldF-A5-Jo3" firstAttribute="leading" secondItem="wdy-tr-47e" secondAttribute="leading" constant="16" id="mFv-Dr-2pb"/>
<constraint firstAttribute="trailing" secondItem="0HQ-hc-mvu" secondAttribute="trailing" constant="16" id="o8v-fv-loA"/>
<constraint firstItem="0HQ-hc-mvu" firstAttribute="leading" secondItem="wdy-tr-47e" secondAttribute="leading" constant="16" id="tED-fC-gYF"/>
<constraint firstItem="q7R-7R-aMD" firstAttribute="top" secondItem="0HQ-hc-mvu" secondAttribute="bottom" constant="22" id="u95-8m-bpq"/>
<constraint firstItem="Ns9-3f-AnX" firstAttribute="top" secondItem="ANW-J1-K9x" secondAttribute="bottom" constant="20" id="uJa-y4-6sW"/>
<constraint firstItem="ldF-A5-Jo3" firstAttribute="centerX" secondItem="Axo-F2-0Xb" secondAttribute="centerX" id="w4N-6B-zSQ"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="bottomSpacing" destination="d8R-jg-AMN" id="NKs-4Y-gl7"/>
<outlet property="mapTitleLabel" destination="ldF-A5-Jo3" id="SCT-Zb-Xxq"/>
<outlet property="owner" destination="-1" id="uiR-Xb-rRc"/>
<outlet property="unknownPositionLabelBottomOffset" destination="u95-8m-bpq" id="qXZ-7m-zS1"/>
<outlet property="verticalFreeSpace" destination="SM5-r0-AS2" id="aXL-lW-az3"/>
</connections>
<point key="canvasLocation" x="71" y="376"/>
</view>
</objects>
<resources>
<image name="radioBtnOff" width="22" height="22"/>
<image name="radioBtnOn" width="22" height="22"/>
</resources>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>

View file

@ -0,0 +1,17 @@
//
// MWMDownloadMapRequestView.h
// Maps
//
// Created by Ilya Grechuhin on 10.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UIKitCategories.h"
@interface MWMDownloadMapRequestView : SolidTouchView
- (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("initWithFrame is not available")));
- (instancetype)init __attribute__((unavailable("init is not available")));
@end

View file

@ -0,0 +1,82 @@
//
// MWMDownloadMapRequestView.m
// Maps
//
// Created by Ilya Grechuhin on 10.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import "MWMDownloadMapRequest.h"
#import "MWMDownloadMapRequestView.h"
#import "UIKitCategories.h"
@interface MWMDownloadMapRequestView ()
@property (weak, nonatomic) IBOutlet UILabel * mapTitleLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * verticalFreeSpace;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * bottomSpacing;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * unknownPositionLabelBottomOffset;
@property (weak, nonatomic) IBOutlet MWMDownloadMapRequest * owner;
@end
@implementation MWMDownloadMapRequestView
- (void)layoutSubviews
{
[super layoutSubviews];
UIView * superview = self.superview;
BOOL const isLandscape = superview.height > superview.width;
if (IPAD || isLandscape)
{
self.verticalFreeSpace.constant = 44.0;
self.bottomSpacing.constant = 24.0;
self.unknownPositionLabelBottomOffset.constant = 22.0;
}
else
{
self.verticalFreeSpace.constant = 20.0;
self.bottomSpacing.constant = 8.0;
self.unknownPositionLabelBottomOffset.constant = 18.0;
CGFloat const iPhone6LandscapeHeight = 375.0;
if (self.width < iPhone6LandscapeHeight)
{
self.mapTitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
self.mapTitleLabel.numberOfLines = 1;
}
else
{
self.mapTitleLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.mapTitleLabel.numberOfLines = 0;
}
}
self.width = superview.width;
self.minX = 0.0;
if (self.minY > 0.0)
{
[UIView animateWithDuration:0.3 animations:^
{
[self move];
}];
}
else
{
[self move];
}
}
- (void)move
{
if (self.owner.state == MWMDownloadMapRequestProgress)
{
UIView * superview = self.superview;
BOOL const isLandscape = superview.height > superview.width;
self.minY = (IPAD || isLandscape) ? 0.3 * self.superview.height : 0.0;
}
else
{
self.maxY = self.superview.height;
}
}
@end

View file

@ -7,7 +7,6 @@
//
#import "BookmarksRootVC.h"
#import "CountryTreeVC.h"
#import "Framework.h"
#import "LocationManager.h"
#import "MapsAppDelegate.h"
@ -76,9 +75,7 @@ extern NSString * const kAlohalyticsTapEventKey;
- (IBAction)menuActionDownloadMaps
{
self.state = MWMSideMenuStateInactive;
[Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"downloader"];
CountryTreeVC * const vc = [[CountryTreeVC alloc] initWithNodePosition:-1];
[self.controller.navigationController pushViewController:vc animated:YES];
[self.controller pushDownloadMaps];
}
- (IBAction)menuActionOpenSettings

View file

@ -0,0 +1,25 @@
//
// MWMSearchDownloadMapRequest.h
// Maps
//
// Created by Ilya Grechuhin on 10.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MWMDownloadMapRequest.h"
@interface MWMSearchDownloadMapRequest : NSObject
- (nonnull instancetype)init __attribute__((unavailable("init is not available")));
- (nonnull instancetype)initWithParentView:(nonnull UIView *)parentView delegate:(nonnull id <MWMCircularProgressDelegate>)delegate;
- (void)showForLocationWithName:(nonnull NSString *)locationName mapSize:(nonnull NSString *)mapSize mapAndRouteSize:(nonnull NSString *)mapAndRouteSize download:(nonnull MWMDownloadMapRequestDownloadCallback)download select:(nonnull MWMDownloadMapRequestSelectCallback)select;
- (void)showForUnknownLocation:(nonnull MWMDownloadMapRequestSelectCallback)select;
- (void)startDownload;
- (void)stopDownload;
- (void)downloadProgress:(CGFloat)progress countryName:(nonnull NSString *)countryName;
- (void)setDownloadFailed;
@end

View file

@ -0,0 +1,112 @@
//
// MWMSearchDownloadMapRequest.m
// Maps
//
// Created by Ilya Grechuhin on 10.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import "MWMSearchDownloadMapRequest.h"
#import "MWMSearchDownloadMapRequestView.h"
@interface MWMSearchDownloadMapRequest ()
@property (nonatomic) IBOutlet MWMSearchDownloadMapRequestView * rootView;
@property (nonatomic) IBOutlet UIView * downloadRequestHolder;
@property (nonatomic) MWMDownloadMapRequest * downloadRequest;
@property (strong, nonatomic) IBOutlet UIButton * dimButton;
@end
@implementation MWMSearchDownloadMapRequest
- (nonnull instancetype)initWithParentView:(nonnull UIView *)parentView delegate:(nonnull id <MWMCircularProgressDelegate>)delegate
{
self = [super init];
if (self)
{
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:self options:nil];
[parentView addSubview:self.rootView];
self.downloadRequest = [[MWMDownloadMapRequest alloc] initWithParentView:self.downloadRequestHolder delegate:delegate];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillhide:) name:UIKeyboardWillHideNotification object:nil];
}
return self;
}
- (void)showForLocationWithName:(nonnull NSString *)locationName mapSize:(nonnull NSString *)mapSize mapAndRouteSize:(nonnull NSString *)mapAndRouteSize download:(nonnull MWMDownloadMapRequestDownloadCallback)download select:(nonnull MWMDownloadMapRequestSelectCallback)select;
{
[self.downloadRequest showForLocationWithName:locationName mapSize:mapSize mapAndRouteSize:mapAndRouteSize download:download select:select];
}
- (void)showForUnknownLocation:(nonnull MWMDownloadMapRequestSelectCallback)select
{
[self.downloadRequest showForUnknownLocation:select];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.rootView removeFromSuperview];
}
- (void)keyboardWillShow:(nonnull NSNotification *)aNotification
{
UIButton * dim = self.dimButton;
dim.hidden = NO;
dim.alpha = 0.0;
NSNumber * duration = aNotification.userInfo[UIKeyboardAnimationDurationUserInfoKey];
[UIView animateWithDuration:duration.floatValue animations:^
{
dim.alpha = 1.0;
}];
}
- (void)keyboardWillhide:(nonnull NSNotification *)aNotification
{
UIButton * dim = self.dimButton;
dim.alpha = 1.0;
NSNumber * duration = aNotification.userInfo[UIKeyboardAnimationDurationUserInfoKey];
[UIView animateWithDuration:duration.floatValue animations:^
{
dim.alpha = 0.0;
}
completion:^(BOOL finished)
{
dim.hidden = YES;
}];
}
#pragma mark - Process control
- (void)startDownload
{
self.rootView.hintHidden = YES;
[self.downloadRequest startDownload];
}
- (void)stopDownload
{
self.rootView.hintHidden = NO;
[self.downloadRequest stopDownload];
}
- (void)downloadProgress:(CGFloat)progress countryName:(nonnull NSString *)countryName
{
[self.downloadRequest downloadProgress:progress countryName:countryName];
}
- (void)setDownloadFailed
{
[self.downloadRequest setDownloadFailed];
}
#pragma mark - Actions
- (IBAction)dimTouchUpInside:(nonnull UIButton *)sender
{
[[UIApplication sharedApplication].keyWindow endEditing:YES];
}
@end

View file

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MWMSearchDownloadMapRequest">
<connections>
<outlet property="dimButton" destination="iMA-Nl-9RY" id="deG-kr-rgy"/>
<outlet property="downloadRequestHolder" destination="uzQ-gk-yJp" id="NLf-AO-JMD"/>
<outlet property="rootView" destination="wP9-g7-AZb" id="w00-AT-5Lz"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="wP9-g7-AZb" customClass="MWMSearchDownloadMapRequestView">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Для поиска мест, построения маршрута скачайте карту и интернет вам больше не понадобится." textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="280" translatesAutoresizingMaskIntoConstraints="NO" id="Gwe-nt-eeI" userLabel="Hint">
<rect key="frame" x="20" y="40" width="280" height="49"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="regular14"/>
<userDefinedRuntimeAttribute type="string" keyPath="colorName" value="blackSecondaryText"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="search_without_internet_advertisement"/>
</userDefinedRuntimeAttributes>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uzQ-gk-yJp" userLabel="DownloadRequestHolder">
<rect key="frame" x="0.0" y="89" width="320" height="479"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iMA-Nl-9RY" userLabel="Dim">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.26000000000000001" colorSpace="calibratedRGB"/>
<state key="normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="blackHintText"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="dimTouchUpInside:" destination="-1" eventType="touchUpInside" id="bAP-fC-rHH"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="uzQ-gk-yJp" secondAttribute="trailing" id="1sz-bn-Jdf"/>
<constraint firstItem="iMA-Nl-9RY" firstAttribute="leading" secondItem="wP9-g7-AZb" secondAttribute="leading" id="7Lk-yw-xOq"/>
<constraint firstAttribute="bottom" secondItem="uzQ-gk-yJp" secondAttribute="bottom" id="9jx-hz-YeX"/>
<constraint firstItem="iMA-Nl-9RY" firstAttribute="top" secondItem="wP9-g7-AZb" secondAttribute="top" id="IpH-y1-AKW"/>
<constraint firstItem="uzQ-gk-yJp" firstAttribute="leading" secondItem="wP9-g7-AZb" secondAttribute="leading" id="NjZ-WD-2h3"/>
<constraint firstAttribute="bottom" secondItem="iMA-Nl-9RY" secondAttribute="bottom" id="PEJ-EP-gTU"/>
<constraint firstAttribute="trailing" secondItem="iMA-Nl-9RY" secondAttribute="trailing" id="Te8-04-GWH"/>
<constraint firstAttribute="trailing" secondItem="Gwe-nt-eeI" secondAttribute="trailing" constant="20" id="YaN-ox-CCC"/>
<constraint firstItem="Gwe-nt-eeI" firstAttribute="leading" secondItem="wP9-g7-AZb" secondAttribute="leading" constant="20" id="iNJ-np-5B7"/>
<constraint firstItem="uzQ-gk-yJp" firstAttribute="top" secondItem="Gwe-nt-eeI" secondAttribute="bottom" id="rBW-h2-v2z"/>
<constraint firstItem="Gwe-nt-eeI" firstAttribute="top" secondItem="wP9-g7-AZb" secondAttribute="top" constant="40" id="y9t-mi-Gpm"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="hint" destination="Gwe-nt-eeI" id="3Eo-4z-h1w"/>
<outlet property="hintTopOffset" destination="y9t-mi-Gpm" id="fpl-Z4-dx8"/>
</connections>
<point key="canvasLocation" x="162" y="354"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>

View file

@ -0,0 +1,19 @@
//
// MWMSearchDownloadMapRequestView.h
// Maps
//
// Created by Ilya Grechuhin on 09.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UIKitCategories.h"
@interface MWMSearchDownloadMapRequestView : SolidTouchView
@property (nonatomic) BOOL hintHidden;
- (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("initWithFrame is not available")));
- (instancetype)init __attribute__((unavailable("init is not available")));
@end

View file

@ -0,0 +1,58 @@
//
// MWMSearchDownloadMapRequestView.m
// Maps
//
// Created by Ilya Grechuhin on 09.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import "Macros.h"
#import "MWMDownloadMapRequestView.h"
#import "MWMSearchDownloadMapRequestView.h"
#import "UIKitCategories.h"
@interface MWMSearchDownloadMapRequestView ()
@property (weak, nonatomic) IBOutlet UILabel * hint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * hintTopOffset;
@end
@implementation MWMSearchDownloadMapRequestView
- (void)layoutSubviews
{
[super layoutSubviews];
UIView * superview = self.superview;
self.frame = superview.bounds;
// @TODO Remove on new search!
CGFloat const someCrazyTopOfsetForCurrentSearchViewImplementation = 64.0;
CGFloat const topOffset = (IPAD || superview.height > superview.width ? 40.0 : 12.0);
self.hintTopOffset.constant = someCrazyTopOfsetForCurrentSearchViewImplementation + topOffset;
}
#pragma mark - Properties
- (void)setHintHidden:(BOOL)hintHidden
{
if (self.hint.hidden == hintHidden)
return;
if (!hintHidden)
self.hint.hidden = hintHidden;
[UIView animateWithDuration:0.3 animations:^
{
self.hint.alpha = hintHidden ? 0.0 : 1.0;
}
completion:^(BOOL finished)
{
if (hintHidden)
self.hint.hidden = hintHidden;
}];
}
- (BOOL)hintHidden
{
return self.hint.hidden;
}
@end

View file

@ -0,0 +1,13 @@
//
// MWMNavigationDelegate.h
// Maps
//
// Created by Ilya Grechuhin on 11.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
@protocol MWMNavigationDelegate <NSObject>
- (void)pushDownloadMaps;
@end

View file

@ -1,9 +1,10 @@
#import <UIKit/UIKit.h>
#import "ViewController.h"
#import "LocationManager.h"
#import "SearchView.h"
#import "LocationPredictor.h"
#import "MWMNavigationDelegate.h"
#import "SearchView.h"
#import "ViewController.h"
#import <UIKit/UIKit.h>
#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"
@ -14,7 +15,7 @@ namespace search { struct AddressInfo; }
@class MWMMapViewControlsManager, MWMPlacePageViewManager;
@class ShareActionSheet;
@interface MapViewController : ViewController <LocationObserver, UIPopoverControllerDelegate>
@interface MapViewController : ViewController <LocationObserver, UIPopoverControllerDelegate, MWMNavigationDelegate>
{
bool m_isSticking;
size_t m_StickyThreshold;

View file

@ -1,7 +1,9 @@
#import "AppInfo.h"
#import "Common.h"
#import "CountryTreeVC.h"
#import "EAGLView.h"
#import "MapsAppDelegate.h"
#import "MapsObservers.h"
#import "MapViewController.h"
#import "MWMAlertViewController.h"
#import "MWMMapViewControlsManager.h"
@ -84,7 +86,7 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
@end
@interface MapViewController () <RouteViewDelegate, SearchViewDelegate, MWMPlacePageViewManagerDelegate>
@interface MapViewController () <RouteViewDelegate, SearchViewDelegate, MWMPlacePageViewManagerDelegate, ActiveMapsObserverProtocol>
@property (nonatomic) UIView * routeViewWrapper;
@property (nonatomic) RouteView * routeView;
@ -103,9 +105,15 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
@property (nonatomic) MapInfoView mapInfoView;
@property (nonatomic) BOOL haveCurrentMap;
@end
@implementation MapViewController
{
ActiveMapsObserver * m_mapsObserver;
int m_mapsObserverSlotId;
}
#pragma mark - LocationManager Callbacks
@ -553,6 +561,10 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
[self invalidate];
m_mapsObserverSlotId = GetFramework().GetCountryTree().GetActiveMapLayout().AddListener(m_mapsObserver);
if (self.searchView.state == SearchViewStateFullscreen)
[self.searchView setState:SearchViewStateFullscreen animated:NO];
}
- (void)viewDidLoad
@ -563,6 +575,9 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
self.placePageManager = [[MWMPlacePageViewManager alloc] initWithViewController:self];
self.controlsManager = [[MWMMapViewControlsManager alloc] initWithParentController:self];
[self.view addSubview:self.searchView];
__weak MapViewController * weakSelf = self;
m_mapsObserver = new ActiveMapsObserver(weakSelf);
}
- (void)viewDidAppear:(BOOL)animated
@ -578,10 +593,13 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
- (void)viewWillDisappear:(BOOL)animated
{
GetFramework().SetUpdatesEnabled(false);
[super viewWillDisappear:animated];
Framework & f = GetFramework();
f.SetUpdatesEnabled(false);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
[super viewWillDisappear:animated];
f.GetCountryTree().GetActiveMapLayout().RemoveListener(m_mapsObserverSlotId);
}
- (void)orientationChanged:(NSNotification *)notification
@ -891,6 +909,56 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
[RouteState remove];
}
#pragma mark - Map state
- (void)checkCurrentLocationMap
{
Framework & f = GetFramework();
ActiveMapsLayout & activeMapLayout = f.GetCountryTree().GetActiveMapLayout();
int const mapsCount = activeMapLayout.GetCountInGroup(ActiveMapsLayout::TGroup::EOutOfDate) + activeMapLayout.GetCountInGroup(ActiveMapsLayout::TGroup::EUpToDate);
if (mapsCount == 0)
{
self.haveCurrentMap = NO;
}
else
{
double lat, lon;
if ([[MapsAppDelegate theApp].m_locationManager getLat:lat Lon:lon])
{
m2::PointD const mercatorLocation = MercatorBounds::FromLatLon(lat, lon);
storage::TIndex const countryIndex = f.GetCountryIndex(mercatorLocation);
if (countryIndex == storage::TIndex())
{
self.haveCurrentMap = f.IsCountryLoaded(mercatorLocation);
}
else
{
storage::TStatus const countryStatus = activeMapLayout.GetCountryStatus(countryIndex);
self.haveCurrentMap = (countryStatus == storage::TStatus::EOnDisk || countryStatus == storage::TStatus::EOnDiskOutOfDate);
}
}
else
{
self.haveCurrentMap = YES;
}
}
}
- (void)startMapDownload:(storage::TIndex const &)index type:(TMapOptions)type
{
GetFramework().GetCountryTree().GetActiveMapLayout().DownloadMap(index, type);
}
- (void)stopMapsDownload
{
GetFramework().GetCountryTree().GetActiveMapLayout().CancelAll();
}
- (void)restartMapDownload:(storage::TIndex const &)index
{
GetFramework().GetCountryTree().GetActiveMapLayout().RetryDownloading(index);
}
#pragma mark - RouteViewDelegate
- (void)routeViewDidStartFollowing:(RouteView *)routeView
@ -925,6 +993,7 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
- (void)searchViewWillEnterState:(SearchViewState)state
{
[self checkCurrentLocationMap];
switch (state)
{
case SearchViewStateHidden:
@ -961,6 +1030,15 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
[self updateStatusBarStyle];
}
#pragma mark - MWMNavigationDelegate
- (void)pushDownloadMaps
{
[Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"downloader"];
CountryTreeVC * vc = [[CountryTreeVC alloc] initWithNodePosition:-1];
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - Layout
- (void)moveRouteViewAnimatedtoOffset:(CGFloat)offset
@ -991,6 +1069,29 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
}];
}
#pragma mark - ActiveMapsObserverProtocol
- (void)countryStatusChangedAtPosition:(int)position inGroup:(ActiveMapsLayout::TGroup const &)group
{
if (self.searchView.state != SearchViewStateFullscreen)
return;
TStatus const status = GetFramework().GetCountryTree().GetActiveMapLayout().GetCountryStatus(group, position);
if (status == TStatus::EDownloadFailed)
[self.searchView downloadFailed];
else if (status == TStatus::EOnDisk)
[self.searchView downloadComplete];
}
- (void)countryDownloadingProgressChanged:(LocalAndRemoteSizeT const &)progress atPosition:(int)position inGroup:(ActiveMapsLayout::TGroup const &)group
{
if (self.searchView.state != SearchViewStateFullscreen)
return;
CGFloat const normProgress = (CGFloat)progress.first / (CGFloat)progress.second;
ActiveMapsLayout & activeMapLayout = GetFramework().GetCountryTree().GetActiveMapLayout();
NSString * countryName = [NSString stringWithUTF8String:activeMapLayout.GetFormatedCountryName(activeMapLayout.GetCoreIndex(group, position)).c_str()];
[self.searchView downloadProgress:normProgress countryName:countryName];
}
#pragma mark - Public methods
- (void)setApiMode:(BOOL)apiMode animated:(BOOL)animated

View file

@ -1,6 +1,10 @@
#import <UIKit/UIKit.h>
#import "MWMNavigationDelegate.h"
#import "SearchBar.h"
#import <UIKit/UIKit.h>
#include "platform/country_defines.hpp"
#include "storage/index.hpp"
typedef NS_ENUM(NSUInteger, SearchViewState) {
SearchViewStateHidden,
@ -13,21 +17,31 @@ typedef NS_ENUM(NSUInteger, SearchViewState) {
@protocol SearchViewDelegate <NSObject>
@property (nonatomic, readonly) BOOL haveCurrentMap;
- (void)searchViewWillEnterState:(SearchViewState)state;
- (void)searchViewDidEnterState:(SearchViewState)state;
- (void)startMapDownload:(storage::TIndex const &)index type:(TMapOptions)type;
- (void)stopMapsDownload;
- (void)restartMapDownload:(storage::TIndex const &)index;
@end
@interface SearchView : UIView
@property (nonatomic) SearchBar * searchBar;
@property (nonnull, nonatomic) SearchBar * searchBar;
- (void)setState:(SearchViewState)state animated:(BOOL)animated;
- (CGFloat)defaultSearchBarMinY;
@property (weak, nonatomic) id <SearchViewDelegate> delegate;
@property (nonnull, weak, nonatomic) id <SearchViewDelegate, MWMNavigationDelegate> delegate;
@property (nonatomic, readonly) SearchViewState state;
@property (nonatomic, readonly) CGRect infoRect;
- (void)downloadProgress:(CGFloat)progress countryName:(nonnull NSString *)countryName;
- (void)downloadComplete;
- (void)downloadFailed;
@end

View file

@ -5,6 +5,7 @@
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "MWMMapViewControlsManager.h"
#import "MWMSearchDownloadMapRequest.h"
#import "SearchCategoryCell.h"
#import "SearchResultCell.h"
#import "SearchShowOnMapCell.h"
@ -104,12 +105,14 @@ typedef NS_ENUM(NSUInteger, CellType)
};
@interface SearchView () <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource, SearchBarDelegate, LocationObserver>
@interface SearchView () <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource, SearchBarDelegate, LocationObserver, MWMCircularProgressDelegate>
@property (nonatomic) UITableView * tableView;
@property (nonatomic) SolidTouchView * topBackgroundView;
@property (nonatomic) UILabel * emptyResultLabel;
@property (nonatomic) MWMSearchDownloadMapRequest * downloadRequest;
@property (nonatomic) SearchResultsWrapper * wrapper;
@property (nonatomic) NSArray * categoriesNames;
@ -170,7 +173,8 @@ static BOOL keyboardLoaded = NO;
GetFramework().PrepareSearch();
if (keyboardLoaded)
[self showDownloadMapRequestIfRequired];
if (keyboardLoaded && !self.downloadRequest)
[self.searchBar.textField becomeFirstResponder];
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.tableView.alpha = 1;
@ -185,7 +189,7 @@ static BOOL keyboardLoaded = NO;
self.searchBar.textField.width = textFieldWidth;
[self.searchBar.clearButton setImage:[UIImage imageNamed:@"SearchBarClearButton"] forState:UIControlStateNormal];
} completion:^(BOOL) {
if (!keyboardLoaded)
if (!keyboardLoaded && !self.downloadRequest)
{
keyboardLoaded = YES;
[self.searchBar.textField becomeFirstResponder];
@ -418,10 +422,13 @@ static BOOL keyboardLoaded = NO;
if ([currentText length])
{
[self hideDownloadMapRequest];
[self search:currentText];
}
else
{
if (sender)
[self showDownloadMapRequestIfRequired];
// nil wrapper means "Display Categories" mode
self.wrapper = nil;
[self.searchBar setSearching:NO];
@ -508,6 +515,7 @@ static BOOL keyboardLoaded = NO;
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.state == SearchViewStateFullscreen)
self.searchBar.minY = [self defaultSearchBarMinY];
self.tableView.contentInset = UIEdgeInsetsMake(self.topBackgroundView.height, 0, 0, 0);
@ -808,8 +816,114 @@ static BOOL keyboardLoaded = NO;
// [super touchesBegan:touches withEvent:event];
}
#pragma mark - Download request
- (void)showDownloadMapRequestIfRequired
{
if (self.delegate.haveCurrentMap)
return;
self.downloadRequest = [[MWMSearchDownloadMapRequest alloc] initWithParentView:self.tableView delegate:self];
Framework & f = GetFramework();
ActiveMapsLayout & activeMapLayout = f.GetCountryTree().GetActiveMapLayout();
if (activeMapLayout.IsDownloadingActive())
{
[self.downloadRequest startDownload];
}
else
{
double lat, lon;
if ([[MapsAppDelegate theApp].m_locationManager getLat:lat Lon:lon])
{
m2::PointD const mercatorLocation = MercatorBounds::FromLatLon(lat, lon);
storage::TIndex const countryIndex = f.GetCountryIndex(mercatorLocation);
NSString * countryName = [NSString stringWithUTF8String:activeMapLayout.GetFormatedCountryName(countryIndex).c_str()];
LocalAndRemoteSizeT const sizes = activeMapLayout.GetRemoteCountrySizes(countryIndex);
NSString * mapSize = formattedSize(sizes.first);
NSString * mapAndRouteSize = formattedSize(sizes.first + sizes.second);
__weak SearchView * weakSelf = self;
[self.downloadRequest showForLocationWithName:countryName mapSize:mapSize mapAndRouteSize:mapAndRouteSize download:^(BOOL needRoute)
{
__strong SearchView * self = weakSelf;
[self.downloadRequest startDownload];
[self.delegate startMapDownload:countryIndex type:needRoute ? TMapOptions::EMapWithCarRouting : TMapOptions::EMap];
}
select:^
{
[self selectMapsAction];
}];
}
else
{
[self.downloadRequest showForUnknownLocation:^
{
[self selectMapsAction];
}];
}
}
}
- (void)hideDownloadMapRequest
{
self.downloadRequest = nil;
}
#pragma mark - Download callbacks
- (void)downloadProgress:(CGFloat)progress countryName:(NSString *)countryName
{
[self.downloadRequest downloadProgress:progress countryName:countryName];
}
- (void)downloadComplete
{
[self hideDownloadMapRequest];
}
- (void)downloadFailed
{
[self.downloadRequest setDownloadFailed];
}
#pragma mark - MWMCircularProgressDelegate
- (void)progressButtonPressed:(nonnull MWMCircularProgress *)progress
{
if (progress.failed)
{
double lat, lon;
if ([[MapsAppDelegate theApp].m_locationManager getLat:lat Lon:lon])
{
Framework & f = GetFramework();
m2::PointD const mercatorLocation = MercatorBounds::FromLatLon(lat, lon);
storage::TIndex const countryIndex = f.GetCountryIndex(mercatorLocation);
[self.delegate restartMapDownload:countryIndex];
}
}
else
{
[self.downloadRequest stopDownload];
[self.delegate stopMapsDownload];
}
}
#pragma mark - MWMNavigationDelegate
- (void)selectMapsAction
{
[self.delegate pushDownloadMaps];
}
#pragma mark - Properties
- (void)setDownloadRequest:(MWMSearchDownloadMapRequest *)downloadRequest
{
_downloadRequest = downloadRequest;
self.tableView.scrollEnabled = (downloadRequest == nil);
}
- (CGRect)infoRect
{
return [self convertRect:self.topBackgroundView.frame toView:self.superview];

View file

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "radioBtnOff@1x.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "radioBtnOff@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "radioBtnOff@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "radioBtnOn@1x.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "radioBtnOn@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "radioBtnOn@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -41,6 +41,12 @@
349A357A1B53D4C9009677EE /* MWMCircularProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 349A35761B53D4C9009677EE /* MWMCircularProgress.m */; };
349A357B1B53D4C9009677EE /* MWMCircularProgress.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A35771B53D4C9009677EE /* MWMCircularProgress.xib */; };
349A357C1B53D4C9009677EE /* MWMCircularProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = 349A35791B53D4C9009677EE /* MWMCircularProgressView.m */; };
349A35831B53E967009677EE /* MWMDownloadMapRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 349A357F1B53E967009677EE /* MWMDownloadMapRequest.m */; };
349A35841B53E967009677EE /* MWMDownloadMapRequest.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A35801B53E967009677EE /* MWMDownloadMapRequest.xib */; };
349A35851B53E967009677EE /* MWMDownloadMapRequestView.m in Sources */ = {isa = PBXBuildFile; fileRef = 349A35821B53E967009677EE /* MWMDownloadMapRequestView.m */; };
349A358C1B53EABC009677EE /* MWMSearchDownloadMapRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 349A35881B53EABC009677EE /* MWMSearchDownloadMapRequest.m */; };
349A358D1B53EABC009677EE /* MWMSearchDownloadMapRequest.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A35891B53EABC009677EE /* MWMSearchDownloadMapRequest.xib */; };
349A358E1B53EABC009677EE /* MWMSearchDownloadMapRequestView.m in Sources */ = {isa = PBXBuildFile; fileRef = 349A358B1B53EABC009677EE /* MWMSearchDownloadMapRequestView.m */; };
34A742FE1AE5461A00CE15EB /* index.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A742FD1AE5461A00CE15EB /* index.cpp */; };
34A743001AE5468200CE15EB /* storage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A742FF1AE5468200CE15EB /* storage.cpp */; };
34BC72211B0DECAE0012A34B /* MWMLocationButton.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34BC720C1B0DECAE0012A34B /* MWMLocationButton.mm */; };
@ -388,6 +394,16 @@
349A35771B53D4C9009677EE /* MWMCircularProgress.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMCircularProgress.xib; sourceTree = "<group>"; };
349A35781B53D4C9009677EE /* MWMCircularProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMCircularProgressView.h; sourceTree = "<group>"; };
349A35791B53D4C9009677EE /* MWMCircularProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWMCircularProgressView.m; sourceTree = "<group>"; };
349A357E1B53E967009677EE /* MWMDownloadMapRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMDownloadMapRequest.h; sourceTree = "<group>"; };
349A357F1B53E967009677EE /* MWMDownloadMapRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWMDownloadMapRequest.m; sourceTree = "<group>"; };
349A35801B53E967009677EE /* MWMDownloadMapRequest.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMDownloadMapRequest.xib; sourceTree = "<group>"; };
349A35811B53E967009677EE /* MWMDownloadMapRequestView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMDownloadMapRequestView.h; sourceTree = "<group>"; };
349A35821B53E967009677EE /* MWMDownloadMapRequestView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWMDownloadMapRequestView.m; sourceTree = "<group>"; };
349A35871B53EABC009677EE /* MWMSearchDownloadMapRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMSearchDownloadMapRequest.h; sourceTree = "<group>"; };
349A35881B53EABC009677EE /* MWMSearchDownloadMapRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWMSearchDownloadMapRequest.m; sourceTree = "<group>"; };
349A35891B53EABC009677EE /* MWMSearchDownloadMapRequest.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMSearchDownloadMapRequest.xib; sourceTree = "<group>"; };
349A358A1B53EABC009677EE /* MWMSearchDownloadMapRequestView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMSearchDownloadMapRequestView.h; sourceTree = "<group>"; };
349A358B1B53EABC009677EE /* MWMSearchDownloadMapRequestView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWMSearchDownloadMapRequestView.m; sourceTree = "<group>"; };
34A742FD1AE5461A00CE15EB /* index.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = index.cpp; path = ../../../storage/index.cpp; sourceTree = "<group>"; };
34A742FF1AE5468200CE15EB /* storage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = storage.cpp; path = ../../../storage/storage.cpp; sourceTree = "<group>"; };
34BC720B1B0DECAE0012A34B /* MWMLocationButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMLocationButton.h; sourceTree = "<group>"; };
@ -1080,6 +1096,32 @@
path = CustomViews/CircularProgress;
sourceTree = "<group>";
};
349A357D1B53E967009677EE /* DownloadMapRequest */ = {
isa = PBXGroup;
children = (
349A357E1B53E967009677EE /* MWMDownloadMapRequest.h */,
349A357F1B53E967009677EE /* MWMDownloadMapRequest.m */,
349A35801B53E967009677EE /* MWMDownloadMapRequest.xib */,
349A35811B53E967009677EE /* MWMDownloadMapRequestView.h */,
349A35821B53E967009677EE /* MWMDownloadMapRequestView.m */,
);
name = DownloadMapRequest;
path = CustomViews/DownloadMapRequest;
sourceTree = "<group>";
};
349A35861B53EABC009677EE /* SearchDownloadMapRequest */ = {
isa = PBXGroup;
children = (
349A35871B53EABC009677EE /* MWMSearchDownloadMapRequest.h */,
349A35881B53EABC009677EE /* MWMSearchDownloadMapRequest.m */,
349A35891B53EABC009677EE /* MWMSearchDownloadMapRequest.xib */,
349A358A1B53EABC009677EE /* MWMSearchDownloadMapRequestView.h */,
349A358B1B53EABC009677EE /* MWMSearchDownloadMapRequestView.m */,
);
name = SearchDownloadMapRequest;
path = CustomViews/SearchDownloadMapRequest;
sourceTree = "<group>";
};
34BC72091B0DECAE0012A34B /* MapViewControls */ = {
isa = PBXGroup;
children = (
@ -1244,6 +1286,8 @@
97B4E9271851DAB300BEC5D7 /* Custom Views */ = {
isa = PBXGroup;
children = (
349A35861B53EABC009677EE /* SearchDownloadMapRequest */,
349A357D1B53E967009677EE /* DownloadMapRequest */,
349A35741B53D4C9009677EE /* CircularProgress */,
34BC72091B0DECAE0012A34B /* MapViewControls */,
B0E1FCD61A23386D00A8E08B /* Route */,
@ -2009,10 +2053,12 @@
F7E7BA231672328F00B4492E /* atm@2x.png in Resources */,
F7E7BA241672328F00B4492E /* bank.png in Resources */,
34BC72231B0DECAE0012A34B /* MWMLocationButton.xib in Resources */,
349A358D1B53EABC009677EE /* MWMSearchDownloadMapRequest.xib in Resources */,
F7E7BA251672328F00B4492E /* bank@2x.png in Resources */,
349A357B1B53D4C9009677EE /* MWMCircularProgress.xib in Resources */,
F7E7BA261672328F00B4492E /* entertainment.png in Resources */,
F6CB21621AEE902B00FB8963 /* PlacePageLinkCell.xib in Resources */,
349A35841B53E967009677EE /* MWMDownloadMapRequest.xib in Resources */,
F7E7BA271672328F00B4492E /* entertainment@2x.png in Resources */,
F7E7BA281672328F00B4492E /* food.png in Resources */,
F7E7BA291672328F00B4492E /* food@2x.png in Resources */,
@ -2145,6 +2191,7 @@
B08AA8CE1A24C7BC00810B1C /* LocalNotificationInfoProvider.m in Sources */,
1D3623260D0F684500981E51 /* MapsAppDelegate.mm in Sources */,
F67BBB571AC54A7800D162C7 /* MWMFeedbackAlert.mm in Sources */,
349A35831B53E967009677EE /* MWMDownloadMapRequest.m in Sources */,
A32B6D4C1A14980500E54A65 /* iosOGLContext.mm in Sources */,
B0E1FCDF1A2343BC00A8E08B /* NextTurnPhoneView.m in Sources */,
46F26CD810F623BA00ECCA39 /* EAGLView.mm in Sources */,
@ -2168,6 +2215,7 @@
EE7F29821219ECA300EB67A9 /* RenderContext.mm in Sources */,
34BC72251B0DECAE0012A34B /* MWMSideMenuButton.mm in Sources */,
F6ED13911B1EF96B0095C6DE /* MWMBookmarkDescriptionViewController.mm in Sources */,
349A35851B53E967009677EE /* MWMDownloadMapRequestView.m in Sources */,
F64F19991AB81A00006EAF7E /* MWMAlertViewController.mm in Sources */,
FAFCB63613366E78001A5C59 /* WebViewController.mm in Sources */,
F6FE2C0F1B03A006009814AA /* MWMPlacePageNavigationBar.mm in Sources */,
@ -2201,6 +2249,7 @@
FA36B80D15403A4F004560CC /* BookmarksVC.mm in Sources */,
F6ED135B1B18AA930095C6DE /* MWMExtendedPlacePageView.m in Sources */,
F6588E2F1B15D2BC00EE1E58 /* MWMBookmarkColorViewController.mm in Sources */,
349A358E1B53EABC009677EE /* MWMSearchDownloadMapRequestView.m in Sources */,
A32B6D4D1A14980500E54A65 /* iosOGLContextFactory.mm in Sources */,
FAF457E715597D4600DCCC49 /* Framework.cpp in Sources */,
97CC93BB19599F4700369B42 /* SearchSuggestCell.m in Sources */,
@ -2230,6 +2279,7 @@
B0FBFA271A515AFD0086819E /* ViewController.m in Sources */,
3472EC051B4D44BE0085CB79 /* UIFont+MapsMeFonts.mm in Sources */,
342AD76F1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m in Sources */,
349A358C1B53EABC009677EE /* MWMSearchDownloadMapRequest.m in Sources */,
F63732961AE9431E00A03764 /* MWMBasePlacePageView.mm in Sources */,
97A8001018B21395000C07A2 /* SearchBar.mm in Sources */,
EDC5C543175F2CA600420E92 /* ShareActionSheet.mm in Sources */,