Skip to content

Commit

Permalink
Add PopoverMenuManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Mar 23, 2024
1 parent e8368ca commit 4011ea8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import FTPopOverMenu
import UIKit

protocol UserCollectionPresenterProtocol {
Expand Down Expand Up @@ -69,16 +68,6 @@ final class UserCollectionPresenter: UserCollectionPresenterProtocol {
try? database?.save(object: object)
}

private func popOverMenuConfiguration() -> FTConfiguration {
let config = FTConfiguration()
config.backgoundTintColor = ColorPalette.appTheme
config.borderColor = ColorPalette.appTheme
config.menuSeparatorColor = .lightGray
config.textColor = .white
config.textAlignment = .center
return config
}

private func getUserCollection() -> UserCollectionDTO {
var user = UserCollectionDTO()
try? database?.fetch(UserCollectionDTO.self, predicate: nil, sorted: nil) { [weak self] results in
Expand Down Expand Up @@ -125,13 +114,12 @@ final class UserCollectionPresenter: UserCollectionPresenterProtocol {

@objc
private func sort(_ sender: UIBarButtonItem, event: UIEvent) {
FTPopOverMenu.showForEvent(event: event,
with: [L10n.aToZ, L10n.cardNumber, L10n.color],
config: popOverMenuConfiguration(),
done: { [weak self] selectedIndex in
self?.controller?.sort(selectedIndex)
self?.currentSortIndex = selectedIndex
}, cancel: {})
let manager = PopoverMenuManager()
manager.showPopoverMenu(forEvent: event,
with: [L10n.aToZ, L10n.cardNumber, L10n.color]) { [weak self] selectedIndex in
self?.controller?.sort(selectedIndex)
self?.currentSortIndex = selectedIndex
}
}
}

Expand Down
41 changes: 41 additions & 0 deletions SWDestinyTrades/Classes/Utils/PopoverMenuManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// PopoverMenuManager.swift
// SWDestinyTrades
//
// Created by Diogo Autilio on 23/03/24.
// Copyright © 2024 Diogo Autilio. All rights reserved.
//

import Foundation
import FTPopOverMenu
import UIKit

protocol PopoverMenuManagerType {
func showPopoverMenu(forEvent event: UIEvent, with menuArray: [String], done: ((NSInteger) -> Void)?, cancel: (() -> Void)?)
}

final class PopoverMenuManager: PopoverMenuManagerType {

// Configures the appearance of the popover menu
private func appearance() -> FTConfiguration {
let config = FTConfiguration()
config.backgoundTintColor = ColorPalette.appTheme
config.borderColor = ColorPalette.appTheme
config.menuSeparatorColor = .lightGray
config.textColor = .white
config.textAlignment = .center
return config
}

// Displays the popover menu for the given event
func showPopoverMenu(forEvent event: UIEvent,
with menuArray: [String],
done: ((NSInteger) -> Void)?,
cancel: (() -> Void)? = nil) {
FTPopOverMenu.showForEvent(event: event,
with: menuArray,
config: appearance(),
done: done,
cancel: cancel)
}
}

0 comments on commit 4011ea8

Please sign in to comment.