[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

@@ -85,6 +85,8 @@
9974CA2A23DF1968003FE824 /* ElevationProfileData.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9974CA2823DF1968003FE824 /* ElevationProfileData.mm */; };
9974CA2D23DF197B003FE824 /* ElevationProfileData+Core.h in Headers */ = {isa = PBXBuildFile; fileRef = 9974CA2B23DF197B003FE824 /* ElevationProfileData+Core.h */; };
AC6A585728057EF6003EABAF /* StringUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = AC6A585628057CC1003EABAF /* StringUtils.h */; settings = {ATTRIBUTES = (Public, ); }; };
CE838D272D9D834F00476DD0 /* PlacePagePhone.h in Headers */ = {isa = PBXBuildFile; fileRef = CE838D252D9D834F00476DD0 /* PlacePagePhone.h */; settings = {ATTRIBUTES = (Public, ); }; };
CE838D282D9D834F00476DD0 /* PlacePagePhone.m in Sources */ = {isa = PBXBuildFile; fileRef = CE838D262D9D834F00476DD0 /* PlacePagePhone.m */; };
ED0B1FF42CAAE3FF006E31A4 /* DeepLinkInAppFeatureHighlightData.h in Headers */ = {isa = PBXBuildFile; fileRef = ED0B1FF22CAAE3FF006E31A4 /* DeepLinkInAppFeatureHighlightData.h */; settings = {ATTRIBUTES = (Public, ); }; };
ED0B1FF52CAAE3FF006E31A4 /* DeepLinkInAppFeatureHighlightData.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED0B1FF32CAAE3FF006E31A4 /* DeepLinkInAppFeatureHighlightData.mm */; };
ED46DE3A2D09BE21007CACD6 /* PlacePageTrackData.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED46DE382D09BE21007CACD6 /* PlacePageTrackData.mm */; };
@@ -196,6 +198,8 @@
9974CA2823DF1968003FE824 /* ElevationProfileData.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ElevationProfileData.mm; sourceTree = "<group>"; };
9974CA2B23DF197B003FE824 /* ElevationProfileData+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ElevationProfileData+Core.h"; sourceTree = "<group>"; };
AC6A585628057CC1003EABAF /* StringUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtils.h; sourceTree = "<group>"; };
CE838D252D9D834F00476DD0 /* PlacePagePhone.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlacePagePhone.h; sourceTree = "<group>"; };
CE838D262D9D834F00476DD0 /* PlacePagePhone.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PlacePagePhone.m; sourceTree = "<group>"; };
ED0B1FF22CAAE3FF006E31A4 /* DeepLinkInAppFeatureHighlightData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeepLinkInAppFeatureHighlightData.h; sourceTree = "<group>"; };
ED0B1FF32CAAE3FF006E31A4 /* DeepLinkInAppFeatureHighlightData.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DeepLinkInAppFeatureHighlightData.mm; sourceTree = "<group>"; };
ED46DE372D09BE21007CACD6 /* PlacePageTrackData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlacePageTrackData.h; sourceTree = "<group>"; };
@@ -319,6 +323,8 @@
47942D9A237D927800DEFAE3 /* PlacePageBookmarkData.h */,
47942D9E237D954400DEFAE3 /* PlacePageBookmarkData+Core.h */,
47942D9B237D927800DEFAE3 /* PlacePageBookmarkData.mm */,
CE838D252D9D834F00476DD0 /* PlacePagePhone.h */,
CE838D262D9D834F00476DD0 /* PlacePagePhone.m */,
47942D53237CC3B500DEFAE3 /* PlacePagePreviewData.h */,
47942D54237CC3B500DEFAE3 /* PlacePagePreviewData+Core.h */,
47942D55237CC3B500DEFAE3 /* PlacePagePreviewData.mm */,
@@ -537,6 +543,7 @@
ED49D75F2CEFA8C0004AF27E /* Product+Core.h in Headers */,
47942D6E237CC3E800DEFAE3 /* PlacePagePreviewData+Core.h in Headers */,
47942D87237CC55800DEFAE3 /* MWMOpeningHoursCommon.h in Headers */,
CE838D272D9D834F00476DD0 /* PlacePagePhone.h in Headers */,
47942DAB237ED9FE00DEFAE3 /* IOpeningHoursLocalization.h in Headers */,
479F7063234FBC5900011E2E /* MWMCarPlayBookmarkObject.h in Headers */,
47E8163723B188D3008FD836 /* MWMStorage.h in Headers */,
@@ -664,6 +671,7 @@
47F701F0238C86F000D18E95 /* PlacePageButtonsData.mm in Sources */,
ED49D7222CED0395004AF27E /* ProductsConfiguration+Core.mm in Sources */,
9940622123EAC57900493D1A /* ElevationHeightPoint.m in Sources */,
CE838D282D9D834F00476DD0 /* PlacePagePhone.m in Sources */,
ED965B2A2CDA1C440049E39E /* DateTimeFormatter.swift in Sources */,
47EEAFF42350CEDB005CF316 /* AppInfo.mm in Sources */,
47E8163623B1889C008FD836 /* MWMStorage.mm in Sources */,

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

View File

@@ -4,6 +4,7 @@
#import <CoreApi/PlacePageData.h>
#import <CoreApi/PlacePagePreviewData.h>
#import <CoreApi/PlacePageInfoData.h>
#import <CoreApi/PlacePagePhone.h>
#import <LinkPresentation/LPLinkMetadata.h>
NSString * httpGe0Url(NSString * shortUrl)
@@ -139,7 +140,7 @@ NSString * httpGe0Url(NSString * shortUrl)
std::vector<NSString *> strings{self.data.previewData.title,
self.data.previewData.subtitle,
self.data.previewData.secondarySubtitle,
self.data.infoData.phone,
self.data.infoData.phone.phone,
url,
ge0Url};

View File

@@ -159,17 +159,17 @@ class PlacePageInfoViewController: UIViewController {
if let phone = placePageInfoData.phone {
var cellStyle: Style = .regular
if let phoneUrl = placePageInfoData.phoneUrl, UIApplication.shared.canOpenURL(phoneUrl) {
if let phoneUrl = phone.url, UIApplication.shared.canOpenURL(phoneUrl) {
cellStyle = .link
}
phoneView = createInfoItem(phone,
phoneView = createInfoItem(phone.phone,
icon: UIImage(named: "ic_placepage_phone_number"),
style: cellStyle,
tapHandler: { [weak self] in
self?.delegate?.didPressCall()
},
longPressHandler: { [weak self] in
self?.delegate?.didCopy(phone)
self?.delegate?.didCopy(phone.phone)
})
}

View File

@@ -195,8 +195,9 @@ using namespace storage;
}
- (void)call:(PlacePageData *)data {
if (data.infoData.phoneUrl && [UIApplication.sharedApplication canOpenURL:data.infoData.phoneUrl]) {
[UIApplication.sharedApplication openURL:data.infoData.phoneUrl options:@{} completionHandler:nil];
NSURL * _Nullable phoneURL = data.infoData.phone.url;
if (phoneURL && [UIApplication.sharedApplication canOpenURL:phoneURL]) {
[UIApplication.sharedApplication openURL:phoneURL options:@{} completionHandler:nil];
}
}