[iOS] move interfaces to separate file, minor fixes

This commit is contained in:
Aleksey Belousov 2020-10-13 14:42:12 +03:00 committed by Alexander Boriskov
parent f05ea40437
commit 9f7933e38c
11 changed files with 176 additions and 173 deletions

View file

@ -1,19 +1,9 @@
import UIKit
protocol IBookmakrsListInfoViewModel {
var title: String { get }
var author: String { get }
var hasDescription: Bool { get }
var imageUrl: URL? { get }
var hasLogo: Bool { get } //TODO: maybe replace with logo url or similar
}
protocol BookmarksListInfoViewControllerDelegate: AnyObject {
func didPressDescription()
func didUpdateContent()
}
class BookmarksListInfoViewController: UIViewController {
final class BookmarksListInfoViewController: UIViewController {
var info: IBookmakrsListInfoViewModel? {
didSet {
guard isViewLoaded, let info = info else { return }
@ -23,16 +13,16 @@ class BookmarksListInfoViewController: UIViewController {
weak var delegate: BookmarksListInfoViewControllerDelegate?
@IBOutlet var titleImageView: UIImageView!
@IBOutlet var titleLabel: UILabel!
@IBOutlet var descriptionButton: UIButton!
@IBOutlet var authorContainerView: UIView!
@IBOutlet var authorImageView: UIImageView!
@IBOutlet var authorLabel: UILabel!
@IBOutlet var infoStack: UIStackView!
@IBOutlet var separatorsConstraints: [NSLayoutConstraint]!
@IBOutlet private var titleImageView: UIImageView!
@IBOutlet private var titleLabel: UILabel!
@IBOutlet private var descriptionButton: UIButton!
@IBOutlet private var authorContainerView: UIView!
@IBOutlet private var authorImageView: UIImageView!
@IBOutlet private var authorLabel: UILabel!
@IBOutlet private var infoStack: UIStackView!
@IBOutlet private var separatorsConstraints: [NSLayoutConstraint]!
@IBAction func onDescription(_ sender: UIButton) {
@IBAction private func onDescription(_ sender: UIButton) {
delegate?.didPressDescription()
}

View file

@ -1,31 +1,3 @@
protocol IBookmarksListInteractor {
func getBookmarkGroup() -> BookmarkGroup
func hasDescription() -> Bool
func prepareForSearch()
func search(_ text: String, completion: @escaping ([Bookmark]) -> Void)
func availableSortingTypes(hasMyPosition: Bool) -> [BookmarksListSortingType]
func viewOnMap()
func viewBookmarkOnMap(_ bookmarkId: MWMMarkID)
func viewTrackOnMap(_ trackId: MWMTrackID)
func setGroup(_ groupId: MWMMarkGroupID, visible: Bool)
func sort(_ sortingType: BookmarksListSortingType,
location: CLLocation?,
completion: @escaping ([BookmarksSection]) -> Void)
func resetSort()
func lastSortingType() -> BookmarksListSortingType?
func deleteBookmark(_ bookmarkId: MWMMarkID)
func deleteBookmarksGroup()
func canDeleteGroup() -> Bool
func exportFile(_ completion: @escaping (URL?, ExportFileStatus) -> Void)
func finishExportFile()
}
enum BookmarksListSortingType {
case distance
case date
case type
}
extension BookmarksListSortingType {
init(_ sortingType: BookmarksSortingType) {
switch sortingType {

View file

@ -0,0 +1,121 @@
import Foundation
enum BookmarksListVisibilityButtonState {
case hidden
case hideAll
case showAll
}
protocol IBookmarksListSectionViewModel {
var numberOfItems: Int { get }
var sectionTitle: String { get }
var visibilityButtonState: BookmarksListVisibilityButtonState { get }
var canEdit: Bool { get }
}
protocol IBookmarksSectionViewModel: IBookmarksListSectionViewModel {
var bookmarks: [IBookmarkViewModel] { get }
}
protocol ITracksSectionViewModel: IBookmarksListSectionViewModel {
var tracks: [ITrackViewModel] { get }
}
protocol ISubgroupsSectionViewModel: IBookmarksListSectionViewModel {
var subgroups: [ISubgroupViewModel] { get }
}
protocol IBookmarkViewModel {
var bookmarkName: String { get }
var subtitle: String { get }
var image: UIImage { get }
}
protocol ITrackViewModel {
var trackName: String { get }
var subtitle: String { get }
var image: UIImage { get }
}
protocol ISubgroupViewModel {
var subgroupName: String { get }
var subtitle: String { get }
var isVisible: Bool { get }
}
protocol IBookmarksListMenuItem {
var title: String { get }
var destructive: Bool { get }
var enabled: Bool { get }
var action: () -> Void { get }
}
protocol IBookmarksListView: AnyObject {
func setTitle(_ title: String)
func setInfo(_ info: IBookmakrsListInfoViewModel)
func setSections(_ sections: [IBookmarksListSectionViewModel])
func setMoreItemTitle(_ itemTitle: String)
func showMenu(_ items: [IBookmarksListMenuItem])
func enableEditing(_ enable: Bool)
func share(_ url: URL, completion: @escaping () -> Void)
func showError(title: String, message: String)
}
protocol IBookmarksListPresenter {
func viewDidLoad()
func activateSearch()
func deactivateSearch()
func cancelSearch()
func search(_ text: String)
func sort()
func more()
func deleteBookmark(in section: IBookmarksListSectionViewModel, at index: Int)
func selectItem(in section: IBookmarksListSectionViewModel, at index: Int)
func checkItem(in section: IBookmarksListSectionViewModel, at index: Int, checked: Bool)
func toggleVisibility(in section: IBookmarksListSectionViewModel)
func showDescription()
}
enum BookmarksListSortingType {
case distance
case date
case type
}
protocol IBookmarksListInteractor {
func getBookmarkGroup() -> BookmarkGroup
func hasDescription() -> Bool
func prepareForSearch()
func search(_ text: String, completion: @escaping ([Bookmark]) -> Void)
func availableSortingTypes(hasMyPosition: Bool) -> [BookmarksListSortingType]
func viewOnMap()
func viewBookmarkOnMap(_ bookmarkId: MWMMarkID)
func viewTrackOnMap(_ trackId: MWMTrackID)
func setGroup(_ groupId: MWMMarkGroupID, visible: Bool)
func sort(_ sortingType: BookmarksListSortingType,
location: CLLocation?,
completion: @escaping ([BookmarksSection]) -> Void)
func resetSort()
func lastSortingType() -> BookmarksListSortingType?
func deleteBookmark(_ bookmarkId: MWMMarkID)
func deleteBookmarksGroup()
func canDeleteGroup() -> Bool
func exportFile(_ completion: @escaping (URL?, ExportFileStatus) -> Void)
func finishExportFile()
}
protocol IBookmarksListRouter {
func listSettings(_ bookmarkGroup: BookmarkGroup, delegate: CategorySettingsViewControllerDelegate?)
func sharingOptions(_ bookmarkGroup: BookmarkGroup)
func viewOnMap(_ bookmarkGroup: BookmarkGroup)
func showDescription(_ bookmarkGroup: BookmarkGroup)
func showSubgroup(_ subgroupId: MWMMarkGroupID)
}
protocol IBookmakrsListInfoViewModel {
var title: String { get }
var author: String { get }
var hasDescription: Bool { get }
var imageUrl: URL? { get }
var hasLogo: Bool { get } //TODO: maybe replace with logo url or similar
}

View file

@ -1,18 +1,3 @@
protocol IBookmarksListPresenter {
func viewDidLoad()
func activateSearch()
func deactivateSearch()
func cancelSearch()
func search(_ text: String)
func sort()
func more()
func deleteBookmark(in section: IBookmarksListSectionViewModel, at index: Int)
func selectItem(in section: IBookmarksListSectionViewModel, at index: Int)
func checkItem(in section: IBookmarksListSectionViewModel, at index: Int, checked: Bool)
func toggleVisibility(in section: IBookmarksListSectionViewModel)
func showDescription()
}
protocol BookmarksListDelegate: AnyObject {
func bookmarksListDidDeleteGroup()
}
@ -349,6 +334,27 @@ extension BookmarksListPresenter: CategorySettingsViewControllerDelegate {
}
}
extension IBookmarksSectionViewModel {
var numberOfItems: Int { bookmarks.count }
var visibilityButtonState: BookmarksListVisibilityButtonState { .hidden }
var canEdit: Bool { true }
}
extension ITracksSectionViewModel {
var numberOfItems: Int { tracks.count }
var sectionTitle: String { L("tracks_title") }
var visibilityButtonState: BookmarksListVisibilityButtonState { .hidden }
var canEdit: Bool { true }
}
extension ISubgroupsSectionViewModel {
var numberOfItems: Int { subgroups.count }
var visibilityButtonState: BookmarksListVisibilityButtonState {
subgroups.reduce(false) { $0 ? $0 : $1.isVisible } ? .hideAll : .showAll
}
var canEdit: Bool { false }
}
fileprivate struct BookmarkViewModel: IBookmarkViewModel {
let bookmarkId: MWMMarkID
let bookmarkName: String

View file

@ -1,11 +1,3 @@
protocol IBookmarksListRouter {
func listSettings(_ bookmarkGroup: BookmarkGroup, delegate: CategorySettingsViewControllerDelegate?)
func sharingOptions(_ bookmarkGroup: BookmarkGroup)
func viewOnMap(_ bookmarkGroup: BookmarkGroup)
func showDescription(_ bookmarkGroup: BookmarkGroup)
func showSubgroup(_ subgroupId: MWMMarkGroupID)
}
final class BookmarksListRouter {
private let mapViewController: MapViewController
private weak var coordinator: BookmarksCoordinator?

View file

@ -1,85 +1,3 @@
enum BookmarksListVisibilityButtonState {
case hidden
case hideAll
case showAll
}
protocol IBookmarksListSectionViewModel {
var numberOfItems: Int { get }
var sectionTitle: String { get }
var visibilityButtonState: BookmarksListVisibilityButtonState { get }
var canEdit: Bool { get }
}
protocol IBookmarksSectionViewModel: IBookmarksListSectionViewModel {
var bookmarks: [IBookmarkViewModel] { get }
}
extension IBookmarksSectionViewModel {
var numberOfItems: Int { bookmarks.count }
var visibilityButtonState: BookmarksListVisibilityButtonState { .hidden }
var canEdit: Bool { true }
}
protocol ITracksSectionViewModel: IBookmarksListSectionViewModel {
var tracks: [ITrackViewModel] { get }
}
extension ITracksSectionViewModel {
var numberOfItems: Int { tracks.count }
var sectionTitle: String { L("tracks_title") }
var visibilityButtonState: BookmarksListVisibilityButtonState { .hidden }
var canEdit: Bool { true }
}
protocol ISubgroupsSectionViewModel: IBookmarksListSectionViewModel {
var subgroups: [ISubgroupViewModel] { get }
}
extension ISubgroupsSectionViewModel {
var numberOfItems: Int { subgroups.count }
var visibilityButtonState: BookmarksListVisibilityButtonState {
subgroups.reduce(false) { $0 ? $0 : $1.isVisible } ? .hideAll : .showAll
}
var canEdit: Bool { false }
}
protocol IBookmarkViewModel {
var bookmarkName: String { get }
var subtitle: String { get }
var image: UIImage { get }
}
protocol ITrackViewModel {
var trackName: String { get }
var subtitle: String { get }
var image: UIImage { get }
}
protocol ISubgroupViewModel {
var subgroupName: String { get }
var subtitle: String { get }
var isVisible: Bool { get }
}
protocol IBookmarksListMenuItem {
var title: String { get }
var destructive: Bool { get }
var enabled: Bool { get }
var action: () -> Void { get }
}
protocol IBookmarksListView: AnyObject {
func setTitle(_ title: String)
func setInfo(_ info: IBookmakrsListInfoViewModel)
func setSections(_ sections: [IBookmarksListSectionViewModel])
func setMoreItemTitle(_ itemTitle: String)
func showMenu(_ items: [IBookmarksListMenuItem])
func enableEditing(_ enable: Bool)
func share(_ url: URL, completion: @escaping () -> Void)
func showError(title: String, message: String)
}
final class BookmarksListViewController: MWMViewController {
var presenter: IBookmarksListPresenter!
@ -88,11 +6,11 @@ final class BookmarksListViewController: MWMViewController {
private var canEdit = false
@IBOutlet var tableView: UITableView!
@IBOutlet var searchBar: UISearchBar!
@IBOutlet var toolBar: UIToolbar!
@IBOutlet var sortToolbarItem: UIBarButtonItem!
@IBOutlet var moreToolbarItem: UIBarButtonItem!
@IBOutlet private var tableView: UITableView!
@IBOutlet private var searchBar: UISearchBar!
@IBOutlet private var toolBar: UIToolbar!
@IBOutlet private var sortToolbarItem: UIBarButtonItem!
@IBOutlet private var moreToolbarItem: UIBarButtonItem!
private lazy var infoViewController: BookmarksListInfoViewController = {
let infoViewController = BookmarksListInfoViewController()
@ -137,11 +55,11 @@ final class BookmarksListViewController: MWMViewController {
tableView.tableHeaderView = infoView
}
@IBAction func onSortItem(_ sender: UIBarButtonItem) {
@IBAction private func onSortItem(_ sender: UIBarButtonItem) {
presenter.sort()
}
@IBAction func onMoreItem(_ sender: UIBarButtonItem) {
@IBAction private func onMoreItem(_ sender: UIBarButtonItem) {
presenter.more()
}

View file

@ -1,7 +1,7 @@
final class BookmarkCell: UITableViewCell {
@IBOutlet var bookmarkImageView: UIImageView!
@IBOutlet var bookmarkTitleLabel: UILabel!
@IBOutlet var bookmarkSubtitleLabel: UILabel!
@IBOutlet private var bookmarkImageView: UIImageView!
@IBOutlet private var bookmarkTitleLabel: UILabel!
@IBOutlet private var bookmarkSubtitleLabel: UILabel!
func config(_ bookmark: IBookmarkViewModel) {
bookmarkImageView.image = bookmark.image

View file

@ -1,11 +1,11 @@
final class BookmarksListSectionHeader: UITableViewHeaderFooterView {
@IBOutlet var titleLabel: UILabel!
@IBOutlet var visibilityButton: UIButton!
@IBOutlet private var titleLabel: UILabel!
@IBOutlet private var visibilityButton: UIButton!
typealias VisibilityHandlerClosure = () -> Void
var visibilityHandler: VisibilityHandlerClosure?
@IBAction func onVisibilityButton(_ sender: UIButton) {
@IBAction private func onVisibilityButton(_ sender: UIButton) {
visibilityHandler?()
}

View file

@ -1,7 +1,7 @@
final class SubgroupCell: UITableViewCell {
@IBOutlet var subgroupTitleLabel: UILabel!
@IBOutlet var subgroupSubtitleLabel: UILabel!
@IBOutlet var subgroupVisibleMark: Checkmark!
@IBOutlet private var subgroupTitleLabel: UILabel!
@IBOutlet private var subgroupSubtitleLabel: UILabel!
@IBOutlet private var subgroupVisibleMark: Checkmark!
typealias CheckHandlerClosure = (Bool) -> Void
var checkHandler: CheckHandlerClosure?
@ -12,7 +12,7 @@ final class SubgroupCell: UITableViewCell {
subgroupVisibleMark.isChecked = subgroup.isVisible
}
@IBAction func onCheck(_ sender: Checkmark) {
@IBAction private func onCheck(_ sender: Checkmark) {
checkHandler?(sender.isChecked)
}
}

View file

@ -1,7 +1,7 @@
final class TrackCell: UITableViewCell {
@IBOutlet var trackImageView: UIImageView!
@IBOutlet var trackTitleLabel: UILabel!
@IBOutlet var trackSubtitleLabel: UILabel!
@IBOutlet private var trackImageView: UIImageView!
@IBOutlet private var trackTitleLabel: UILabel!
@IBOutlet private var trackSubtitleLabel: UILabel!
func config(_ track: ITrackViewModel) {
trackImageView.image = track.image

View file

@ -354,6 +354,7 @@
474AC76C2139E4F2002F9BF9 /* RemoveAdsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474AC76A2139E4F2002F9BF9 /* RemoveAdsViewController.swift */; };
474AC76D2139E4F2002F9BF9 /* RemoveAdsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 474AC76B2139E4F2002F9BF9 /* RemoveAdsViewController.xib */; };
474C9F5A213FF75800369009 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 474C9F59213FF75800369009 /* StoreKit.framework */; };
4757D6212535BB6E0062364F /* BookmarksListInterfaces.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4757D6202535BB6E0062364F /* BookmarksListInterfaces.swift */; };
475EC36D244EDE66003BC295 /* GuidesGalleryPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475EC36C244EDE66003BC295 /* GuidesGalleryPresenter.swift */; };
475EC36F244EF7A9003BC295 /* GuidesGalleryBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475EC36E244EF7A9003BC295 /* GuidesGalleryBuilder.swift */; };
475EC373244F0992003BC295 /* PlacePageGalleryLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475EC372244F0992003BC295 /* PlacePageGalleryLayout.swift */; };
@ -1507,6 +1508,7 @@
474AC76A2139E4F2002F9BF9 /* RemoveAdsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoveAdsViewController.swift; sourceTree = "<group>"; };
474AC76B2139E4F2002F9BF9 /* RemoveAdsViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RemoveAdsViewController.xib; sourceTree = "<group>"; };
474C9F59213FF75800369009 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
4757D6202535BB6E0062364F /* BookmarksListInterfaces.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksListInterfaces.swift; sourceTree = "<group>"; };
475EC36C244EDE66003BC295 /* GuidesGalleryPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuidesGalleryPresenter.swift; sourceTree = "<group>"; };
475EC36E244EF7A9003BC295 /* GuidesGalleryBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuidesGalleryBuilder.swift; sourceTree = "<group>"; };
475EC372244F0992003BC295 /* PlacePageGalleryLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlacePageGalleryLayout.swift; sourceTree = "<group>"; };
@ -3615,6 +3617,7 @@
47CA68D92500469400671019 /* BookmarksListBuilder.swift */,
470E1672252AD7F2002D201A /* BookmarksListInfoViewController.swift */,
470E1673252AD7F2002D201A /* BookmarksListInfoViewController.xib */,
4757D6202535BB6E0062364F /* BookmarksListInterfaces.swift */,
);
path = BookmarksList;
sourceTree = "<group>";
@ -5559,6 +5562,7 @@
472E3F4C2147D5700020E412 /* Subscription.swift in Sources */,
340B33C61F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm in Sources */,
F6E2FE191E097BA00083EBEC /* MWMOpeningHoursTimeSpanTableViewCell.mm in Sources */,
4757D6212535BB6E0062364F /* BookmarksListInterfaces.swift in Sources */,
F6E407D01FC45EF5001F7821 /* MWMDiscoveryController.mm in Sources */,
F6E2FDEC1E097BA00083EBEC /* MWMOpeningHoursAddClosedTableViewCell.mm in Sources */,
34BBD64C1F826DB10070CA50 /* AuthorizationViewController.swift in Sources */,