[ios] Welcome and WhatsNew refactoring

This commit is contained in:
Aleksey Belousov 2018-05-23 02:24:32 +03:00 committed by yoksnod
parent ff15443f1b
commit 7266d30271
18 changed files with 243 additions and 283 deletions

View file

@ -2,17 +2,17 @@
"images" : [
{
"idiom" : "universal",
"filename" : "img_wn_way_of_booking.png",
"filename" : "img_wn_business.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "img_wn_way_of_booking@2x.png",
"filename" : "img_wn_business@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "img_wn_way_of_booking@3x.png",
"filename" : "img_wn_business@3x.png",
"scale" : "3x"
}
],

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View file

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

View file

@ -176,7 +176,6 @@
3490D2E11CE9DD2500D0B838 /* MWMSideButtonsView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3490D2DC1CE9DD2500D0B838 /* MWMSideButtonsView.mm */; };
3490D2E31CE9DD2500D0B838 /* MWMSideButtonsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3490D2DD1CE9DD2500D0B838 /* MWMSideButtonsView.xib */; };
34926BE71EA4C2A700DCF14C /* SearchBanners.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34926BE51EA4C2A700DCF14C /* SearchBanners.swift */; };
34943BB71E26222300B14F84 /* WelcomeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34943BB51E26222300B14F84 /* WelcomeProtocol.swift */; };
34943BBB1E2626B200B14F84 /* WelcomePageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34943BB91E2626B200B14F84 /* WelcomePageController.swift */; };
3495433D1EB22D9600F08F73 /* MPAdBrowserController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3495433C1EB22D9600F08F73 /* MPAdBrowserController.xib */; };
349A13831DEC138C00C7DB60 /* MWMMobileInternetAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13801DEC138C00C7DB60 /* MWMMobileInternetAlert.mm */; };
@ -348,6 +347,7 @@
4767CDA420AAF66B00BD8166 /* NSAttributedString+HTML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4767CDA320AAF66B00BD8166 /* NSAttributedString+HTML.swift */; };
4767CDA620AB1F6200BD8166 /* LeftAlignedIconButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4767CDA520AB1F6200BD8166 /* LeftAlignedIconButton.swift */; };
4767CDA820AB401000BD8166 /* LinkTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4767CDA720AB401000BD8166 /* LinkTextView.swift */; };
4767CDC120B477BA00BD8166 /* WelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4767CDC020B477BA00BD8166 /* WelcomeViewController.swift */; };
4A300ED51C6DCFD400140018 /* countries-strings in Resources */ = {isa = PBXBuildFile; fileRef = 4A300ED31C6DCFD400140018 /* countries-strings */; };
56C74C391C74A3BC00B71B9F /* MWMInputEmailValidator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34ABA62F1C2D58F300FE1BEC /* MWMInputEmailValidator.mm */; };
56EE14D11FE804550036F20C /* libtransit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 56EE14D21FE804550036F20C /* libtransit.a */; };
@ -975,7 +975,6 @@
3490D2DC1CE9DD2500D0B838 /* MWMSideButtonsView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMSideButtonsView.mm; sourceTree = "<group>"; };
3490D2DD1CE9DD2500D0B838 /* MWMSideButtonsView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMSideButtonsView.xib; sourceTree = "<group>"; };
34926BE51EA4C2A700DCF14C /* SearchBanners.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBanners.swift; sourceTree = "<group>"; };
34943BB51E26222300B14F84 /* WelcomeProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomeProtocol.swift; sourceTree = "<group>"; };
34943BB91E2626B200B14F84 /* WelcomePageController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomePageController.swift; sourceTree = "<group>"; };
3495433C1EB22D9600F08F73 /* MPAdBrowserController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = MPAdBrowserController.xib; path = 3party/MoPubSDK/Internal/Common/MPAdBrowserController.xib; sourceTree = "<group>"; };
349A137F1DEC138C00C7DB60 /* MWMMobileInternetAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMobileInternetAlert.h; sourceTree = "<group>"; };
@ -1278,6 +1277,7 @@
4767CDA320AAF66B00BD8166 /* NSAttributedString+HTML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+HTML.swift"; sourceTree = "<group>"; };
4767CDA520AB1F6200BD8166 /* LeftAlignedIconButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftAlignedIconButton.swift; sourceTree = "<group>"; };
4767CDA720AB401000BD8166 /* LinkTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkTextView.swift; sourceTree = "<group>"; };
4767CDC020B477BA00BD8166 /* WelcomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeViewController.swift; sourceTree = "<group>"; };
4A00DBDE1AB704C400113624 /* drules_proto_dark.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_dark.bin; path = ../../data/drules_proto_dark.bin; sourceTree = "<group>"; };
4A23D1561B8B4DD700D4EB6F /* drules_proto_clear.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_clear.bin; path = ../../data/drules_proto_clear.bin; sourceTree = "<group>"; };
4A23D1571B8B4DD700D4EB6F /* resources-6plus_clear */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-6plus_clear"; path = "../../data/resources-6plus_clear"; sourceTree = "<group>"; };
@ -2661,10 +2661,10 @@
34943BB01E2620C600B14F84 /* Welcome */ = {
isa = PBXGroup;
children = (
34943BB51E26222300B14F84 /* WelcomeProtocol.swift */,
34943BB91E2626B200B14F84 /* WelcomePageController.swift */,
34D4FA611E26572D003F53EF /* FirstLaunchController.swift */,
34D4FA651E265749003F53EF /* WhatsNewController.swift */,
4767CDC020B477BA00BD8166 /* WelcomeViewController.swift */,
);
path = Welcome;
sourceTree = "<group>";
@ -4498,7 +4498,6 @@
34B846A12029DCC10081ECCD /* BMCCategoriesHeader.swift in Sources */,
346DB8341E5C4F6700E3123E /* GalleryViewController.swift in Sources */,
F61757ED1FC73027000AD0D0 /* DiscoveryOnlineTemplateCell.swift in Sources */,
34943BB71E26222300B14F84 /* WelcomeProtocol.swift in Sources */,
F6E2FD5F1E097BA00083EBEC /* MWMMapDownloaderLargeCountryTableViewCell.mm in Sources */,
34F4073B1E9E1AFF00E57AC0 /* MopubBanner.swift in Sources */,
F6E2FF481E097BA00083EBEC /* SettingsTableViewSelectableCell.swift in Sources */,
@ -4599,6 +4598,7 @@
3472B5EB200F8CFF00DC6CD5 /* MWMUGCHelper.mm in Sources */,
3454D7C21E07F045004AF2AD /* NSString+Categories.mm in Sources */,
6741A9FE1BF340DE002C974C /* SelectSetVC.mm in Sources */,
4767CDC120B477BA00BD8166 /* WelcomeViewController.swift in Sources */,
34E7761F1F14DB48003040B3 /* PlacePageArea.swift in Sources */,
346DB82E1E5C4F6700E3123E /* GalleryItemViewController.swift in Sources */,
340475561E081A4600C92850 /* Statistics.mm in Sources */,

View file

@ -1,35 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<array key="HelveticaNeue.ttc">
<string>HelveticaNeue</string>
<string>HelveticaNeue-Medium</string>
</array>
</customFonts>
<scenes>
<!--Welcome Page Controller-->
<scene sceneID="1ZX-3C-7bF">
<objects>
<pageViewController storyboardIdentifier="WelcomePageScrollController" autoresizesArchivedViewToFullSize="NO" transitionStyle="scroll" navigationOrientation="horizontal" spineLocation="none" id="hqM-da-ko0" customClass="MWMWelcomePageController" propertyAccessControl="all" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="fu9-Ui-e6Z" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1881" y="495"/>
</scene>
<!--First Launch Controller-->
<scene sceneID="AgG-8B-fRd">
<objects>
<viewController storyboardIdentifier="FirstLaunchController" id="Gh3-qE-FWN" customClass="FirstLaunchController" customModule="maps_me" customModuleProvider="target" propertyAccessControl="all" sceneMemberID="viewController">
<viewController storyboardIdentifier="FirstLaunchController" id="Gh3-qE-FWN" customClass="FirstLaunchController" customModule="maps_me" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="RNH-dF-vbJ" customClass="SolidTouchView">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@ -41,10 +27,10 @@
<rect key="frame" x="16" y="40" width="488" height="456"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="y7O-d8-Zqv" userLabel="CenteredView">
<rect key="frame" x="44" y="50" width="400" height="357"/>
<rect key="frame" x="44.5" y="49.5" width="400" height="357"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalCompressionResistancePriority="749" image="ic_placeholder" translatesAutoresizingMaskIntoConstraints="NO" id="3yX-3O-NmI">
<rect key="frame" x="80.5" y="0.0" width="240" height="240"/>
<rect key="frame" x="80" y="0.0" width="240" height="240"/>
<constraints>
<constraint firstAttribute="height" relation="lessThanOrEqual" priority="800" constant="280" id="0jq-yV-Ew3"/>
<constraint firstAttribute="width" secondItem="3yX-3O-NmI" secondAttribute="height" multiplier="1:1" id="OJT-CV-liK"/>
@ -100,7 +86,7 @@
</constraints>
</view>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="UqX-Ni-ms1" userLabel="NotNow">
<rect key="frame" x="140.5" y="516" width="240" height="44"/>
<rect key="frame" x="140" y="516" width="240" height="44"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="66G-KS-XdJ"/>
@ -121,6 +107,9 @@
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="linkBlue"/>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundHighlightedColorName" value="linkBlueHighlighted"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="nextPage" destination="Gh3-qE-FWN" eventType="touchUpInside" id="ECl-7U-cG4"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
@ -161,20 +150,12 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Tm5-G5-Xsm" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2563" y="1224"/>
</scene>
<!--Welcome Page Controller-->
<scene sceneID="yjG-6M-B0J">
<objects>
<pageViewController storyboardIdentifier="WelcomePageCurlController" autoresizesArchivedViewToFullSize="NO" transitionStyle="pageCurl" navigationOrientation="horizontal" spineLocation="none" id="Co6-CL-XGB" customClass="MWMWelcomePageController" propertyAccessControl="all" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="QyJ-ER-oPm" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2563" y="495"/>
<point key="canvasLocation" x="-7980" y="136"/>
</scene>
<!--Whats New Controller-->
<scene sceneID="tit-8N-P9M">
<objects>
<viewController storyboardIdentifier="WhatsNewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="BOY-Lz-6Ub" customClass="WhatsNewController" customModule="maps_me" customModuleProvider="target" propertyAccessControl="all" sceneMemberID="viewController">
<viewController storyboardIdentifier="WhatsNewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="BOY-Lz-6Ub" customClass="WhatsNewController" customModule="maps_me" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="MhV-XF-2d3" customClass="SolidTouchView">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@ -186,7 +167,7 @@
<rect key="frame" x="16" y="40" width="488" height="456"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="umw-NL-UxH" userLabel="CenteredView">
<rect key="frame" x="44" y="62" width="400" height="333"/>
<rect key="frame" x="44.5" y="62" width="400" height="333"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalCompressionResistancePriority="749" image="ic_placeholder" translatesAutoresizingMaskIntoConstraints="NO" id="oT6-Mu-189">
<rect key="frame" x="80.5" y="0.0" width="240" height="240"/>
@ -197,7 +178,7 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Бронируй отель из приложения" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3d2-EJ-eSS" userLabel="Title">
<rect key="frame" x="0.0" y="260" width="400" height="24"/>
<rect key="frame" x="1" y="260" width="399.5" height="24"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="20"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
@ -207,7 +188,7 @@
</userDefinedRuntimeAttributes>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="При выборе отелей на карте будут отображаться ценовая категория и рейтинг заведения." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Il6-Xw-i2E" userLabel="Text">
<rect key="frame" x="0.0" y="300" width="400" height="33"/>
<rect key="frame" x="1" y="300" width="399.5" height="33"/>
<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="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
@ -245,7 +226,7 @@
</constraints>
</view>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fc6-q2-mnq" userLabel="NotNow">
<rect key="frame" x="140.5" y="516" width="240" height="44"/>
<rect key="frame" x="140" y="516" width="240" height="44"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="4a0-nS-HLp"/>
@ -266,6 +247,9 @@
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="linkBlue"/>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundHighlightedColorName" value="linkBlueHighlighted"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="nextPage" destination="BOY-Lz-6Ub" eventType="touchUpInside" id="lwz-30-RgL"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
@ -320,7 +304,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ftD-7X-i1Z" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3230" y="2742"/>
<point key="canvasLocation" x="-7097" y="136"/>
</scene>
</scenes>
<resources>

View file

@ -1,69 +1,70 @@
import UIKit
fileprivate struct FirstLaunchConfig: WelcomeConfig {
let image: UIImage
let title: String
let text: String
let buttonTitle: String
let requestLocationPermission: Bool
let requestNotificationsPermission: Bool
}
final class FirstLaunchController: MWMViewController, WelcomeProtocol {
final class FirstLaunchController: WelcomeViewController {
static var welcomeConfigs: [WelcomeConfig] = [
WelcomeConfig(image: #imageLiteral(resourceName: "img_onboarding_offline_maps"),
title: "onboarding_offline_maps_title",
text: "onboarding_offline_maps_message",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "img_onboarding_geoposition"),
title: "onboarding_location_title",
text: "onboarding_location_message",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "img_onboarding_notification"),
title: "onboarding_notifications_title",
text: "onboarding_notifications_message",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "img_onboarding_done"),
title: "first_launch_congrats_title",
text: "first_launch_congrats_text",
buttonTitle: "done",
buttonAction: #selector(close)),
]
var pageIndex: Int!
weak var pageController: WelcomePageController!
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var alertTitle: UILabel!
@IBOutlet weak var alertText: UILabel!
@IBOutlet weak var nextPageButton: UIButton!
@IBOutlet weak var containerWidth: NSLayoutConstraint!
@IBOutlet weak var containerHeight: NSLayoutConstraint!
@IBOutlet weak var imageMinHeight: NSLayoutConstraint!
@IBOutlet weak var imageHeight: NSLayoutConstraint!
@IBOutlet weak var titleTopOffset: NSLayoutConstraint!
@IBOutlet weak var titleImageOffset: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
config()
static var welcomeConfigs: [WelcomeConfig] {
return [
FirstLaunchConfig(image: #imageLiteral(resourceName: "img_onboarding_offline_maps"),
title: "onboarding_offline_maps_title",
text: "onboarding_offline_maps_message",
buttonTitle: "whats_new_next_button",
requestLocationPermission: false,
requestNotificationsPermission: false),
FirstLaunchConfig(image: #imageLiteral(resourceName: "img_onboarding_geoposition"),
title: "onboarding_location_title",
text: "onboarding_location_message",
buttonTitle: "whats_new_next_button",
requestLocationPermission: false,
requestNotificationsPermission: false),
FirstLaunchConfig(image: #imageLiteral(resourceName: "img_onboarding_notification"),
title: "onboarding_notifications_title",
text: "onboarding_notifications_message",
buttonTitle: "whats_new_next_button",
requestLocationPermission: true,
requestNotificationsPermission: false),
FirstLaunchConfig(image: #imageLiteral(resourceName: "img_onboarding_done"),
title: "first_launch_congrats_title",
text: "first_launch_congrats_text",
buttonTitle: "done",
requestLocationPermission: false,
requestNotificationsPermission: true)
]
}
override class var key: String { return toString(self) }
static func controllers() -> [FirstLaunchController] {
var result = [FirstLaunchController]()
let sb = UIStoryboard.instance(.welcome)
FirstLaunchController.welcomeConfigs.forEach { (config) in
let vc = sb.instantiateViewController(withIdentifier: toString(self)) as! FirstLaunchController
vc.pageConfig = config
result.append(vc)
}
return result
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateSize()
if pageIndex == 2 {
MWMLocationManager.start()
} else if pageIndex == 3 {
MWMPushNotifications.setup(nil)
if let config = pageConfig as? FirstLaunchConfig {
if config.requestLocationPermission {
MWMLocationManager.start()
}
if config.requestNotificationsPermission {
MWMPushNotifications.setup(nil)
}
}
}
@objc
private func nextPage() {
pageController.nextPage()
}
@objc
private func close() {
pageController.close()
override func close() {
super.close()
MWMFrameworkHelper.processFirstLaunch()
}
}

View file

@ -11,7 +11,7 @@ protocol WelcomePageControllerProtocol {
@objc(MWMWelcomePageController)
final class WelcomePageController: UIPageViewController {
fileprivate var controllers: [UIViewController] = []
private var parentController: WelcomePageControllerProtocol!
private var iPadBackgroundView: SolidTouchView?
@ -34,15 +34,19 @@ final class WelcomePageController: UIPageViewController {
}
@objc static func controller(parent: WelcomePageControllerProtocol) -> WelcomePageController? {
let isFirstSession = Alohalytics.isFirstSession()
let welcomeKey = isFirstSession ? FirstLaunchController.key : WhatsNewController.key
guard UserDefaults.standard.bool(forKey: welcomeKey) == false else { return nil }
let pagesCount = isFirstSession ? FirstLaunchController.pagesCount : WhatsNewController.pagesCount
let id = pagesCount == 1 ? "WelcomePageCurlController" : "WelcomePageScrollController"
let sb = UIStoryboard.instance(.welcome)
let vc = sb.instantiateViewController(withIdentifier: id) as! WelcomePageController
vc.config(parent)
if (!WelcomeViewController.shouldShowWelcome) { return nil }
guard let welcomeControllers = WelcomeViewController.controllers(firstSession: Alohalytics.isFirstSession())
else { return nil }
let vc = WelcomePageController(transitionStyle: welcomeControllers.count > 1 ? .scroll : .pageCurl,
navigationOrientation: .horizontal,
options: [:])
vc.parentController = parent
vc.dataSource = vc
welcomeControllers.forEach { (controller) in
controller.delegate = vc
}
vc.controllers = welcomeControllers
vc.show()
return vc
}
@ -62,32 +66,20 @@ final class WelcomePageController: UIPageViewController {
currentController = controllers.first
}
private func config(_ parent: WelcomePageControllerProtocol) {
parentController = parent
let isFirstSession = Alohalytics.isFirstSession()
let pagesCount = isFirstSession ? FirstLaunchController.pagesCount : WhatsNewController.pagesCount
let welcomeClass: WelcomeProtocolBase.Type = isFirstSession ? FirstLaunchController.self : WhatsNewController.self
(0 ..< pagesCount).forEach {
let vc = welcomeClass.controller($0)
(vc as! WelcomeProtocolBase).pageController = self
controllers.append(vc)
}
dataSource = self
}
func nextPage() {
let welcomeKey = Alohalytics.isFirstSession() ? FirstLaunchController.key : WhatsNewController.key
Statistics.logEvent(kStatEventName(kStatWhatsNew, welcomeKey),
withParameters: [kStatAction: kStatNext])
currentController = pageViewController(self, viewControllerAfter: currentController)
if let controller = currentController as? WelcomeViewController {
Statistics.logEvent(kStatEventName(kStatWhatsNew, type(of: controller).key),
withParameters: [kStatAction: kStatNext])
}
}
func close() {
UserDefaults.standard.set(true, forKey: FirstLaunchController.key)
UserDefaults.standard.set(true, forKey: WhatsNewController.key)
let welcomeKey = Alohalytics.isFirstSession() ? FirstLaunchController.key : WhatsNewController.key
Statistics.logEvent(kStatEventName(kStatWhatsNew, welcomeKey),
WelcomeViewController.shouldShowWelcome = false
if let controller = currentController as? WelcomeViewController {
Statistics.logEvent(kStatEventName(kStatWhatsNew, type(of: controller).key),
withParameters: [kStatAction: kStatClose])
}
iPadBackgroundView?.removeFromSuperview()
view.removeFromSuperview()
removeFromParentViewController()
@ -95,9 +87,10 @@ final class WelcomePageController: UIPageViewController {
}
func show() {
let welcomeKey = Alohalytics.isFirstSession() ? FirstLaunchController.key : WhatsNewController.key
Statistics.logEvent(kStatEventName(kStatWhatsNew, welcomeKey),
withParameters: [kStatAction: kStatOpen])
if let controller = currentController as? WelcomeViewController {
Statistics.logEvent(kStatEventName(kStatWhatsNew, type(of: controller).key),
withParameters: [kStatAction: kStatOpen])
}
parentController.addChildViewController(self)
parentController.view.addSubview(view)
updateFrame()
@ -107,7 +100,7 @@ final class WelcomePageController: UIPageViewController {
let parentView = parentController.view!
view.frame = alternative(iPhone: CGRect(origin: CGPoint(), size: parentView.size),
iPad: CGRect(x: parentView.center.x - 260, y: parentView.center.y - 300, width: 520, height: 600))
(currentController as! WelcomeProtocolBase).updateSize()
(currentController as! WelcomeViewController).updateSize()
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@ -139,3 +132,25 @@ extension WelcomePageController: UIPageViewControllerDataSource {
return controllers.index(of: vc)!
}
}
extension WelcomePageController: WelcomeViewControllerDelegate {
func viewSize() -> CGSize {
return view.size
}
func welcomeViewControllerDidPressNext(_ viewContoller: WelcomeViewController) {
guard let index = controllers.index(of: viewContoller) else {
close()
return
}
if index + 1 < controllers.count {
nextPage()
} else {
close()
}
}
func welcomeViewControllerDidPressClose(_ viewContoller: WelcomeViewController) {
close()
}
}

View file

@ -1,80 +0,0 @@
protocol WelcomeProtocolBase: AnyObject {
static var key: String { get }
var pageIndex: Int! { get set }
var pageController: WelcomePageController! { get set }
func updateSize()
var image: UIImageView! { get set }
var alertTitle: UILabel! { get set }
var alertText: UILabel! { get set }
var nextPageButton: UIButton! { get set }
var containerWidth: NSLayoutConstraint! { get set }
var containerHeight: NSLayoutConstraint! { get set }
var imageMinHeight: NSLayoutConstraint! { get set }
var imageHeight: NSLayoutConstraint! { get set }
var titleTopOffset: NSLayoutConstraint! { get set }
var titleImageOffset: NSLayoutConstraint! { get set }
}
extension WelcomeProtocolBase {
static func controller(_ pageIndex: Int) -> UIViewController {
let sb = UIStoryboard.instance(.welcome)
let vc = sb.instantiateViewController(withIdentifier: toString(self))
(vc as! Self).pageIndex = pageIndex
return vc
}
func setup(image: UIImage, title: String, text: String, buttonTitle: String, buttonAction: Selector) {
self.image.image = image
alertTitle.text = title
alertText.text = text
nextPageButton.setTitle(buttonTitle, for: .normal)
nextPageButton.addTarget(self, action: buttonAction, for: .touchUpInside)
}
func updateSize() {
let size = pageController.view!.size
let (width, height) = (size.width, size.height)
let hideImage = (imageHeight.multiplier * height <= imageMinHeight.constant)
titleImageOffset.priority = hideImage ? UILayoutPriority.defaultLow : UILayoutPriority.defaultHigh
image.isHidden = hideImage
containerWidth.constant = width
containerHeight.constant = height
}
}
struct WelcomeConfig {
let image: UIImage
let title: String
let text: String
let buttonTitle: String
let buttonAction: Selector
}
protocol WelcomeProtocol: WelcomeProtocolBase {
typealias ConfigBlock = (Self) -> Void
static var welcomeConfigs: [WelcomeConfig] { get }
static func configBlock(pageIndex: Int) -> ConfigBlock
func config()
}
extension WelcomeProtocol {
static var key: String { return welcomeConfigs.reduce("\(self)@") { "\($0)\($1.title):" } }
static func configBlock(pageIndex: Int) -> ConfigBlock {
let welcomeConfig = welcomeConfigs[pageIndex]
return {
$0.setup(image: welcomeConfig.image,
title: L(welcomeConfig.title),
text: L(welcomeConfig.text),
buttonTitle: L(welcomeConfig.buttonTitle),
buttonAction: welcomeConfig.buttonAction)
}
}
static var pagesCount: Int { return welcomeConfigs.count }
func config() { type(of: self).configBlock(pageIndex: pageIndex)(self) }
}

View file

@ -0,0 +1,85 @@
protocol WelcomeConfig {
var image: UIImage { get }
var title: String { get }
var text: String { get }
var buttonTitle: String { get }
}
protocol WelcomeViewControllerDelegate: class {
func welcomeViewControllerDidPressNext(_ viewContoller: WelcomeViewController)
func welcomeViewControllerDidPressClose(_ viewContoller: WelcomeViewController)
func viewSize() -> CGSize
}
class WelcomeViewController: MWMViewController {
weak var delegate: WelcomeViewControllerDelegate?
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var alertTitle: UILabel!
@IBOutlet weak var alertText: UILabel!
@IBOutlet weak var nextPageButton: UIButton!
@IBOutlet weak var containerWidth: NSLayoutConstraint!
@IBOutlet weak var containerHeight: NSLayoutConstraint!
@IBOutlet weak var imageMinHeight: NSLayoutConstraint!
@IBOutlet weak var imageHeight: NSLayoutConstraint!
@IBOutlet weak var titleTopOffset: NSLayoutConstraint!
@IBOutlet weak var titleImageOffset: NSLayoutConstraint!
var pageConfig: WelcomeConfig?
class var key: String { return "" }
static var shouldShowWelcome: Bool {
get {
return !UserDefaults.standard.bool(forKey: WhatsNewController.key)
}
set {
UserDefaults.standard.set(!newValue, forKey: WhatsNewController.key)
}
}
static func controllers(firstSession: Bool) -> [WelcomeViewController]? {
let result = firstSession ? FirstLaunchController.controllers() : WhatsNewController.controllers()
return result
}
override func viewDidLoad() {
super.viewDidLoad()
configInternal()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateSize()
}
func updateSize() {
let size = (delegate?.viewSize())!
let (width, height) = (size.width, size.height)
let hideImage = (imageHeight.multiplier * height <= imageMinHeight.constant)
titleImageOffset.priority = hideImage ? UILayoutPriority.defaultLow : UILayoutPriority.defaultHigh
image.isHidden = hideImage
containerWidth.constant = width
containerHeight.constant = height
}
private func configInternal() {
if let config = pageConfig {
image.image = config.image
alertTitle.text = L(config.title)
alertText.text = L(config.text)
nextPageButton.setTitle(L(config.buttonTitle), for: .normal)
}
}
@IBAction func nextPage() {
delegate?.welcomeViewControllerDidPressNext(self)
}
@IBAction func close() {
delegate?.welcomeViewControllerDidPressClose(self)
}
}

View file

@ -1,53 +1,31 @@
import UIKit
fileprivate struct WhatsNewConfig: WelcomeConfig {
let image: UIImage
let title: String
let text: String
let buttonTitle: String
}
final class WhatsNewController: MWMViewController, WelcomeProtocol {
final class WhatsNewController: WelcomeViewController {
static var welcomeConfigs: [WelcomeConfig] = [
WelcomeConfig(image: #imageLiteral(resourceName: "img_wn_reinvented_bookmarks"),
title: "wn_reinvented_bookmarks_title",
text: "wn_reinvented_bookmarks_message",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "img_wn_way_of_booking"),
title: "wn_way_of_booking_title",
text: "wn_way_of_booking_message",
buttonTitle: "done",
buttonAction: #selector(close)),
]
var pageIndex: Int!
weak var pageController: WelcomePageController!
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var alertTitle: UILabel!
@IBOutlet weak var alertText: UILabel!
@IBOutlet weak var nextPageButton: UIButton!
@IBOutlet weak var containerWidth: NSLayoutConstraint!
@IBOutlet weak var containerHeight: NSLayoutConstraint!
@IBOutlet weak var imageMinHeight: NSLayoutConstraint!
@IBOutlet weak var imageHeight: NSLayoutConstraint!
@IBOutlet weak var titleTopOffset: NSLayoutConstraint!
@IBOutlet weak var titleImageOffset: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
config()
static var welcomeConfigs: [WelcomeConfig] {
return [
WhatsNewConfig(image: #imageLiteral(resourceName: "img_wn_business"),
title: "whats_new_localbiz_title",
text: "whats_new_localbiz_message",
buttonTitle: "done")
]
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateSize()
}
@objc
private func nextPage() {
pageController.nextPage()
}
@IBAction
private func close() {
pageController.close()
override class var key: String { return welcomeConfigs.reduce("\(self)", { return "\($0)_\($1.title)" }) }
static func controllers() -> [WelcomeViewController] {
var result = [WelcomeViewController]()
let sb = UIStoryboard.instance(.welcome)
WhatsNewController.welcomeConfigs.forEach { (config) in
let vc = sb.instantiateViewController(withIdentifier: toString(self)) as! WelcomeViewController
vc.pageConfig = config
result.append(vc)
}
return result
}
}