diff --git a/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj b/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj index 15c49fe04e..85c83a62e9 100644 --- a/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj +++ b/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj @@ -86,6 +86,9 @@ 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, ); }; }; + EDC4E3512C5D222D009286A2 /* RecentlyDeletedCategory.mm in Sources */ = {isa = PBXBuildFile; fileRef = EDC4E34E2C5D222D009286A2 /* RecentlyDeletedCategory.mm */; }; + EDC4E3522C5D222D009286A2 /* RecentlyDeletedCategory.h in Headers */ = {isa = PBXBuildFile; fileRef = EDC4E34F2C5D222D009286A2 /* RecentlyDeletedCategory.h */; settings = {ATTRIBUTES = (Public, ); }; }; + EDC4E3532C5D222D009286A2 /* RecentlyDeletedCategory+Core.h in Headers */ = {isa = PBXBuildFile; fileRef = EDC4E3502C5D222D009286A2 /* RecentlyDeletedCategory+Core.h */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -175,6 +178,9 @@ 9974CA2823DF1968003FE824 /* ElevationProfileData.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ElevationProfileData.mm; sourceTree = ""; }; 9974CA2B23DF197B003FE824 /* ElevationProfileData+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ElevationProfileData+Core.h"; sourceTree = ""; }; AC6A585628057CC1003EABAF /* StringUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtils.h; sourceTree = ""; }; + EDC4E34E2C5D222D009286A2 /* RecentlyDeletedCategory.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RecentlyDeletedCategory.mm; sourceTree = ""; }; + EDC4E34F2C5D222D009286A2 /* RecentlyDeletedCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecentlyDeletedCategory.h; sourceTree = ""; }; + EDC4E3502C5D222D009286A2 /* RecentlyDeletedCategory+Core.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RecentlyDeletedCategory+Core.h"; sourceTree = ""; }; FAA6D8CF29205D2D00E8D50D /* libcppjansson.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libcppjansson.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -338,6 +344,7 @@ 47CA68E72506F61300671019 /* MWMTrack.mm */, 47F0D2132516847F00BC685E /* MWMBookmarksSection.h */, 47F0D2142516847F00BC685E /* MWMBookmarksSection.m */, + EDC4E3542C5D2251009286A2 /* RecentlyDeletedCategory */, ); path = Bookmarks; sourceTree = ""; @@ -410,6 +417,16 @@ path = ElevationProfile; sourceTree = ""; }; + EDC4E3542C5D2251009286A2 /* RecentlyDeletedCategory */ = { + isa = PBXGroup; + children = ( + EDC4E34F2C5D222D009286A2 /* RecentlyDeletedCategory.h */, + EDC4E34E2C5D222D009286A2 /* RecentlyDeletedCategory.mm */, + EDC4E3502C5D222D009286A2 /* RecentlyDeletedCategory+Core.h */, + ); + path = RecentlyDeletedCategory; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -452,6 +469,7 @@ 479F7063234FBC5900011E2E /* MWMCarPlayBookmarkObject.h in Headers */, 47E8163723B188D3008FD836 /* MWMStorage.h in Headers */, 47EEAFF62350CF48005CF316 /* AppInfo.h in Headers */, + EDC4E3532C5D222D009286A2 /* RecentlyDeletedCategory+Core.h in Headers */, 47F701F3238C877C00D18E95 /* PlacePageButtonsData+Core.h in Headers */, 47CA68E12506C01F00671019 /* MWMBookmark+Core.h in Headers */, 471527392491EDAA00E91BBA /* MWMBookmarkColor.h in Headers */, @@ -459,6 +477,7 @@ 479F704A234F785B00011E2E /* MWMTypes.h in Headers */, 47C637D72354AEBE00E12DE0 /* MWMMapOverlayManager.h in Headers */, 47942D9C237D927800DEFAE3 /* PlacePageBookmarkData.h in Headers */, + EDC4E3522C5D222D009286A2 /* RecentlyDeletedCategory.h in Headers */, 47942D72237CC40B00DEFAE3 /* OpeningHours.h in Headers */, 47942D6B237CC3D600DEFAE3 /* PlacePageData.h in Headers */, 47D609DC234FE625008ECC47 /* MWMBookmarksObserver.h in Headers */, @@ -567,6 +586,7 @@ 9940622123EAC57900493D1A /* ElevationHeightPoint.m in Sources */, 47EEAFF42350CEDB005CF316 /* AppInfo.mm in Sources */, 47E8163623B1889C008FD836 /* MWMStorage.mm in Sources */, + EDC4E3512C5D222D009286A2 /* RecentlyDeletedCategory.mm in Sources */, 47CA68DE2502022400671019 /* MWMBookmark.mm in Sources */, 9957FAE9237AE5B000855F48 /* Logger.mm in Sources */, ); diff --git a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.h b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.h index 8d0948f0de..e23bb0d857 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.h +++ b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.h @@ -9,6 +9,7 @@ @class MWMBookmarksSection; @class MWMCarPlayBookmarkObject; @class MWMTrack; +@class RecentlyDeletedCategory; @class UIColor; NS_ASSUME_NONNULL_BEGIN @@ -26,14 +27,18 @@ typedef void (^SearchBookmarksCompletionBlock)(NSArray *bookmarks typedef void (^SortBookmarksCompletionBlock)(NSArray * _Nullable sortedSections); typedef void (^SharingResultCompletionHandler)(MWMBookmarksShareStatus status, NSURL * _Nullable urlToALocalFile); +@protocol RecentlyDeletedCategoriesManager +- (uint64_t)recentlyDeletedCategoriesCount; +- (NSArray *)getRecentlyDeletedCategories; +- (void)deleteRecentlyDeletedCategoryAtURLs:(NSArray *)urls; +- (void)recoverRecentlyDeletedCategoriesAtURLs:(NSArray *)urls; +@end + NS_SWIFT_NAME(BookmarksManager) -@interface MWMBookmarksManager : NSObject +@interface MWMBookmarksManager : NSObject + (MWMBookmarksManager *)sharedManager; -- (void)addObserver:(id)observer; -- (void)removeObserver:(id)observer; - - (BOOL)areBookmarksLoaded; - (void)loadBookmarks; - (void)loadBookmarkFile:(NSURL *)url; diff --git a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm index 907155a415..d32fc2eaca 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm +++ b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm @@ -5,6 +5,7 @@ #import "MWMBookmarkGroup.h" #import "MWMCarPlayBookmarkObject.h" #import "MWMTrack+Core.h" +#import "RecentlyDeletedCategory+Core.h" #include "Framework.h" @@ -355,7 +356,7 @@ static KmlFileType convertFileTypeToCore(MWMKmlFileType fileType) { - (void)deleteCategory:(MWMMarkGroupID)groupId { - self.bm.GetEditSession().DeleteBmCategory(groupId); + self.bm.GetEditSession().DeleteBmCategory(groupId, false /* move to the Trash */); [self loopObservers:^(id observer) { if ([observer respondsToSelector:@selector(onBookmarksCategoryDeleted:)]) [observer onBookmarksCategoryDeleted:groupId]; @@ -787,6 +788,37 @@ static KmlFileType convertFileTypeToCore(MWMKmlFileType fileType) { } } +// MARK: - RecentlyDeletedCategoriesManager +- (uint64_t)recentlyDeletedCategoriesCount { + return self.bm.GetRecentlyDeletedCategoriesCount(); +} + +- (NSArray *)getRecentlyDeletedCategories { + auto const categoriesCollection = self.bm.GetRecentlyDeletedCategories(); + NSMutableArray * recentlyDeletedCategories = [[NSMutableArray alloc] initWithCapacity:categoriesCollection->size()]; + + for (auto const & [filePath, categoryPtr] : * categoriesCollection) { + ASSERT(categoryPtr, ("Recently deleted category shouldn't be nil.")); + RecentlyDeletedCategory * category = [[RecentlyDeletedCategory alloc] initWithCategoryData:categoryPtr->m_categoryData filePath:filePath]; + [recentlyDeletedCategories addObject:category]; + } + return recentlyDeletedCategories; +} + +- (void)deleteRecentlyDeletedCategoryAtURLs:(NSArray *)urls { + std::vector filePaths; + for (NSURL * url in urls) + filePaths.push_back(url.filePathURL.path.UTF8String); + self.bm.DeleteRecentlyDeletedCategoriesAtPaths(filePaths); +} + +- (void)recoverRecentlyDeletedCategoriesAtURLs:(NSArray *)urls { + std::vector filePaths; + for (NSURL * url in urls) + filePaths.push_back(url.filePathURL.path.UTF8String); + self.bm.RecoverRecentlyDeletedCategoriesAtPaths(filePaths); +} + #pragma mark - Helpers - (void)loopObservers:(void (^)(id observer))block diff --git a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksObserver.h b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksObserver.h index c24baded9f..82e2eacc10 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksObserver.h +++ b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksObserver.h @@ -10,7 +10,13 @@ NS_SWIFT_NAME(BookmarksObserver) - (void)onBookmarksFileLoadSuccess; - (void)onBookmarksFileLoadError; - (void)onBookmarksCategoryDeleted:(MWMMarkGroupID)groupId; +- (void)onRecentlyDeletedBookmarksCategoriesChanged; - (void)onBookmarkDeleted:(MWMMarkID)bookmarkId; - @end + +@protocol BookmarksObservable +- (void)addObserver:(id)observer; +- (void)removeObserver:(id)observer; +@end + NS_ASSUME_NONNULL_END diff --git a/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory+Core.h b/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory+Core.h new file mode 100644 index 0000000000..4d2ed99575 --- /dev/null +++ b/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory+Core.h @@ -0,0 +1,9 @@ +#import "RecentlyDeletedCategory.h" + +#include "kml/types.hpp" + +@interface RecentlyDeletedCategory (Core) + +- (instancetype)initWithCategoryData:(kml::CategoryData)data filePath:(std::string const &)filePath; + +@end diff --git a/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory.h b/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory.h new file mode 100644 index 0000000000..bcb15dcd94 --- /dev/null +++ b/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory.h @@ -0,0 +1,15 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RecentlyDeletedCategory : NSObject + +@property(nonatomic, readonly) NSString * title; +@property(nonatomic, readonly) NSURL * fileURL; +@property(nonatomic, readonly) NSDate * deletionDate; + +- (instancetype)initTitle:(NSString *)title fileURL:(NSURL *)fileURL deletionDate:(NSDate *)deletionDate; + +@end + +NS_ASSUME_NONNULL_END diff --git a/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory.mm b/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory.mm new file mode 100644 index 0000000000..0248302639 --- /dev/null +++ b/iphone/CoreApi/CoreApi/Bookmarks/RecentlyDeletedCategory/RecentlyDeletedCategory.mm @@ -0,0 +1,35 @@ +#import "RecentlyDeletedCategory+Core.h" + +#include +#include + +@implementation RecentlyDeletedCategory + +- (instancetype)initTitle:(NSString *)title fileURL:(NSURL *)fileURL deletionDate:(NSDate *)deletionDate { + self = [super init]; + if (self) { + _title = title; + _fileURL = fileURL; + _deletionDate = deletionDate; + } + return self; +} + +@end + +@implementation RecentlyDeletedCategory (Core) + +- (instancetype)initWithCategoryData:(kml::CategoryData)data filePath:(std::string const &)filePath { + self = [super init]; + if (self) { + auto const name = GetPreferredBookmarkStr(data.m_name); + _title = [NSString stringWithCString:name.c_str() encoding:NSUTF8StringEncoding]; + auto const pathString = [NSString stringWithCString:filePath.c_str() encoding:NSUTF8StringEncoding]; + _fileURL = [NSURL fileURLWithPath:pathString]; + NSTimeInterval creationTime = Platform::GetFileCreationTime(filePath); + _deletionDate = [NSDate dateWithTimeIntervalSince1970:creationTime]; + } + return self; +} + +@end diff --git a/iphone/CoreApi/CoreApi/CoreApi-swift.h b/iphone/CoreApi/CoreApi/CoreApi-swift.h index 3a2b904cf4..3f4b7ce8aa 100644 --- a/iphone/CoreApi/CoreApi/CoreApi-swift.h +++ b/iphone/CoreApi/CoreApi/CoreApi-swift.h @@ -26,6 +26,7 @@ FOUNDATION_EXPORT const unsigned char CoreApiVersionString[]; #import #import #import +#import #pragma mark - Place Page