Skip to content

Refactor map objects selecting #4611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open

Conversation

nnngrach
Copy link
Contributor

@nnngrach nnngrach commented May 27, 2025

issue

skipped for now:
TravelGpx
ClickableWay

@nnngrach nnngrach changed the title draft Refactor map objects selecting Jun 3, 2025

- (NSString *) getGpxFileName;

@end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use macros in .h files

NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_END

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • (NSString *)getGpxFileName;


- (void) commonInit
{
_clickableTags = [NSSet setWithObjects:@"piste:type", @"piste:difficulty", @"mtb:scale", @"dirtbike:scale", nil];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NSSet setWithArray:@[
    @"piste:type",
    @"piste:difficulty",
    @"mtb:scale",
    @"dirtbike:scale"
]];

- (void) commonInit
{
_clickableTags = [NSSet setWithObjects:@"piste:type", @"piste:difficulty", @"mtb:scale", @"dirtbike:scale", nil];
_requiredTagsAny = [NSSet setWithObjects:@"name", @"ref", @"piste:name", @"mtb:name", nil];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up


- (BOOL) isClickableWayTags:(NSDictionary<NSString *, NSString *> *)tags
{
for (NSString *forbiddenKey in _forbiddenTags.allKeys)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for-in loop over an NSDictionary iterates directly over its keys, similar to using allKeys, but more efficient because it avoids creating an intermediate array

{
for (NSString *forbiddenKey in _forbiddenTags.allKeys)
{
NSString *forbiddenValue = _forbiddenTags[forbiddenKey];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add NSString *tagValue = tags[forbiddenKey];

travelGpx.file = file

//TODO: delete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: delete

@@ -2771,6 +2794,29 @@ + (NSString *) createNewFileName:(NSString *)oldName
return newName;
}

+ (NSString *) simplifyFileName:(NSString *)filename
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add example

[supported addObjectsFromArray:[self getNames:CONTENT_TAG defTag:@"en"]];
[supported addObjectsFromArray:[self getNames:DESCRIPTION_TAG defTag:@"en"]];
[supported addObjectsFromArray:[self getNames:@"wiki_lang" defTag:@"en"]];
return supported;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[locales copy]; ?

- (NSArray<NSString *> *) getAdditionalInfoKeys
{
NSDictionary<NSString *, NSString *> *info = [self getAdditionalInfo];
return info == nil ? @[] : [info allKeys];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return info ? info.allKeys : @[];

@@ -339,6 +412,67 @@ - (NSString *)getAdditionalInfo:(NSString *)key
return [_values objectForKey:key];
}

- (NSMutableDictionary<NSString *, NSString *> *)getInternalAdditionalInfoMap
{
return _values ? _values : [NSMutableDictionary new];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return _values ?: [NSMutableDictionary dictionary];

@@ -405,9 +405,9 @@ - (BOOL) isUniqueTravelGpx:(NSMutableArray<OASelectedMapObject *> *)selectedObje
[selectedObject.provider isKindOfClass:OAGPXLayer.class])
{
NSArray *pair = (NSArray *)selectedObject.object;
if ([pair[0] isKindOfClass:OATravelGpx.class])
if ([pair firstObject] && [[pair firstObject] isKindOfClass:OATravelGpx.class])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to extract [pair firstObject] into a let variable. Also, checking with if ([yourLet isKindOfClass:OATravelGpx.class]) {} is sufficient.

if ([obj isKindOfClass:OAOnlineOsmNoteWrapper.class])
{
OAOnlineOsmNoteWrapper *note = (OAOnlineOsmNoteWrapper *)obj;
NSString *name = note.description ? note.description : @"";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?: @"";

{
OAOnlineOsmNoteWrapper *note = (OAOnlineOsmNoteWrapper *)obj;
NSString *name = note.description ? note.description : @"";
NSString *typeName = note.typeName ? note.typeName : OALocalizedString(@"osn_bug_name");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up

}

let shortLinkTiles = amenity.getTagContent(TravelGpx.ROUTE_SHORTLINK_TILES)
if let shortLinkTiles {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if let shortLinkTiles = amenity.getTagContent(TravelGpx.ROUTE_SHORTLINK_TILES) {}

}

if activityType == nil || activityType!.isEmpty {
for key in amenity.getAdditionalInfoKeys() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where key.hasPrefix(Self.ROUTE_ACTIVITY_TYPE)



func isTravelGpxTags(_ tags: [String: String]) -> Bool {
return tags[ROUTE_ID] != nil &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove return

@@ -175,6 +175,15 @@ - (void) rLineToX:(CGFloat)x y:(CGFloat)y

@end

@implementation NSArray (util)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- (BOOL)isEmpty {
    return !array || array.count == 0;
}
if ([myArray isEmpty]) {
    // ...
}


+ (BOOL)isEmpty:(NSDictionary *)dictionary
{
return !dictionary || dictionary.count == 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up

@@ -495,6 +513,11 @@ - (void) setMinLineHeight:(CGFloat)height alignment:(NSTextAlignment)alignment f

@implementation NSString (util)

+ (BOOL)isEmpty:(NSString *)string
{
return !string || string.length == 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up

@@ -0,0 +1,38 @@
//
// OAPlaceDetailsObject.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It became BaseDetailsObject in java recently altogether with some code refactoring. So looks like new changes in Android code should be reviewed and introduced in iOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants