Skip to content

Commit

Permalink
Move applicationModeChangedObservable from appData
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-osm committed Jul 23, 2024
1 parent bdda83f commit 19c30ab
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Sources/AppHost/OsmAndAppImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ - (instancetype) init
[defaults registerDefaults:defResetSettings];
NSDictionary *defResetRouting = [NSDictionary dictionaryWithObject:@"NO" forKey:@"reset_routing"];
[defaults registerDefaults:defResetRouting];

_applicationModeChangedObservable = [[OAObservable alloc] init];
}
return self;
}
Expand Down Expand Up @@ -426,6 +428,7 @@ - (BOOL) initializeImpl

// Unpack app data
_data = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:kAppData]];
[_data postInit];

settings.simulateNavigation = NO;
settings.simulateNavigationMode = [OASimulationMode toKey:EOASimulationModePreview];
Expand Down Expand Up @@ -1197,6 +1200,7 @@ - (void) setMapMode:(OAMapMode)mapMode
}

@synthesize mapModeObservable = _mapModeObservable;
@synthesize applicationModeChangedObservable = _applicationModeChangedObservable;

@synthesize gpxCollectionChangedObservable = _gpxCollectionChangedObservable;
@synthesize gpxChangedObservable = _gpxChangedObservable;
Expand Down
1 change: 1 addition & 0 deletions Sources/AppHost/OsmAndAppProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
@property(nonatomic) OAMapMode mapMode;
@property(nonatomic) OAMapMode prevMapMode;
@property(readonly) OAObservable* mapModeObservable;
@property(readonly) OAObservable* applicationModeChangedObservable;

@property(nonatomic) OAMapViewState* initialURLMapState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ - (void)initView
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productsRestored:) name:OAIAPProductsRestoredNotification object:nil];
_applicationModeObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onApplicationModeChanged)
andObserve:_app.data.applicationModeChangedObservable];
andObserve:_app.applicationModeChangedObservable];
}

- (void)deinitView
Expand Down
2 changes: 1 addition & 1 deletion Sources/Controllers/Map/Layers/OATerrainMapLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void) initLayer

_applicationModeChangedObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onAppModeChanged)
andObserve:[OsmAndApp instance].data.applicationModeChangedObservable];
andObserve:OsmAndApp.instance.applicationModeChangedObservable];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onProfileSettingSet:)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Controllers/Map/OAMapHudViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ - (void) commonInit
_applicaionModeObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onApplicationModeChanged:)
andObserve:[OsmAndApp instance].data.applicationModeChangedObservable];
andObserve:[OsmAndApp instance].applicationModeChangedObservable];
_weatherSettingsChangeObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onWeatherSettingsChange:withKey:andValue:)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Controllers/Map/OAMapViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ - (void) commonInit

_applicationModeChangedObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onAppModeChanged)
andObserve:[OsmAndApp instance].data.applicationModeChangedObservable];
andObserve:[OsmAndApp instance].applicationModeChangedObservable];

_mapZoomObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onMapZoomChanged:withKey:andValue:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ - (void)viewDidLoad
andObserve:[OARootViewController instance].mapPanel.mapViewController.elevationAngleObservable];
_applicationModeObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onApplicationModeChanged)
andObserve:[OsmAndApp instance].data.applicationModeChangedObservable];
andObserve:[OsmAndApp instance].applicationModeChangedObservable];
_actionsChangedObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onQuickActionButtonChanged:withKey:)
andObserve:[OAMapButtonsHelper sharedInstance].quickActionsChangedObservable];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ - (void) updateCopiedOrResetPrefs
[[OARootViewController instance].mapPanel recreateAllControls];
[OAMapStyleSettings.sharedInstance loadParameters];
[[[OsmAndApp instance] mapSettingsChangeObservable] notifyEvent];
[[[OsmAndApp instance].data applicationModeChangedObservable] notifyEventWithKey:nil];
[OsmAndApp.instance.applicationModeChangedObservable notifyEventWithKey:nil];
[self updateView];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ - (void)registerObservers
andObserve:[OsmAndApp instance].availableAppModesChangedObservable]];
[self addObserver:[[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onAvailableAppModesChanged)
andObserve:OsmAndApp.instance.data.applicationModeChangedObservable]];
andObserve:OsmAndApp.instance.applicationModeChangedObservable]];
}

