[ios] Editor viral.

This commit is contained in:
VladiMihaylenko 2016-03-24 15:06:08 +03:00
parent 2017f81564
commit 237427e743
15 changed files with 116 additions and 31 deletions

View file

@ -33,7 +33,7 @@
- (void)presentDownloaderNotEnoughSpaceAlert;
- (void)presentDownloaderInternalErrorAlertWithOkBlock:(nonnull TMWMVoidBlock)okBlock cancelBlock:(nonnull TMWMVoidBlock)cancelBlock;
- (void)presentDownloaderNeedUpdateAlertWithOkBlock:(nonnull TMWMVoidBlock)okBlock;
- (void)presentEditorViralAlertWithShareBlock:(nonnull TMWMVoidBlock)share;
- (void)presentEditorViralAlert;
- (void)closeAlertWithCompletion:(nullable TMWMVoidBlock)completion;
- (nonnull instancetype)init __attribute__((unavailable("call -initWithViewController: instead!")));

View file

@ -190,9 +190,9 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController
[self displayAlert:[MWMAlert downloaderNeedUpdateAlertWithOkBlock:okBlock]];
}
- (void)presentEditorViralAlertWithShareBlock:(nonnull TMWMVoidBlock)share
- (void)presentEditorViralAlert
{
[self displayAlert:[MWMAlert editorViralAlertWithShareBlock:share]];
[self displayAlert:[MWMAlert editorViralAlert]];
}
- (void)closeAlertWithCompletion:(nullable TMWMVoidBlock)completion

View file

@ -31,7 +31,7 @@
+ (MWMAlert *)downloaderNotEnoughSpaceAlert;
+ (MWMAlert *)downloaderInternalErrorAlertWithOkBlock:(TMWMVoidBlock)okBlock cancelBlock:(TMWMVoidBlock)cancelBlock;
+ (MWMAlert *)downloaderNeedUpdateAlertWithOkBlock:(TMWMVoidBlock)okBlock;
+ (MWMAlert *)editorViralAlertWithShareBlock:(TMWMVoidBlock)share;
+ (MWMAlert *)editorViralAlert;
- (void)close;
- (void)setNeedsCloseAlertAfterEnterBackground;

View file

