forked from organicmaps/organicmaps
[ios] MWMBookmarksManager refactoring
This commit is contained in:
parent
c515cf0e39
commit
016ecbe8bf
14 changed files with 279 additions and 274 deletions
|
@ -249,7 +249,7 @@ CGFloat const kPinDiameter = 18.0f;
|
|||
else
|
||||
{
|
||||
kml::MarkId const bmId = [self getBookmarkIdByRow:indexPath.row];
|
||||
[MWMBookmarksManager deleteBookmark:bmId];
|
||||
[[MWMBookmarksManager sharedManager] deleteBookmark:bmId];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ CGFloat const kPinDiameter = 18.0f;
|
|||
// Disable all notifications in BM on appearance of this view.
|
||||
// It allows to significantly improve performance in case of bookmarks
|
||||
// modification. All notifications will be sent on controller's disappearance.
|
||||
[MWMBookmarksManager setNotificationsEnabled: NO];
|
||||
[[MWMBookmarksManager sharedManager] setNotificationsEnabled: NO];
|
||||
|
||||
[super viewDidAppear:animated];
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ CGFloat const kPinDiameter = 18.0f;
|
|||
- (void)viewDidDisappear:(BOOL)animated
|
||||
{
|
||||
// Allow to send all notifications in BM.
|
||||
[MWMBookmarksManager setNotificationsEnabled: YES];
|
||||
[[MWMBookmarksManager sharedManager] setNotificationsEnabled: YES];
|
||||
|
||||
[super viewDidDisappear:animated];
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ final class CatalogWebViewController: WebViewController {
|
|||
var toolbar = UIToolbar()
|
||||
|
||||
@objc init() {
|
||||
super.init(url: MWMBookmarksManager.catalogFrontendUrl()!, title: L("guides"))!
|
||||
super.init(url: MWMBookmarksManager.shared().catalogFrontendUrl()!, title: L("guides"))!
|
||||
backButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_catalog_back"), style: .plain, target: self, action: #selector(onBack))
|
||||
fwdButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_catalog_fwd"), style: .plain, target: self, action: #selector(onFwd))
|
||||
backButton.tintColor = .blackSecondaryText()
|
||||
|
@ -140,7 +140,7 @@ final class CatalogWebViewController: WebViewController {
|
|||
}
|
||||
}
|
||||
|
||||
if MWMBookmarksManager.isCategoryDownloading(id) || MWMBookmarksManager.hasCategoryDownloaded(id) {
|
||||
if MWMBookmarksManager.shared().isCategoryDownloading(id) || MWMBookmarksManager.shared().hasCategoryDownloaded(id) {
|
||||
MWMAlertViewController.activeAlert().presentDefaultAlert(withTitle: L("error_already_downloaded_guide"),
|
||||
message: nil,
|
||||
rightButtonTitle: L("ok"),
|
||||
|
@ -149,7 +149,7 @@ final class CatalogWebViewController: WebViewController {
|
|||
return
|
||||
}
|
||||
|
||||
MWMBookmarksManager.downloadItem(withId: id, name: name, progress: { [weak self] (progress) in
|
||||
MWMBookmarksManager.shared().downloadItem(withId: id, name: name, progress: { [weak self] (progress) in
|
||||
self?.updateProgress()
|
||||
}) { [weak self] (categoryId, error) in
|
||||
if let error = error as NSError? {
|
||||
|
@ -179,7 +179,7 @@ final class CatalogWebViewController: WebViewController {
|
|||
self?.showImportError()
|
||||
}
|
||||
} else {
|
||||
if MWMBookmarksManager.getCatalogDownloadsCount() == 0 {
|
||||
if MWMBookmarksManager.shared().getCatalogDownloadsCount() == 0 {
|
||||
MapViewController.shared().showBookmarksLoadedAlert(categoryId)
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ final class CatalogWebViewController: WebViewController {
|
|||
}
|
||||
|
||||
private func updateProgress() {
|
||||
let numberOfTasks = MWMBookmarksManager.getCatalogDownloadsCount()
|
||||
let numberOfTasks = MWMBookmarksManager.shared().getCatalogDownloadsCount()
|
||||
numberOfTasksLabel.text = "\(numberOfTasks)"
|
||||
progressView.isHidden = numberOfTasks == 0
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class DownloadedBookmarksDataSource {
|
||||
|
||||
|
||||
private var categories: [MWMCatalogCategory] = []
|
||||
var categoriesCount: NSInteger {
|
||||
get {
|
||||
|
@ -17,7 +17,7 @@ class DownloadedBookmarksDataSource {
|
|||
categories.forEach {
|
||||
$0.visible = !newValue
|
||||
}
|
||||
MWMBookmarksManager.setCatalogCategoriesVisible(!newValue)
|
||||
MWMBookmarksManager.shared().setCatalogCategoriesVisible(!newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,17 +30,17 @@ class DownloadedBookmarksDataSource {
|
|||
}
|
||||
|
||||
func reloadData() {
|
||||
categories = MWMBookmarksManager.categoriesFromCatalog()
|
||||
categories = MWMBookmarksManager.shared().categoriesFromCatalog()
|
||||
}
|
||||
|
||||
func setCategory(visible: Bool, at index: Int) {
|
||||
let category = categories[index]
|
||||
category.visible = visible
|
||||
MWMBookmarksManager.setCategory(category.categoryId, isVisible: visible)
|
||||
MWMBookmarksManager.shared().setCategory(category.categoryId, isVisible: visible)
|
||||
}
|
||||
|
||||
func deleteCategory(at index: Int) {
|
||||
MWMBookmarksManager.deleteCategory(category(at: index).categoryId)
|
||||
MWMBookmarksManager.shared().deleteCategory(category(at: index).categoryId)
|
||||
reloadData()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class DownloadedBookmarksViewController: MWMViewController {
|
|||
|
||||
private func shareCategory(at index: Int) {
|
||||
let category = dataSource.category(at: index)
|
||||
guard let url = MWMBookmarksManager.sharingUrl(forCategoryId: category.categoryId) else {
|
||||
guard let url = MWMBookmarksManager.shared().sharingUrl(forCategoryId: category.categoryId) else {
|
||||
assertionFailure()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
final class BMCDefaultViewModel: NSObject {
|
||||
typealias BM = MWMBookmarksManager
|
||||
var manager: MWMBookmarksManager {
|
||||
return MWMBookmarksManager.shared()
|
||||
}
|
||||
|
||||
var view: BMCView!
|
||||
|
||||
|
@ -34,21 +36,22 @@ final class BMCDefaultViewModel: NSObject {
|
|||
if !isAuthenticated {
|
||||
Statistics.logEvent(kStatBookmarksSyncProposalShown, withParameters: [kStatHasAuthorization: 0])
|
||||
permissions = [.signup]
|
||||
} else if !BM.isCloudEnabled() {
|
||||
} else if !manager.isCloudEnabled() {
|
||||
Statistics.logEvent(kStatBookmarksSyncProposalShown, withParameters: [kStatHasAuthorization: 1])
|
||||
isPendingPermission = false
|
||||
permissions = [.backup]
|
||||
} else {
|
||||
isPendingPermission = false
|
||||
permissions = [.restore(BM.lastSynchronizationDate())]
|
||||
permissions = [.restore(manager.lastSynchronizationDate())]
|
||||
}
|
||||
}
|
||||
|
||||
private func setCategories() {
|
||||
categories = BM.groupsIdList().map { categoryId -> BMCCategory in
|
||||
let title = BM.getCategoryName(categoryId)!
|
||||
let count = BM.getCategoryMarksCount(categoryId) + BM.getCategoryTracksCount(categoryId)
|
||||
let isVisible = BM.isCategoryVisible(categoryId)
|
||||
categories = manager.groupsIdList().map {
|
||||
let categoryId = $0.uint64Value
|
||||
let title = manager.getCategoryName(categoryId)
|
||||
let count = manager.getCategoryMarksCount(categoryId) + manager.getCategoryTracksCount(categoryId)
|
||||
let isVisible = manager.isCategoryVisible(categoryId)
|
||||
return BMCCategory(identifier: categoryId, title: title, count: count, isVisible: isVisible)
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +70,7 @@ final class BMCDefaultViewModel: NSObject {
|
|||
sections.append(.permissions)
|
||||
setPermissions()
|
||||
|
||||
if BM.areBookmarksLoaded() {
|
||||
if manager.areBookmarksLoaded() {
|
||||
sections.append(.categories)
|
||||
setCategories()
|
||||
|
||||
|
@ -127,12 +130,12 @@ extension BMCDefaultViewModel: BMCViewModel {
|
|||
categories.forEach {
|
||||
$0.isVisible = isShowAll
|
||||
}
|
||||
BM.setUserCategoriesVisible(isShowAll)
|
||||
manager.setUserCategoriesVisible(isShowAll)
|
||||
}
|
||||
|
||||
func updateCategoryVisibility(category: BMCCategory) {
|
||||
category.isVisible = !category.isVisible
|
||||
BM.setCategory(category.identifier, isVisible: category.isVisible)
|
||||
manager.setCategory(category.identifier, isVisible: category.isVisible)
|
||||
}
|
||||
|
||||
func addCategory(name: String) {
|
||||
|
@ -141,13 +144,13 @@ extension BMCDefaultViewModel: BMCViewModel {
|
|||
return
|
||||
}
|
||||
|
||||
categories.append(BMCCategory(identifier: BM.createCategory(withName: name), title: name))
|
||||
categories.append(BMCCategory(identifier: manager.createCategory(withName: name), title: name))
|
||||
view.insert(at: [IndexPath(row: categories.count - 1, section: section)])
|
||||
}
|
||||
|
||||
func renameCategory(category: BMCCategory, name: String) {
|
||||
category.title = name
|
||||
BM.setCategory(category.identifier, name: name)
|
||||
manager.setCategory(category.identifier, name: name)
|
||||
}
|
||||
|
||||
func deleteCategory(category: BMCCategory) {
|
||||
|
@ -158,21 +161,21 @@ extension BMCDefaultViewModel: BMCViewModel {
|
|||
}
|
||||
|
||||
categories.remove(at: row)
|
||||
BM.deleteCategory(category.identifier)
|
||||
manager.deleteCategory(category.identifier)
|
||||
view.delete(at: [IndexPath(row: row, section: section)])
|
||||
}
|
||||
|
||||
func checkCategory(name: String) -> Bool {
|
||||
return BM.checkCategoryName(name)
|
||||
return manager.checkCategoryName(name)
|
||||
}
|
||||
|
||||
func shareCategory(category: BMCCategory, handler: @escaping onPreparedToShareHandler) {
|
||||
onPreparedToShareCategory = handler
|
||||
BM.shareCategory(category.identifier)
|
||||
manager.shareCategory(category.identifier)
|
||||
}
|
||||
|
||||
func finishShareCategory() {
|
||||
BM.finishShareCategory()
|
||||
manager.finishShareCategory()
|
||||
onPreparedToShareCategory = nil
|
||||
}
|
||||
|
||||
|
@ -193,7 +196,7 @@ extension BMCDefaultViewModel: BMCViewModel {
|
|||
kStatNetwork: Statistics.connectionTypeString(),
|
||||
kStatHasAuthorization: isAuthenticated ? 1 : 0,
|
||||
])
|
||||
BM.setCloudEnabled(true)
|
||||
manager.setCloudEnabled(true)
|
||||
case .restore:
|
||||
assertionFailure("Not implemented")
|
||||
}
|
||||
|
@ -202,38 +205,38 @@ extension BMCDefaultViewModel: BMCViewModel {
|
|||
}
|
||||
|
||||
func convertAllKMLIfNeeded() {
|
||||
let count = BM.filesCountForConversion()
|
||||
let count = manager.filesCountForConversion()
|
||||
if count > 0 {
|
||||
MWMAlertViewController.activeAlert().presentConvertBookmarksAlert(withCount: count) {
|
||||
MWMAlertViewController.activeAlert().presentConvertBookmarksAlert(withCount: count) { [weak self] in
|
||||
MWMAlertViewController.activeAlert().presentSpinnerAlert(withTitle: L("converting"),
|
||||
cancel: nil)
|
||||
BM.convertAll()
|
||||
self?.manager.convertAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addToObserverList() {
|
||||
BM.add(self)
|
||||
manager.add(self)
|
||||
}
|
||||
|
||||
func removeFromObserverList() {
|
||||
BM.remove(self)
|
||||
manager.remove(self)
|
||||
}
|
||||
|
||||
func setNotificationsEnabled(_ enabled: Bool) {
|
||||
BM.setNotificationsEnabled(enabled)
|
||||
manager.setNotificationsEnabled(enabled)
|
||||
}
|
||||
|
||||
func areNotificationsEnabled() -> Bool {
|
||||
return BM.areNotificationsEnabled()
|
||||
return manager.areNotificationsEnabled()
|
||||
}
|
||||
|
||||
func requestRestoring() {
|
||||
BM.requestRestoring()
|
||||
manager.requestRestoring()
|
||||
}
|
||||
|
||||
func applyRestoring() {
|
||||
BM.applyRestoring()
|
||||
manager.applyRestoring()
|
||||
}
|
||||
|
||||
func cancelRestoring() {
|
||||
|
@ -241,7 +244,7 @@ extension BMCDefaultViewModel: BMCViewModel {
|
|||
return
|
||||
}
|
||||
|
||||
BM.cancelRestoring()
|
||||
manager.cancelRestoring()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,7 +337,7 @@ extension BMCDefaultViewModel: MWMBookmarksObserver {
|
|||
func onBookmarksCategoryFilePrepared(_ status: MWMBookmarksShareStatus) {
|
||||
switch status {
|
||||
case .success:
|
||||
onPreparedToShareCategory?(.success(BM.shareCategoryURL()))
|
||||
onPreparedToShareCategory?(.success(manager.shareCategoryURL()))
|
||||
case .emptyCategory:
|
||||
onPreparedToShareCategory?(.error(title: L("bookmarks_error_title_share_empty"), text: L("bookmarks_error_message_share_empty")))
|
||||
case .archiveError: fallthrough
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
- (void)reloadData
|
||||
{
|
||||
self.groupIds = [MWMBookmarksManager groupsIdList];
|
||||
self.groupIds = [[MWMBookmarksManager sharedManager] groupsIdList];
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
|
@ -102,10 +102,10 @@
|
|||
isNewCategory:YES
|
||||
callback:^BOOL (NSString * name)
|
||||
{
|
||||
if (![MWMBookmarksManager checkCategoryName:name])
|
||||
if (![[MWMBookmarksManager sharedManager] checkCategoryName:name])
|
||||
return false;
|
||||
|
||||
auto const id = [MWMBookmarksManager createCategoryWithName:name];
|
||||
auto const id = [[MWMBookmarksManager sharedManager] createCategoryWithName:name];
|
||||
[self moveBookmarkToSetWithCategoryId:id];
|
||||
return true;
|
||||
}];
|
||||
|
|
|
@ -377,7 +377,7 @@ BOOL gIsFirstMyPositionMode = YES;
|
|||
});
|
||||
|
||||
self.userTouchesAction = UserTouchesActionNone;
|
||||
[MWMBookmarksManager loadBookmarks];
|
||||
[[MWMBookmarksManager sharedManager] loadBookmarks];
|
||||
[MWMFrameworkListener addObserver:self];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
extension MWMBookmarksManager {
|
||||
@nonobjc static func groupsIdList() -> [MWMMarkGroupID] {
|
||||
return groupsIdList().map { $0.uint64Value }
|
||||
}
|
||||
}
|
|
@ -4,66 +4,61 @@
|
|||
|
||||
@class MWMCatalogCategory;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@interface MWMBookmarksManager : NSObject
|
||||
|
||||
+ (void)addObserver:(id<MWMBookmarksObserver>)observer;
|
||||
+ (void)removeObserver:(id<MWMBookmarksObserver>)observer;
|
||||
+ (MWMBookmarksManager *)sharedManager;
|
||||
|
||||
+ (BOOL)areBookmarksLoaded;
|
||||
+ (void)loadBookmarks;
|
||||
- (void)addObserver:(id<MWMBookmarksObserver>)observer;
|
||||
- (void)removeObserver:(id<MWMBookmarksObserver>)observer;
|
||||
|
||||
+ (MWMGroupIDCollection)groupsIdList;
|
||||
+ (NSString *)getCategoryName:(MWMMarkGroupID)groupId;
|
||||
+ (uint64_t)getCategoryMarksCount:(MWMMarkGroupID)groupId;
|
||||
+ (uint64_t)getCategoryTracksCount:(MWMMarkGroupID)groupId;
|
||||
- (BOOL)areBookmarksLoaded;
|
||||
- (void)loadBookmarks;
|
||||
|
||||
+ (MWMMarkGroupID)createCategoryWithName:(NSString *)name;
|
||||
+ (void)setCategory:(MWMMarkGroupID)groupId name:(NSString *)name;
|
||||
+ (BOOL)isCategoryVisible:(MWMMarkGroupID)groupId;
|
||||
+ (void)setCategory:(MWMMarkGroupID)groupId isVisible:(BOOL)isVisible;
|
||||
+ (void)setUserCategoriesVisible:(BOOL)isVisible;
|
||||
+ (void)setCatalogCategoriesVisible:(BOOL)isVisible;
|
||||
+ (void)deleteCategory:(MWMMarkGroupID)groupId;
|
||||
- (MWMGroupIDCollection)groupsIdList;
|
||||
- (NSString *)getCategoryName:(MWMMarkGroupID)groupId;
|
||||
- (uint64_t)getCategoryMarksCount:(MWMMarkGroupID)groupId;
|
||||
- (uint64_t)getCategoryTracksCount:(MWMMarkGroupID)groupId;
|
||||
|
||||
+ (void)deleteBookmark:(MWMMarkID)bookmarkId;
|
||||
+ (BOOL)checkCategoryName:(NSString *)name;
|
||||
- (MWMMarkGroupID)createCategoryWithName:(NSString *)name;
|
||||
- (void)setCategory:(MWMMarkGroupID)groupId name:(NSString *)name;
|
||||
- (BOOL)isCategoryVisible:(MWMMarkGroupID)groupId;
|
||||
- (void)setCategory:(MWMMarkGroupID)groupId isVisible:(BOOL)isVisible;
|
||||
- (void)setUserCategoriesVisible:(BOOL)isVisible;
|
||||
- (void)setCatalogCategoriesVisible:(BOOL)isVisible;
|
||||
- (void)deleteCategory:(MWMMarkGroupID)groupId;
|
||||
|
||||
+ (void)shareCategory:(MWMMarkGroupID)groupId;
|
||||
+ (NSURL *)shareCategoryURL;
|
||||
+ (void)finishShareCategory;
|
||||
- (void)deleteBookmark:(MWMMarkID)bookmarkId;
|
||||
- (BOOL)checkCategoryName:(NSString *)name;
|
||||
|
||||
+ (NSDate *)lastSynchronizationDate;
|
||||
+ (BOOL)isCloudEnabled;
|
||||
+ (void)setCloudEnabled:(BOOL)enabled;
|
||||
- (void)shareCategory:(MWMMarkGroupID)groupId;
|
||||
- (NSURL *)shareCategoryURL;
|
||||
- (void)finishShareCategory;
|
||||
|
||||
+ (NSUInteger)filesCountForConversion;
|
||||
+ (void)convertAll;
|
||||
- (NSDate *)lastSynchronizationDate;
|
||||
- (BOOL)isCloudEnabled;
|
||||
- (void)setCloudEnabled:(BOOL)enabled;
|
||||
- (void)requestRestoring;
|
||||
- (void)applyRestoring;
|
||||
- (void)cancelRestoring;
|
||||
|
||||
+ (void)setNotificationsEnabled:(BOOL)enabled;
|
||||
+ (BOOL)areNotificationsEnabled;
|
||||
- (NSUInteger)filesCountForConversion;
|
||||
- (void)convertAll;
|
||||
|
||||
+ (void)requestRestoring;
|
||||
+ (void)applyRestoring;
|
||||
+ (void)cancelRestoring;
|
||||
- (void)setNotificationsEnabled:(BOOL)enabled;
|
||||
- (BOOL)areNotificationsEnabled;
|
||||
|
||||
+ (NSURL * _Nullable)catalogFrontendUrl;
|
||||
+ (NSURL * _Nullable)sharingUrlForCategoryId:(MWMMarkGroupID)groupId;
|
||||
+ (void)downloadItemWithId:(NSString * _Nonnull)itemId
|
||||
name:(NSString * _Nonnull)name
|
||||
- (NSURL * _Nullable)catalogFrontendUrl;
|
||||
- (NSURL * _Nullable)sharingUrlForCategoryId:(MWMMarkGroupID)groupId;
|
||||
- (void)downloadItemWithId:(NSString *)itemId
|
||||
name:(NSString *)name
|
||||
progress:(_Nullable ProgressBlock)progress
|
||||
completion:(_Nullable CompletionBlock)completion;
|
||||
+ (BOOL)isCategoryFromCatalog:(MWMMarkGroupID)groupId;
|
||||
+ (NSArray<MWMCatalogCategory *> * _Nonnull)categoriesFromCatalog;
|
||||
+ (NSInteger)getCatalogDownloadsCount;
|
||||
+ (BOOL)isCategoryDownloading:(NSString * _Nonnull)itemId;
|
||||
+ (BOOL)hasCategoryDownloaded:(NSString * _Nonnull)itemId;
|
||||
|
||||
- (instancetype)init __attribute__((unavailable("call +manager instead")));
|
||||
- (instancetype)copy __attribute__((unavailable("call +manager instead")));
|
||||
- (instancetype)copyWithZone:(NSZone *)zone __attribute__((unavailable("call +manager instead")));
|
||||
+ (instancetype)alloc __attribute__((unavailable("call +manager instead")));
|
||||
+ (instancetype)allocWithZone:(struct _NSZone *)zone
|
||||
__attribute__((unavailable("call +manager instead")));
|
||||
+ (instancetype) new __attribute__((unavailable("call +manager instead")));
|
||||
- (BOOL)isCategoryFromCatalog:(MWMMarkGroupID)groupId;
|
||||
- (NSArray<MWMCatalogCategory *> *)categoriesFromCatalog;
|
||||
- (NSInteger)getCatalogDownloadsCount;
|
||||
- (BOOL)isCategoryDownloading:(NSString *)itemId;
|
||||
- (BOOL)hasCategoryDownloaded:(NSString *)itemId;
|
||||
|
||||
@end
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -12,13 +12,6 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
namespace
|
||||
{
|
||||
using Observer = id<MWMBookmarksObserver>;
|
||||
using Observers = NSHashTable<Observer>;
|
||||
|
||||
using TLoopBlock = void (^)(Observer observer);
|
||||
|
||||
NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
||||
{
|
||||
switch (result)
|
||||
|
@ -31,11 +24,12 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
case Cloud::SynchronizationResult::InvalidCall: return kStatInvalidCall;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@interface MWMBookmarksManager ()
|
||||
|
||||
@property(nonatomic) Observers * observers;
|
||||
@property(nonatomic, readonly) BookmarkManager & bm;
|
||||
|
||||
@property(nonatomic) NSHashTable<id<MWMBookmarksObserver>> * observers;
|
||||
@property(nonatomic) BOOL areBookmarksLoaded;
|
||||
@property(nonatomic) NSURL * shareCategoryURL;
|
||||
|
||||
|
@ -45,7 +39,7 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
|
||||
@implementation MWMBookmarksManager
|
||||
|
||||
+ (instancetype)manager
|
||||
+ (instancetype)sharedManager
|
||||
{
|
||||
static MWMBookmarksManager * manager;
|
||||
static dispatch_once_t onceToken;
|
||||
|
@ -55,17 +49,22 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
return manager;
|
||||
}
|
||||
|
||||
+ (void)addObserver:(Observer)observer
|
||||
- (BookmarkManager &)bm
|
||||
{
|
||||
return GetFramework().GetBookmarkManager();
|
||||
}
|
||||
|
||||
- (void)addObserver:(id<MWMBookmarksObserver>)observer
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[MWMBookmarksManager manager].observers addObject:observer];
|
||||
[self.observers addObject:observer];
|
||||
});
|
||||
}
|
||||
|
||||
+ (void)removeObserver:(Observer)observer
|
||||
- (void)removeObserver:(id<MWMBookmarksObserver>)observer
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[MWMBookmarksManager manager].observers removeObject:observer];
|
||||
[self.observers removeObject:observer];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -74,8 +73,9 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
_observers = [Observers weakObjectsHashTable];
|
||||
_observers = [NSHashTable<id<MWMBookmarksObserver>> weakObjectsHashTable];
|
||||
[self registerBookmarksObserver];
|
||||
[self registerCatalogObservers];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
if (!self)
|
||||
return;
|
||||
self.areBookmarksLoaded = YES;
|
||||
[self loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onBookmarksLoadFinished)])
|
||||
[observer onBookmarksLoadFinished];
|
||||
}];
|
||||
|
@ -110,7 +110,7 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
if (!self)
|
||||
return;
|
||||
[self processFileEvent:YES];
|
||||
[self loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onBookmarksFileLoadSuccess)])
|
||||
[observer onBookmarksFileLoadSuccess];
|
||||
}];
|
||||
|
@ -124,18 +124,71 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
[wSelf processFileEvent:NO];
|
||||
};
|
||||
}
|
||||
GetFramework().GetBookmarkManager().SetAsyncLoadingCallbacks(std::move(bookmarkCallbacks));
|
||||
self.bm.SetAsyncLoadingCallbacks(std::move(bookmarkCallbacks));
|
||||
}
|
||||
|
||||
+ (BOOL)areBookmarksLoaded { return [MWMBookmarksManager manager].areBookmarksLoaded; }
|
||||
|
||||
+ (void)loadBookmarks
|
||||
- (void)registerCatalogObservers
|
||||
{
|
||||
[MWMBookmarksManager manager];
|
||||
|
||||
auto & bm = GetFramework().GetBookmarkManager();
|
||||
|
||||
auto onSynchronizationStarted = [](Cloud::SynchronizationType type)
|
||||
self.catalogObservers = [NSMutableDictionary dictionary];
|
||||
auto onDownloadStarted = [self](std::string const & serverCatId)
|
||||
{
|
||||
auto observer = self.catalogObservers[@(serverCatId.c_str())];
|
||||
if (observer)
|
||||
[observer onDownloadStart];
|
||||
};
|
||||
auto onDownloadFinished = [self](std::string const & serverCatId, platform::RemoteFile::Result const & result)
|
||||
{
|
||||
auto observer = self.catalogObservers[@(serverCatId.c_str())];
|
||||
if (observer)
|
||||
{
|
||||
[observer onDownloadComplete:result.m_status];
|
||||
if (result.m_status != platform::RemoteFile::Status::Ok) {
|
||||
[self.catalogObservers removeObjectForKey:observer.categoryId];
|
||||
}
|
||||
}
|
||||
};
|
||||
auto onImportStarted = [self](std::string const & serverCatId)
|
||||
{
|
||||
auto observer = self.catalogObservers[@(serverCatId.c_str())];
|
||||
if (observer)
|
||||
[observer onImportStart];
|
||||
};
|
||||
auto onImportFinished = [self](std::string const & serverCatId, kml::MarkGroupId categoryId, bool successful)
|
||||
{
|
||||
auto observer = self.catalogObservers[@(serverCatId.c_str())];
|
||||
if (observer)
|
||||
{
|
||||
[observer onImportCompleteSuccessful:successful forCategoryId:categoryId];
|
||||
[self.catalogObservers removeObjectForKey:observer.categoryId];
|
||||
}
|
||||
};
|
||||
auto onUploadStarted = [](kml::MarkGroupId originCategoryId)
|
||||
{
|
||||
//TODO(@beloal): Implement me.
|
||||
};
|
||||
auto onUploadFinished = [](BookmarkCatalog::UploadResult uploadResult,std::string const & description,
|
||||
kml::MarkGroupId originCategoryId, kml::MarkGroupId resultCategoryId)
|
||||
{
|
||||
//TODO(@beloal): Implement me.
|
||||
};
|
||||
GetFramework().GetBookmarkManager().SetCatalogHandlers(std::move(onDownloadStarted),
|
||||
std::move(onDownloadFinished),
|
||||
std::move(onImportStarted),
|
||||
std::move(onImportFinished),
|
||||
std::move(onUploadStarted),
|
||||
std::move(onUploadFinished));
|
||||
}
|
||||
|
||||
#pragma mark - Bookmarks loading
|
||||
|
||||
- (BOOL)areBookmarksLoaded
|
||||
{
|
||||
return _areBookmarksLoaded;
|
||||
}
|
||||
|
||||
- (void)loadBookmarks
|
||||
{
|
||||
auto onSynchronizationStarted = [self](Cloud::SynchronizationType type)
|
||||
{
|
||||
if (type == Cloud::SynchronizationType::Backup)
|
||||
{
|
||||
|
@ -143,14 +196,14 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
}
|
||||
else
|
||||
{
|
||||
[[MWMBookmarksManager manager] loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onRestoringStarted)])
|
||||
[observer onRestoringStarted];
|
||||
}];
|
||||
}
|
||||
};
|
||||
|
||||
auto onSynchronizationFinished = [](Cloud::SynchronizationType type, Cloud::SynchronizationResult result,
|
||||
auto onSynchronizationFinished = [self](Cloud::SynchronizationType type, Cloud::SynchronizationResult result,
|
||||
std::string const & errorStr)
|
||||
{
|
||||
if (result == Cloud::SynchronizationResult::Success)
|
||||
|
@ -165,13 +218,13 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
withParameters:@{kStatType: error, kStatError: @(errorStr.c_str())}];
|
||||
}
|
||||
|
||||
[[MWMBookmarksManager manager] loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onSynchronizationFinished:)])
|
||||
[observer onSynchronizationFinished:static_cast<MWMSynchronizationResult>(base::Key(result))];
|
||||
}];
|
||||
};
|
||||
|
||||
auto onRestoreRequested = [](Cloud::RestoringRequestResult result, std::string const & deviceName,
|
||||
auto onRestoreRequested = [self](Cloud::RestoringRequestResult result, std::string const & deviceName,
|
||||
uint64_t backupTimestampInMs)
|
||||
{
|
||||
auto const res = static_cast<MWMRestoringRequestResult>(base::Key(result));
|
||||
|
@ -193,26 +246,28 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
withParameters:@{kStatType: kStatDisk, kStatError: @("Not enough disk space")}];
|
||||
}
|
||||
|
||||
[[MWMBookmarksManager manager] loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onRestoringRequest:deviceName:backupDate:)])
|
||||
[observer onRestoringRequest:res deviceName:@(deviceName.c_str()) backupDate:date];
|
||||
}];
|
||||
};
|
||||
|
||||
auto onRestoredFilesPrepared = []
|
||||
auto onRestoredFilesPrepared = [self]
|
||||
{
|
||||
[[MWMBookmarksManager manager] loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onRestoringFilesPrepared)])
|
||||
[observer onRestoringFilesPrepared];
|
||||
}];
|
||||
};
|
||||
|
||||
bm.SetCloudHandlers(std::move(onSynchronizationStarted), std::move(onSynchronizationFinished),
|
||||
self.bm.SetCloudHandlers(std::move(onSynchronizationStarted), std::move(onSynchronizationFinished),
|
||||
std::move(onRestoreRequested), std::move(onRestoredFilesPrepared));
|
||||
bm.LoadBookmarks();
|
||||
self.bm.LoadBookmarks();
|
||||
}
|
||||
|
||||
+ (MWMGroupIDCollection)groupsIdList
|
||||
#pragma mark - Categories
|
||||
|
||||
- (MWMGroupIDCollection)groupsIdList
|
||||
{
|
||||
auto const & list = GetFramework().GetBookmarkManager().GetBmGroupsIdList();
|
||||
NSMutableArray<NSNumber *> * collection = @[].mutableCopy;
|
||||
|
@ -224,89 +279,90 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
return collection.copy;
|
||||
}
|
||||
|
||||
+ (NSString *)getCategoryName:(MWMMarkGroupID)groupId
|
||||
- (NSString *)getCategoryName:(MWMMarkGroupID)groupId
|
||||
{
|
||||
return @(GetFramework().GetBookmarkManager().GetCategoryName(groupId).c_str());
|
||||
}
|
||||
|
||||
+ (uint64_t)getCategoryMarksCount:(MWMMarkGroupID)groupId
|
||||
- (uint64_t)getCategoryMarksCount:(MWMMarkGroupID)groupId
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().GetUserMarkIds(groupId).size();
|
||||
}
|
||||
|
||||
+ (uint64_t)getCategoryTracksCount:(MWMMarkGroupID)groupId
|
||||
- (uint64_t)getCategoryTracksCount:(MWMMarkGroupID)groupId
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().GetTrackIds(groupId).size();
|
||||
}
|
||||
|
||||
+ (MWMMarkGroupID)createCategoryWithName:(NSString *)name
|
||||
- (MWMMarkGroupID)createCategoryWithName:(NSString *)name
|
||||
{
|
||||
auto groupId = GetFramework().GetBookmarkManager().CreateBookmarkCategory(name.UTF8String);
|
||||
GetFramework().GetBookmarkManager().SetLastEditedBmCategory(groupId);
|
||||
return groupId;
|
||||
}
|
||||
|
||||
+ (void)setCategory:(MWMMarkGroupID)groupId name:(NSString *)name
|
||||
- (void)setCategory:(MWMMarkGroupID)groupId name:(NSString *)name
|
||||
{
|
||||
GetFramework().GetBookmarkManager().GetEditSession().SetCategoryName(groupId, name.UTF8String);
|
||||
}
|
||||
|
||||
+ (BOOL)isCategoryVisible:(MWMMarkGroupID)groupId
|
||||
- (BOOL)isCategoryVisible:(MWMMarkGroupID)groupId
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().IsVisible(groupId);
|
||||
}
|
||||
|
||||
+ (void)setCategory:(MWMMarkGroupID)groupId isVisible:(BOOL)isVisible
|
||||
- (void)setCategory:(MWMMarkGroupID)groupId isVisible:(BOOL)isVisible
|
||||
{
|
||||
GetFramework().GetBookmarkManager().GetEditSession().SetIsVisible(groupId, isVisible);
|
||||
}
|
||||
|
||||
+ (void)setUserCategoriesVisible:(BOOL)isVisible {
|
||||
- (void)setUserCategoriesVisible:(BOOL)isVisible {
|
||||
GetFramework().GetBookmarkManager()
|
||||
.SetAllCategoriesVisibility(BookmarkManager::CategoryFilterType::Private, isVisible);
|
||||
}
|
||||
|
||||
+ (void)setCatalogCategoriesVisible:(BOOL)isVisible {
|
||||
- (void)setCatalogCategoriesVisible:(BOOL)isVisible {
|
||||
GetFramework().GetBookmarkManager()
|
||||
.SetAllCategoriesVisibility(BookmarkManager::CategoryFilterType::Public, isVisible);
|
||||
}
|
||||
|
||||
+ (void)deleteCategory:(MWMMarkGroupID)groupId
|
||||
- (void)deleteCategory:(MWMMarkGroupID)groupId
|
||||
{
|
||||
GetFramework().GetBookmarkManager().GetEditSession().DeleteBmCategory(groupId);
|
||||
[[self manager] loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onBookmarksCategoryDeleted:)])
|
||||
[observer onBookmarksCategoryDeleted:groupId];
|
||||
}];
|
||||
}
|
||||
|
||||
+ (void)deleteBookmark:(MWMMarkID)bookmarkId
|
||||
- (void)deleteBookmark:(MWMMarkID)bookmarkId
|
||||
{
|
||||
GetFramework().GetBookmarkManager().GetEditSession().DeleteBookmark(bookmarkId);
|
||||
[[self manager] loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onBookmarkDeleted:)])
|
||||
[observer onBookmarkDeleted:bookmarkId];
|
||||
}];
|
||||
}
|
||||
|
||||
+ (BOOL)checkCategoryName:(NSString *)name
|
||||
- (BOOL)checkCategoryName:(NSString *)name
|
||||
{
|
||||
return !GetFramework().GetBookmarkManager().IsUsedCategoryName(name.UTF8String);
|
||||
}
|
||||
|
||||
+ (void)shareCategory:(MWMMarkGroupID)groupId
|
||||
#pragma mark - Category sharing
|
||||
|
||||
- (void)shareCategory:(MWMMarkGroupID)groupId
|
||||
{
|
||||
GetFramework().GetBookmarkManager().PrepareFileForSharing(groupId, [](auto sharingResult)
|
||||
GetFramework().GetBookmarkManager().PrepareFileForSharing(groupId, [self](auto sharingResult)
|
||||
{
|
||||
MWMBookmarksShareStatus status;
|
||||
MWMBookmarksManager * manager = [MWMBookmarksManager manager];
|
||||
switch (sharingResult.m_code)
|
||||
{
|
||||
case BookmarkManager::SharingResult::Code::Success:
|
||||
{
|
||||
manager.shareCategoryURL = [NSURL fileURLWithPath:@(sharingResult.m_sharingPath.c_str())
|
||||
self.shareCategoryURL = [NSURL fileURLWithPath:@(sharingResult.m_sharingPath.c_str())
|
||||
isDirectory:NO];
|
||||
ASSERT(manager.shareCategoryURL, ("Invalid share category url"));
|
||||
ASSERT(self.shareCategoryURL, ("Invalid share category url"));
|
||||
status = MWMBookmarksShareStatusSuccess;
|
||||
break;
|
||||
}
|
||||
|
@ -321,45 +377,47 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
break;
|
||||
}
|
||||
|
||||
[manager loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onBookmarksCategoryFilePrepared:)])
|
||||
[observer onBookmarksCategoryFilePrepared:status];
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
+ (NSUInteger)filesCountForConversion
|
||||
- (NSURL *)shareCategoryURL
|
||||
{
|
||||
NSAssert(_shareCategoryURL != nil, @"Invalid share category url");
|
||||
return _shareCategoryURL;
|
||||
}
|
||||
|
||||
- (void)finishShareCategory
|
||||
{
|
||||
if (!self.shareCategoryURL)
|
||||
return;
|
||||
|
||||
base::DeleteFileX(self.shareCategoryURL.path.UTF8String);
|
||||
self.shareCategoryURL = nil;
|
||||
}
|
||||
|
||||
#pragma mark - klm conversion
|
||||
|
||||
- (NSUInteger)filesCountForConversion
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().GetKmlFilesCountForConversion();
|
||||
}
|
||||
|
||||
+ (void)convertAll
|
||||
- (void)convertAll
|
||||
{
|
||||
GetFramework().GetBookmarkManager().ConvertAllKmlFiles([](bool success) {
|
||||
[[MWMBookmarksManager manager] loopObservers:^(Observer observer) {
|
||||
GetFramework().GetBookmarkManager().ConvertAllKmlFiles([self](bool success) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
[observer onConversionFinish:success];
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
+ (NSURL *)shareCategoryURL
|
||||
{
|
||||
MWMBookmarksManager * manager = [MWMBookmarksManager manager];
|
||||
NSAssert(manager.shareCategoryURL != nil, @"Invalid share category url");
|
||||
return manager.shareCategoryURL;
|
||||
}
|
||||
#pragma mark - Cloud sync
|
||||
|
||||
+ (void)finishShareCategory
|
||||
{
|
||||
MWMBookmarksManager * manager = [MWMBookmarksManager manager];
|
||||
if (!manager.shareCategoryURL)
|
||||
return;
|
||||
|
||||
base::DeleteFileX(manager.shareCategoryURL.path.UTF8String);
|
||||
manager.shareCategoryURL = nil;
|
||||
}
|
||||
|
||||
+ (NSDate *)lastSynchronizationDate
|
||||
- (NSDate *)lastSynchronizationDate
|
||||
{
|
||||
auto timestampInMs = GetFramework().GetBookmarkManager().GetLastSynchronizationTimestampInMs();
|
||||
if (timestampInMs == 0)
|
||||
|
@ -367,14 +425,17 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
return [NSDate dateWithTimeIntervalSince1970:timestampInMs / 1000];
|
||||
}
|
||||
|
||||
+ (BOOL)isCloudEnabled { return GetFramework().GetBookmarkManager().IsCloudEnabled(); }
|
||||
- (BOOL)isCloudEnabled
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().IsCloudEnabled();
|
||||
}
|
||||
|
||||
+ (void)setCloudEnabled:(BOOL)enabled
|
||||
- (void)setCloudEnabled:(BOOL)enabled
|
||||
{
|
||||
GetFramework().GetBookmarkManager().SetCloudEnabled(enabled);
|
||||
}
|
||||
|
||||
+ (void)requestRestoring
|
||||
- (void)requestRestoring
|
||||
{
|
||||
auto const status = Platform::ConnectionStatus();
|
||||
auto statusStr = [](Platform::EConnectionType type) -> NSString * {
|
||||
|
@ -394,7 +455,7 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
|
||||
if (status == Platform::EConnectionType::CONNECTION_NONE)
|
||||
{
|
||||
[self.manager loopObservers:^(Observer observer) {
|
||||
[self loopObservers:^(id<MWMBookmarksObserver> observer) {
|
||||
if ([observer respondsToSelector:@selector(onRestoringRequest:deviceName:backupDate:)])
|
||||
[observer onRestoringRequest:MWMRestoringRequestResultNoInternet deviceName:nil backupDate:nil];
|
||||
}];
|
||||
|
@ -404,131 +465,62 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
GetFramework().GetBookmarkManager().RequestCloudRestoring();
|
||||
}
|
||||
|
||||
+ (void)applyRestoring
|
||||
- (void)applyRestoring
|
||||
{
|
||||
GetFramework().GetBookmarkManager().ApplyCloudRestoring();
|
||||
}
|
||||
|
||||
+ (void)cancelRestoring
|
||||
- (void)cancelRestoring
|
||||
{
|
||||
[Statistics logEvent:kStatBookmarksRestoreProposalCancel];
|
||||
GetFramework().GetBookmarkManager().CancelCloudRestoring();
|
||||
}
|
||||
|
||||
- (void)loopObservers:(TLoopBlock)block
|
||||
{
|
||||
for (Observer observer in self.observers)
|
||||
{
|
||||
if (observer)
|
||||
block(observer);
|
||||
}
|
||||
}
|
||||
#pragma mark - Notifications
|
||||
|
||||
- (void)processFileEvent:(BOOL)success
|
||||
{
|
||||
UIAlertController * alert = [UIAlertController
|
||||
alertControllerWithTitle:L(@"load_kmz_title")
|
||||
message:success ? L(@"load_kmz_successful") : L(@"load_kmz_failed")
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction * action =
|
||||
[UIAlertAction actionWithTitle:L(@"ok") style:UIAlertActionStyleDefault handler:nil];
|
||||
[alert addAction:action];
|
||||
alert.preferredAction = action;
|
||||
[[UIViewController topViewController] presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
+ (void)setNotificationsEnabled:(BOOL)enabled
|
||||
- (void)setNotificationsEnabled:(BOOL)enabled
|
||||
{
|
||||
GetFramework().GetBookmarkManager().SetNotificationsEnabled(enabled);
|
||||
}
|
||||
|
||||
+ (BOOL)areNotificationsEnabled
|
||||
- (BOOL)areNotificationsEnabled
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().AreNotificationsEnabled();
|
||||
}
|
||||
|
||||
+ (NSURL *)catalogFrontendUrl
|
||||
#pragma mark - Catalog
|
||||
|
||||
- (NSURL *)catalogFrontendUrl
|
||||
{
|
||||
NSString * urlString = @(GetFramework().GetBookmarkManager().GetCatalog().GetFrontendUrl().c_str());
|
||||
return urlString ? [NSURL URLWithString:urlString] : nil;
|
||||
}
|
||||
|
||||
+ (NSURL *)sharingUrlForCategoryId:(MWMMarkGroupID)groupId
|
||||
- (NSURL *)sharingUrlForCategoryId:(MWMMarkGroupID)groupId
|
||||
{
|
||||
NSString * urlString = @(GetFramework().GetBookmarkManager().GetCategoryCatalogDeeplink(groupId).c_str());
|
||||
return urlString ? [NSURL URLWithString:urlString] : nil;
|
||||
}
|
||||
|
||||
+ (void)downloadItemWithId:(NSString *)itemId
|
||||
- (void)downloadItemWithId:(NSString *)itemId
|
||||
name:(NSString *)name
|
||||
progress:(ProgressBlock)progress
|
||||
completion:(CompletionBlock)completion
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[MWMBookmarksManager manager].catalogObservers = [NSMutableDictionary dictionary];
|
||||
auto onDownloadStarted = [](std::string const & serverCatId)
|
||||
{
|
||||
auto observer = [MWMBookmarksManager manager].catalogObservers[@(serverCatId.c_str())];
|
||||
if (observer)
|
||||
[observer onDownloadStart];
|
||||
};
|
||||
auto onDownloadFinished = [](std::string const & serverCatId, BookmarkCatalog::DownloadResult result)
|
||||
{
|
||||
auto observer = [MWMBookmarksManager manager].catalogObservers[@(serverCatId.c_str())];
|
||||
if (observer)
|
||||
{
|
||||
[observer onDownloadComplete:result];
|
||||
if (result != BookmarkCatalog::DownloadResult::Success) {
|
||||
[[MWMBookmarksManager manager].catalogObservers removeObjectForKey:observer.categoryId];
|
||||
}
|
||||
}
|
||||
};
|
||||
auto onImportStarted = [](std::string const & serverCatId)
|
||||
{
|
||||
auto observer = [MWMBookmarksManager manager].catalogObservers[@(serverCatId.c_str())];
|
||||
if (observer)
|
||||
[observer onImportStart];
|
||||
};
|
||||
auto onImportFinished = [](std::string const & serverCatId, kml::MarkGroupId categoryId, bool successful)
|
||||
{
|
||||
auto observer = [MWMBookmarksManager manager].catalogObservers[@(serverCatId.c_str())];
|
||||
if (observer)
|
||||
{
|
||||
[observer onImportCompleteSuccessful:successful forCategoryId:categoryId];
|
||||
[[MWMBookmarksManager manager].catalogObservers removeObjectForKey:observer.categoryId];
|
||||
}
|
||||
};
|
||||
auto onUploadStarted = [](kml::MarkGroupId originCategoryId)
|
||||
{
|
||||
//TODO(@beloal): Implement me.
|
||||
};
|
||||
auto onUploadFinished = [](BookmarkCatalog::UploadResult uploadResult,std::string const & description,
|
||||
kml::MarkGroupId originCategoryId, kml::MarkGroupId resultCategoryId)
|
||||
{
|
||||
//TODO(@beloal): Implement me.
|
||||
};
|
||||
GetFramework().GetBookmarkManager().SetCatalogHandlers(std::move(onDownloadStarted),
|
||||
std::move(onDownloadFinished),
|
||||
std::move(onImportStarted),
|
||||
std::move(onImportFinished),
|
||||
std::move(onUploadStarted),
|
||||
std::move(onUploadFinished));
|
||||
});
|
||||
auto observer = [[MWMCatalogObserver alloc] init];
|
||||
observer.categoryId = itemId;
|
||||
observer.progressBlock = progress;
|
||||
observer.completionBlock = completion;
|
||||
[[MWMBookmarksManager manager].catalogObservers setObject:observer forKey:itemId];
|
||||
[self.catalogObservers setObject:observer forKey:itemId];
|
||||
GetFramework().GetBookmarkManager().DownloadFromCatalogAndImport(itemId.UTF8String, name.UTF8String);
|
||||
}
|
||||
|
||||
+ (BOOL)isCategoryFromCatalog:(MWMMarkGroupID)groupId
|
||||
- (BOOL)isCategoryFromCatalog:(MWMMarkGroupID)groupId
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().IsCategoryFromCatalog(groupId);
|
||||
}
|
||||
|
||||
+ (NSArray<MWMCatalogCategory *> *)categoriesFromCatalog
|
||||
- (NSArray<MWMCatalogCategory *> *)categoriesFromCatalog
|
||||
{
|
||||
NSMutableArray * result = [NSMutableArray array];
|
||||
auto const & list = GetFramework().GetBookmarkManager().GetBmGroupsIdList();
|
||||
|
@ -546,19 +538,43 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
return [result copy];
|
||||
}
|
||||
|
||||
+ (NSInteger)getCatalogDownloadsCount
|
||||
- (NSInteger)getCatalogDownloadsCount
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().GetCatalog().GetDownloadingCount();
|
||||
}
|
||||
|
||||
+ (BOOL)isCategoryDownloading:(NSString *)itemId
|
||||
- (BOOL)isCategoryDownloading:(NSString *)itemId
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().GetCatalog().IsDownloading(itemId.UTF8String);
|
||||
}
|
||||
|
||||
+ (BOOL)hasCategoryDownloaded:(NSString *)itemId
|
||||
- (BOOL)hasCategoryDownloaded:(NSString *)itemId
|
||||
{
|
||||
return GetFramework().GetBookmarkManager().GetCatalog().HasDownloaded(itemId.UTF8String);
|
||||
}
|
||||
|
||||
#pragma mark - Helpers
|
||||
|
||||
- (void)loopObservers:(void (^)(id<MWMBookmarksObserver> observer))block
|
||||
{
|
||||
for (id<MWMBookmarksObserver> observer in self.observers)
|
||||
{
|
||||
if (observer)
|
||||
block(observer);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)processFileEvent:(BOOL)success
|
||||
{
|
||||
UIAlertController * alert = [UIAlertController
|
||||
alertControllerWithTitle:L(@"load_kmz_title")
|
||||
message:success ? L(@"load_kmz_successful") : L(@"load_kmz_failed")
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction * action =
|
||||
[UIAlertAction actionWithTitle:L(@"ok") style:UIAlertActionStyleDefault handler:nil];
|
||||
[alert addAction:action];
|
||||
alert.preferredAction = action;
|
||||
[[UIViewController topViewController] presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -195,7 +195,6 @@
|
|||
349D1CE41E3F836900A878FD /* UIViewController+Hierarchy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349D1CE21E3F836900A878FD /* UIViewController+Hierarchy.swift */; };
|
||||
349FC5481F680DAE00968C9F /* ExpandableTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349FC5451F680DAE00968C9F /* ExpandableTextView.swift */; };
|
||||
349FC54B1F680DAE00968C9F /* ExpandableTextViewSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349FC5461F680DAE00968C9F /* ExpandableTextViewSettings.swift */; };
|
||||
34A320CE2035ABE200BC36D5 /* MWMBookmarksManager+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A320CD2035ABE200BC36D5 /* MWMBookmarksManager+Swift.swift */; };
|
||||
34AB39C21D2BD8310021857D /* MWMStopButton.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34AB39C01D2BD8310021857D /* MWMStopButton.mm */; };
|
||||
34AB66051FC5AA320078E451 /* MWMNavigationDashboardManager+Entity.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34AB65C51FC5AA320078E451 /* MWMNavigationDashboardManager+Entity.mm */; };
|
||||
34AB66081FC5AA320078E451 /* MWMNavigationDashboardManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34AB65C61FC5AA320078E451 /* MWMNavigationDashboardManager.mm */; };
|
||||
|
@ -1064,7 +1063,6 @@
|
|||
349D1CE21E3F836900A878FD /* UIViewController+Hierarchy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Hierarchy.swift"; sourceTree = "<group>"; };
|
||||
349FC5451F680DAE00968C9F /* ExpandableTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableTextView.swift; sourceTree = "<group>"; };
|
||||
349FC5461F680DAE00968C9F /* ExpandableTextViewSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableTextViewSettings.swift; sourceTree = "<group>"; };
|
||||
34A320CD2035ABE200BC36D5 /* MWMBookmarksManager+Swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MWMBookmarksManager+Swift.swift"; sourceTree = "<group>"; };
|
||||
34AB39BF1D2BD8310021857D /* MWMStopButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMStopButton.h; sourceTree = "<group>"; };
|
||||
34AB39C01D2BD8310021857D /* MWMStopButton.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMStopButton.mm; sourceTree = "<group>"; };
|
||||
34AB65C51FC5AA320078E451 /* MWMNavigationDashboardManager+Entity.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "MWMNavigationDashboardManager+Entity.mm"; sourceTree = "<group>"; };
|
||||
|
@ -2738,7 +2736,6 @@
|
|||
347039A61FB9A5CF00E47496 /* MWMBookmarksManager.h */,
|
||||
347039A71FB9A5CF00E47496 /* MWMBookmarksManager.mm */,
|
||||
347039AB1FB9A97E00E47496 /* MWMBookmarksObserver.h */,
|
||||
34A320CD2035ABE200BC36D5 /* MWMBookmarksManager+Swift.swift */,
|
||||
B33D21B020DBCC5D00BAD749 /* MWMCatalogObserver.h */,
|
||||
B33D21B120DBCC5D00BAD749 /* MWMCatalogObserver.mm */,
|
||||
B33D21B320DBF3EB00BAD749 /* MWMCatalogCommon.h */,
|
||||
|
@ -5002,7 +4999,6 @@
|
|||
348F8A4F1F863A8500060C2A /* UGCYourReview.swift in Sources */,
|
||||
F6E2FEE21E097BA00083EBEC /* MWMSearchManager.mm in Sources */,
|
||||
F6E2FE221E097BA00083EBEC /* MWMOpeningHoursEditorViewController.mm in Sources */,
|
||||
34A320CE2035ABE200BC36D5 /* MWMBookmarksManager+Swift.swift in Sources */,
|
||||
34943BBB1E2626B200B14F84 /* WelcomePageController.swift in Sources */,
|
||||
34D3AFE21E376F7E004100F9 /* UITableView+Updates.swift in Sources */,
|
||||
3404164C1E7BF42E00E2B6D6 /* UIView+Coordinates.swift in Sources */,
|
||||
|
|
|
@ -519,7 +519,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
|
|||
if (bookmark)
|
||||
{
|
||||
f.ResetBookmarkInfo(*bookmark, m_info);
|
||||
[MWMBookmarksManager deleteBookmark:bookmarkId];
|
||||
[[MWMBookmarksManager sharedManager] deleteBookmark:bookmarkId];
|
||||
}
|
||||
|
||||
m_sections.erase(remove(m_sections.begin(), m_sections.end(), Sections::Bookmark));
|
||||
|
@ -749,7 +749,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
|
|||
|
||||
- (BOOL)isBookmarkFromCatalog
|
||||
{
|
||||
return self.isBookmark && [MWMBookmarksManager isCategoryFromCatalog:self.bookmarkCategoryId];
|
||||
return self.isBookmark && [[MWMBookmarksManager sharedManager] isCategoryFromCatalog:self.bookmarkCategoryId];
|
||||
}
|
||||
|
||||
#pragma mark - Local Ads
|
||||
|
|
|
@ -100,7 +100,7 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName)
|
|||
}
|
||||
|
||||
[MWMLocationManager addObserver:self];
|
||||
[MWMBookmarksManager addObserver:self];
|
||||
[[MWMBookmarksManager sharedManager] addObserver:self];
|
||||
|
||||
[self setupSpeedAndDistance];
|
||||
|
||||
|
@ -114,7 +114,7 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName)
|
|||
{
|
||||
[self.layout close];
|
||||
self.data = nil;
|
||||
[MWMBookmarksManager removeObserver:self];
|
||||
[[MWMBookmarksManager sharedManager] removeObserver:self];
|
||||
[MWMLocationManager removeObserver:self];
|
||||
[MWMFrameworkListener removeObserver:self];
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ extern NSString * const kAlohalyticsTapEventKey;
|
|||
|
||||
[self.backupBookmarksCell configWithDelegate:self
|
||||
title:L(@"settings_backup_bookmarks")
|
||||
isOn:[MWMBookmarksManager isCloudEnabled]];
|
||||
isOn:[[MWMBookmarksManager sharedManager] isCloudEnabled]];
|
||||
|
||||
NSString * mobileInternet = nil;
|
||||
switch (network_policy::GetStage())
|
||||
|
@ -232,7 +232,7 @@ extern NSString * const kAlohalyticsTapEventKey;
|
|||
withParameters:@{
|
||||
kStatState: (value ? @1 : @0)
|
||||
}];
|
||||
[MWMBookmarksManager setCloudEnabled:value];
|
||||
[[MWMBookmarksManager sharedManager] setCloudEnabled:value];
|
||||
}
|
||||
else if (cell == self.fontScaleCell)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue