[ios] Discovery additionals.

This commit is contained in:
VladiMihaylenko 2017-12-04 16:46:17 +03:00 committed by Ilya Grechuhin
parent 8ddbacffd5
commit cee591fc40
9 changed files with 111 additions and 10 deletions

View file

@ -27,6 +27,7 @@ static NSString * const kStatApplication = @"Application";
static NSString * const kStatApplicationColdStartupInfo = @"Application_ColdStartup_info";
static NSString * const kStatApply = @"Apply";
static NSString * const kStatAsk = @"Ask";
static NSString * const kStatAttractions = @"Attractions";
static NSString * const kStatAuthorization = @"Authorization";
static NSString * const kStatAutoDownload = @"Auto download";
static NSString * const kStatAutoZoom = @"Autozoom";
@ -76,6 +77,9 @@ static NSString * const kStatDeleteWithChanges = @"delete_with_changes";
static NSString * const kStatDestination = @"Destination";
static NSString * const kStatDeviceInfo = @"Device info";
static NSString * const kStatDeviceType = @"Device type";
static NSString * const kStatDiscoveryButtonItemClick = @"DiscoveryButton_Item_Click";
static NSString * const kStatDiscoveryButtonItemShow = @"DiscoveryButton_Item_Show";
static NSString * const kStatDiscoveryButtonOpen = @"DiscoveryButton_Open";
static NSString * const kStatDownload = @"download";
static NSString * const kStatDownloadGroup = @"download_group";
static NSString * const kStatDownloadMap = @"Download map";
@ -98,6 +102,7 @@ static NSString * const kStatDownloaderOnStartScreenError = @"Downloader_OnStart
static NSString * const kStatDownloaderOnStartScreenManualDownload = @"Downloader_OnStartScreen_manual_download";
static NSString * const kStatDownloaderOnStartScreenSelectLater = @"Downloader_OnStartScreen_select_later";
static NSString * const kStatDownloaderOnStartScreenShow = @"Downloader_OnStartScreen_show";
static NSString * const kStatEatAndDrink = @"Eat and drink";
static NSString * const kStatEdit = @"Edit";
static NSString * const kStatEditTime = @"Edit time";
static NSString * const kStatEditorAddCancel = @"Editor_Add_cancel";
@ -151,6 +156,8 @@ static NSString * const kStatKML = @"KML";
static NSString * const kStatKilometers = @"Kilometers";
static NSString * const kStatLandscape = @"Landscape";
static NSString * const kStatLanguage = @"Language";
static NSString * const kStatLocals = @"Locals";
static NSString * const kStatLocalsProvider = @"locals.maps.me";
static NSString * const kStatLocation = @"Location";
static NSString * const kStatLogout = @"Logout";
static NSString * const kStatMap = @"map";
@ -177,6 +184,7 @@ static NSString * const kStatNever = @"Never";
static NSString * const kStatNext = @"Next";
static NSString * const kStatNightMode = @"NightMode";
static NSString * const kStatNo = @"No";
static NSString * const kStatNone = @"none";
static NSString * const kStatNoConnection = @"no_connection";
static NSString * const kStatNoSpace = @"no_space";
static NSString * const kStatOSM = @"OSM";
@ -220,6 +228,7 @@ static NSString * const kStatPlacepageSponsoredShow = @"Placepage_SponsoredGalle
static NSString * const kStatPlacepageTaxiShow = @"Placepage_Taxi_show";
static NSString * const kStatPointToPoint = @"Point to point";
static NSString * const kStatPortrait = @"Portrait";
static NSString * const kStatPosition = @"position";
static NSString * const kStatPriceCategory = @"price_category";
static NSString * const kStatProblem = @"Problem";
static NSString * const kStatProfile = @"Profile";
@ -300,6 +309,7 @@ static NSString * const kStatTable = @"Table";
static NSString * const kStatTags = @"tags";
static NSString * const kStatTaxi = @"Taxi";
static NSString * const kStatThor = @"Thor";
static NSString * const kStatThingsToDo = @"Things to do";
static NSString * const kStatToLocation = @"to_location";
static NSString * const kStatToMyPosition = @"To my position";
static NSString * const kStatToggleBookmark = @"Toggle bookmark";

View file

