Skip to content

Commit 1cf28ef

Browse files
authored
Merge pull request #4076 from osmandapp/sharedLib_refactoring
Shared lib refactoring
2 parents e661321 + aa0d889 commit 1cf28ef

File tree

230 files changed

+6729
-7903
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+6729
-7903
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ xcuserdata
1111
# Dependencies via CocoaPods
1212
/Podfile.lock
1313
/Pods
14+
/Libraries/Charts/build
1415

1516
*.xcscmblueprint
1617
/build

OsmAnd.xcodeproj/project.pbxproj

Lines changed: 43 additions & 31 deletions
Large diffs are not rendered by default.

OsmAnd.xcworkspace/contents.xcworkspacedata

Lines changed: 243 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/AppHost/OAAppDelegate.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ - (void)invalidateIfNeededCheckUpdatesTimer
277277
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
278278
{
279279
_didFinishLaunching = YES;
280+
280281
if (!_dataFetchQueue)
281282
{
282283
// Set the background fetch

Sources/AppHost/OsmAndAppImpl.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,6 @@ - (BOOL) initializeImpl
556556
}
557557
if (prevVersion < VERSION_4_2)
558558
{
559-
[OAGPXDatabase.sharedDb save];
560-
[OAGPXDatabase.sharedDb load];
561-
562559
NSError *error;
563560
NSArray *inboxFiles = [NSFileManager.defaultManager contentsOfDirectoryAtPath:_inboxPath error:&error];
564561
if (!error)
@@ -704,6 +701,7 @@ - (BOOL) initializeImpl
704701

705702
[[OATargetPointsHelper sharedInstance] removeAllWayPoints:NO clearBackup:NO];
706703

704+
[[OASGpxDbHelper shared] loadItemsBlocking];
707705
// Init track recorder
708706
[OASavingTrackHelper sharedInstance];
709707

Sources/AppHost/OsmAndSharedWrapper.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// OsmAndSharedWrapper.h
3+
// OsmAnd
4+
//
5+
// Created by Oleksandr Panchenko on 04.09.2024.
6+
// Copyright © 2024 OsmAnd. All rights reserved.
7+
//
8+
9+
#ifdef emit
10+
#pragma push_macro("emit")
11+
#undef emit
12+
#define EMIT_WAS_DEFINED 1
13+
#endif
14+
#define emit emit_renamed
15+
16+
#import <OsmAndShared/OsmAndShared.h>
17+
18+
#undef emit
19+
#ifdef EMIT_WAS_DEFINED
20+
#pragma pop_macro("emit")
21+
#undef EMIT_WAS_DEFINED
22+
#endif

Sources/Backup/LocalBackup/SettingsItems/OAFavoritesSettingsItem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import "OACollectionSettingsItem.h"
1010

11-
@class OAFavoriteItem, OAFavoriteGroup, OAWptPt;
11+
@class OAFavoriteItem, OAFavoriteGroup, OASWptPt;
1212

1313
@interface OAFavoritesSettingsItem : OACollectionSettingsItem<OAFavoriteGroup *>
1414

Sources/Backup/LocalBackup/SettingsItems/OAFavoritesSettingsItem.mm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#import "OAFavoritesSettingsItem.h"
1010
#import "OAAppSettings.h"
11-
#import "OAGPXDocument.h"
1211
#import "OASelectedGPXHelper.h"
1312
#import "OsmAndApp.h"
1413
#import "OAFavoriteItem.h"
@@ -18,6 +17,7 @@
1817
#import "OAIndexConstants.h"
1918
#import "OAPluginsHelper.h"
2019
#import "Localization.h"
20+
#import "OsmAndSharedWrapper.h"
2121

2222
#define APPROXIMATE_FAVOURITE_SIZE_BYTES 470
2323

@@ -265,8 +265,8 @@ - (OASettingsItemReader *) getReader
265265

266266
- (OASettingsItemWriter *)getWriter
267267
{
268-
OAGPXMutableDocument *doc = [OAFavoritesHelper asGpxFile:self.items];
269-
return [self getGpxWriter:(OAGPXDocument *) doc];
268+
OASGpxFile *gpxFile = [OAFavoritesHelper asGpxFile:self.items];
269+
return [self getGpxWriter:gpxFile];
270270
}
271271

272272
@end
@@ -285,11 +285,12 @@ - (BOOL) readFromFile:(NSString *)filePath error:(NSError * _Nullable *)error
285285
return NO;
286286
}
287287

288-
OAGPXDocument *gpxFile = [[OAGPXDocument alloc] initWithGpxFile:filePath];
288+
OASKFile *file = [[OASKFile alloc] initWithFilePath:filePath];
289+
OASGpxFile *gpxFile = [OASGpxUtilities.shared loadGpxFileFile:file];
289290
if (gpxFile)
290291
{
291292
NSMutableDictionary<NSString *, OAFavoriteGroup *> *flatGroups = [NSMutableDictionary dictionary];
292-
NSArray<OAFavoriteItem *> *favorites = [OAFavoritesHelper wptAsFavorites:gpxFile.points defaultCategory:@""];
293+
NSArray<OAFavoriteItem *> *favorites = [OAFavoritesHelper wptAsFavorites:gpxFile.getPointsList defaultCategory:@""];
293294
for (OAFavoriteItem *point in favorites)
294295
{
295296
OAFavoriteGroup *group = flatGroups[[point getCategory]];
@@ -307,13 +308,13 @@ - (BOOL) readFromFile:(NSString *)filePath error:(NSError * _Nullable *)error
307308
return YES;
308309
}
309310

310-
- (OAFavoriteGroup *)createFavoriteGroup:(OAGPXDocument *)gpxFile point:(OAFavoriteItem *)point
311+
- (OAFavoriteGroup *)createFavoriteGroup:(OASGpxFile *)gpxFile point:(OAFavoriteItem *)point
311312
{
312313
OAFavoriteGroup *favoriteGroup = [[OAFavoriteGroup alloc] initWithPoint:point];
313-
OAPointsGroup *pointsGroup = gpxFile.pointsGroups[favoriteGroup.name];
314+
OASGpxUtilitiesPointsGroup *pointsGroup = gpxFile.pointsGroups[favoriteGroup.name];
314315
if (pointsGroup)
315316
{
316-
favoriteGroup.color = pointsGroup.color;
317+
favoriteGroup.color = UIColorFromRGB(pointsGroup.color);
317318
favoriteGroup.iconName = pointsGroup.iconName;
318319
favoriteGroup.backgroundType = pointsGroup.backgroundType;
319320
}

Sources/Backup/LocalBackup/SettingsItems/OAFileSettingsItem.mm

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#import "OASettingsHelper.h"
1111
#import "OAAppSettings.h"
1212
#import "OsmAndApp.h"
13-
#import "OAGPXDocument.h"
14-
#import "OAGPXTrackAnalysis.h"
1513
#import "OAGPXDatabase.h"
1614
#import "OAIndexConstants.h"
1715
#import "OASettingsItemReader.h"
@@ -343,13 +341,33 @@ - (void) installItem:(NSString *)destFilePath
343341
{
344342
case EOASettingsItemFileSubtypeGpx:
345343
{
346-
OAGPXDocument *doc = [[OAGPXDocument alloc] initWithGpxFile:destFilePath];
347-
[doc saveTo:destFilePath];
348-
OAGPX *gpx = [[OAGPXDatabase sharedDb] addGpxItem:destFilePath title:doc.metadata.name desc:doc.metadata.desc bounds:doc.bounds document:doc];
349-
[[OAGPXDatabase sharedDb] save];
350-
const auto& activeGpx = OASelectedGPXHelper.instance.activeGpx;
351-
if (activeGpx.find(QString::fromNSString(gpx.gpxFilePath)) != activeGpx.end())
352-
[OAAppSettings.sharedManager showGpx:@[gpx.gpxFilePath]];
344+
345+
OAGPXDatabase *gpxDb = [OAGPXDatabase sharedDb];
346+
OASGpxDataItem *gpx = [gpxDb getGPXItem:destFilePath];
347+
if (!gpx)
348+
{
349+
gpx = [gpxDb addGPXFileToDBIfNeeded:destFilePath];
350+
if (gpx)
351+
{
352+
OASGpxTrackAnalysis *analysis = [gpx getAnalysis];
353+
354+
if (analysis.locationStart)
355+
{
356+
OAPOI *nearestCityPOI = [OAGPXUIHelper searchNearestCity:analysis.locationStart.position];
357+
NSString *nearestCityString = nearestCityPOI ? nearestCityPOI.nameLocalized : @"";
358+
[[OASGpxDbHelper shared] updateDataItemParameterItem:gpx
359+
parameter:OASGpxParameter.nearestCityName
360+
value:nearestCityString];
361+
}
362+
}
363+
}
364+
365+
NSDictionary<NSString *, OASGpxFile *> *activeGpx = OASelectedGPXHelper.instance.activeGpx;
366+
NSString *gpxFilePath = gpx.gpxFilePath;
367+
if ([activeGpx.allKeys containsObject:gpxFilePath])
368+
{
369+
[OAAppSettings.sharedManager showGpx:@[gpxFilePath]];
370+
}
353371

354372
break;
355373
}

Sources/Backup/LocalBackup/SettingsItems/OAGpxSettingsItem.mm

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#import "OAGPXUIHelper.h"
1212
#import "OsmAndApp.h"
1313
#import "OAGPXAppearanceCollection.h"
14-
#import "OAGPXDocument.h"
14+
#import "OsmAnd_Maps-Swift.h"
1515

1616
@interface OAGpxSettingsItem()
1717

@@ -136,11 +136,17 @@ - (void)applyAdditionalParams:(NSString *)filePath
136136
- (void)updateGpxParams:(NSString *)filePath
137137
{
138138
OAGPXDatabase *gpxDb = [OAGPXDatabase sharedDb];
139-
OAGPX *gpx = [gpxDb getGPXItem:[OAUtilities getGpxShortPath:self.filePath]];
139+
OASGpxDataItem *gpx = [gpxDb getGPXItem:self.filePath];
140140
if (!gpx)
141141
{
142-
OAGPXDocument *doc = [[OAGPXDocument alloc] initWithGpxFile:filePath];
143-
gpx = [gpxDb addGpxItem:filePath title:doc.metadata.name desc:doc.metadata.desc bounds:doc.bounds document:doc];
142+
gpx = [gpxDb addGPXFileToDBIfNeeded:filePath];
143+
OASGpxTrackAnalysis *analysis = [gpx getAnalysis];
144+
145+
if (analysis.locationStart)
146+
{
147+
OAPOI *nearestCityPOI = [OAGPXUIHelper searchNearestCity:analysis.locationStart.position];
148+
gpx.nearestCity = nearestCityPOI ? nearestCityPOI.nameLocalized : @"";
149+
}
144150
}
145151
gpx.color = _appearanceInfo.color;
146152
gpx.coloringType = _appearanceInfo.coloringType;
@@ -154,14 +160,16 @@ - (void)updateGpxParams:(NSString *)filePath
154160
gpx.visualization3dPositionType = _appearanceInfo.visualization3dPositionType;
155161
gpx.splitType = _appearanceInfo.splitType;
156162
gpx.splitInterval = _appearanceInfo.splitInterval;
157-
[gpxDb save];
163+
164+
[gpxDb updateDataItem:gpx];
165+
158166
if (gpx.color != 0)
159167
[[OAGPXAppearanceCollection sharedInstance] getColorItemWithValue:gpx.color];
160168
}
161169

162170
- (void) createGpxAppearanceInfo
163171
{
164-
OAGPX *gpx = [[OAGPXDatabase sharedDb] getGPXItem:[OAUtilities getGpxShortPath:self.filePath]];
172+
OASGpxDataItem *gpx = [[OAGPXDatabase sharedDb] getGPXItem:[OAUtilities getGpxShortPath:self.filePath]];
165173
if (gpx)
166174
_appearanceInfo = [[OAGpxAppearanceInfo alloc] initWithItem:gpx];
167175
}

Sources/Backup/LocalBackup/SettingsItems/OAHistoryMarkersSettingsItem.mm

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
//
88

99
#import "OAHistoryMarkersSettingsItem.h"
10-
#import "OAGPXMutableDocument.h"
1110
#import "OAHistoryHelper.h"
1211
#import "Localization.h"
12+
#import "OAAppVersion.h"
13+
#import "OsmAnd_Maps-Swift.h"
14+
#import "OsmAndSharedWrapper.h"
1315

1416
#define APPROXIMATE_HISTORY_MARKER_SIZE_BYTES 380
1517

@@ -132,30 +134,28 @@ - (OASettingsItemReader *) getReader
132134

133135
- (OASettingsItemWriter *)getWriter
134136
{
135-
OAGPXDocument *gpxFile = [self generateGpx:self.items];
137+
OASGpxFile *gpxFile = [self generateGpx:self.items];
136138
return [self getGpxWriter:gpxFile];
137139
}
138140

139-
- (OAGPXDocument *) generateGpx:(NSArray<OAHistoryItem *> *)historyItems
141+
- (OASGpxFile *) generateGpx:(NSArray<OAHistoryItem *> *)historyItems
140142
{
141-
OAGPXMutableDocument *doc = [[OAGPXMutableDocument alloc] init];
143+
OASGpxFile *gpxFile = [[OASGpxFile alloc] initWithAuthor:[OAAppVersion getFullVersionWithAppName]];
144+
142145
for (OAHistoryItem *historyItem in historyItems)
143146
{
144-
OAWptPt *wpt = [[OAWptPt alloc] init];
147+
OASWptPt *wpt = [[OASWptPt alloc] init];
145148
wpt.position = CLLocationCoordinate2DMake(historyItem.latitude, historyItem.longitude);
146149
wpt.name = historyItem.name;
147-
148-
OAGpxExtension *e = [[OAGpxExtension alloc] init];
149-
e.name = VISITED_TIME_EXTENSION;
150-
150+
151+
OASMutableDictionary *exts = wpt.getExtensionsToWrite;
151152
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
152153
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z"];
153-
e.value = [dateFormatter stringFromDate:historyItem.date];
154+
exts[@"visited_date"] = [dateFormatter stringFromDate:historyItem.date];
154155

155-
wpt.extensions = @[e];
156-
[doc addWpt:wpt];
156+
[gpxFile addPointPoint:wpt];
157157
}
158-
return doc;
158+
return gpxFile;
159159
}
160160

161161
@end
@@ -173,24 +173,26 @@ - (BOOL) readFromFile:(NSString *)filePath error:(NSError * _Nullable *)error
173173

174174
return NO;
175175
}
176+
177+
OASKFile *file = [[OASKFile alloc] initWithFilePath:filePath];
178+
OASGpxFile *gpxFile = [OASGpxUtilities.shared loadGpxFileFile:file];
176179

177-
OAGPXDocument *gpxFile = [[OAGPXDocument alloc] initWithGpxFile:filePath];
178180
if (gpxFile)
179181
{
180-
for (OAWptPt *wpt in gpxFile.points)
182+
for (OASWptPt *wpt in gpxFile.getPointsList)
181183
{
182184
OAHistoryItem *historyItem = [[OAHistoryItem alloc] init];
183185
historyItem.name = wpt.name;
184186
historyItem.latitude = wpt.getLatitude;
185187
historyItem.longitude = wpt.getLongitude;
186188
historyItem.hType = OAHistoryTypeDirection;
187-
188-
for (OAGpxExtension *e in wpt.extensions)
189+
NSDictionary<NSString *, NSString *> *extensions = [wpt getExtensionsToRead];
190+
for (NSString *key in extensions.allKeys)
189191
{
190-
if ([e.name isEqualToString:VISITED_TIME_EXTENSION]) {
192+
if ([key isEqualToString:@"visited_date"]) {
191193
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
192194
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z"];
193-
historyItem.date = [dateFormatter dateFromString:e.value];
195+
historyItem.date = [dateFormatter dateFromString:extensions[key]];
194196
}
195197
}
196198
[[OAHistoryHelper sharedInstance] addPoint:historyItem];

Sources/Backup/LocalBackup/SettingsItems/OAMarkersSettingsItem.mm

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
#import "OAMarkersSettingsItem.h"
1010
#import "OADestination.h"
1111
#import "OADestinationsHelper.h"
12-
#import "OAGPXDocument.h"
1312
#import "OAUtilities.h"
1413
#import "OAColors.h"
1514
#import "Localization.h"
15+
#import "OsmAndSharedWrapper.h"
16+
1617

1718
#define APPROXIMATE_MARKER_SIZE_BYTES 240
1819

@@ -158,7 +159,7 @@ - (OASettingsItemReader *) getReader
158159

159160
- (OASettingsItemWriter *)getWriter
160161
{
161-
OAGPXDocument *gpxFile = [_destinationsHelper generateGpx:self.items completeBackup:YES];
162+
OASGpxFile *gpxFile = [_destinationsHelper generateGpx:self.items completeBackup:YES];
162163
return [self getGpxWriter:gpxFile];
163164
}
164165

@@ -194,24 +195,26 @@ - (BOOL) readFromFile:(NSString *)filePath error:(NSError * _Nullable *)error
194195

195196
return NO;
196197
}
198+
199+
OASKFile *file = [[OASKFile alloc] initWithFilePath:filePath];
200+
OASGpxFile *gpxFile = [OASGpxUtilities.shared loadGpxFileFile:file];
197201

198-
OAGPXDocument *gpxFile = [[OAGPXDocument alloc] initWithGpxFile:filePath];
199202
if (gpxFile)
200203
{
201-
for (OAWptPt *wpt in gpxFile.points)
204+
for (OASWptPt *wpt in gpxFile.getPointsList)
202205
{
203206
OADestination *dest = [[OADestination alloc] initWithDesc:wpt.name latitude:wpt.getLatitude longitude:wpt.getLongitude];
204-
int color = [wpt getColor:0];
207+
int color = [wpt getColor];
205208
dest.color = color != 0 ? UIColorFromRGBA(color) : UIColorFromRGB(marker_pin_color_blue);
206209
dest.markerResourceName = [self getResourceName:[dest.color.toHexString upperCase]];
207-
208-
for (OAGpxExtension *e in wpt.extensions)
210+
NSDictionary<NSString *, NSString *> *extensions = [wpt getExtensionsToRead];
211+
for (NSString *key in extensions.allKeys)
209212
{
210-
if ([e.name isEqualToString:@"creation_date"])
213+
if ([key isEqualToString:@"creation_date"])
211214
{
212215
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
213216
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z"];
214-
dest.creationDate = [dateFormatter dateFromString:e.value];
217+
dest.creationDate = [dateFormatter dateFromString:extensions[key]];
215218
}
216219
}
217220
[self.item.items addObject:dest];

Sources/Backup/LocalBackup/SettingsItems/OASettingsItem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
1818
FOUNDATION_EXTERN NSString *const kSettingsItemErrorDomain;
1919
FOUNDATION_EXTERN NSInteger const kSettingsItemErrorCodeAlreadyRead;
2020

21-
@class OAGPXDocument;
21+
@class OASGpxFile;
2222

2323
@interface OASettingsItem : NSObject
2424

@@ -62,7 +62,7 @@ FOUNDATION_EXTERN NSInteger const kSettingsItemErrorCodeAlreadyRead;
6262
- (void) applyRoutingPreferences:(NSDictionary<NSString *,NSString *> *)prefs;
6363
- (OASettingsItemReader *) getJsonReader;
6464
- (OASettingsItemWriter *) getJsonWriter;
65-
- (OASettingsItemWriter *) getGpxWriter:(OAGPXDocument *)gpxFile;
65+
- (OASettingsItemWriter *) getGpxWriter:(OASGpxFile *)gpxFile;
6666

6767
@end
6868

@@ -76,7 +76,7 @@ FOUNDATION_EXTERN NSInteger const kSettingsItemErrorCodeAlreadyRead;
7676

7777
@interface OASettingsItemGpxWriter : OASettingsItemWriter<OASettingsItem *>
7878

79-
- (instancetype) initWithItem:(OASettingsItem *)item gpxDocument:(OAGPXDocument *)gpxFile;
79+
- (instancetype) initWithItem:(OASettingsItem *)item gpxDocument:(OASGpxFile *)gpxFile;
8080

8181
@end
8282

0 commit comments

Comments
 (0)