Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
134
iphone/Maps/UI/Downloader/DownloadAllView/DownloadAllView.swift
Normal file
134
iphone/Maps/UI/Downloader/DownloadAllView/DownloadAllView.swift
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
import UIKit
|
||||
|
||||
protocol DownloadAllViewDelegate: AnyObject {
|
||||
func onDownloadButtonPressed()
|
||||
func onRetryButtonPressed()
|
||||
func onCancelButtonPressed()
|
||||
func onStateChanged(state: DownloadAllView.State)
|
||||
}
|
||||
|
||||
class DownloadAllView: UIView {
|
||||
enum State {
|
||||
case none
|
||||
case ready
|
||||
case error
|
||||
case dowloading
|
||||
}
|
||||
enum Style {
|
||||
case download
|
||||
case update
|
||||
}
|
||||
|
||||
@IBOutlet private var iconImageView: UIImageView!
|
||||
@IBOutlet private var title: UILabel!
|
||||
@IBOutlet private var downloadSizeLabel: UILabel!
|
||||
@IBOutlet private var stateWrapper: UIView!
|
||||
@IBOutlet private var downloadButton: UIButton!
|
||||
@IBOutlet private var titleCenterConstraint: NSLayoutConstraint!
|
||||
lazy private var progress: MWMCircularProgress = {
|
||||
let view = MWMCircularProgress.downloaderProgress(forParentView: stateWrapper)
|
||||
view.delegate = self
|
||||
return view
|
||||
}()
|
||||
|
||||
var isSizeHidden: Bool = false {
|
||||
didSet {
|
||||
if oldValue != isSizeHidden {
|
||||
updateView()
|
||||
}
|
||||
}
|
||||
}
|
||||
var style: Style = .download {
|
||||
didSet {
|
||||
if oldValue != style {
|
||||
updateView()
|
||||
}
|
||||
}
|
||||
}
|
||||
var state: State = .ready {
|
||||
didSet {
|
||||
if oldValue != state {
|
||||
updateView()
|
||||
delegate?.onStateChanged(state: state)
|
||||
}
|
||||
}
|
||||
}
|
||||
var downloadSize: UInt64 = 0 {
|
||||
didSet {
|
||||
downloadSizeLabel.text = formattedSize(downloadSize)
|
||||
}
|
||||
}
|
||||
var downloadProgress: CGFloat = 0 {
|
||||
didSet {
|
||||
self.progress.progress = downloadProgress
|
||||
}
|
||||
}
|
||||
weak var delegate: DownloadAllViewDelegate?
|
||||
|
||||
@IBAction func onDownloadButtonPress(_ sender: Any) {
|
||||
if state == .error {
|
||||
delegate?.onRetryButtonPressed()
|
||||
} else {
|
||||
delegate?.onDownloadButtonPressed()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateView() {
|
||||
let readyTitle: String
|
||||
let downloadingTitle: String
|
||||
let readyButtonTitle: String
|
||||
let errorTitle = L("country_status_download_failed")
|
||||
let errorButtonTitle = L("downloader_retry")
|
||||
|
||||
switch style {
|
||||
case .download:
|
||||
iconImageView.image = UIImage(named: "ic_download_all")
|
||||
readyTitle = L("downloader_download_all_button")
|
||||
downloadingTitle = L("downloader_loading_ios")
|
||||
readyButtonTitle = L("download_button")
|
||||
case .update:
|
||||
iconImageView.image = UIImage(named: "ic_update_all")
|
||||
readyTitle = L("downloader_update_maps")
|
||||
downloadingTitle = L("downloader_updating_ios")
|
||||
readyButtonTitle = L("downloader_update_all_button")
|
||||
}
|
||||
|
||||
titleCenterConstraint.priority = isSizeHidden ? .defaultHigh : .defaultLow
|
||||
downloadSizeLabel.isHidden = isSizeHidden
|
||||
|
||||
switch state {
|
||||
case .error:
|
||||
iconImageView.image = UIImage(named: "ic_download_error")
|
||||
title.text = errorTitle
|
||||
title.setFontStyleAndApply(.red)
|
||||
downloadButton.setTitle(errorButtonTitle, for: .normal)
|
||||
downloadButton.isHidden = false
|
||||
stateWrapper.isHidden = true
|
||||
progress.state = .spinner
|
||||
downloadSizeLabel.isHidden = false
|
||||
case .ready:
|
||||
title.text = readyTitle
|
||||
title.setFontStyleAndApply(.blackPrimary)
|
||||
downloadButton.setTitle(readyButtonTitle, for: .normal)
|
||||
downloadButton.isHidden = false
|
||||
stateWrapper.isHidden = true
|
||||
progress.state = .spinner
|
||||
downloadSizeLabel.isHidden = false
|
||||
case .dowloading:
|
||||
title.text = downloadingTitle
|
||||
title.setFontStyleAndApply(.blackPrimary)
|
||||
downloadButton.isHidden = true
|
||||
stateWrapper.isHidden = false
|
||||
progress.state = .spinner
|
||||
case .none:
|
||||
self.downloadButton.isHidden = true
|
||||
self.stateWrapper.isHidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DownloadAllView: MWMCircularProgressProtocol {
|
||||
func progressButtonPressed(_ progress: MWMCircularProgress) {
|
||||
delegate?.onCancelButtonPressed()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
|
||||
<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"/>
|
||||
<view contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="iN0-l3-epB" customClass="DownloadAllView" customModule="CoMaps" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="64"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="cKg-JT-LQ3">
|
||||
<rect key="frame" x="16" y="20" width="24" height="24"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="24" id="IoI-GO-nG3"/>
|
||||
<constraint firstAttribute="height" constant="24" id="TMm-8V-jMo"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4vQ-dY-JAM">
|
||||
<rect key="frame" x="58" y="10" width="32" height="20"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" relation="greaterThanOrEqual" priority="750" constant="20" id="38P-x2-HCd"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="0.87" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular17:blackPrimaryText"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="760" text="..." textAlignment="right" lineBreakMode="wordWrap" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mVA-td-yVW">
|
||||
<rect key="frame" x="58" y="38" width="12" height="16"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<color key="textColor" red="0.66666666669999997" green="0.66666666669999997" blue="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular14:blackSecondaryText"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
</label>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NBt-lB-IvV">
|
||||
<rect key="frame" x="352" y="17" width="46" height="30"/>
|
||||
<state key="normal" title="Button"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular17:linkBlueText"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
<connections>
|
||||
<action selector="onDownloadButtonPress:" destination="iN0-l3-epB" eventType="touchUpInside" id="6kx-3L-wc2"/>
|
||||
</connections>
|
||||
</button>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wlz-tD-b2M">
|
||||
<rect key="frame" x="354" y="14" width="36" height="36"/>
|
||||
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="36" id="C2G-Y6-VKF"/>
|
||||
<constraint firstAttribute="width" constant="36" id="Uo3-uS-WpU"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstItem="mVA-td-yVW" firstAttribute="leading" secondItem="cKg-JT-LQ3" secondAttribute="trailing" constant="18" id="1J4-kU-lyG"/>
|
||||
<constraint firstItem="cKg-JT-LQ3" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="16" id="2AL-TB-z3U"/>
|
||||
<constraint firstItem="wlz-tD-b2M" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="8aq-IR-Ffz"/>
|
||||
<constraint firstItem="4vQ-dY-JAM" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" priority="500" constant="10" id="AOx-bc-GRy"/>
|
||||
<constraint firstItem="cKg-JT-LQ3" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="Ehd-uD-6HS"/>
|
||||
<constraint firstItem="4vQ-dY-JAM" firstAttribute="leading" secondItem="cKg-JT-LQ3" secondAttribute="trailing" constant="18" id="IH6-Jq-o9T"/>
|
||||
<constraint firstItem="NBt-lB-IvV" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="KUE-7v-eNY"/>
|
||||
<constraint firstAttribute="trailing" secondItem="NBt-lB-IvV" secondAttribute="trailing" constant="16" id="PgQ-HZ-Ui5"/>
|
||||
<constraint firstItem="4vQ-dY-JAM" firstAttribute="centerY" secondItem="cKg-JT-LQ3" secondAttribute="centerY" priority="250" id="gWz-3d-LHv"/>
|
||||
<constraint firstAttribute="bottom" secondItem="mVA-td-yVW" secondAttribute="bottom" constant="10" id="gj3-BP-k3L"/>
|
||||
<constraint firstAttribute="trailing" secondItem="wlz-tD-b2M" secondAttribute="trailing" constant="24" id="s3R-CP-1zA"/>
|
||||
</constraints>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="PressBackground"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
<connections>
|
||||
<outlet property="downloadButton" destination="NBt-lB-IvV" id="RDS-Sj-rmo"/>
|
||||
<outlet property="downloadSizeLabel" destination="mVA-td-yVW" id="G7H-Vl-OQQ"/>
|
||||
<outlet property="iconImageView" destination="cKg-JT-LQ3" id="lvM-rM-apH"/>
|
||||
<outlet property="stateWrapper" destination="wlz-tD-b2M" id="7XI-dP-yUS"/>
|
||||
<outlet property="title" destination="4vQ-dY-JAM" id="bZv-x2-pe5"/>
|
||||
<outlet property="titleCenterConstraint" destination="gWz-3d-LHv" id="6b1-Ah-2ns"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="137.68115942028987" y="-162.72321428571428"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
Loading…
Add table
Add a link
Reference in a new issue