@ -7,12 +7,16 @@
#import "MWMCommon.h"
#import "MWMDiscoveryController.h"
#import "MWMMapViewControlsManager.h"
#import "MWMNetworkPolicy.h"
#import "MapViewController.h"
#import "MapsAppDelegate.h"
#import "Statistics.h"
#import "SwiftBridge.h"
#include "Framework.h"
#include "platform/platform.hpp"
extern NSString * const kAlohalyticsTapEventKey;
extern NSString * const kSearchStateKey;
@ -286,8 +290,41 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) {
- (IBAction)discoveryTap
{
// Log event
auto mode = ^MWMDiscoveryMode (BOOL canUseNetwork) {
return canUseNetwork ? MWMDiscoveryModeOnline : MWMDiscoveryModeOffline;
};
auto const connectionType = GetPlatform().ConnectionStatus();
auto connectionKey = ^NSString * (Platform::EConnectionType type)
{
switch (type)
{
case Platform::EConnectionType::CONNECTION_WWAN:
return kStatMobile;
case Platform::EConnectionType::CONNECTION_WIFI:
return kStatWifi;
case Platform::EConnectionType::CONNECTION_NONE:
return kStatNone;
}
} (connectionType);
[Statistics logEvent:kStatDiscoveryButtonOpen
withParameters:@{kStatConnection : connectionKey}];
auto discovery = [MWMDiscoveryController instance];
using namespace network_policy;
auto const canUseNetwork = CanUseNetwork();
if (!canUseNetwork && connectionType == Platform::EConnectionType::CONNECTION_WWAN &&
GetStage() == platform::NetworkPolicy::Stage::Session)
{
[[MWMAlertViewController activeAlertController] presentMobileInternetAlertWithBlock:^{
discovery.mode = mode(CanUseNetwork());
[self.controller.navigationController pushViewController:discovery animated:YES];
}];
return;
}
discovery.mode = mode(canUseNetwork);
[self.controller.navigationController pushViewController:discovery animated:YES];
}

View file

@ -34,6 +34,7 @@ final class DiscoveryCollectionHolderCell: UITableViewCell {
@objc func configSearchLayout() {
let size = Size.search;
cellHeight.constant = size.height;
setNeedsLayout()
collectionView.collectionViewLayout = DiscoveryItemLayout(size: Size.search)
collectionView.register(cellClass: DiscoverySearchCell.self)
}
@ -41,6 +42,7 @@ final class DiscoveryCollectionHolderCell: UITableViewCell {
@objc func configViatorLayout() {
let size = Size.viator;
cellHeight.constant = size.height;
setNeedsLayout()
collectionView.collectionViewLayout = DiscoveryItemLayout(size: Size.viator)
collectionView.register(cellClass: ViatorElement.self)
}

View file

@ -32,11 +32,11 @@ final class DiscoveryOnlineTemplateCell: MWMTableViewCell {
switch type {
case .viator:
title.text = L("Discover_button_viator_loading_title")
subtitle.text = L("Discover_button_viator_loading_subtitle")
title.text = L("preloader_viator_title")
subtitle.text = L("preloader_viator_message")
case .locals:
title.text = L("Discover_button_viator_loading_title")
subtitle.text = L("Discover_button_viator_loading_subtitle")
title.text = L("preloader_locals_title")
subtitle.text = L("preloader_locals_message")
}
spinner.isHidden = !needSpinner

View file

@ -31,7 +31,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="Discover_button_other_loading_title"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="discovery_button_other_loading_message"/>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="regular14"/>
<userDefinedRuntimeAttribute type="string" keyPath="colorName" value="blackSecondaryText"/>
</userDefinedRuntimeAttributes>

View file

@ -1,7 +1,14 @@
#import "MWMViewController.h"
typedef NS_ENUM(NSUInteger, MWMDiscoveryMode)
{
MWMDiscoveryModeOnline,
MWMDiscoveryModeOffline
};
@interface MWMDiscoveryController : MWMViewController
+ (instancetype)instance;
- (void)setMode:(MWMDiscoveryMode)mode;
@end

View file

@ -4,6 +4,7 @@
#import "MWMDiscoveryTapDelegate.h"
#import "MWMRoutePoint+CPP.h"
#import "MWMRouter.h"
#import "Statistics.h"
#import "UIKitCategories.h"
#include "DiscoveryControllerViewModel.hpp"
@ -79,6 +80,7 @@ struct Callback
@property(weak, nonatomic) IBOutlet UITableView * tableView;
@property(nonatomic) MWMDiscoveryTableManager * tableManager;
@property(nonatomic) MWMDiscoveryMode mode;
@end
@ -114,9 +116,14 @@ struct Callback
delegate:self
model:move(callback)];
vector<ItemType> types{ItemType::Viator, ItemType::Attractions, ItemType::Cafes};
auto getTypes = [](MWMDiscoveryMode m) -> vector<ItemType> {
if (m == MWMDiscoveryModeOnline)
return {ItemType::Viator, ItemType::Attractions, ItemType::Cafes};
return {ItemType::Attractions, ItemType::Cafes};
};
vector<ItemType> types = getTypes(self.mode);
[self.tableManager loadItems:types];
// TODO: check connection before ask for viator and local experts
ClientParams p;
p.m_itemTypes = move(types);
GetFramework().Discover(move(p), m_callback,
@ -154,6 +161,13 @@ struct Callback
break;
}
}
auto const categoryAndProvider = StatCategoryAndProvider(type);
[Statistics logEvent:kStatDiscoveryButtonItemClick
withParameters:@{kStatCategory : categoryAndProvider.first,
kStatProvider : categoryAndProvider.second,
kStatDestination : kStatPlacePage,
kStatPosition : @(index + 1)}];
}
- (void)routeToItem:(ItemType const)type atIndex:(size_t const)index
@ -169,6 +183,13 @@ struct Callback
intermediateIndex:0];
[MWMRouter buildToPoint:pt bestRouter:YES];
[self.navigationController popViewControllerAnimated:YES];
auto const categoryAndProvider = StatCategoryAndProvider(type);
[Statistics logEvent:kStatDiscoveryButtonItemClick
withParameters:@{kStatCategory : categoryAndProvider.first,
kStatProvider : categoryAndProvider.second,
kStatDestination : kStatRouting,
kStatPosition : @(index + 1)}];
}
- (void)openURLForItem:(discovery::ItemType const)type

