Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 13:58:55 +01:00
parent 4af19165ec
commit 68073add76
12458 changed files with 12350765 additions and 2 deletions

View file

@ -0,0 +1,50 @@
import UIKit
protocol BookmarkColorViewControllerDelegate: AnyObject {
func bookmarkColorViewController(_ viewController: BookmarkColorViewController, didSelect color: BookmarkColor)
}
final class BookmarkColorViewController: MWMTableViewController {
weak var delegate: BookmarkColorViewControllerDelegate?
private let bookmarkColor: BookmarkColor
private let colors: [BookmarkColor] = BookmarkColor.allCases
init(bookmarkColor: BookmarkColor) {
self.bookmarkColor = bookmarkColor
super.init(style: .grouped)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
title = L("change_color")
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelButtonDidTap))
}
@objc private func cancelButtonDidTap() {
dismiss(animated: true, completion: nil)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
colors.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueDefaultCell(for: indexPath)
let color = colors[indexPath.row]
let selected = color == bookmarkColor
cell.textLabel?.text = color.title
cell.imageView?.image = color.image(selected)
cell.accessoryType = selected ? .checkmark : .none
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let color = colors[indexPath.row]
delegate?.bookmarkColorViewController(self, didSelect: color)
}
}

View file

@ -0,0 +1,22 @@
import UIKit
protocol BookmarkTitleCellDelegate: AnyObject {
func didFinishEditingTitle(_ title: String)
}
final class BookmarkTitleCell: MWMTableViewCell {
@IBOutlet var textField: UITextField!
weak var delegate: BookmarkTitleCellDelegate?
func configure(name: String, delegate: BookmarkTitleCellDelegate, hint: String) {
textField.text = name
textField.placeholder = hint
self.delegate = delegate
}
}
extension BookmarkTitleCell: UITextFieldDelegate {
func textFieldDidEndEditing(_ textField: UITextField) {
delegate?.didFinishEditingTitle(textField.text ?? "")
}
}

View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="oz5-CE-QZ8" customClass="BookmarkTitleCell" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="oz5-CE-QZ8" id="v5X-p8-TtT">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="Ykx-ep-qjo">
<rect key="frame" x="20" y="12" width="280" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular17:blackPrimaryText"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedPlaceholder" value="placepage_bookmark_name_hint"/>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="delegate" destination="oz5-CE-QZ8" id="d6l-ER-j3P"/>
</connections>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="Ykx-ep-qjo" secondAttribute="bottom" constant="12" id="cfm-oE-z2I"/>
<constraint firstAttribute="trailing" secondItem="Ykx-ep-qjo" secondAttribute="trailing" constant="20" id="dyn-Ae-apB"/>
<constraint firstItem="Ykx-ep-qjo" firstAttribute="top" secondItem="v5X-p8-TtT" secondAttribute="top" constant="12" id="e37-GE-Eth"/>
<constraint firstItem="Ykx-ep-qjo" firstAttribute="leading" secondItem="v5X-p8-TtT" secondAttribute="leading" constant="20" id="gXL-r9-dr7"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="textField" destination="Ykx-ep-qjo" id="Vsa-Aq-FNB"/>
</connections>
<point key="canvasLocation" x="234" y="339"/>
</tableViewCell>
</objects>
</document>

View file

