forked from organicmaps/organicmaps
[ios] Fixed non-working my position button due to late callback initialization.
It should be initialized before Drape engine, which copies empty functor otherwise. It worked before due to side effect of calling already deleted reloadPlacePage method.
This commit is contained in:
parent
f4c5429d73
commit
e33e1f961e
7 changed files with 21 additions and 45 deletions
|
@ -28,4 +28,6 @@
|
|||
|
||||
- (void)refreshLayout;
|
||||
|
||||
- (void)processMyPositionStateModeEvent:(location::EMyPositionMode)mode;
|
||||
|
||||
@end
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell)
|
|||
MWMBottomMenuViewCellCount
|
||||
};
|
||||
|
||||
@interface MWMBottomMenuViewController () <UICollectionViewDataSource, UICollectionViewDelegate, MWMFrameworkMyPositionObserver>
|
||||
@interface MWMBottomMenuViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
|
||||
|
||||
@property (weak, nonatomic) MapViewController * controller;
|
||||
@property (weak, nonatomic) IBOutlet UICollectionView * buttonsCollectionView;
|
||||
|
@ -79,7 +79,6 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell)
|
|||
selector:@selector(searchStateWillChange:)
|
||||
name:kSearchStateWillChangeNotification
|
||||
object:nil];
|
||||
[MWMFrameworkListener addObserver:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -166,8 +165,6 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell)
|
|||
self.state = MWMBottomMenuStateGo;
|
||||
}
|
||||
|
||||
#pragma mark - MWMFrameworkMyPositionObserver
|
||||
|
||||
- (void)processMyPositionStateModeEvent:(location::EMyPositionMode)mode
|
||||
{
|
||||
UIButton * locBtn = self.locationButton;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
@property (nonatomic) MWMBottomMenuState menuState;
|
||||
@property (nonatomic, readonly) MWMNavigationDashboardState navigationState;
|
||||
@property (nonatomic, readonly) MWMPlacePageEntity * placePageEntity;
|
||||
@property (nonatomic, readonly) MWMBottomMenuViewController * menuController;
|
||||
@property (nonatomic) BOOL searchHidden;
|
||||
|
||||
- (instancetype)init __attribute__((unavailable("init is not available")));
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#import "MWMFrameworkObservers.h"
|
||||
|
||||
#include "platform/location.hpp"
|
||||
|
||||
@interface MWMFrameworkListener : NSObject
|
||||
|
||||
+ (MWMFrameworkListener *)listener;
|
||||
+ (void)addObserver:(id<MWMFrameworkObserver>)observer;
|
||||
+ (void)removeObserver:(id<MWMFrameworkObserver>)observer;
|
||||
|
||||
@property (nonatomic, readonly) location::EMyPositionMode myPositionMode;
|
||||
@property (nonatomic) location::EMyPositionMode myPositionMode;
|
||||
|
||||
- (instancetype)init __attribute__((unavailable("call +listener instead")));
|
||||
- (instancetype)copy __attribute__((unavailable("call +listener instead")));
|
||||
|
|
|
@ -9,14 +9,12 @@ namespace
|
|||
{
|
||||
using TObserver = id<MWMFrameworkObserver>;
|
||||
using TRouteBuildingObserver = id<MWMFrameworkRouteBuilderObserver>;
|
||||
using TMyPositionObserver = id<MWMFrameworkMyPositionObserver>;
|
||||
using TStorageObserver = id<MWMFrameworkStorageObserver>;
|
||||
using TDrapeObserver = id<MWMFrameworkDrapeObserver>;
|
||||
|
||||
using TObservers = NSHashTable<__kindof TObserver>;
|
||||
|
||||
Protocol * pRouteBuildingObserver = @protocol(MWMFrameworkRouteBuilderObserver);
|
||||
Protocol * pMyPositionObserver = @protocol(MWMFrameworkMyPositionObserver);
|
||||
Protocol * pStorageObserver = @protocol(MWMFrameworkStorageObserver);
|
||||
Protocol * pDrapeObserver = @protocol(MWMFrameworkDrapeObserver);
|
||||
|
||||
|
@ -38,12 +36,9 @@ void loopWrappers(TObservers * observers, TLoopBlock block)
|
|||
@interface MWMFrameworkListener ()
|
||||
|
||||
@property (nonatomic) TObservers * routeBuildingObservers;
|
||||
@property (nonatomic) TObservers * myPositionObservers;
|
||||
@property (nonatomic) TObservers * storageObservers;
|
||||
@property (nonatomic) TObservers * drapeObservers;
|
||||
|
||||
@property (nonatomic, readwrite) location::EMyPositionMode myPositionMode;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MWMFrameworkListener
|
||||
|
@ -63,8 +58,6 @@ void loopWrappers(TObservers * observers, TLoopBlock block)
|
|||
MWMFrameworkListener * listener = [MWMFrameworkListener listener];
|
||||
if ([observer conformsToProtocol:pRouteBuildingObserver])
|
||||
[listener.routeBuildingObservers addObject:observer];
|
||||
if ([observer conformsToProtocol:pMyPositionObserver])
|
||||
[listener.myPositionObservers addObject:observer];
|
||||
if ([observer conformsToProtocol:pStorageObserver])
|
||||
[listener.storageObservers addObject:observer];
|
||||
if ([observer conformsToProtocol:pDrapeObserver])
|
||||
|
@ -78,7 +71,6 @@ void loopWrappers(TObservers * observers, TLoopBlock block)
|
|||
{
|
||||
MWMFrameworkListener * listener = [MWMFrameworkListener listener];
|
||||
[listener.routeBuildingObservers removeObject:observer];
|
||||
[listener.myPositionObservers removeObject:observer];
|
||||
[listener.storageObservers removeObject:observer];
|
||||
[listener.drapeObservers removeObject:observer];
|
||||
});
|
||||
|
@ -90,12 +82,10 @@ void loopWrappers(TObservers * observers, TLoopBlock block)
|
|||
if (self)
|
||||
{
|
||||
_routeBuildingObservers = [TObservers weakObjectsHashTable];
|
||||
_myPositionObservers = [TObservers weakObjectsHashTable];
|
||||
_storageObservers = [TObservers weakObjectsHashTable];
|
||||
_drapeObservers = [TObservers weakObjectsHashTable];
|
||||
|
||||
[self registerRouteBuilderListener];
|
||||
[self registerMyPositionListener];
|
||||
[self registerStorageObserver];
|
||||
[self registerDrapeObserver];
|
||||
}
|
||||
|
@ -132,22 +122,6 @@ void loopWrappers(TObservers * observers, TLoopBlock block)
|
|||
});
|
||||
}
|
||||
|
||||
#pragma mark - MWMFrameworkMyPositionObserver
|
||||
|
||||
- (void)registerMyPositionListener
|
||||
{
|
||||
TObservers * observers = self.myPositionObservers;
|
||||
auto & f = GetFramework();
|
||||
f.SetMyPositionModeListener([self, observers](location::EMyPositionMode mode)
|
||||
{
|
||||
self.myPositionMode = mode;
|
||||
loopWrappers(observers, [mode](TMyPositionObserver observer)
|
||||
{
|
||||
[observer processMyPositionStateModeEvent:mode];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - MWMFrameworkStorageObserver
|
||||
|
||||
- (void)registerStorageObserver
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#include "map/user_mark.hpp"
|
||||
#include "platform/location.hpp"
|
||||
#include "routing/router.hpp"
|
||||
#include "storage/index.hpp"
|
||||
#include "storage/storage_defines.hpp"
|
||||
|
@ -21,12 +19,6 @@ using namespace storage;
|
|||
|
||||
@end
|
||||
|
||||
@protocol MWMFrameworkMyPositionObserver <MWMFrameworkObserver>
|
||||
|
||||
- (void)processMyPositionStateModeEvent:(location::EMyPositionMode)mode;
|
||||
|
||||
@end
|
||||
|
||||
@protocol MWMFrameworkStorageObserver <MWMFrameworkObserver>
|
||||
|
||||
- (void)processCountryEvent:(TCountryId const &)countryId;
|
||||
|
|
|
@ -102,8 +102,7 @@ NSString * const kEditorSegue = @"Map2EditorSegue";
|
|||
@end
|
||||
|
||||
@interface MapViewController ()<MTRGNativeAppwallAdDelegate, MWMFrameworkRouteBuilderObserver,
|
||||
MWMFrameworkMyPositionObserver, MWMFrameworkDrapeObserver,
|
||||
MWMFrameworkStorageObserver>
|
||||
MWMFrameworkDrapeObserver, MWMFrameworkStorageObserver>
|
||||
|
||||
@property (nonatomic, readwrite) MWMMapViewControlsManager * controlsManager;
|
||||
@property (nonatomic) MWMBottomMenuState menuRestoreState;
|
||||
|
@ -492,9 +491,20 @@ NSString * const kEditorSegue = @"Map2EditorSegue";
|
|||
- (void)initialize
|
||||
{
|
||||
Framework & f = GetFramework();
|
||||
|
||||
// TODO: Review and improve this code.
|
||||
f.SetMapSelectionListeners([self](place_page::Info const & info) { [self onMapObjectSelected:info]; },
|
||||
[self](bool switchFullScreen){ [self onMapObjectDeselected:switchFullScreen]; });
|
||||
[self](bool switchFullScreen) { [self onMapObjectDeselected:switchFullScreen]; });
|
||||
// TODO: Review and improve this code.
|
||||
f.SetMyPositionModeListener([self](location::EMyPositionMode mode)
|
||||
{
|
||||
MWMFrameworkListener.listener.myPositionMode = mode;
|
||||
// Two global listeners are subscribed to the same event from the core.
|
||||
// Probably it's better to subscribe only wnen needed and usubscribe in other cases.
|
||||
// May be better solution would be multiobservers support in the C++ core.
|
||||
[self processMyPositionStateModeEvent:mode];
|
||||
[self.controlsManager.menuController processMyPositionStateModeEvent:mode];
|
||||
});
|
||||
|
||||
m_predictor = [[LocationPredictor alloc] initWithObserver:self];
|
||||
self.forceRoutingStateChange = ForceRoutingStateChangeNone;
|
||||
self.userTouchesAction = UserTouchesActionNone;
|
||||
|
@ -532,8 +542,6 @@ NSString * const kEditorSegue = @"Map2EditorSegue";
|
|||
[self performSegueWithIdentifier:kEditorSegue sender:self.controlsManager.placePageEntity];
|
||||
}
|
||||
|
||||
#pragma mark - MWMFrameworkMyPositionObserver
|
||||
|
||||
- (void)processMyPositionStateModeEvent:(location::EMyPositionMode)mode
|
||||
{
|
||||
[m_predictor setMode:mode];
|
||||
|
|
Loading…
Add table
Reference in a new issue