[ios] Extract PlacePagePhone class

It groups two phone-related properties, `phone` and `phoneUrl` (renamed
to `url`), that used to be in `PlacePageInfoData`. This will make it
easier to support an array of phones for one POI.

Signed-off-by: Eugene Nikolsky <omaps@egeek.me>
This commit is contained in:
Eugene Nikolsky
2025-04-02 18:18:33 +03:00
committed by Konstantin Pastbin
parent f1db7d7f98
commit 9be9f17df9
9 changed files with 60 additions and 12 deletions

View File

@@ -44,3 +44,4 @@ FOUNDATION_EXPORT const unsigned char CoreApiVersionString[];
#import <CoreApi/PlacePageData.h>
#import <CoreApi/PlacePageInfoData.h>
#import <CoreApi/PlacePagePreviewData.h>
#import <CoreApi/PlacePagePhone.h>

View File

@@ -1,6 +1,7 @@
#import <Foundation/Foundation.h>
@class OpeningHours;
@class PlacePagePhone;
NS_ASSUME_NONNULL_BEGIN
@@ -8,8 +9,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly, nullable) NSString *openingHoursString;
@property(nonatomic, readonly, nullable) OpeningHours *openingHours;
@property(nonatomic, readonly, nullable) NSString *phone;
@property(nonatomic, readonly, nullable) NSURL *phoneUrl;
@property(nonatomic, readonly, nullable) PlacePagePhone *phone;
@property(nonatomic, readonly, nullable) NSString *website;
@property(nonatomic, readonly, nullable) NSString *wikipedia;
@property(nonatomic, readonly, nullable) NSString *wikimediaCommons;

View File

@@ -1,6 +1,7 @@
#import "PlacePageInfoData+Core.h"
#import "OpeningHours.h"
#import "PlacePagePhone.h"
#import <CoreApi/StringUtils.h>
@@ -46,12 +47,14 @@ NSString * GetLocalizedMetadataValueString(MapObject::MetadataID metaID, std::st
break;
case MetadataID::FMD_PHONE_NUMBER:
{
_phone = ToNSString(value);
NSString *filteredDigits = [[_phone componentsSeparatedByCharactersInSet:
NSString *phone = ToNSString(value);
NSString *filteredDigits = [[phone componentsSeparatedByCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:@""];
NSString *resultNumber = [_phone hasPrefix:@"+"] ? [NSString stringWithFormat:@"+%@", filteredDigits] : filteredDigits;
_phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", resultNumber]];
NSString *resultNumber = [phone hasPrefix:@"+"] ? [NSString stringWithFormat:@"+%@", filteredDigits] : filteredDigits;
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", resultNumber]];
_phone = [PlacePagePhone placePagePhoneWithPhone:phone andURL:phoneUrl];
break;
}
case MetadataID::FMD_WEBSITE: _website = ToNSString(value); break;

View File

@@ -0,0 +1,16 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PlacePagePhone : NSObject
/// User-visible string of the phone number.
@property(nonatomic, readonly) NSString *phone;
/// Optional `tel:` URL, which can be used to ask iOS to call the phone number.
@property(nonatomic, readonly, nullable) NSURL *url;
+ (instancetype)placePagePhoneWithPhone:(NSString *)phone andURL:(nullable NSURL *)url;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,18 @@
#import "PlacePagePhone.h"
@implementation PlacePagePhone
- (instancetype)initWithPhone:(NSString *)phone andURL:(nullable NSURL *)url {
self = [super init];
if (self) {
_phone = phone;
_url = url;
}
return self;
}
+ (instancetype)placePagePhoneWithPhone:(NSString *)phone andURL:(nullable NSURL *)url {
return [[self alloc] initWithPhone:phone andURL:url];
}
@end