Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(polls): Added missing error handling and activity indicator in p…
…oll voting view

Signed-off-by: Ivan Sein <[email protected]>
  • Loading branch information
Ivansss committed Jan 15, 2025
commit b190b4332ba4f46515c406dee996761883e773b5
34 changes: 20 additions & 14 deletions NextcloudTalk/PollCreationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,7 @@ import UIKit
self.creatingPollIndicatorView = UIActivityIndicatorView()
self.creatingPollIndicatorView.color = NCAppBranding.themeTextColor()

if draftsAvailable {
let menuAction = UIAction(title: NSLocalizedString("Browse poll drafts", comment: ""), image: UIImage(systemName: "doc")) { _ in
self.presentPollDraftsView()
}

let menu = UIMenu(title: "", options: .displayInline, children: [menuAction])
let menuButton = UIBarButtonItem(
image: UIImage(systemName: "ellipsis.circle"),
menu: menu
)

navigationItem.rightBarButtonItem = menuButton
}
self.setMoreOptionsButton()

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCAppBranding.themeTextColor()]
self.navigationController?.navigationBar.tintColor = NCAppBranding.themeTextColor()
Expand Down Expand Up @@ -146,7 +134,25 @@ import UIKit
func removePollCreationUI() {
enablePollCreationButtons()
creatingPollIndicatorView.stopAnimating()
navigationItem.rightBarButtonItem = nil
setMoreOptionsButton()
}

func setMoreOptionsButton() {
if draftsAvailable {
let menuAction = UIAction(title: NSLocalizedString("Browse poll drafts", comment: ""), image: UIImage(systemName: "doc")) { _ in
self.presentPollDraftsView()
}

let menu = UIMenu(title: "", options: .displayInline, children: [menuAction])
let menuButton = UIBarButtonItem(
image: UIImage(systemName: "ellipsis.circle"),
menu: menu
)

navigationItem.rightBarButtonItem = menuButton
} else {
navigationItem.rightBarButtonItem = nil
}
}

func enablePollCreationButtons() {
Expand Down
62 changes: 48 additions & 14 deletions NextcloudTalk/PollVotingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import UIKit
let footerView = PollFooterView(frame: CGRect.zero)
var pollBackgroundView: PlaceholderView = PlaceholderView(for: .grouped)
var userSelectedOptions: [Int] = []
var activityIndicatorView = UIActivityIndicatorView()

required init?(coder aDecoder: NSCoder) {
self.room = NCRoom()
Expand All @@ -46,6 +47,11 @@ import UIKit
override func viewDidLoad() {
super.viewDidLoad()

self.activityIndicatorView = UIActivityIndicatorView()
self.activityIndicatorView.color = NCAppBranding.themeTextColor()

self.setMoreOptionsButton()

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCAppBranding.themeTextColor()]
self.navigationController?.navigationBar.tintColor = NCAppBranding.themeTextColor()
self.navigationController?.navigationBar.barTintColor = NCAppBranding.themeColor()
Expand All @@ -64,20 +70,6 @@ import UIKit
pollBackgroundView.loadingView.startAnimating()
self.tableView.backgroundView = pollBackgroundView

if draftsAvailable {
let menuAction = UIAction(title: NSLocalizedString("Save as draft", comment: ""), image: UIImage(systemName: "doc")) { _ in
self.createPollDraft()
}

let menu = UIMenu(title: "", options: .displayInline, children: [menuAction])
let menuButton = UIBarButtonItem(
image: UIImage(systemName: "ellipsis.circle"),
menu: menu
)

navigationItem.rightBarButtonItem = menuButton
}

self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.cancelButtonPressed))
self.navigationItem.leftBarButtonItem?.tintColor = NCAppBranding.themeTextColor()
}
Expand Down Expand Up @@ -223,17 +215,59 @@ import UIKit
}
}

func showActivityIndicatorView() {
activityIndicatorView.startAnimating()
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: activityIndicatorView)
}

func removeActivityIndicatorView() {
activityIndicatorView.stopAnimating()
setMoreOptionsButton()
}

func setMoreOptionsButton() {
if draftsAvailable {
let menuAction = UIAction(title: NSLocalizedString("Save as draft", comment: ""), image: UIImage(systemName: "doc")) { _ in
self.createPollDraft()
}

let menu = UIMenu(title: "", options: .displayInline, children: [menuAction])
let menuButton = UIBarButtonItem(
image: UIImage(systemName: "ellipsis.circle"),
menu: menu
)

navigationItem.rightBarButtonItem = menuButton
} else {
navigationItem.rightBarButtonItem = nil
}
}

func showDraftCreationSuccess() {
NotificationPresenter.shared().present(text: NSLocalizedString("Poll draft has been saved", comment: ""), dismissAfterDelay: 5.0, includedStyle: .dark)
}

func showDraftCreationError() {
let alert = UIAlertController(title: NSLocalizedString("Creating poll draft failed", comment: ""),
message: NSLocalizedString("An error occurred while creating poll draft", comment: ""),
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .cancel, handler: nil))
self.present(alert, animated: true)
}

func createPollDraft() {
guard let poll else {return}

showActivityIndicatorView()

NCAPIController.sharedInstance().createPoll(withQuestion: poll.question, options: poll.options, resultMode: poll.resultMode, maxVotes: poll.maxVotes, inRoom: room.token, asDraft: true, for: room.account) { _, error, _ in
if error == nil {
self.showDraftCreationSuccess()
} else {
self.showDraftCreationError()
}

self.removeActivityIndicatorView()
}
}

Expand Down