[iOS] reload routes gallery when requested by core

This commit is contained in:
Aleksey Belousov 2020-06-04 18:52:53 +03:00 committed by Vladimir Byko-Ianko
parent 72eae517c4
commit c0d5c5b55e
13 changed files with 46 additions and 111 deletions

View file

@ -14,11 +14,8 @@
470016082342541100EBF03D /* MWMTagGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 470016052342541000EBF03D /* MWMTagGroup.m */; };
4700160F2342579000EBF03D /* MWMTag.h in Headers */ = {isa = PBXBuildFile; fileRef = 470016042342540F00EBF03D /* MWMTag.h */; settings = {ATTRIBUTES = (Public, ); }; };
470016102342579200EBF03D /* MWMTagGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = 470016032342540E00EBF03D /* MWMTagGroup.h */; settings = {ATTRIBUTES = (Public, ); }; };
470B3620244DD9E400C0EA9E /* GuidesGalleryData.h in Headers */ = {isa = PBXBuildFile; fileRef = 470B361E244DD9E400C0EA9E /* GuidesGalleryData.h */; settings = {ATTRIBUTES = (Public, ); }; };
470B3621244DD9E400C0EA9E /* GuidesGalleryData.mm in Sources */ = {isa = PBXBuildFile; fileRef = 470B361F244DD9E400C0EA9E /* GuidesGalleryData.mm */; };
470B3624244DDA0A00C0EA9E /* GuidesGalleryItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 470B3622244DDA0A00C0EA9E /* GuidesGalleryItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
470B3625244DDA0A00C0EA9E /* GuidesGalleryItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 470B3623244DDA0A00C0EA9E /* GuidesGalleryItem.mm */; };
470B3628244DDA2600C0EA9E /* GuidesGalleryData+Core.h in Headers */ = {isa = PBXBuildFile; fileRef = 470B3626244DDA2600C0EA9E /* GuidesGalleryData+Core.h */; };
470B362C244DDBF600C0EA9E /* GuidesGalleryItem+Core.h in Headers */ = {isa = PBXBuildFile; fileRef = 470B362A244DDBF600C0EA9E /* GuidesGalleryItem+Core.h */; };
4718C4322355FC3C00640DF1 /* MWMNetworkPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4718C4302355FC3C00640DF1 /* MWMNetworkPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; };
4718C4332355FC3C00640DF1 /* MWMNetworkPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4718C4312355FC3C00640DF1 /* MWMNetworkPolicy.mm */; };
@ -153,11 +150,8 @@
470016062342541100EBF03D /* MWMTag.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MWMTag.m; sourceTree = "<group>"; };
4700161223425CFD00EBF03D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
470016142342633D00EBF03D /* CoreApi.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = CoreApi.modulemap; sourceTree = "<group>"; };
470B361E244DD9E400C0EA9E /* GuidesGalleryData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GuidesGalleryData.h; sourceTree = "<group>"; };
470B361F244DD9E400C0EA9E /* GuidesGalleryData.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GuidesGalleryData.mm; sourceTree = "<group>"; };
470B3622244DDA0A00C0EA9E /* GuidesGalleryItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GuidesGalleryItem.h; sourceTree = "<group>"; };
470B3623244DDA0A00C0EA9E /* GuidesGalleryItem.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GuidesGalleryItem.mm; sourceTree = "<group>"; };
470B3626244DDA2600C0EA9E /* GuidesGalleryData+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GuidesGalleryData+Core.h"; sourceTree = "<group>"; };
470B362A244DDBF600C0EA9E /* GuidesGalleryItem+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GuidesGalleryItem+Core.h"; sourceTree = "<group>"; };
4718C4302355FC3C00640DF1 /* MWMNetworkPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMNetworkPolicy.h; sourceTree = "<group>"; };
4718C4312355FC3C00640DF1 /* MWMNetworkPolicy.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMNetworkPolicy.mm; sourceTree = "<group>"; };
@ -370,9 +364,6 @@
470B361D244DD98B00C0EA9E /* GuidesGallery */ = {
isa = PBXGroup;
children = (
470B361E244DD9E400C0EA9E /* GuidesGalleryData.h */,
470B3626244DDA2600C0EA9E /* GuidesGalleryData+Core.h */,
470B361F244DD9E400C0EA9E /* GuidesGalleryData.mm */,
470B3622244DDA0A00C0EA9E /* GuidesGalleryItem.h */,
470B362A244DDBF600C0EA9E /* GuidesGalleryItem+Core.h */,
470B3623244DDA0A00C0EA9E /* GuidesGalleryItem.mm */,
@ -696,7 +687,6 @@
47942D74237CC41A00DEFAE3 /* HotelBookingData.h in Headers */,
479F705F234FBB8F00011E2E /* MWMCategory.h in Headers */,
47EF73F9246E035C00D32AB8 /* MWMGuidesManager.h in Headers */,
470B3620244DD9E400C0EA9E /* GuidesGalleryData.h in Headers */,
471AB99123AB931000F56D49 /* MWMMapSearchResult+Core.h in Headers */,
4738A8E0239FACE7007C0F43 /* CoreBanner.h in Headers */,
47942D6D237CC3E300DEFAE3 /* PlacePagePreviewData.h in Headers */,
@ -736,7 +726,6 @@
47942D6E237CC3E800DEFAE3 /* PlacePagePreviewData+Core.h in Headers */,
4738A8E4239FB46E007C0F43 /* CoreBanner+Core.h in Headers */,
47942D7B237CC41A00DEFAE3 /* HotelRoom+Core.h in Headers */,
470B3628244DDA2600C0EA9E /* GuidesGalleryData+Core.h in Headers */,
47942D94237D673E00DEFAE3 /* CatalogPromoItem.h in Headers */,
470016102342579200EBF03D /* MWMTagGroup.h in Headers */,
47942D87237CC55800DEFAE3 /* MWMOpeningHoursCommon.h in Headers */,
@ -891,7 +880,6 @@
47E8163623B1889C008FD836 /* MWMStorage.mm in Sources */,
9957FAE9237AE5B000855F48 /* Logger.mm in Sources */,
999D3A65237B097C00C5F7A8 /* DeepLinkSubscriptionData.mm in Sources */,
470B3621244DD9E400C0EA9E /* GuidesGalleryData.mm in Sources */,
47942D7C237CC41A00DEFAE3 /* HotelRoom.mm in Sources */,
47942D76237CC41A00DEFAE3 /* HotelBookingData.mm in Sources */,
);

View file

@ -56,5 +56,4 @@ FOUNDATION_EXPORT const unsigned char CoreApiVersionString[];
#import <CoreApi/ElevationProfileData.h>
#import <CoreApi/OpeningHours.h>
#import <CoreApi/IOpeningHoursLocalization.h>
#import <CoreApi/GuidesGalleryData.h>
#import <CoreApi/GuidesGalleryItem.h>

View file

@ -1,5 +1,7 @@
#import <Foundation/Foundation.h>
@class GuidesGalleryItem;
NS_ASSUME_NONNULL_BEGIN
typedef void(^GalleryChangedBlock)(bool reloadGallery);
@ -9,6 +11,7 @@ NS_SWIFT_NAME(GuidesManager)
+ (instancetype)sharedManager;
- (NSString *)activeGuideId;
- (NSArray<GuidesGalleryItem *> *)galleryItems;
- (void)setActiveGuide:(NSString *)guideId;
- (void)setGalleryChangedCallback:(GalleryChangedBlock)callback;
- (void)resetGalleryChangedCallback;

View file

@ -1,4 +1,5 @@
#import "MWMGuidesManager.h"
#import "GuidesGalleryItem+Core.h"
#include "Framework.h"
@ -19,6 +20,24 @@ static GuidesManager & guidesManager() { return GetFramework().GetGuidesManager(
return manager;
}
- (NSArray<GuidesGalleryItem *> *)galleryItems {
auto const &guidesGallery = guidesManager().GetGallery();
NSMutableArray *itemsArray = [NSMutableArray arrayWithCapacity:guidesGallery.m_items.size()];
for (auto const &item : guidesGallery.m_items) {
GuidesGalleryItem *galleryItem;
switch (item.m_type) {
case GuidesManager::GuidesGallery::Item::Type::City:
galleryItem = [[CityGalleryItem alloc] initWithGuidesGalleryItem:item];
break;
case GuidesManager::GuidesGallery::Item::Type::Outdoor:
galleryItem = [[OutdoorGalleryItem alloc] initWithGuidesGalleryItem:item];
break;
}
[itemsArray addObject:galleryItem];
}
return [itemsArray copy];
}
- (NSString *)activeGuideId {
return @(guidesManager().GetActiveGuide().c_str());
}

View file

@ -1,14 +0,0 @@
#import "GuidesGalleryData.h"
#include <CoreApi/Framework.h>
NS_ASSUME_NONNULL_BEGIN
@interface GuidesGalleryData (Core)
- (instancetype)initWithGuidesGallery:(GuidesManager::GuidesGallery const &)guidesGallery
activeGuideId:(NSString *)activeGuideId;
@end
NS_ASSUME_NONNULL_END

View file

@ -1,14 +0,0 @@
#import <Foundation/Foundation.h>
@class GuidesGalleryItem;
NS_ASSUME_NONNULL_BEGIN
@interface GuidesGalleryData : NSObject
@property(nonatomic, readonly) NSArray<GuidesGalleryItem *> *galleryItems;
@property(nonatomic, readonly) NSString *activeGuideId;
@end
NS_ASSUME_NONNULL_END

View file

@ -1,33 +0,0 @@
#import "GuidesGalleryData+Core.h"
#import "GuidesGalleryItem+Core.h"
@implementation GuidesGalleryData
@end
@implementation GuidesGalleryData (Core)
- (instancetype)initWithGuidesGallery:(GuidesManager::GuidesGallery const &)guidesGallery
activeGuideId:(NSString *)activeGuideId {
self = [super init];
if (self) {
NSMutableArray *itemsArray = [NSMutableArray arrayWithCapacity:guidesGallery.m_items.size()];
for (auto const &item : guidesGallery.m_items) {
GuidesGalleryItem *galleryItem;
switch (item.m_type) {
case GuidesManager::GuidesGallery::Item::Type::City:
galleryItem = [[CityGalleryItem alloc] initWithGuidesGalleryItem:item];
break;
case GuidesManager::GuidesGallery::Item::Type::Outdoor:
galleryItem = [[OutdoorGalleryItem alloc] initWithGuidesGalleryItem:item];
break;
}
[itemsArray addObject:galleryItem];
}
_galleryItems = [itemsArray copy];
_activeGuideId = [activeGuideId copy];
}
return self;
}
@end

View file

@ -12,7 +12,6 @@
@class HotelRooms;
@class UgcData;
@class ElevationProfileData;
@class GuidesGalleryData;
@class MWMMapNodeAttributes;
typedef NS_ENUM(NSInteger, PlacePageSponsoredType) {
@ -64,7 +63,6 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly, nullable) HotelRooms *hotelRooms;
@property(nonatomic, readonly, nullable) UgcData *ugcData;
@property(nonatomic, readonly, nullable) ElevationProfileData *elevationProfileData;
@property(nonatomic, readonly, nullable) GuidesGalleryData *guidesGalleryData;
@property(nonatomic, readonly, nullable) MWMMapNodeAttributes *mapNodeAttributes;
@property(nonatomic, readonly, nullable) NSString *bookingSearchUrl;
@property(nonatomic, readonly) BOOL isLargeToponim;

View file

@ -9,7 +9,6 @@
#import "HotelRooms+Core.h"
#import "UgcData+Core.h"
#import "ElevationProfileData+Core.h"
#import "GuidesGalleryData+Core.h"
#import "MWMMapNodeAttributes.h"
#include <CoreApi/CoreApi.h>
@ -151,13 +150,6 @@ static PlacePageRoadType convertRoadType(RoadWarningMarkType roadType) {
_previewData = [[PlacePagePreviewData alloc] initWithRawData:rawData()];
}
if (rawData().IsGuide()) {
auto const &gm = GetFramework().GetGuidesManager();
auto const &galleryData = gm.GetGallery();
NSString *activeGuideId = @(gm.GetActiveGuide().c_str());
_guidesGalleryData = [[GuidesGalleryData alloc] initWithGuidesGallery:galleryData activeGuideId:activeGuideId];
}
auto const &countryId = rawData().GetCountryId();
if (!countryId.empty()) {
_mapNodeAttributes = [[MWMStorage sharedStorage] attributesForCountry:@(rawData().GetCountryId().c_str())];

View file

@ -1,15 +1,10 @@
@objc(MWMGuidesGalleryBuilder)
final class GuidesGalleryBuilder: NSObject {
@objc static func build() -> GuidesGalleryViewController {
let placePageData = PlacePageData(localizationProvider: OpeinigHoursLocalization())
guard let guidesGalleryData = placePageData.guidesGalleryData else {
fatalError()
}
let storyboard = UIStoryboard.instance(.placePage)
let viewController = storyboard.instantiateViewController(ofType: GuidesGalleryViewController.self);
let router = GuidesGalleryRouter(MapViewController.shared())
let interactor = GuidesGalleryInteractor(guidesGalleryData)
let interactor = GuidesGalleryInteractor()
let presenter = GuidesGalleryPresenter(view: viewController, router: router, interactor: interactor)
viewController.presenter = presenter
return viewController

View file

@ -11,15 +11,12 @@ protocol IGuidesGalleryInteractor {
}
final class GuidesGalleryInteractor {
private var guidesGallery: GuidesGalleryData
init(_ guidesGallery: GuidesGalleryData) {
self.guidesGallery = guidesGallery
}
}
extension GuidesGalleryInteractor: IGuidesGalleryInteractor {
func galleryItems() -> [GuidesGalleryItem] {
guidesGallery.galleryItems
GuidesManager.shared().galleryItems()
}
func toggleItemVisibility(_ item: GuidesGalleryItem) {

View file

@ -50,22 +50,10 @@ final class GuidesGalleryPresenter {
}
return model
}
}
extension GuidesGalleryPresenter: IGuidesGalleryPresenter {
func viewDidLoad() {
private func reloadGallery() {
galleryItems = interactor.galleryItems()
interactor.setGalleryChangedCallback { [weak self] (reloadGallery) in
self?.setActiveItem()
}
view.setGalleryItems(galleryItems.map({ makeViewModel($0) }))
setActiveItem()
Statistics.logEvent(kStatPlacepageSponsoredShow, withParameters: [kStatProvider : kStatMapsmeGuides,
kStatPlacement : kStatMap,
kStatState : kStatOnline,
kStatCount : galleryItems.count])
}
private func setActiveItem() {
@ -87,6 +75,26 @@ extension GuidesGalleryPresenter: IGuidesGalleryPresenter {
kStatId : item.guideId],
with: .realtime)
}
}
extension GuidesGalleryPresenter: IGuidesGalleryPresenter {
func viewDidLoad() {
reloadGallery()
setActiveItem()
interactor.setGalleryChangedCallback { [weak self] (reloadGallery) in
if reloadGallery {
self?.reloadGallery()
}
self?.setActiveItem()
}
Statistics.logEvent(kStatPlacepageSponsoredShow, withParameters: [kStatProvider : kStatMapsmeGuides,
kStatPlacement : kStatMap,
kStatState : kStatOnline,
kStatCount : galleryItems.count])
}
func selectItemAtIndex(_ index: Int) {
let galleryItem = galleryItems[index]

View file

@ -76,9 +76,6 @@ extension GuidesGalleryViewController: IGuidesGalleryView {
func setGalleryItems(_ items: [IGuidesGalleryItemViewModel]) {
galleryItems = items
collectionView.reloadData()
collectionView.performBatchUpdates(nil) { [weak self] _ in
self?.applyTransform()
}
}
func setActiveItem(_ index: Int, animated: Bool) {