NCMoreAppSuggestionsCell.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 SafariServices
  25. import SwiftUI
  26. class NCMoreAppSuggestionsCell: BaseNCMoreCell {
  27. @IBOutlet weak var assistantView: UIStackView!
  28. @IBOutlet weak var talkView: UIStackView!
  29. @IBOutlet weak var notesView: UIStackView!
  30. @IBOutlet weak var moreAppsView: UIStackView!
  31. static let reuseIdentifier = "NCMoreAppSuggestionsCell"
  32. static func fromNib() -> UINib {
  33. return UINib(nibName: "NCMoreAppSuggestionsCell", bundle: nil)
  34. }
  35. override func awakeFromNib() {
  36. super.awakeFromNib()
  37. backgroundColor = .clear
  38. assistantView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(assistantTapped)))
  39. talkView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(talkTapped)))
  40. notesView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(notesTapped)))
  41. moreAppsView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(moreAppsTapped)))
  42. if !NCGlobal.shared.capabilityAssistantEnabled {
  43. assistantView.isHidden = true
  44. }
  45. }
  46. @objc func assistantTapped() {
  47. if let viewController = self.window?.rootViewController {
  48. let assistant = NCAssistant().environmentObject(NCAssistantTask())
  49. let hostingController = UIHostingController(rootView: assistant)
  50. viewController.present(hostingController, animated: true, completion: nil)
  51. }
  52. }
  53. @objc func talkTapped() {
  54. guard let url = URL(string: NCGlobal.shared.talkSchemeUrl) else { return }
  55. if UIApplication.shared.canOpenURL(url) {
  56. UIApplication.shared.open(url)
  57. } else {
  58. guard let url = URL(string: NCGlobal.shared.talkAppStoreUrl) else { return }
  59. UIApplication.shared.open(url)
  60. }
  61. }
  62. @objc func notesTapped() {
  63. guard let url = URL(string: NCGlobal.shared.notesSchemeUrl) else { return }
  64. if UIApplication.shared.canOpenURL(url) {
  65. UIApplication.shared.open(url)
  66. } else {
  67. guard let url = URL(string: NCGlobal.shared.notesAppStoreUrl) else { return }
  68. UIApplication.shared.open(url)
  69. }
  70. }
  71. @objc func moreAppsTapped() {
  72. guard let url = URL(string: NCGlobal.shared.moreAppsUrl) else { return }
  73. UIApplication.shared.open(url)
  74. }
  75. }