From b226126a4e6e75b755ce979ed0c668ceaaea5d30 Mon Sep 17 00:00:00 2001 From: Alexey Belousov Date: Wed, 20 Jun 2018 17:01:41 +0300 Subject: [PATCH] [ios] add info section to bookmark list screen --- iphone/Maps/Bookmarks/BookmarksVC.mm | 97 ++++++++++--------- .../DownloadedBookmarksViewController.swift | 9 ++ .../DownloadedBookmarksViewController.xib | 14 +-- iphone/Maps/Bookmarks/MWMCategoryInfoCell.h | 17 ++++ iphone/Maps/Bookmarks/MWMCategoryInfoCell.m | 80 +++++++++++++++ iphone/Maps/Bookmarks/MWMCategoryInfoCell.xib | 96 ++++++++++++++++++ iphone/Maps/Maps.xcodeproj/project.pbxproj | 10 ++ 7 files changed, 272 insertions(+), 51 deletions(-) create mode 100644 iphone/Maps/Bookmarks/MWMCategoryInfoCell.h create mode 100644 iphone/Maps/Bookmarks/MWMCategoryInfoCell.m create mode 100644 iphone/Maps/Bookmarks/MWMCategoryInfoCell.xib diff --git a/iphone/Maps/Bookmarks/BookmarksVC.mm b/iphone/Maps/Bookmarks/BookmarksVC.mm index fd0a73f1a2..2d3327ffdb 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.mm +++ b/iphone/Maps/Bookmarks/BookmarksVC.mm @@ -5,6 +5,7 @@ #import "MWMLocationHelpers.h" #import "MWMLocationObserver.h" #import "MWMSearchManager.h" +#import "MWMCategoryInfoCell.h" #import "SwiftBridge.h" #include "Framework.h" @@ -18,8 +19,9 @@ #define EMPTY_SECTION -666 -@interface BookmarksVC() +@interface BookmarksVC() { + int m_infoSection; int m_trackSection; int m_bookmarkSection; int m_numberOfSections; @@ -68,7 +70,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - if (section == 0) + if (section == m_infoSection) return 1; else if (section == m_trackSection) return GetFramework().GetBookmarkManager().GetTrackIds(m_categoryId).size(); @@ -78,16 +80,10 @@ return 0; } -- (void)onVisibilitySwitched:(UISwitch *)sender -{ - [Statistics logEvent:kStatEventName(kStatBookmarks, kStatToggleVisibility) - withParameters:@{kStatValue : sender.on ? kStatVisible : kStatHidden}]; - auto & bmManager = GetFramework().GetBookmarkManager(); - bmManager.GetEditSession().SetIsVisible(m_categoryId, sender.on); -} - - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { + if (section == m_infoSection) + return L(@"placepage_place_description"); if (section == m_trackSection) return L(@"tracks"); if (section == m_bookmarkSection) @@ -105,22 +101,19 @@ UITableViewCell * cell = nil; // First section, contains info about current set - if (indexPath.section == 0) + if (indexPath.section == m_infoSection) { - cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCSetVisibilityCell"]; - if (!cell) - { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BookmarksVCSetVisibilityCell"]; - cell.textLabel.text = L(@"visible"); - cell.accessoryView = [[UISwitch alloc] init]; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - } - UISwitch * sw = (UISwitch *)cell.accessoryView; - sw.on = bmManager.IsVisible(m_categoryId); - sw.onTintColor = [UIColor linkBlue]; - [sw addTarget:self action:@selector(onVisibilitySwitched:) forControlEvents:UIControlEventValueChanged]; + cell = [tableView dequeueReusableCellWithCellClass:MWMCategoryInfoCell.class indexPath:indexPath]; + MWMCategoryInfoCell * infoCell = (MWMCategoryInfoCell * )cell; + NSString * title = @(bmManager.GetCategoryName(m_categoryId).c_str()); + auto categoryData = bmManager.GetCategoryData(m_categoryId); + NSString * author = [NSString stringWithCoreFormat:L(@"author_name_by_prefix") + arguments:@[@(categoryData.m_authorName.c_str())]]; + NSString * info = @(kml::GetDefaultStr(categoryData.m_description).c_str()); + NSString * shortInfo = @(kml::GetDefaultStr(categoryData.m_annotation).c_str()); + [infoCell updateWithTitle:title author:author info:info shortInfo:shortInfo]; + infoCell.delegate = self; } - else if (indexPath.section == m_trackSection) { cell = [tableView dequeueReusableCellWithIdentifier:@"TrackCell"]; @@ -187,15 +180,7 @@ auto & bmManager = f.GetBookmarkManager(); bool const categoryExists = bmManager.HasBmCategory(m_categoryId); ASSERT(categoryExists, ("Nonexistent category")); - if (indexPath.section == 0) - { - if (indexPath.row == 0) - { - // Edit name - // @TODO - } - } - else if (indexPath.section == m_trackSection) + if (indexPath.section == m_trackSection) { if (categoryExists) { @@ -230,7 +215,8 @@ - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.section == m_trackSection || indexPath.section == m_bookmarkSection) + if (!GetFramework().GetBookmarkManager().IsCategoryFromCatalog(m_categoryId) && + (indexPath.section == m_trackSection || indexPath.section == m_bookmarkSection)) return YES; return NO; } @@ -271,6 +257,28 @@ } } +- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { + UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view; + + header.textLabel.textColor = [UIColor blackSecondaryText]; + header.textLabel.font = [UIFont medium14]; +} + +- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.section == m_infoSection) + return nil; + return indexPath; +} + +#pragma mark - MWMCategoryInfoCellDelegate + +- (void)categoryInfoCellDidPressMore:(MWMCategoryInfoCell *)cell { + [self.tableView beginUpdates]; + cell.expanded = YES; + [self.tableView endUpdates]; +} + #pragma mark - MWMLocationObserver - (void)onLocationUpdate:(location::GpsInfo const &)info @@ -302,13 +310,19 @@ //*********** End of Location manager callbacks ******************** //****************************************************************** +- (void)viewDidLoad { + [super viewDidLoad]; + + [self.tableView registerWithCellClass:MWMCategoryInfoCell.class]; +} + - (void)viewWillAppear:(BOOL)animated { [MWMLocationManager addObserver:self]; // Display Edit button only if table is not empty auto & bmManager = GetFramework().GetBookmarkManager(); - if (bmManager.HasBmCategory(m_categoryId) + if (bmManager.HasBmCategory(m_categoryId) && !bmManager.IsCategoryFromCatalog(m_categoryId) && (bmManager.GetUserMarkIds(m_categoryId).size() + bmManager.GetTrackIds(m_categoryId).size())) self.navigationItem.rightBarButtonItem = self.editButtonItem; else @@ -350,16 +364,11 @@ - (void)calculateSections { - int index = 1; + int index = 0; auto & bmManager = GetFramework().GetBookmarkManager(); - if (bmManager.GetTrackIds(m_categoryId).size()) - m_trackSection = index++; - else - m_trackSection = EMPTY_SECTION; - if (bmManager.GetUserMarkIds(m_categoryId).size()) - m_bookmarkSection = index++; - else - m_bookmarkSection = EMPTY_SECTION; + m_infoSection = bmManager.IsCategoryFromCatalog(m_categoryId) ? index++ : EMPTY_SECTION; + m_trackSection = bmManager.GetTrackIds(m_categoryId).size() ? index++ : EMPTY_SECTION; + m_bookmarkSection = bmManager.GetUserMarkIds(m_categoryId).size() ? index ++ : EMPTY_SECTION; m_numberOfSections = index; } diff --git a/iphone/Maps/Bookmarks/Catalog/DownloadedBookmarksViewController.swift b/iphone/Maps/Bookmarks/Catalog/DownloadedBookmarksViewController.swift index ec73565a62..65d745200c 100644 --- a/iphone/Maps/Bookmarks/Catalog/DownloadedBookmarksViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/DownloadedBookmarksViewController.swift @@ -48,6 +48,15 @@ class DownloadedBookmarksViewController: UITableViewController { return headerView } + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) + let category = dataSource.category(at: indexPath.row) + if let bmViewController = BookmarksVC(category: category.categoryId) { + MapViewController.topViewController().navigationController?.pushViewController(bmViewController, + animated: true) + } + } + @IBAction func onDownloadBookmarks(_ sender: Any) { if let url = MWMBookmarksManager.catalogFrontendUrl(), let webViewController = CatalogWebViewController(url: url, andTitleOrNil: L("routes_and_bookmarks")) { diff --git a/iphone/Maps/Bookmarks/Catalog/DownloadedBookmarksViewController.xib b/iphone/Maps/Bookmarks/Catalog/DownloadedBookmarksViewController.xib index 6987c4021a..76ad00c819 100644 --- a/iphone/Maps/Bookmarks/Catalog/DownloadedBookmarksViewController.xib +++ b/iphone/Maps/Bookmarks/Catalog/DownloadedBookmarksViewController.xib @@ -36,7 +36,7 @@ - + @@ -70,11 +70,11 @@ - - + + - + - diff --git a/iphone/Maps/Bookmarks/MWMCategoryInfoCell.h b/iphone/Maps/Bookmarks/MWMCategoryInfoCell.h new file mode 100644 index 0000000000..8211f730da --- /dev/null +++ b/iphone/Maps/Bookmarks/MWMCategoryInfoCell.h @@ -0,0 +1,17 @@ +#import + +@class MWMCategoryInfoCell; + +@protocol MWMCategoryInfoCellDelegate +- (void)categoryInfoCellDidPressMore:(MWMCategoryInfoCell *)cell; +@end + +@interface MWMCategoryInfoCell : UITableViewCell +@property (nonatomic) BOOL expanded; +@property (weak, nonatomic) id delegate; + +- (void)updateWithTitle:(NSString *)title + author:(NSString *)author + info:(NSString *)info + shortInfo:(NSString *)shortInfo; +@end diff --git a/iphone/Maps/Bookmarks/MWMCategoryInfoCell.m b/iphone/Maps/Bookmarks/MWMCategoryInfoCell.m new file mode 100644 index 0000000000..f12ae1cff5 --- /dev/null +++ b/iphone/Maps/Bookmarks/MWMCategoryInfoCell.m @@ -0,0 +1,80 @@ +#import "MWMCategoryInfoCell.h" + +@interface MWMCategoryInfoCell() + +@property (weak, nonatomic) IBOutlet UILabel * titleLabel; +@property (weak, nonatomic) IBOutlet UILabel * authorLabel; +@property (weak, nonatomic) IBOutlet UILabel * infoLabel; +@property (weak, nonatomic) IBOutlet UIButton *moreButton; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *infoToBottomConstraint; + +@property (copy, nonatomic) NSString * info; +@property (copy, nonatomic) NSString * shortInfo; + +@end + +@implementation MWMCategoryInfoCell + +- (void)awakeFromNib { + [super awakeFromNib]; + + self.titleLabel.text = nil; + self.authorLabel.text = nil; + self.infoLabel.text = nil; +} + +- (void)setExpanded:(BOOL)expanded +{ + _expanded = expanded; + if (self.shortInfo.length > 0 && self.info.length > 0) + self.infoLabel.text = expanded ? self.info : self.shortInfo; + else + self.infoLabel.numberOfLines = expanded ? 0 : 2; + + self.infoToBottomConstraint.active = expanded; + self.moreButton.hidden = expanded; +} + +- (void)updateWithTitle:(NSString *)title + author:(NSString *)author + info:(NSString *)info + shortInfo:(NSString *)shortInfo +{ + self.titleLabel.text = title; + self.authorLabel.text = author; + if (info.length > 0 && shortInfo.length > 0) + { + self.info = info; + self.shortInfo = shortInfo; + self.infoLabel.text = shortInfo; + self.infoLabel.numberOfLines = 0; + } + else if (info.length > 0 || shortInfo.length > 0) + { + self.infoLabel.text = info.length > 0 ? info : shortInfo; + } + else + { + self.expanded = YES; + } +} + +- (void)prepareForReuse +{ + [super prepareForReuse]; + + self.titleLabel.text = nil; + self.authorLabel.text = nil; + self.infoLabel.text = nil; + self.expanded = NO; + self.info = nil; + self.shortInfo = nil; + self.delegate = nil; +} + +- (IBAction)onMoreButton:(UIButton *)sender +{ + [self.delegate categoryInfoCellDidPressMore:self]; +} + +@end diff --git a/iphone/Maps/Bookmarks/MWMCategoryInfoCell.xib b/iphone/Maps/Bookmarks/MWMCategoryInfoCell.xib new file mode 100644 index 0000000000..6cb1b66a07 --- /dev/null +++ b/iphone/Maps/Bookmarks/MWMCategoryInfoCell.xib @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 1ecc6ae536..eaa3e664d9 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -468,6 +468,8 @@ B32FE74020D2844600EF7446 /* DownloadedBookmarksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B32FE73E20D2844600EF7446 /* DownloadedBookmarksViewController.swift */; }; B32FE74120D2844600EF7446 /* DownloadedBookmarksViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = B32FE73F20D2844600EF7446 /* DownloadedBookmarksViewController.xib */; }; B32FE74320D2B09600EF7446 /* CatalogWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B32FE74220D2B09600EF7446 /* CatalogWebViewController.swift */; }; + B33D21AC20DA515800BAD749 /* MWMCategoryInfoCell.m in Sources */ = {isa = PBXBuildFile; fileRef = B33D21AA20DA515800BAD749 /* MWMCategoryInfoCell.m */; }; + B33D21AD20DA515800BAD749 /* MWMCategoryInfoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B33D21AB20DA515800BAD749 /* MWMCategoryInfoCell.xib */; }; B366130420D5D9BC00E7DC3E /* MWMCatalogCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = B366130320D5D9BC00E7DC3E /* MWMCatalogCategory.m */; }; B366130720D5DD2300E7DC3E /* MWMCatalogCategory+Convenience.mm in Sources */ = {isa = PBXBuildFile; fileRef = B366130620D5DD2300E7DC3E /* MWMCatalogCategory+Convenience.mm */; }; B366130A20D5E2E000E7DC3E /* CatalogCategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B366130820D5E2E000E7DC3E /* CatalogCategoryCell.swift */; }; @@ -1393,6 +1395,9 @@ B32FE73E20D2844600EF7446 /* DownloadedBookmarksViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadedBookmarksViewController.swift; sourceTree = ""; }; B32FE73F20D2844600EF7446 /* DownloadedBookmarksViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DownloadedBookmarksViewController.xib; sourceTree = ""; }; B32FE74220D2B09600EF7446 /* CatalogWebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CatalogWebViewController.swift; sourceTree = ""; }; + B33D21A920DA515800BAD749 /* MWMCategoryInfoCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMCategoryInfoCell.h; sourceTree = ""; }; + B33D21AA20DA515800BAD749 /* MWMCategoryInfoCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MWMCategoryInfoCell.m; sourceTree = ""; }; + B33D21AB20DA515800BAD749 /* MWMCategoryInfoCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MWMCategoryInfoCell.xib; sourceTree = ""; }; B366130220D5D9BC00E7DC3E /* MWMCatalogCategory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMCatalogCategory.h; sourceTree = ""; }; B366130320D5D9BC00E7DC3E /* MWMCatalogCategory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MWMCatalogCategory.m; sourceTree = ""; }; B366130520D5DD2300E7DC3E /* MWMCatalogCategory+Convenience.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MWMCatalogCategory+Convenience.h"; sourceTree = ""; }; @@ -4101,6 +4106,9 @@ B32FE73D20D283D600EF7446 /* Catalog */, FA36B80515403A4F004560CC /* BookmarksVC.h */, FA36B80615403A4F004560CC /* BookmarksVC.mm */, + B33D21A920DA515800BAD749 /* MWMCategoryInfoCell.h */, + B33D21AA20DA515800BAD749 /* MWMCategoryInfoCell.m */, + B33D21AB20DA515800BAD749 /* MWMCategoryInfoCell.xib */, 3404F4A02028A6C00090E401 /* Categories */, FA054610155C465E001F4E37 /* SelectSetVC.h */, FA054611155C465E001F4E37 /* SelectSetVC.mm */, @@ -4428,6 +4436,7 @@ 340E1EF51E2F614400CE49BF /* SearchFilters.storyboard in Resources */, B32FE74120D2844600EF7446 /* DownloadedBookmarksViewController.xib in Resources */, F682249F1E5B105900BC1C18 /* PPHotelDescriptionCell.xib in Resources */, + B33D21AD20DA515800BAD749 /* MWMCategoryInfoCell.xib in Resources */, 340E1EF81E2F614400CE49BF /* Settings.storyboard in Resources */, 6741A9421BF340DE002C974C /* sound-strings in Resources */, F69018BD1E9F7CB600B3C10B /* MWMAutoupdateController.xib in Resources */, @@ -4603,6 +4612,7 @@ F6E2FF631E097BA00083EBEC /* MWMTTSLanguageViewController.mm in Sources */, 342EE4121C43DAA7009F6A49 /* MWMAuthorizationWebViewLoginViewController.mm in Sources */, 34AB667D1FC5AA330078E451 /* MWMRoutePreview.mm in Sources */, + B33D21AC20DA515800BAD749 /* MWMCategoryInfoCell.m in Sources */, 34845DAF1E1649F6003D55B9 /* DownloaderNoResultsEmbedViewController.swift in Sources */, F6791B141C43DF0B007A8A6E /* MWMStartButton.mm in Sources */, F6E2FEDF1E097BA00083EBEC /* MWMSearchManager+Layout.mm in Sources */,