mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-23 06:33:42 +00:00
[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:
committed by
Konstantin Pastbin
parent
f1db7d7f98
commit
9be9f17df9
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
16
iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePhone.h
Normal file
16
iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePhone.h
Normal 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
|
||||
18
iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePhone.m
Normal file
18
iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePhone.m
Normal 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
|
||||
Reference in New Issue
Block a user