#pragma mark - UIViewController
Expand Down
2 changes: 1 addition & 1 deletion Sources/Data/OAAppData.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static const NSInteger kSlopeDefMaxZoom = 16;
@property (nonatomic) OARTargetPoint *pointToNavigateBackup;
@property (nonatomic) NSMutableArray<OARTargetPoint *> *intermediatePointsBackup;

@property (readonly) OAObservable* applicationModeChangedObservable;
- (void) postInit;

- (void) clearPointToStart;
- (void) clearPointToNavigate;
Expand Down
16 changes: 11 additions & 5 deletions Sources/Data/OAAppData.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ @implementation OAAppData
OACommonBoolean *_weatherWindAnimationUnitAutoProfile;
}

@synthesize applicationModeChangedObservable = _applicationModeChangedObservable, mapLayersConfiguration = _mapLayersConfiguration, weatherSettingsChangeObservable = _weatherSettingsChangeObservable;
@synthesize mapLayersConfiguration = _mapLayersConfiguration, weatherSettingsChangeObservable = _weatherSettingsChangeObservable;

- (instancetype) init
{
Expand Down Expand Up @@ -265,10 +265,6 @@ - (void) commonInit

_wikipediaChangeObservable = [[OAObservable alloc] init];

_applicationModeChangedObservable = [[OAObservable alloc] init];
_applicationModeChangedObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onAppModeChanged)
andObserve:_applicationModeChangedObservable];
_mapLayersConfiguration = [[OAMapLayersConfiguration alloc] init];
// Profile settings
_lastMapSourceProfile = [OACommonMapSource withKey:kLastMapSourceKey defValue:[[OAMapSource alloc] initWithResource:@"default.render.xml"
Expand Down Expand Up @@ -445,6 +441,16 @@ - (void) dealloc
}
}

- (void) postInit
{
if (!_applicationModeChangedObserver)
{
_applicationModeChangedObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onAppModeChanged)
andObserve:OsmAndApp.instance.applicationModeChangedObservable];
}
}

- (void) onAppModeChanged
{
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down
2 changes: 1 addition & 1 deletion Sources/Helpers/OAAppSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -5016,7 +5016,7 @@ - (void)setApplicationModePref:(OAApplicationMode *)applicationMode markAsLastUs
if (markAsLastUsed)
[_lastUsedApplicationMode set:applicationMode.stringKey];
[[ThemeManager shared] configureWithAppMode: applicationMode];
[[[OsmAndApp instance].data applicationModeChangedObservable] notifyEventWithKey:prevAppMode];
[OsmAndApp.instance.applicationModeChangedObservable notifyEventWithKey:prevAppMode];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Helpers/ScreenOrientationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ScreenOrientationHelper : NSObject {

let app: OsmAndAppProtocol = OsmAndApp.swiftInstance()
let applicationModeChangedSelector = #selector(onApplicationModeChanged as () -> Void)
applicationModeChangedObserver = OAAutoObserverProxy(self, withHandler: applicationModeChangedSelector, andObserve: app.data.applicationModeChangedObservable)
applicationModeChangedObserver = OAAutoObserverProxy(self, withHandler: applicationModeChangedSelector, andObserve: app.applicationModeChangedObservable)
}

deinit {
Expand Down
2 changes: 1 addition & 1 deletion Sources/POI/OAPOIFiltersHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ - (instancetype)init

_applicationModeObserver = [[OAAutoObserverProxy alloc] initWith:self
withHandler:@selector(onApplicationModeChanged)
andObserve:OsmAndApp.instance.data.applicationModeChangedObservable];
andObserve:OsmAndApp.instance.applicationModeChangedObservable];
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ - (void)disable
- (void)setEnabled:(BOOL)enabled
{
[super setEnabled:enabled];
[[OARootViewController instance] updateLeftPanelMenu];
if (OsmAndApp.instance.initialized)
dispatch_async(dispatch_get_main_queue(), ^{
[[OARootViewController instance] updateLeftPanelMenu];
});
}

- (BOOL)isEnabled
Expand Down

0 comments on commit 19c30ab

Please sign in to comment.