@ -151,9 +151,9 @@
return [MWMDefaultAlert downloaderNeedUpdateAlertWithOkBlock:okBlock];
}
+ (MWMAlert *)editorViralAlertWithShareBlock:(TMWMVoidBlock)share
+ (MWMAlert *)editorViralAlert
{
return [MWMEditorViralAlert alertWithShareBlock:share];
return [MWMEditorViralAlert alert];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation

View file

@ -2,6 +2,6 @@
@interface MWMEditorViralAlert : MWMAlert
+ (nonnull instancetype)alertWithShareBlock:(nonnull TMWMVoidBlock)share;
+ (nonnull instancetype)alert;
@end

View file

@ -1,3 +1,6 @@
#import "Common.h"
#import "MWMActivityViewController.h"
#import "MWMAlertViewController.h"
#import "MWMAuthorizationCommon.h"
#import "MWMEditorViralAlert.h"
#import "Statistics.h"
@ -8,34 +11,29 @@
namespace
{
array<NSString *, 3> const kMessages {{L(@"editor_done_dialog_1"), L(@"editor_done_dialog_2"), L(@"editor_done_dialog_3")}};
array<NSString *, 2> const kMessages {{L(@"editor_done_dialog_1"), L(@"editor_done_dialog_2")}};
} // namespace
@interface MWMEditorViralAlert ()
@property (weak, nonatomic) IBOutlet UILabel * message;
@property (copy, nonatomic) TMWMVoidBlock share;
@property (weak, nonatomic) IBOutlet UIButton * shareButton;
@end
@implementation MWMEditorViralAlert
+ (nonnull instancetype)alertWithShareBlock:(nonnull TMWMVoidBlock)share
+ (nonnull instancetype)alert
{
MWMEditorViralAlert * alert = [[[NSBundle mainBundle] loadNibNamed:[MWMEditorViralAlert className] owner:nil options:nil] firstObject];
NSAssert(share, @"Share block can't be nil!");
alert.share = share;
int const index = rand() % kMessages.size();
NSString * message = kMessages[index];
if (index == 1)
{
auto const edits = osm::Editor::Instance().GetStats().m_edits.size();
int const ratingValue = (rand() % 1000) + 1000;
int const rating = ceil(ratingValue / (ceil(edits / 10)));
message = [NSString stringWithFormat:message, edits, rating];
message = [NSString stringWithFormat:message, ratingValue];
}
alert.message.text = message;
NSMutableDictionary <NSString *, NSString *> * info = [@{kStatValue : message} mutableCopy];
if (NSString * un = osm_auth_ios::OSMUserName())
[info setObject:un forKey:kStatOSMUserName];
@ -47,8 +45,9 @@ namespace
- (IBAction)shareTap
{
[Statistics logEvent:kStatEditorSecondTimeShareClick withParameters:@{kStatValue : self.message.text}];
self.share();
MWMActivityViewController * shareVC = [MWMActivityViewController shareControllerForEditorViral];
[self close];
[shareVC presentInParentViewController:self.alertController.ownerViewController anchorView:self.shareButton];
}
- (IBAction)cancelTap

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment version="2048" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<customFonts key="customFonts">
<mutableArray key="HelveticaNeue.ttc">
@ -36,14 +36,14 @@
</userDefinedRuntimeAttributes>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="img_socializing" translatesAutoresizingMaskIntoConstraints="NO" id="m8G-07-Mf3">
<rect key="frame" x="60" y="54" width="160" height="160"/>
<rect key="frame" x="60" y="53" width="160" height="160"/>
<constraints>
<constraint firstAttribute="height" constant="160" id="j6u-9U-ijj"/>
<constraint firstAttribute="width" constant="160" id="zUT-wz-832"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Message" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ffp-Nm-vdI" userLabel="Message">
<rect key="frame" x="20" y="230" width="240" height="20"/>
<rect key="frame" x="20" y="229" width="240" height="20"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="20" id="Zgj-S1-C3z"/>
<constraint firstAttribute="width" constant="240" id="t4I-mS-iNs"/>
@ -57,7 +57,7 @@
</userDefinedRuntimeAttributes>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="G21-zf-Val" userLabel="hDivider">
<rect key="frame" x="0.0" y="270" width="280" height="1"/>
<rect key="frame" x="0.0" y="269" width="280" height="1"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.12" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="3gT-zA-0eH"/>
@ -120,7 +120,7 @@
</button>
</subviews>
<constraints>
<constraint firstItem="Xcl-gD-T7R" firstAttribute="top" secondItem="G21-zf-Val" secondAttribute="bottom" id="0Yv-Ng-AJG"/>
<constraint firstItem="Xcl-gD-T7R" firstAttribute="top" secondItem="G21-zf-Val" secondAttribute="bottom" constant="1" id="0Yv-Ng-AJG"/>
<constraint firstAttribute="width" secondItem="G21-zf-Val" secondAttribute="width" id="AE0-FM-k3r"/>
<constraint firstItem="ffp-Nm-vdI" firstAttribute="top" secondItem="m8G-07-Mf3" secondAttribute="bottom" constant="16" id="Dup-dp-LKY"/>
<constraint firstItem="esF-hg-RBd" firstAttribute="top" secondItem="Xcl-gD-T7R" secondAttribute="bottom" id="HTB-8j-TTM"/>
@ -155,6 +155,7 @@
</constraints>
<connections>
<outlet property="message" destination="ffp-Nm-vdI" id="bXH-zX-hr6"/>
<outlet property="shareButton" destination="Xcl-gD-T7R" id="1Dr-cC-7Ah"/>
</connections>
<point key="canvasLocation" x="305" y="172"/>
</view>

View file

@ -447,16 +447,13 @@ NSString * const kReportSegue = @"Map2ReportSegue";
if (!AuthorizationIsNeedCheck() || [ud objectForKey:kUDViralAlertWasShown] || !AuthorizationHaveCredentials())
return;
if (osm::Editor::Instance().GetStats().m_edits.size() < 2)
if (osm::Editor::Instance().GetStats().m_edits.size() != 2)
return;
if (!Platform::IsConnected())
return;
[self.alertController presentEditorViralAlertWithShareBlock:^
{
}];
[self.alertController presentEditorViralAlert];
[ud setObject:[NSDate date] forKey:kUDViralAlertWasShown];
[ud synchronize];

View file

@ -4,6 +4,8 @@
myPosition:(BOOL)myPosition;
+ (instancetype)shareControllerForPedestrianRoutesToast;
+ (instancetype)shareControllerForEditorViral;
- (void)presentInParentViewController:(UIViewController *)parentVC anchorView:(UIView *)anchorView;
@end

View file

@ -1,4 +1,5 @@
#import "MWMActivityViewController.h"
#import "MWMEditorViralActivityItem.h"
#import "MWMShareLocationActivityItem.h"
#import "MWMSharePedestrianRoutesToastActivityItem.h"
@ -13,11 +14,16 @@
- (instancetype)initWithActivityItem:(id<UIActivityItemSource>)activityItem
{
self = [super initWithActivityItems:@[activityItem] applicationActivities:nil];
return [self initWithActivityItems:@[activityItem]];
}
- (instancetype)initWithActivityItems:(NSArray *)activityItems
{
self = [super initWithActivityItems:activityItems applicationActivities:nil];
if (self)
self.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypeAirDrop, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
UIActivityTypeAirDrop, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
return self;
}
@ -38,6 +44,16 @@
return vc;
}
+ (instancetype)shareControllerForEditorViral
{
MWMEditorViralActivityItem * item = [[MWMEditorViralActivityItem alloc] init];
UIImage * image = [UIImage imageNamed:@"img_sharing_editor"];
MWMActivityViewController * vc = [[self alloc] initWithActivityItems:@[item, image]];
if ([vc respondsToSelector:@selector(popoverPresentationController)])
vc.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
return vc;
}
- (void)presentInParentViewController:(UIViewController *)parentVC anchorView:(UIView *)anchorView
{
self.ownerViewController = parentVC;

View file

@ -0,0 +1,3 @@
@interface MWMEditorViralActivityItem : NSObject <UIActivityItemSource>
@end

View file

@ -0,0 +1,38 @@
#import "MWMEditorViralActivityItem.h"
#include "platform/preferred_languages.hpp"
@implementation MWMEditorViralActivityItem
#pragma mark - UIActivityItemSource
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
{
return @"";
}
- (id)activityViewController:(UIActivityViewController *)activityViewController
itemForActivityType:(NSString *)activityType
{
if ([activityType isEqualToString:UIActivityTypePostToFacebook] ||
[activityType isEqualToString:@"com.facebook.Facebook.ShareExtension"] ||
[activityType.lowercaseString rangeOfString:@"facebook"].length)
{
NSString * url = [NSString stringWithFormat:@"http://maps.me/fb-editor-v1?lang=%@",
@(languages::GetCurrentNorm().c_str())];
return [NSURL URLWithString:url];
}
if ([activityType isEqualToString:UIActivityTypeMail])
return L(@"whatsnew_editor_message_1");
return [NSString stringWithFormat:@"%@\n%@", L(@"editor_sharing_title"), L(@"whatsnew_editor_message_1")];
}
- (NSString *)activityViewController:(UIActivityViewController *)activityViewController
subjectForActivityType:(NSString *)activityType
{
return L(@"editor_sharing_title");
}
@end

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

View file

@ -741,6 +741,8 @@
F6830F111B85F6B900C42AAE /* MWMLanesPanel.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6830F101B85F6B900C42AAE /* MWMLanesPanel.mm */; };
F68E6BD21B8DB7AE0040566D /* MWMRouteHelperPanel.mm in Sources */ = {isa = PBXBuildFile; fileRef = F68E6BD11B8DB7AE0040566D /* MWMRouteHelperPanel.mm */; };
F696CCBB1C2816FB00150DFD /* MyTrackerSDKCorp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F696CCBA1C2816FB00150DFD /* MyTrackerSDKCorp.framework */; };
F6A218491CA3F26800BE2CC6 /* MWMEditorViralActivityItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6A218481CA3F26800BE2CC6 /* MWMEditorViralActivityItem.mm */; };
F6A2184A1CA3F26800BE2CC6 /* MWMEditorViralActivityItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6A218481CA3F26800BE2CC6 /* MWMEditorViralActivityItem.mm */; };
F6A750B91BE8C74400981B41 /* MWMSearchHistoryMyPositionCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6A750B81BE8C74400981B41 /* MWMSearchHistoryMyPositionCell.mm */; };
F6A750BB1BE8C7BA00981B41 /* MWMSearchHistoryMyPositionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F6A750BA1BE8C7BA00981B41 /* MWMSearchHistoryMyPositionCell.xib */; };
F6AD57BA1C87039F00CED368 /* MWMEditorCategoryCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6AD57B91C87039F00CED368 /* MWMEditorCategoryCell.mm */; };
@ -1418,6 +1420,8 @@
F68E6BD01B8DB7AE0040566D /* MWMRouteHelperPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMRouteHelperPanel.h; sourceTree = "<group>"; };
F68E6BD11B8DB7AE0040566D /* MWMRouteHelperPanel.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMRouteHelperPanel.mm; sourceTree = "<group>"; };
F696CCBA1C2816FB00150DFD /* MyTrackerSDKCorp.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MyTrackerSDKCorp.framework; path = MyTracker/MyTrackerSDKCorp.framework; sourceTree = "<group>"; };
F6A218471CA3F26800BE2CC6 /* MWMEditorViralActivityItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMEditorViralActivityItem.h; sourceTree = "<group>"; };
F6A218481CA3F26800BE2CC6 /* MWMEditorViralActivityItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMEditorViralActivityItem.mm; sourceTree = "<group>"; };
F6A750B71BE8C74400981B41 /* MWMSearchHistoryMyPositionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMSearchHistoryMyPositionCell.h; sourceTree = "<group>"; };
F6A750B81BE8C74400981B41 /* MWMSearchHistoryMyPositionCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMSearchHistoryMyPositionCell.mm; sourceTree = "<group>"; };
F6A750BA1BE8C7BA00981B41 /* MWMSearchHistoryMyPositionCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMSearchHistoryMyPositionCell.xib; sourceTree = "<group>"; };
@ -1850,6 +1854,8 @@
340837151B72451A00B5C185 /* MWMShareLocationActivityItem.mm */,
347BAC6C1B736BA70010FF78 /* MWMSharePedestrianRoutesToastActivityItem.h */,
347BAC6D1B736BA70010FF78 /* MWMSharePedestrianRoutesToastActivityItem.mm */,
F6A218471CA3F26800BE2CC6 /* MWMEditorViralActivityItem.h */,
F6A218481CA3F26800BE2CC6 /* MWMEditorViralActivityItem.mm */,
);
path = Share;
sourceTree = "<group>";
@ -3714,6 +3720,7 @@
ED48BBBA17C2B1E2003E7E92 /* CircleView.mm in Sources */,
340E10631B949D1900D975D5 /* MWMSearchBookmarksManager.mm in Sources */,
34D15BA81BD8F93C00C8BCBE /* AddSetTableViewCell.mm in Sources */,
F6A218491CA3F26800BE2CC6 /* MWMEditorViralActivityItem.mm in Sources */,
34679F3D1C92FE3700114F20 /* MWMWhatsNewDownloaderEditorController.mm in Sources */,
34CFFE901B7DE83D009D0C9F /* MWMSearchView.mm in Sources */,
F62F1D951C3281F1006CF38E /* UIImageView+Coloring.mm in Sources */,
@ -3930,6 +3937,7 @@
6741AA2B1BF340DE002C974C /* CircleView.mm in Sources */,
56D545631C74A41900E3719C /* Framework.cpp in Sources */,
6741AA2C1BF340DE002C974C /* MWMSearchBookmarksManager.mm in Sources */,
F6A2184A1CA3F26800BE2CC6 /* MWMEditorViralActivityItem.mm in Sources */,
34679F3E1C92FE3700114F20 /* MWMWhatsNewDownloaderEditorController.mm in Sources */,
6741AA2D1BF340DE002C974C /* AddSetTableViewCell.mm in Sources */,
6741AA2E1BF340DE002C974C /* MWMSearchView.mm in Sources */,