DashboardData.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // DashboardData.swift
  3. // Widget
  4. //
  5. // Created by Marino Faggiana on 20/08/22.
  6. // Copyright © 2022 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 WidgetKit
  24. struct DashboardData: Identifiable, Codable, Hashable {
  25. var id: Int
  26. var image: String
  27. var title: String
  28. var subTitle: String
  29. var url: URL
  30. }
  31. struct DashboardDataEntry: TimelineEntry {
  32. let date: Date
  33. let dashboardDatas: [DashboardData]
  34. let isPlaceholder: Bool
  35. let title: String
  36. let footerText: String
  37. }
  38. func getTitle(account: tableAccount?) -> String {
  39. let hour = Calendar.current.component(.hour, from: Date())
  40. var good = ""
  41. switch hour {
  42. case 6..<12: good = NSLocalizedString("_good_morning_", value: "Good morning", comment: "")
  43. case 12: good = NSLocalizedString("_good_noon_", value: "Good noon", comment: "")
  44. case 13..<17: good = NSLocalizedString("_good_afternoon_", value: "Good afternoon", comment: "")
  45. case 17..<22: good = NSLocalizedString("_good_evening_", value: "Good evening", comment: "")
  46. default: good = NSLocalizedString("_good_night_", value: "Good night", comment: "")
  47. }
  48. if let account = account {
  49. return good + ", " + account.displayName
  50. } else {
  51. return good
  52. }
  53. }