@ -0,0 +1,104 @@
import Foundation
extension BookmarkColor {
public static var allCases: [BookmarkColor] = [.red, .pink, .purple, .deepPurple, .blue, .lightBlue, .cyan, .teal, .green,
.lime, .yellow, .orange, .deepOrange, .brown, .gray, .blueGray]
var title: String {
localizedTitleForBookmarkColor(self)
}
var color: UIColor {
uiColorForBookmarkColor(self)
}
func image(_ selected: Bool) -> UIImage {
if selected {
return circleImageForColor(color, frameSize: 22, iconName: "ic_bm_none")
} else {
return circleImageForColor(color, frameSize: 22, diameter: 14)
}
}
func image(_ iconName: String) -> UIImage {
circleImageForColor(color, frameSize: 22, iconName: iconName)
}
static func bookmarkColor(from color: UIColor) -> BookmarkColor? {
allCases.first(where: { uiColorForBookmarkColor($0) == color })
}
}
fileprivate func titleForBookmarkColor(_ color: BookmarkColor) -> String {
switch color {
case .red: return "red"
case .blue: return "blue"
case .purple: return "purple"
case .yellow: return "yellow"
case .pink: return "pink"
case .brown: return "brown"
case .green: return "green"
case .orange: return "orange"
case .deepPurple: return "deep_purple"
case .lightBlue: return "light_blue"
case .cyan: return "cyan"
case .teal: return "teal"
case .lime: return "lime"
case .deepOrange: return "deep_orange"
case .gray: return "gray"
case .blueGray: return "blue_gray"
case .none, .count: return ""
@unknown default:
fatalError()
}
}
fileprivate func localizedTitleForBookmarkColor(_ color: BookmarkColor) -> String {
L(titleForBookmarkColor(color))
}
fileprivate func rgbColor(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat) -> UIColor {
UIColor(red: r / 255, green: g / 255, blue: b / 255, alpha: 0.8)
}
fileprivate func uiColorForBookmarkColor(_ color: BookmarkColor) -> UIColor {
switch color {
case .red: return rgbColor(229, 27, 35);
case .pink: return rgbColor(255, 65, 130);
case .purple: return rgbColor(155, 36, 178);
case .deepPurple: return rgbColor(102, 57, 191);
case .blue: return rgbColor(0, 102, 204);
case .lightBlue: return rgbColor(36, 156, 242);
case .cyan: return rgbColor(20, 190, 205);
case .teal: return rgbColor(0, 165, 140);
case .green: return rgbColor(60, 140, 60);
case .lime: return rgbColor(147, 191, 57);
case .yellow: return rgbColor(255, 200, 0);
case .orange: return rgbColor(255, 150, 0);
case .deepOrange: return rgbColor(240, 100, 50);
case .brown: return rgbColor(128, 70, 51);
case .gray: return rgbColor(115, 115, 115);
case .blueGray: return rgbColor(89, 115, 128);
case .none, .count:
fatalError()
@unknown default:
fatalError()
}
}
func circleImageForColor(_ color: UIColor,
frameSize: CGFloat,
diameter: CGFloat? = nil,
iconName: String? = nil) -> UIImage {
let renderer = UIGraphicsImageRenderer(size: CGSize(width: frameSize, height: frameSize))
return renderer.image { context in
let d = diameter ?? frameSize
let rect = CGRect(x: (frameSize - d) / 2, y: (frameSize - d) / 2, width: d, height: d)
context.cgContext.addEllipse(in: rect)
context.cgContext.setFillColor(color.cgColor)
context.cgContext.fillPath()
guard let iconName = iconName, let image = UIImage(named: iconName) else { return }
image.draw(in: rect.insetBy(dx: 3, dy: 3))
}
}

View file

