NCCollectionViewCommon+EasyTipView.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // NCCollectionViewCommon+EasyTipView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 20/07/24.
  6. // Copyright © 2024 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 EasyTipView
  26. extension NCCollectionViewCommon: EasyTipViewDelegate {
  27. func showTip() {
  28. guard !session.account.isEmpty,
  29. self is NCFiles,
  30. self.view.window != nil,
  31. !NCBrandOptions.shared.disable_multiaccount,
  32. self.serverUrl == utilityFileSystem.getHomeServer(session: session),
  33. let view = self.navigationItem.leftBarButtonItem?.customView,
  34. !database.tipExists(global.tipNCCollectionViewCommonAccountRequest) else { return }
  35. var preferences = EasyTipView.Preferences()
  36. preferences.drawing.foregroundColor = .white
  37. preferences.drawing.backgroundColor = NCBrandColor.shared.nextcloud
  38. preferences.drawing.textAlignment = .left
  39. preferences.drawing.arrowPosition = .top
  40. preferences.drawing.cornerRadius = 10
  41. preferences.animating.dismissTransform = CGAffineTransform(translationX: 0, y: 100)
  42. preferences.animating.showInitialTransform = CGAffineTransform(translationX: 0, y: -100)
  43. preferences.animating.showInitialAlpha = 0
  44. preferences.animating.showDuration = 1.5
  45. preferences.animating.dismissDuration = 1.5
  46. if appDelegate.tipView == nil {
  47. appDelegate.tipView = EasyTipView(text: NSLocalizedString("_tip_accountrequest_", comment: ""), preferences: preferences, delegate: self)
  48. appDelegate.tipView?.show(forView: view)
  49. }
  50. }
  51. func easyTipViewDidTap(_ tipView: EasyTipView) {
  52. database.addTip(global.tipNCCollectionViewCommonAccountRequest)
  53. }
  54. func easyTipViewDidDismiss(_ tipView: EasyTipView) { }
  55. func dismissTip() {
  56. if !database.tipExists(global.tipNCCollectionViewCommonAccountRequest) {
  57. database.addTip(global.tipNCCollectionViewCommonAccountRequest)
  58. }
  59. appDelegate.tipView?.dismiss()
  60. appDelegate.tipView = nil
  61. }
  62. }