Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// NotificationListViewModel.swift// twogetskills//// Created by Efrain Yanez Recanatini on 7/31/22.//import Foundationimport SwiftUIclass NotificationListViewModel: ObservableObject{@Published public var notifications = [UserNotificationModel]()private let appData = AppData.sharedInstanceinit() {fetchAll()}func fetchAll(){let now = Date()let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: now)!let dateFormatter = DateFormatter()dateFormatter.dateFormat = Constants.FORMAT_DATE_YMDlet sToday = dateFormatter.string(from: now)let sYesterday = dateFormatter.string(from: yesterday)let showFormatter = DateFormatter()showFormatter.dateFormat = Constants.FORMAT_DATE_DMYlet userNotificationDao = UserNotificationDao.sharedInstancenotifications.removeAll()notifications = userNotificationDao.selectAllByUserUuid(userUuid: appData.userUuid)var i : Int = 0while i < notifications.count {switch notifications[i].dateOn{case sToday :notifications[i].dateOn = Config.LANG_COMMON_TODAYbreakcase sYesterday :notifications[i].dateOn = Config.LANG_COMMON_YESTERDAYbreakdefault :let d = dateFormatter.date(from: notifications[i].dateOn) ?? Date()notifications[i].dateOn = showFormatter.string(from: d)break}i += 1}/*let dates = userNotificationDao.selectAllDistinctDateByUserUuid(userUuid: appData.userUuid)var i : Int = 0var d : Datevar sDate : Stringwhile i < dates.count {sDate = dates[i]userNotificationGroupModel = UserNotificationGroupModel()switch sDate{case sToday :userNotificationGroupModel.label = Config.LANG_COMMON_TODAYbreakcase sYesterday :userNotificationGroupModel.label = Config.LANG_COMMON_YESTERDAYbreakdefault :d = dateFormatter.date(from: sDate) ?? Date()userNotificationGroupModel.label = showFormatter.string(from: d)break}userNotificationGroupModel.notifications = userNotificationDao.selectAllByUserUuidAndDate(userUuid: appData.userUuid, date: sDate)groups.append(userNotificationGroupModel)i += 1}*/}}