From 98f8e50ebaef63f2b4aeeb39176f923937ed87a7 Mon Sep 17 00:00:00 2001 From: Alexey Belousov Date: Tue, 19 Jun 2018 18:41:46 +0300 Subject: [PATCH] [ios] disable editing for categories from catalog --- .../BMCView/BMCViewController.swift | 6 +-- .../BMCViewModel/BMCDefaultViewModel.swift | 10 +++-- iphone/Maps/Bookmarks/SelectSetVC.mm | 16 ++++++-- iphone/Maps/Classes/Components/MWMButton.mm | 11 +++++ .../Maps/Core/Bookmarks/MWMBookmarksManager.h | 3 -- .../Core/Bookmarks/MWMBookmarksManager.mm | 13 +----- iphone/Maps/UI/PlacePage/MWMPlacePageData.h | 1 + iphone/Maps/UI/PlacePage/MWMPlacePageData.mm | 4 ++ .../ActionBar/MWMActionBarButton.h | 3 +- .../ActionBar/MWMActionBarButton.mm | 7 +++- .../ActionBar/MWMPlacePageActionBar.h | 1 + .../ActionBar/MWMPlacePageActionBar.mm | 4 +- .../PlacePageLayout/MWMPlacePageLayout.mm | 2 +- map/bookmark_manager.cpp | 41 ------------------- map/bookmark_manager.hpp | 3 -- 15 files changed, 51 insertions(+), 74 deletions(-) diff --git a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift index a6f248d396..e6922a7c54 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift @@ -245,7 +245,7 @@ extension BMCViewController: UITableViewDelegate { case .permissions: return permissionsHeader case .categories: let categoriesHeader = tableView.dequeueReusableHeaderFooterView(BMCCategoriesHeader.self) - categoriesHeader.isShowAll = viewModel.areAllCategoriesInvisible() + categoriesHeader.isShowAll = !viewModel.areAllCategoriesInvisible() categoriesHeader.delegate = self return categoriesHeader case .actions: return actionsHeader @@ -290,7 +290,7 @@ extension BMCViewController: BMCCategoryCellDelegate { func visibilityAction(category: BMCCategory) { viewModel.updateCategoryVisibility(category: category) let categoriesHeader = tableView.headerView(forSection: viewModel.sectionIndex(section: .categories)) as! BMCCategoriesHeader - categoriesHeader.isShowAll = viewModel.areAllCategoriesInvisible() + categoriesHeader.isShowAll = !viewModel.areAllCategoriesInvisible() } func moreAction(category: BMCCategory, anchor: UIView) { @@ -318,6 +318,6 @@ extension BMCViewController: BMCPermissionsHeaderDelegate { extension BMCViewController: BMCCategoriesHeaderDelegate { func visibilityAction(_ categoriesHeader: BMCCategoriesHeader) { viewModel.updateAllCategoriesVisibility(isShowAll: categoriesHeader.isShowAll) - categoriesHeader.isShowAll = viewModel.areAllCategoriesInvisible() + categoriesHeader.isShowAll = !viewModel.areAllCategoriesInvisible() } } diff --git a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift index 747270ad73..a69be697d4 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift @@ -118,12 +118,16 @@ extension BMCDefaultViewModel: BMCViewModel { } func areAllCategoriesInvisible() -> Bool { - return BM.areAllCategoriesInvisible() + var result = true; + categories.forEach { if !$0.isVisible { result = false } } + return result } func updateAllCategoriesVisibility(isShowAll: Bool) { - categories.forEach { $0.isVisible = isShowAll } - BM.setAllCategoriesVisible(isShowAll) + categories.forEach { + $0.isVisible = isShowAll + BM.setCategory($0.identifier, isVisible: isShowAll) + } } func updateCategoryVisibility(category: BMCCategory) { diff --git a/iphone/Maps/Bookmarks/SelectSetVC.mm b/iphone/Maps/Bookmarks/SelectSetVC.mm index 4d94f9b149..3ea82cfb9c 100644 --- a/iphone/Maps/Bookmarks/SelectSetVC.mm +++ b/iphone/Maps/Bookmarks/SelectSetVC.mm @@ -10,6 +10,7 @@ } @property (copy, nonatomic) NSString * category; +@property (copy, nonatomic) MWMGroupIDCollection groupIds; @property (weak, nonatomic) id delegate; @end @@ -36,6 +37,13 @@ NSAssert(self.category, @"Category can't be nil!"); NSAssert(self.delegate, @"Delegate can't be nil!"); self.title = L(@"bookmark_sets"); + [self reloadData]; + +} + +- (void)reloadData { + self.groupIds = [MWMBookmarksManager groupsIdList]; + [self.tableView reloadData]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView @@ -49,7 +57,7 @@ if (section == 0) return 1; - return GetFramework().GetBookmarkManager().GetBmGroupsIdList().size(); + return self.groupIds.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -64,7 +72,7 @@ else { auto & bmManager = GetFramework().GetBookmarkManager(); - auto categoryId = bmManager.GetBmGroupsIdList()[indexPath.row]; + auto categoryId = [self.groupIds[indexPath.row] unsignedLongLongValue]; if (bmManager.HasBmCategory(categoryId)) cell.textLabel.text = @(bmManager.GetCategoryName(categoryId).c_str()); @@ -80,7 +88,7 @@ { m_categoryId = categoryId; self.category = @(GetFramework().GetBookmarkManager().GetCategoryName(categoryId).c_str()); - [self.tableView reloadData]; + [self reloadData]; [self.delegate didSelectCategory:self.category withCategoryId:categoryId]; } @@ -104,7 +112,7 @@ } else { - auto categoryId = GetFramework().GetBookmarkManager().GetBmGroupsIdList()[indexPath.row]; + auto categoryId = [self.groupIds[indexPath.row] unsignedLongLongValue];; [self moveBookmarkToSetWithCategoryId:categoryId]; [self.delegate didSelectCategory:self.category withCategoryId:categoryId]; [self backTap]; diff --git a/iphone/Maps/Classes/Components/MWMButton.mm b/iphone/Maps/Classes/Components/MWMButton.mm index 448b9e7ae3..9d59801a89 100644 --- a/iphone/Maps/Classes/Components/MWMButton.mm +++ b/iphone/Maps/Classes/Components/MWMButton.mm @@ -112,6 +112,17 @@ namespace } } +- (void)setEnabled:(BOOL)enabled { + [super setEnabled:enabled]; + if (!enabled) { + self.tintColor = [UIColor lightGrayColor]; + } + else + { + [self setDefaultTintColor]; + } +} + - (void)setDefaultTintColor { switch (self.coloring) diff --git a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h index 94ce40cce6..8fa0ddce93 100644 --- a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h +++ b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h @@ -20,7 +20,6 @@ + (void)setCategory:(MWMMarkGroupID)groupId name:(NSString *)name; + (BOOL)isCategoryVisible:(MWMMarkGroupID)groupId; + (void)setCategory:(MWMMarkGroupID)groupId isVisible:(BOOL)isVisible; -+ (void)setAllCategoriesVisible:(BOOL)isVisible; + (void)deleteCategory:(MWMMarkGroupID)groupId; + (void)deleteBookmark:(MWMMarkID)bookmarkId; @@ -37,8 +36,6 @@ + (NSUInteger)filesCountForConversion; + (void)convertAll; -+ (BOOL)areAllCategoriesInvisible; - + (void)setNotificationsEnabled:(BOOL)enabled; + (BOOL)areNotificationsEnabled; diff --git a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm index 70f475044a..5807629bb6 100644 --- a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm +++ b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm @@ -307,12 +307,6 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result) GetFramework().GetBookmarkManager().GetEditSession().SetIsVisible(groupId, isVisible); } -+ (void)setAllCategoriesVisible:(BOOL)isVisible -{ - GetFramework().GetBookmarkManager().SetAllCategoriesVisibility(BookmarkManager::CategoryFilterType::All, - isVisible); -} - + (void)deleteCategory:(MWMMarkGroupID)groupId { GetFramework().GetBookmarkManager().GetEditSession().DeleteBmCategory(groupId); @@ -479,11 +473,6 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result) [[UIViewController topViewController] presentViewController:alert animated:YES completion:nil]; } -+ (BOOL)areAllCategoriesInvisible -{ - return GetFramework().GetBookmarkManager().AreAllCategoriesInvisible(BookmarkManager::CategoryFilterType::All); -} - + (void)setNotificationsEnabled:(BOOL)enabled { GetFramework().GetBookmarkManager().SetNotificationsEnabled(enabled); @@ -496,7 +485,7 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result) + (NSURL * _Nullable )catalogFrontendUrl { - NSString *urlString = @(GetFramework().GetBookmarkManager().GetCatalogFrontendUrl().c_str()); + NSString *urlString = @(GetFramework().GetBookmarkManager().GetCatalog().GetFrontendUrl().c_str()); return urlString ? [NSURL URLWithString:urlString] : nil; } diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h index 2e1357b51b..6e3d6756d8 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h @@ -223,6 +223,7 @@ using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * d - (NSString *)bookmarkCategory; - (kml::MarkId)bookmarkId; - (kml::MarkGroupId)bookmarkCategoryId; +- (BOOL)isFromCatalog; // Local Ads - (NSString *)localAdsURL; diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index aaa0523d66..ddd89b0309 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -736,6 +736,10 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; return m_info.GetBookmarkCategoryId(); } +- (BOOL)isFromCatalog { + return self.isBookmark && [MWMBookmarksManager isCategoryFromCatalog:self.bookmarkCategoryId]; +} + #pragma mark - Local Ads - (NSString *)localAdsURL { return @(m_info.GetLocalAdsUrl().c_str()); } - (void)logLocalAdsEvent:(local_ads::EventType)type diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h index 76a17152fc..b4e77e4c34 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h @@ -31,7 +31,8 @@ NSString * titleForButton(EButton type, int partnerIndex, BOOL isSelected); + (MWMActionBarButton *)buttonWithDelegate:(id)delegate buttonType:(EButton)type partnerIndex:(int)partnerIndex - isSelected:(BOOL)isSelected; + isSelected:(BOOL)isSelected + isDisabled:(BOOL)isDisabled; - (EButton)type; - (MWMCircularProgress *)mapDownloadProgress; diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.mm index bba48f097b..3784399f3a 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.mm @@ -73,7 +73,7 @@ UIColor * backgroundColorForPartner(int partnerIndex) @implementation MWMActionBarButton -- (void)configButton:(BOOL)isSelected +- (void)configButton:(BOOL)isSelected disabled:(BOOL)isDisabled { self.label.text = titleForButton(self.type, self.partnerIndex, isSelected); self.extraBackground.hidden = YES; @@ -157,19 +157,21 @@ UIColor * backgroundColorForPartner(int partnerIndex) self.backgroundColor = backgroundColorForPartner(self.partnerIndex); break; } + self.button.enabled = !isDisabled; } + (MWMActionBarButton *)buttonWithDelegate:(id)delegate buttonType:(EButton)type partnerIndex:(int)partnerIndex isSelected:(BOOL)isSelected + isDisabled:(BOOL)isDisabled { MWMActionBarButton * button = [NSBundle.mainBundle loadNibNamed:[self className] owner:nil options:nil].firstObject; button.delegate = delegate; button.type = type; button.partnerIndex = partnerIndex; - [button configButton:isSelected]; + [button configButton:isSelected disabled:isDisabled]; return button; } @@ -201,6 +203,7 @@ UIColor * backgroundColorForPartner(int partnerIndex) [btn setImage:[UIImage imageNamed:@"ic_bookmarks_off"] forState:UIControlStateNormal]; [btn setImage:[UIImage imageNamed:@"ic_bookmarks_on"] forState:UIControlStateSelected]; [btn setImage:[UIImage imageNamed:@"ic_bookmarks_on"] forState:UIControlStateHighlighted]; + [btn setImage:[UIImage imageNamed:@"ic_bookmarks_on"] forState:UIControlStateDisabled]; [self setBookmarkSelected:isSelected]; diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.h b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.h index 90a74bfb34..20f75f3d23 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.h +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.h @@ -5,6 +5,7 @@ @protocol MWMActionBarSharedData - (BOOL)isBookmark; +- (BOOL)isFromCatalog; - (BOOL)isOpentable; - (BOOL)isPartner; - (BOOL)isBooking; diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm index ab1d346074..cc40bf04f7 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm @@ -130,10 +130,12 @@ for (auto const buttonType : m_visibleButtons) { auto const isSelected = (buttonType == EButton::Bookmark ? [data isBookmark] : NO); + auto const isDisabled = (buttonType == EButton::Bookmark && data.isFromCatalog); auto button = [MWMActionBarButton buttonWithDelegate:self buttonType:buttonType partnerIndex:partnerIndex - isSelected:isSelected]; + isSelected:isSelected + isDisabled:isDisabled]; [self.barButtons addArrangedSubview:button]; } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm index e8b289ae09..43c7703b24 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm @@ -284,7 +284,7 @@ map const kMetaInfoCells = { return 0; switch (data.sections[section]) { - case Sections::Bookmark: return 1; + case Sections::Bookmark: return data.isFromCatalog ? 0 : 1; case Sections::Preview: return data.previewRows.size(); case Sections::SpecialProjects: return data.specialProjectRows.size(); case Sections::Metainfo: return data.metainfoRows.size(); diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 1fc02e4dc0..0c76ebf264 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -1784,47 +1784,6 @@ bool BookmarkManager::IsUsedCategoryName(std::string const & name) const return false; } -bool BookmarkManager::AreAllCategoriesVisible(CategoryFilterType const filter) const -{ - return CheckVisibility(filter, true /* isVisible */); -} - -bool BookmarkManager::AreAllCategoriesInvisible(CategoryFilterType const filter) const -{ - return CheckVisibility(filter, false /* isVisible */); -} - -bool BookmarkManager::CheckVisibility(BookmarkManager::CategoryFilterType const filter, - bool isVisible) const -{ - CHECK_THREAD_CHECKER(m_threadChecker, ()); - for (auto const & category : m_categories) - { - auto const fromCatalog = IsCategoryFromCatalog(category.first); - if (!IsValidFilterType(filter, fromCatalog)) - continue; - if (category.second->IsVisible() != isVisible) - return false; - } - - return true; -} - -void BookmarkManager::SetAllCategoriesVisibility(BookmarkManager::CategoryFilterType const filter, - bool visible) -{ - CHECK_THREAD_CHECKER(m_threadChecker, ()); - auto session = GetEditSession(); - - for (auto & c : m_categories) - { - auto const fromCatalog = IsCategoryFromCatalog(c.first); - if (!IsValidFilterType(filter, fromCatalog)) - continue; - c.second->SetIsVisible(visible); - } -} - bool BookmarkManager::CanConvert() const { // The conversion available only after successful migration. diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 35608df90e..adfc0adadc 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -258,9 +258,6 @@ public: bool IsEditableCategory(kml::MarkGroupId groupId) const; bool IsUsedCategoryName(std::string const & name) const; - bool AreAllCategoriesVisible(CategoryFilterType const filter) const; - bool AreAllCategoriesInvisible(CategoryFilterType const filter) const; - void SetAllCategoriesVisibility(CategoryFilterType const filter, bool visible); // Return number of files for the conversion to the binary format. size_t GetKmlFilesCountForConversion() const;