diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingFlow.storyboard b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingFlow.storyboard index 18ec73da1f..616027dbfc 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingFlow.storyboard +++ b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingFlow.storyboard @@ -350,6 +350,7 @@ + diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift index bf2b1f099b..4b30e69248 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift @@ -27,18 +27,23 @@ final class BookmarksSharingViewController: MWMTableViewController { private let publishUpdateRowIndex = 2 private var rowsInPublicSection: Int { - return category.accessStatus == .public ? 3 : 2 + return category.accessStatus == .public ? (uploadAndPublishCell.cellState == .updating ? 2 : 3) : 2 } private var rowsInPrivateSection: Int { - return category.accessStatus == .private ? 3 : 2 + return category.accessStatus == .private ? (getDirectLinkCell.cellState == .updating ? 2 : 3) : 2 } - @IBOutlet private weak var uploadAndPublishCell: UploadActionCell! - @IBOutlet private weak var getDirectLinkCell: UploadActionCell! - @IBOutlet private weak var updatePublishCell: UITableViewCell! - @IBOutlet private weak var updateDirectLinkCell: UITableViewCell! - @IBOutlet private weak var directLinkInstructionsLabel: UILabel! + @IBOutlet weak var uploadAndPublishCell: UploadActionCell! + @IBOutlet weak var getDirectLinkCell: UploadActionCell! + @IBOutlet weak var updatePublishCell: UITableViewCell! + @IBOutlet weak var updateDirectLinkCell: UITableViewCell! + @IBOutlet weak var directLinkInstructionsLabel: UILabel! + @IBOutlet weak var editOnWebButton: UIButton! { + didSet { + editOnWebButton.setTitle(L("edit_on_web").uppercased(), for: .normal) + } + } @IBOutlet private weak var licenseAgreementTextView: UITextView! { didSet { @@ -82,11 +87,13 @@ final class BookmarksSharingViewController: MWMTableViewController { private func configureActionCells() { uploadAndPublishCell.config(titles: [ .normal : L("upload_and_publish"), .inProgress : L("upload_and_publish_progress_text"), + .updating : L("direct_link_updating_text"), .completed : L("upload_and_publish_success") ], image: UIImage(named: "ic24PxGlobe"), delegate: self) getDirectLinkCell.config(titles: [ .normal : L("upload_and_get_direct_link"), .inProgress : L("direct_link_progress_text"), + .updating : L("direct_link_updating_text"), .completed : L("direct_link_success") ], image: UIImage(named: "ic24PxLink"), delegate: self) @@ -142,7 +149,7 @@ final class BookmarksSharingViewController: MWMTableViewController { if cell == uploadAndPublishCell { startUploadAndPublishFlow() } else if cell == getDirectLinkCell { - uploadAndGetDirectLink() + uploadAndGetDirectLink(update: false) } else if cell == updatePublishCell { updatePublic() } else if cell == updateDirectLinkCell { @@ -151,11 +158,21 @@ final class BookmarksSharingViewController: MWMTableViewController { } private func updatePublic() { - + MWMAlertViewController.activeAlert().presentDefaultAlert(withTitle: L("any_access_update_alert_title"), + message: L("any_access_update_alert_message"), + rightButtonTitle: L("any_access_update_alert_update"), + leftButtonTitle: L("cancel")) { + self.uploadAndPublish(update: true) + } } private func updateDirectLink() { - + MWMAlertViewController.activeAlert().presentDefaultAlert(withTitle: L("any_access_update_alert_title"), + message: L("any_access_update_alert_message"), + rightButtonTitle: L("any_access_update_alert_update"), + leftButtonTitle: L("cancel")) { + self.uploadAndGetDirectLink(update: true) + } } private func startUploadAndPublishFlow() { @@ -167,16 +184,25 @@ final class BookmarksSharingViewController: MWMTableViewController { } } - private func uploadAndPublish() { - guard let tags = sharingTags, let userStatus = sharingUserStatus else { - assert(false, "not enough data for public sharing") - return + private func uploadAndPublish(update: Bool) { + if !update { + guard let tags = sharingTags, let userStatus = sharingUserStatus else { + assert(false, "not enough data for public sharing") + return + } + + manager.setCategory(category.categoryId, authorType: userStatus) + manager.setCategory(category.categoryId, tags: tags) } - - manager.setCategory(category.categoryId, authorType: userStatus) - manager.setCategory(category.categoryId, tags: tags) + + uploadAndPublishCell.cellState = update ? .updating : .inProgress + if update { + self.tableView.deleteRows(at: [IndexPath(row: self.publishUpdateRowIndex, + section: self.publicSectionIndex)], + with: .automatic) + } + manager.uploadAndPublishCategory(withId: category.categoryId, progress: { (progress) in - self.uploadAndPublishCell.cellState = .inProgress }) { (_, error) in if let error = error as NSError? { self.uploadAndPublishCell.cellState = .normal @@ -200,11 +226,14 @@ final class BookmarksSharingViewController: MWMTableViewController { section: self.publicSectionIndex)], with: .automatic) self.tableView.endUpdates() + if update { + Toast.toast(withText: L("direct_link_updating_success")).show() + } } } } - private func uploadAndGetDirectLink() { + private func uploadAndGetDirectLink(update: Bool) { Statistics.logEvent(kStatSharingOptionsClick, withParameters: [kStatItem : kStatPrivate]) performAfterValidation(anchor: getDirectLinkCell) { [weak self] in guard let s = self else { @@ -212,10 +241,13 @@ final class BookmarksSharingViewController: MWMTableViewController { return } + s.getDirectLinkCell.cellState = update ? .updating : .inProgress + if update { + s.tableView.deleteRows(at: [IndexPath(item: s.directLinkUpdateRowIndex, + section: s.privateSectionIndex)], + with: .automatic) + } s.manager.uploadAndGetDirectLinkCategory(withId: s.category.categoryId, progress: { (progress) in - if progress == .uploadStarted { - s.getDirectLinkCell.cellState = .inProgress - } }, completion: { (_, error) in if let error = error as NSError? { s.getDirectLinkCell.cellState = .normal @@ -229,6 +261,9 @@ final class BookmarksSharingViewController: MWMTableViewController { s.tableView.insertRows(at: [IndexPath(item: s.directLinkUpdateRowIndex, section: s.privateSectionIndex)], with: .automatic) + if update { + Toast.toast(withText: L("direct_link_updating_success")).show() + } } }) } @@ -291,13 +326,34 @@ final class BookmarksSharingViewController: MWMTableViewController { } private func showMalformedDataError() { - MWMAlertViewController.activeAlert().presentInfoAlert(L("unable_upload_errorr_title"), - text: L("unable_upload_error_subtitle_broken")) + let alert = EditOnWebAlertViewController(with: L("html_format_error_title"), + message: L("html_format_error_subtitle")) + alert.onAcceptBlock = { + self.dismiss(animated: true, completion: { + self.performSegue(withIdentifier: self.kEditOnWebSegueIdentifier, sender: nil) + }) + } + alert.onCancelBlock = { + self.dismiss(animated: true) + } + + navigationController?.present(alert, animated: true) } private func showAccessError() { - MWMAlertViewController.activeAlert().presentInfoAlert(L("unable_upload_errorr_title"), - text: L("unable_upload_error_subtitle_edited")) + let alert = EditOnWebAlertViewController(with: L("public_or_limited_access_after_edit_online_error_title"), + message: L("public_or_limited_access_after_edit_online_error_message")) + alert.onAcceptBlock = { + self.dismiss(animated: true, completion: { + self.performSegue(withIdentifier: self.kEditOnWebSegueIdentifier, sender: nil) + }) + } + + alert.onCancelBlock = { + self.dismiss(animated: true) + } + + navigationController?.present(alert, animated: true) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { @@ -346,7 +402,7 @@ extension BookmarksSharingViewController: SharingTagsViewControllerDelegate { func sharingTagsViewController(_ viewController: SharingTagsViewController, didSelect tags: [MWMTag]) { navigationController?.popViewController(animated: true) sharingTags = tags - uploadAndPublish() + uploadAndPublish(update: false) } func sharingTagsViewControllerDidCancel(_ viewController: SharingTagsViewController) { diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebAlertViewController.swift b/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebAlertViewController.swift new file mode 100644 index 0000000000..c15f1032db --- /dev/null +++ b/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebAlertViewController.swift @@ -0,0 +1,48 @@ +class EditOnWebAlertViewController: UIViewController { + private let transitioning = FadeTransitioning() + private var alertTitle = "" + private var alertMessage = "" + + var onAcceptBlock: MWMVoidBlock? + var onCancelBlock: MWMVoidBlock? + + @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var messageLabel: UILabel! + @IBOutlet weak var cancelButton: UIButton! + @IBOutlet weak var acceptButton: UIButton! { + didSet { + acceptButton.setTitle(L("edit_on_web").uppercased(), for: .normal) + } + } + + convenience init(with title: String, message: String) { + self.init() + alertTitle = title + alertMessage = message + } + + override func viewDidLoad() { + super.viewDidLoad() + + titleLabel.text = alertTitle + messageLabel.text = alertMessage + } + + override var transitioningDelegate: UIViewControllerTransitioningDelegate? { + get { return transitioning } + set { } + } + + override var modalPresentationStyle: UIModalPresentationStyle { + get { return .custom } + set { } + } + + @IBAction func onAccept(_ sender: UIButton) { + onAcceptBlock?() + } + + @IBAction func onCancel(_ sender: UIButton) { + onCancelBlock?() + } +} diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebAlertViewController.xib b/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebAlertViewController.xib new file mode 100644 index 0000000000..d2fff44f92 --- /dev/null +++ b/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebAlertViewController.xib @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/UploadActionCell.swift b/iphone/Maps/Bookmarks/Categories/Sharing/UploadActionCell.swift index d27f664f01..6a10c67911 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/UploadActionCell.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/UploadActionCell.swift @@ -5,6 +5,7 @@ protocol UploadActionCellDelegate: AnyObject { enum UploadActionCellState: String { case normal case inProgress + case updating case completed case disabled } @@ -48,6 +49,14 @@ final class UploadActionCell: MWMTableViewCell { actionTitle.text = titles?[.inProgress] shareButton.isHidden = true selectionStyle = .none + case .updating: + progressView.isHidden = false + actionImage.tintColor = .blackSecondaryText() + actionTitle.textColor = .blackSecondaryText() + actionTitle.font = .italic16() + actionTitle.text = titles?[.updating] + shareButton.isHidden = true + selectionStyle = .none case .completed: progressView.isHidden = true actionImage.tintColor = .blackSecondaryText() diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index f491e92ceb..7e665e21b1 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -382,6 +382,8 @@ 471BBD942130390F00EB17C9 /* TutorialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 471BBD932130390F00EB17C9 /* TutorialViewController.swift */; }; 4726254921C27D4B00C7BAAD /* PlacePageDescriptionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4726254821C27D4B00C7BAAD /* PlacePageDescriptionViewController.swift */; }; 47289E532209BE3D002ABFC0 /* MWMActivityIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 47289E522209BE3D002ABFC0 /* MWMActivityIndicator.m */; }; + 47289E5A2212DFFF002ABFC0 /* EditOnWebAlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47289E582212DFFF002ABFC0 /* EditOnWebAlertViewController.swift */; }; + 47289E5B2212DFFF002ABFC0 /* EditOnWebAlertViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 47289E592212DFFF002ABFC0 /* EditOnWebAlertViewController.xib */; }; 472E3F472146BCD30020E412 /* SubscriptionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 472E3F462146BCD30020E412 /* SubscriptionManager.swift */; }; 472E3F4A2146C4CD0020E412 /* MWMPurchaseManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 472E3F492146C4CD0020E412 /* MWMPurchaseManager.mm */; }; 472E3F4C2147D5700020E412 /* Subscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 472E3F4B2147D5700020E412 /* Subscription.swift */; }; @@ -1413,6 +1415,8 @@ 4726254821C27D4B00C7BAAD /* PlacePageDescriptionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlacePageDescriptionViewController.swift; sourceTree = ""; }; 47289E512209BE3D002ABFC0 /* MWMActivityIndicator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MWMActivityIndicator.h; path = CustomViews/MWMActivityIndicator.h; sourceTree = ""; }; 47289E522209BE3D002ABFC0 /* MWMActivityIndicator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MWMActivityIndicator.m; path = CustomViews/MWMActivityIndicator.m; sourceTree = ""; }; + 47289E582212DFFF002ABFC0 /* EditOnWebAlertViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditOnWebAlertViewController.swift; sourceTree = ""; }; + 47289E592212DFFF002ABFC0 /* EditOnWebAlertViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = EditOnWebAlertViewController.xib; sourceTree = ""; }; 472E3F462146BCD30020E412 /* SubscriptionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionManager.swift; sourceTree = ""; }; 472E3F482146C4CD0020E412 /* MWMPurchaseManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMPurchaseManager.h; sourceTree = ""; }; 472E3F492146C4CD0020E412 /* MWMPurchaseManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMPurchaseManager.mm; sourceTree = ""; }; @@ -2229,6 +2233,8 @@ 33603C84219F0F6300B11FFE /* SharingPropertiesViewController.swift */, 33F7668E21A57CDF00A88B16 /* EditOnWebViewController.swift */, 33F8BA3B2199858B00ECA8EE /* Tags */, + 47289E582212DFFF002ABFC0 /* EditOnWebAlertViewController.swift */, + 47289E592212DFFF002ABFC0 /* EditOnWebAlertViewController.xib */, ); path = Sharing; sourceTree = ""; @@ -4699,6 +4705,7 @@ 34BBD6471F82649D0070CA50 /* GoogleSignIn.bundle in Resources */, F6E2FE851E097BA00083EBEC /* MWMPlacePageOpeningHoursWeekDayView.xib in Resources */, F6E2FE941E097BA00083EBEC /* PlacePageTaxiCell.xib in Resources */, + 47289E5B2212DFFF002ABFC0 /* EditOnWebAlertViewController.xib in Resources */, F6E2FEA61E097BA00083EBEC /* MWMPPView.xib in Resources */, 47E3C72221108E9F008B3B27 /* BookmarksLoadedViewController.xib in Resources */, 6741A9811BF340DE002C974C /* MWMRateAlert.xib in Resources */, @@ -5193,6 +5200,7 @@ B32FE74020D2844600EF7446 /* DownloadedBookmarksViewController.swift in Sources */, 340416541E7C09C200E2B6D6 /* PhotoScalingView.swift in Sources */, 4767CDA820AB401000BD8166 /* LinkTextView.swift in Sources */, + 47289E5A2212DFFF002ABFC0 /* EditOnWebAlertViewController.swift in Sources */, 34763EE71F2F392300F4D2D3 /* MWMTextToSpeech.mm in Sources */, 34ABA6251C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */, F6E2FD861E097BA00083EBEC /* MWMBaseMapDownloaderViewController.mm in Sources */,