View file

@ -1,12 +1,15 @@
#include "map/discovery/discovery_client_params.hpp"
#include <functional>
#include <utility>
#include <vector>
namespace discovery
{
class DiscoveryControllerViewModel;
}
std::pair<NSString *, NSString *> StatCategoryAndProvider(ItemType const type);
} // namespace discovery
using GetModelCallback = std::function<discovery::DiscoveryControllerViewModel const &()>;

View file

@ -1,5 +1,6 @@
#import "MWMDiscoveryTableManager.h"
#import "MWMDiscoveryTapDelegate.h"
#import "Statistics.h"
#import "SwiftBridge.h"
#include "DiscoveryControllerViewModel.hpp"
@ -21,6 +22,22 @@
#include <utility>
using namespace std;
namespace discovery
{
pair<NSString *, NSString *> StatCategoryAndProvider(ItemType const type)
{
switch (type)
{
case ItemType::Viator: return {kStatThingsToDo, kStatViator};
case ItemType::LocalExperts: return {kStatLocals, kStatLocalsProvider};
case ItemType::Attractions: return {kStatAttractions, kStatSearch};
case ItemType::Cafes: return {kStatEatAndDrink, kStatSearch};
case ItemType::Hotels: ASSERT(false, @""); return {};
}
}
} // namespace discovery
using namespace discovery;
namespace
@ -94,7 +111,6 @@ string GetDistance(m2::PointD const & from, m2::PointD const & to)
[self removeItem:type];
return;
}
m_loadingTypes.erase(remove(m_loadingTypes.begin(), m_loadingTypes.end(), type),
m_loadingTypes.end());
m_failedTypes.erase(remove(m_failedTypes.begin(), m_failedTypes.end(), type),
@ -102,6 +118,11 @@ string GetDistance(m2::PointD const & from, m2::PointD const & to)
auto const position = [self position:type];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:position]]
withRowAnimation:kDefaultRowAnimation];
auto const categoryAndProvider = StatCategoryAndProvider(type);
[Statistics logEvent:kStatDiscoveryButtonItemShow
withParameters:@{kStatCategory : categoryAndProvider.first,
kStatProvider : categoryAndProvider.second}];
}
- (void)errorAtItem:(ItemType const)type