Skip to content

Commit

Permalink
Use menu for topic selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Hengyu committed Dec 17, 2023
1 parent e19d3fa commit 05a13e4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 160 deletions.
72 changes: 0 additions & 72 deletions Sources/FeedbackSwift/DrawUpPresentationController.swift

This file was deleted.

19 changes: 6 additions & 13 deletions Sources/FeedbackSwift/FeedbackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ open class FeedbackViewController: UITableViewController {

wireframe = FeedbackWireframe(
viewController: self,
transitioningDelegate: self,
imagePickerDelegate: self,
mailComposerDelegate: self
)
Expand Down Expand Up @@ -134,8 +133,6 @@ extension FeedbackViewController {
public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let item = configuration.dataSource.section(at: indexPath.section)[indexPath.row]
switch item {
case _ as TopicItem:
wireframe.showTopicsView(with: feedbackEditingService)
case _ as AttachmentItem:
guard let cell = tableView.cellForRow(at: indexPath) else {
fatalError("Can't get cell")
Expand Down Expand Up @@ -191,6 +188,12 @@ extension FeedbackViewController: BodyCellEventProtocol {
}
}

extension FeedbackViewController: TopicCellProtocol {
func topicCellOptionChanged(_ option: TopicProtocol) {
feedbackEditingService.update(selectedTopic: option)
}
}

extension FeedbackViewController: AttachmentCellEventProtocol {
func showImage(of item: AttachmentItem) {
// Pending
Expand Down Expand Up @@ -320,13 +323,3 @@ extension FeedbackViewController: MFMailComposeViewControllerDelegate {
mailComposeDelegate?.mailComposeController?(controller, didFinishWith: result, error: error)
}
}

extension FeedbackViewController: UIViewControllerTransitioningDelegate {
public func presentationController(
forPresented presented: UIViewController,
presenting: UIViewController?,
source: UIViewController
) -> UIPresentationController? {
DrawUpPresentationController(presentedViewController: presented, presenting: presenting)
}
}
11 changes: 0 additions & 11 deletions Sources/FeedbackSwift/FeedbackWireframe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import UIKit
import UniformTypeIdentifiers

protocol FeedbackWireframeProtocol {
func showTopicsView(with service: FeedbackEditingServiceProtocol)
func showMailComposer(with feedback: Feedback)
func showAttachmentActionSheet(
cellRect: CGRect,
Expand All @@ -26,31 +25,21 @@ protocol FeedbackWireframeProtocol {

final class FeedbackWireframe {
private weak var viewController: UIViewController?
private weak var transitioningDelegate: UIViewControllerTransitioningDelegate?
private weak var imagePickerDelegate: (UIImagePickerControllerDelegate & UINavigationControllerDelegate)?
private weak var mailComposerDelegate: MFMailComposeViewControllerDelegate?

init(
viewController: UIViewController,
transitioningDelegate: UIViewControllerTransitioningDelegate,
imagePickerDelegate: UIImagePickerControllerDelegate & UINavigationControllerDelegate,
mailComposerDelegate: MFMailComposeViewControllerDelegate
) {
self.viewController = viewController
self.transitioningDelegate = transitioningDelegate
self.imagePickerDelegate = imagePickerDelegate
self.mailComposerDelegate = mailComposerDelegate
}
}

extension FeedbackWireframe: FeedbackWireframeProtocol {
func showTopicsView(with service: FeedbackEditingServiceProtocol) {
let controller = TopicsViewController(service: service)
controller.modalPresentationStyle = .custom
controller.transitioningDelegate = transitioningDelegate

DispatchQueue.main.async { self.viewController?.present(controller, animated: true) }
}

func showMailComposer(with feedback: Feedback) {
guard MFMailComposeViewController.canSendMail() else { return showMailConfigurationError() }
Expand Down
27 changes: 24 additions & 3 deletions Sources/FeedbackSwift/Items/Topic/TopicCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@

import UIKit

protocol TopicCellProtocol {
func topicCellOptionChanged(_ option: TopicProtocol)
}

final public class TopicCell: UITableViewCell {
private let button: UIButton = .init(type: .system)

public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .value1, reuseIdentifier: TopicCell.reuseIdentifier)
commonInit()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}

private func commonInit() {
button.titleLabel?.font = .preferredFont(forTextStyle: .body)
button.showsMenuAsPrimaryAction = true
accessoryView = button
}
}

Expand All @@ -20,11 +34,18 @@ extension TopicCell: CellFactoryProtocol {
_ cell: TopicCell,
with item: TopicItem,
for indexPath: IndexPath,
eventHandler: Any?
eventHandler: TopicCellProtocol?
) {
cell.textLabel?.text = localized("feedback.Topic")
cell.detailTextLabel?.text = item.topicTitle
cell.accessoryType = .disclosureIndicator
cell.button.setTitle(item.topicTitle, for: .normal)
cell.button.menu = .init(
children: item.topics.map { topic in
UIAction(title: topic.localizedTitle) { action in
eventHandler?.topicCellOptionChanged(topic)
}
}
)
cell.button.sizeToFit()
cell.selectionStyle = .none
}
}
61 changes: 0 additions & 61 deletions Sources/FeedbackSwift/TopicsViewController.swift

This file was deleted.

0 comments on commit 05a13e4

Please sign in to comment.