NCMoreAppSuggestionsCell.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // NCMoreAppSuggestionsCell.swift
  3. // Nextcloud
  4. //
  5. // Created by Milen on 14.06.23.
  6. // Copyright © 2023 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. import UIKit
  25. import SafariServices
  26. import SwiftUI
  27. class NCMoreAppSuggestionsCell: BaseNCMoreCell {
  28. @IBOutlet weak var assistantView: UIStackView!
  29. @IBOutlet weak var talkView: UIStackView!
  30. @IBOutlet weak var notesView: UIStackView!
  31. @IBOutlet weak var moreAppsView: UIStackView!
  32. static let reuseIdentifier = "NCMoreAppSuggestionsCell"
  33. var controller: NCMainTabBarController?
  34. static func fromNib() -> UINib {
  35. return UINib(nibName: "NCMoreAppSuggestionsCell", bundle: nil)
  36. }
  37. override func awakeFromNib() {
  38. super.awakeFromNib()
  39. backgroundColor = .clear
  40. assistantView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(assistantTapped)))
  41. talkView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(talkTapped)))
  42. notesView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(notesTapped)))
  43. moreAppsView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(moreAppsTapped)))
  44. }
  45. override func setupCell(account: String) {
  46. assistantView.isHidden = !NCCapabilities.shared.getCapabilities(account: account).capabilityAssistantEnabled
  47. }
  48. @objc func assistantTapped() {
  49. if let viewController = self.window?.rootViewController {
  50. let assistant = NCAssistant().environmentObject(NCAssistantTask(controller: controller))
  51. let hostingController = UIHostingController(rootView: assistant)
  52. viewController.present(hostingController, animated: true, completion: nil)
  53. }
  54. }
  55. @objc func talkTapped() {
  56. guard let url = URL(string: NCGlobal.shared.talkSchemeUrl) else { return }
  57. if UIApplication.shared.canOpenURL(url) {
  58. UIApplication.shared.open(url)
  59. } else {
  60. guard let url = URL(string: NCGlobal.shared.talkAppStoreUrl) else { return }
  61. UIApplication.shared.open(url)
  62. }
  63. }
  64. @objc func notesTapped() {
  65. guard let url = URL(string: NCGlobal.shared.notesSchemeUrl) else { return }
  66. if UIApplication.shared.canOpenURL(url) {
  67. UIApplication.shared.open(url)
  68. } else {
  69. guard let url = URL(string: NCGlobal.shared.notesAppStoreUrl) else { return }
  70. UIApplication.shared.open(url)
  71. }
  72. }
  73. @objc func moreAppsTapped() {
  74. guard let url = URL(string: NCGlobal.shared.moreAppsUrl) else { return }
  75. UIApplication.shared.open(url)
  76. }
  77. }