@ -0,0 +1,265 @@
import UIKit
@objc(MWMEditBookmarkController)
final class EditBookmarkViewController: MWMTableViewController {
private enum Sections: Int {
case info
case description
case delete
case count
}
private enum InfoSectionRows: Int {
case title
case color
case bookmarkGroup
case count
}
private var editingCompleted: ((Bool) -> Void)?
private var placePageData: PlacePageData?
private var noteCell: MWMNoteCell?
private var bookmarkTitle: String?
private var bookmarkDescription: String?
private var bookmarkGroupTitle: String?
private var bookmarkId = FrameworkHelper.invalidBookmarkId()
private var bookmarkGroupId = FrameworkHelper.invalidCategoryId()
private var newBookmarkGroupId = FrameworkHelper.invalidCategoryId()
private var bookmarkColor: BookmarkColor!
private let bookmarksManager = BookmarksManager.shared()
override func viewDidLoad() {
super.viewDidLoad()
guard bookmarkId != FrameworkHelper.invalidBookmarkId() || placePageData != nil else {
fatalError("controller should be configured with placePageData or bookmarkId first")
}
title = L("bookmark").capitalized
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save,
target: self,
action: #selector(onSave))
tableView.registerNib(cell: BookmarkTitleCell.self)
tableView.registerNib(cell: MWMButtonCell.self)
tableView.registerNib(cell: MWMNoteCell.self)
addToBookmarksManagerObserverList()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateBookmarkIfNeeded()
}
deinit {
removeFromBookmarksManagerObserverList()
}
func configure(with bookmarkId: MWMMarkID, editCompletion completion: ((Bool) -> Void)?) {
self.bookmarkId = bookmarkId
let bookmark = bookmarksManager.bookmark(withId: bookmarkId)
bookmarkTitle = bookmark.bookmarkName
bookmarkColor = bookmark.bookmarkColor
bookmarkDescription = bookmarksManager.description(forBookmarkId: bookmarkId)
let bookmarkGroup = bookmarksManager.category(forBookmarkId: bookmarkId)
bookmarkGroupId = bookmarkGroup.categoryId
bookmarkGroupTitle = bookmarkGroup.title
editingCompleted = completion
}
@objc(configureWithPlacePageData:)
func configure(with placePageData: PlacePageData) {
guard let bookmarkData = placePageData.bookmarkData else { fatalError("placePageData and bookmarkData can't be nil") }
self.placePageData = placePageData
bookmarkTitle = placePageData.previewData.title
bookmarkDescription = bookmarkData.bookmarkDescription
bookmarkGroupTitle = bookmarkData.bookmarkCategory
bookmarkId = bookmarkData.bookmarkId
bookmarkGroupId = bookmarkData.bookmarkGroupId
bookmarkColor = bookmarkData.color
editingCompleted = nil
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
Sections.count.rawValue
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch Sections(rawValue: section) {
case .info:
return InfoSectionRows.count.rawValue
case .description, .delete:
return 1
default:
fatalError()
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch Sections(rawValue: indexPath.section) {
case .info:
switch InfoSectionRows(rawValue: indexPath.row) {
case .title:
let cell = tableView.dequeueReusableCell(cell: BookmarkTitleCell.self, indexPath: indexPath)
cell.configure(name: bookmarkTitle ?? "", delegate: self, hint: L("placepage_bookmark_name_hint"))
return cell
case .color:
let cell = tableView.dequeueDefaultCell(for: indexPath)
cell.accessoryType = .disclosureIndicator
cell.textLabel?.text = bookmarkColor.title
cell.imageView?.image = circleImageForColor(bookmarkColor.color, frameSize: 28, diameter: 22, iconName: "ic_bm_none")
return cell
case .bookmarkGroup:
let cell = tableView.dequeueDefaultCell(for: indexPath)
cell.textLabel?.text = bookmarkGroupTitle
cell.imageView?.image = UIImage(named: "ic_folder")
cell.imageView?.setStyle(.black)
cell.accessoryType = .disclosureIndicator
return cell;
default:
fatalError()
}
case .description:
if let noteCell = noteCell {
return noteCell
} else {
let cell = tableView.dequeueReusableCell(cell: MWMNoteCell.self, indexPath: indexPath)
cell.config(with: self, noteText: bookmarkDescription ?? "", placeholder: L("placepage_personal_notes_hint"))
noteCell = cell
return cell
}
case .delete:
let cell = tableView.dequeueReusableCell(cell: MWMButtonCell.self, indexPath: indexPath)
cell.configure(with: self, title: L("placepage_delete_bookmark_button"), enabled: true)
return cell
default:
fatalError()
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
switch InfoSectionRows(rawValue: indexPath.row) {
case .color:
openColorPicker()
case .bookmarkGroup:
openGroupPicker()
default:
break
}
}
// MARK: - Private
private func updateBookmarkIfNeeded() {
// Skip for the regular place page.
guard bookmarkId != FrameworkHelper.invalidBookmarkId() else { return }
// TODO: Update the bookmark content on the Edit screen instead of closing it when the bookmark gets updated from cloud.
if !bookmarksManager.hasBookmark(bookmarkId) {
goBack()
}
}
private func addToBookmarksManagerObserverList() {
bookmarksManager.add(self)
}
private func removeFromBookmarksManagerObserverList() {
bookmarksManager.remove(self)
}
@objc private func onSave() {
view.endEditing(true)
BookmarksManager.shared().updateBookmark(bookmarkId,
setGroupId: bookmarkGroupId,
title: bookmarkTitle ?? "",
color: bookmarkColor,
description: bookmarkDescription ?? "")
if let placePageData = placePageData {
FrameworkHelper.updatePlacePageData()
placePageData.updateBookmarkStatus()
}
editingCompleted?(true)
goBack()
}
@objc private func openColorPicker() {
ColorPicker.shared.present(from: self, pickerType: .bookmarkColorPicker(bookmarkColor), completionHandler: { [weak self] color in
self?.bookmarkColor = BookmarkColor.bookmarkColor(from: color)
self?.tableView.reloadRows(at: [IndexPath(row: InfoSectionRows.color.rawValue, section: Sections.info.rawValue)], with: .none)
})
}
private func openGroupPicker() {
let groupViewController = SelectBookmarkGroupViewController(groupName: bookmarkGroupTitle ?? "", groupId: bookmarkGroupId)
let navigationController = UINavigationController(rootViewController: groupViewController)
groupViewController.delegate = self
present(navigationController, animated: true, completion: nil)
}
}
extension EditBookmarkViewController: BookmarkTitleCellDelegate {
func didFinishEditingTitle(_ title: String) {
bookmarkTitle = title
}
}
extension EditBookmarkViewController: MWMNoteCellDelegate {
func cell(_ cell: MWMNoteCell, didChangeSizeAndText text: String) {
UIView.setAnimationsEnabled(false)
tableView.refresh()
UIView.setAnimationsEnabled(true)
}
func cell(_ cell: MWMNoteCell, didFinishEditingWithText text: String) {
bookmarkDescription = text
}
}
extension EditBookmarkViewController: MWMButtonCellDelegate {
func cellDidPressButton(_ cell: UITableViewCell) {
BookmarksManager.shared().deleteBookmark(bookmarkId)
if let placePageData = placePageData {
FrameworkHelper.updateAfterDeleteBookmark()
placePageData.updateBookmarkStatus()
}
goBack()
}
}
extension EditBookmarkViewController: SelectBookmarkGroupViewControllerDelegate {
func bookmarkGroupViewController(_ viewController: SelectBookmarkGroupViewController,
didSelect groupTitle: String,
groupId: MWMMarkGroupID) {
viewController.dismiss(animated: true)
bookmarkGroupTitle = groupTitle
bookmarkGroupId = groupId
tableView.reloadRows(at: [IndexPath(row: InfoSectionRows.bookmarkGroup.rawValue, section: Sections.info.rawValue)], with: .none)
}
}
// MARK: - BookmarksObserver
extension EditBookmarkViewController: BookmarksObserver {
func onBookmarksLoadFinished() {
updateBookmarkIfNeeded()
}
func onBookmarksCategoryDeleted(_ groupId: MWMMarkGroupID) {
if bookmarkGroupId == groupId {
goBack()
}
}
}

View file

@ -0,0 +1,236 @@
import UIKit
final class EditTrackViewController: MWMTableViewController {
private enum Sections: Int {
case info
case delete
case count
}
private enum InfoSectionRows: Int {
case title
case color
//case lineWidth // TODO: possible new section & ability - edit track line width
case bookmarkGroup
case count
}
private var editingCompleted: (Bool) -> Void
private var placePageData: PlacePageData?
private let trackId: MWMTrackID
private var trackTitle: String?
private var trackGroupTitle: String?
private var trackGroupId = FrameworkHelper.invalidCategoryId()
private var trackColor: UIColor
private let bookmarksManager = BookmarksManager.shared()
@objc
init(trackId: MWMTrackID, editCompletion completion: @escaping (Bool) -> Void) {
self.trackId = trackId
let track = bookmarksManager.track(withId: trackId)
self.trackTitle = track.trackName
self.trackColor = track.trackColor
let category = bookmarksManager.category(forTrackId: trackId)
self.trackGroupId = category.categoryId
self.trackGroupTitle = category.title
self.editingCompleted = completion
super.init(style: .grouped)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateTrackIfNeeded()
}
deinit {
removeFromBookmarksManagerObserverList()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
title = L("track_title")
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save,
target: self,
action: #selector(onSave))
tableView.registerNib(cell: BookmarkTitleCell.self)
tableView.registerNib(cell: MWMButtonCell.self)
addToBookmarksManagerObserverList()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
Sections.count.rawValue
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch Sections(rawValue: section) {
case .info:
return InfoSectionRows.count.rawValue
case .delete:
return 1
default:
fatalError()
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch Sections(rawValue: indexPath.section) {
case .info:
switch InfoSectionRows(rawValue: indexPath.row) {
case .title:
let cell = tableView.dequeueReusableCell(cell: BookmarkTitleCell.self, indexPath: indexPath)
cell.configure(name: trackTitle ?? "", delegate: self, hint: L("placepage_track_name_hint"))
return cell
case .color:
let cell = tableView.dequeueDefaultCell(for: indexPath)
cell.accessoryType = .disclosureIndicator
cell.textLabel?.text = L("change_color")
cell.imageView?.image = circleImageForColor(trackColor, frameSize: 28, diameter: 22)
return cell
case .bookmarkGroup:
let cell = tableView.dequeueDefaultCell(for: indexPath)
cell.textLabel?.text = trackGroupTitle
cell.imageView?.image = UIImage(named: "ic_folder")
cell.imageView?.setStyle(.black)
cell.accessoryType = .disclosureIndicator
return cell;
default:
fatalError()
}
case .delete:
let cell = tableView.dequeueReusableCell(cell: MWMButtonCell.self, indexPath: indexPath)
cell.configure(with: self, title: L("placepage_delete_track_button"), enabled: true)
return cell
default:
fatalError()
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
switch InfoSectionRows(rawValue: indexPath.row) {
case .color:
openColorPicker()
case .bookmarkGroup:
openGroupPicker()
default:
break
}
}
// MARK: - Private
private func updateTrackIfNeeded() {
// TODO: Update the track content on the Edit screen instead of closing it when the track gets updated from cloud.
if !bookmarksManager.hasTrack(trackId) {
goBack()
}
}
private func addToBookmarksManagerObserverList() {
bookmarksManager.add(self)
}
private func removeFromBookmarksManagerObserverList() {
bookmarksManager.remove(self)
}
@objc private func onSave() {
view.endEditing(true)
BookmarksManager.shared().updateTrack(trackId, setGroupId: trackGroupId, color: trackColor, title: trackTitle ?? "")
editingCompleted(true)
goBack()
}
private func updateColor(_ color: UIColor) {
trackColor = color
tableView.reloadRows(at: [IndexPath(row: InfoSectionRows.color.rawValue, section: Sections.info.rawValue)],
with: .none)
}
@objc private func openColorPicker() {
ColorPicker.shared.present(from: self, pickerType: .defaultColorPicker(trackColor), completionHandler: { [weak self] color in
self?.updateColor(color)
})
}
private func openGroupPicker() {
let groupViewController = SelectBookmarkGroupViewController(groupName: trackGroupTitle ?? "", groupId: trackGroupId)
groupViewController.delegate = self
let navigationController = UINavigationController(rootViewController: groupViewController)
present(navigationController, animated: true, completion: nil)
}
}
extension EditTrackViewController: BookmarkTitleCellDelegate {
func didFinishEditingTitle(_ title: String) {
trackTitle = title
}
}
// MARK: - MWMButtonCellDelegate
extension EditTrackViewController: MWMButtonCellDelegate {
func cellDidPressButton(_ cell: UITableViewCell) {
guard let indexPath = tableView.indexPath(for: cell) else {
fatalError("Invalid cell")
}
switch Sections(rawValue: indexPath.section) {
case .info:
break
case .delete:
bookmarksManager.deleteTrack(trackId)
goBack()
default:
fatalError("Invalid section")
}
}
}
// MARK: - BookmarkColorViewControllerDelegate
extension EditTrackViewController: BookmarkColorViewControllerDelegate {
func bookmarkColorViewController(_ viewController: BookmarkColorViewController, didSelect bookmarkColor: BookmarkColor) {
viewController.dismiss(animated: true)
updateColor(bookmarkColor.color)
}
}
// MARK: - SelectBookmarkGroupViewControllerDelegate
extension EditTrackViewController: SelectBookmarkGroupViewControllerDelegate {
func bookmarkGroupViewController(_ viewController: SelectBookmarkGroupViewController,
didSelect groupTitle: String,
groupId: MWMMarkGroupID) {
viewController.dismiss(animated: true)
trackGroupTitle = groupTitle
trackGroupId = groupId
tableView.reloadRows(at: [IndexPath(row: InfoSectionRows.bookmarkGroup.rawValue, section: Sections.info.rawValue)],
with: .none)
}
}
// MARK: - BookmarksObserver
extension EditTrackViewController: BookmarksObserver {
func onBookmarksLoadFinished() {
updateTrackIfNeeded()
}
func onBookmarksCategoryDeleted(_ groupId: MWMMarkGroupID) {
if trackGroupId == groupId {
goBack()
}
}
}

View file

@ -0,0 +1,95 @@
import UIKit
protocol SelectBookmarkGroupViewControllerDelegate: AnyObject {
func bookmarkGroupViewController(_ viewController: SelectBookmarkGroupViewController,
didSelect groupTitle: String,
groupId: MWMMarkGroupID)
}
final class SelectBookmarkGroupViewController: MWMTableViewController {
private enum Sections: Int {
case addGroup
case groups
case count
}
weak var delegate: SelectBookmarkGroupViewControllerDelegate?
private let groupName: String
private let groupId: MWMMarkGroupID
private let bookmarkGroups = BookmarksManager.shared().sortedUserCategories()
init(groupName: String, groupId: MWMMarkGroupID) {
self.groupName = groupName
self.groupId = groupId
super.init(style: .grouped)
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
title = L("bookmark_sets");
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelButtonDidTap))
}
@objc private func cancelButtonDidTap() {
dismiss(animated: true, completion: nil)
}
override func numberOfSections(in tableView: UITableView) -> Int {
Sections.count.rawValue
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch Sections(rawValue: section) {
case .addGroup:
return 1
case .groups:
return bookmarkGroups.count
default:
fatalError()
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueDefaultCell(for: indexPath)
switch Sections(rawValue: indexPath.section) {
case .addGroup:
cell.textLabel?.text = L("add_new_set")
cell.accessoryType = .disclosureIndicator
case .groups:
let bookmarkGroup = bookmarkGroups[indexPath.row]
cell.textLabel?.text = bookmarkGroup.title
cell.accessoryType = bookmarkGroup.categoryId == groupId ? .checkmark : .none
default:
fatalError()
}
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
switch Sections(rawValue: indexPath.section) {
case .addGroup:
createNewGroup()
case .groups:
let selectedGroup = bookmarkGroups[indexPath.row]
delegate?.bookmarkGroupViewController(self, didSelect: selectedGroup.title, groupId: selectedGroup.categoryId)
default:
fatalError()
}
}
private func createNewGroup() {
alertController.presentCreateBookmarkCategoryAlert(withMaxCharacterNum: 60, minCharacterNum: 0) {
[unowned self] name -> Bool in
guard BookmarksManager.shared().checkCategoryName(name) else { return false }
let newGroupId = BookmarksManager.shared().createCategory(withName: name)
self.delegate?.bookmarkGroupViewController(self, didSelect: name, groupId: newGroupId)
return true
}
}
}

View file

@ -0,0 +1,39 @@
#import "CircleView.h"
#include "kml/types.hpp"
namespace ios_bookmark_ui_helper
{
inline UIColor * UIColorForRGB(int red, int green, int blue)
{
return [UIColor colorWithRed:red/255.f green:green/255.f blue:blue/255.f alpha:0.8];
}
inline UIColor * UIColorForBookmarkColor(kml::PredefinedColor color)
{
auto const dpColor = kml::ColorFromPredefinedColor(color);
return UIColorForRGB(dpColor.red, dpColor.green, dpColor.blue);
}
inline UIImage * ImageForBookmark(kml::PredefinedColor color, kml::BookmarkIcon icon)
{
CGFloat const kPinDiameter = 22;
NSString *imageName = [NSString stringWithFormat:@"%@%@", @"ic_bm_", [@(kml::ToString(icon).c_str()) lowercaseString]];
return [CircleView createCircleImageWithDiameter:kPinDiameter
andColor:UIColorForBookmarkColor(color)
andImageName:imageName];
}
inline UIImage * ImageForTrack(float red, float green, float blue)
{
CGFloat const kPinDiameter = 22;
return [CircleView createCircleImageWithDiameter:kPinDiameter
andColor:[UIColor colorWithRed:red
green:green
blue:blue
alpha:1.f]];
}
} // namespace ios_bookmark_ui_helper