Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 44 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
//
2
//  NotificationListViewModel.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 7/31/22.
6
//
7
 
8
import Foundation
9
import SwiftUI
10
 
11
class NotificationListViewModel: ObservableObject
12
{
31 efrain 13
    @Published public var notifications = [UserNotificationModel]()
23 efrain 14
    private let appData = AppData.sharedInstance
1 efrain 15
 
23 efrain 16
 
1 efrain 17
    init() {
18
 
19
        fetchAll()
20
    }
21
 
22
    func fetchAll()
23
    {
23 efrain 24
        let now = Date()
25
        let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: now)!
26
 
27
 
28
        let dateFormatter = DateFormatter()
29
        dateFormatter.dateFormat = Constants.FORMAT_DATE_YMD
30
 
24 efrain 31
        let sToday = dateFormatter.string(from: now)
23 efrain 32
        let sYesterday = dateFormatter.string(from: yesterday)
33
 
34
        let showFormatter = DateFormatter()
35
        showFormatter.dateFormat = Constants.FORMAT_DATE_DMY
36
 
37
 
61 efrain 38
        let userNotificationDao = UserNotificationDao()
23 efrain 39
 
31 efrain 40
        notifications.removeAll()
41
        notifications = userNotificationDao.selectAllByUserUuid(userUuid: appData.userUuid)
42
 
43
        var i : Int = 0
44
        while i  < notifications.count {
45
 
46
 
47
            switch notifications[i].dateOn
48
            {
49
                case sToday :
50
                    notifications[i].dateOn = Config.LANG_COMMON_TODAY
51
                    break
52
 
53
                case sYesterday :
54
                    notifications[i].dateOn = Config.LANG_COMMON_YESTERDAY
55
                    break
56
 
57
                default :
58
                    let d = dateFormatter.date(from: notifications[i].dateOn) ?? Date()
59
                    notifications[i].dateOn = showFormatter.string(from: d)
60
                    break
61
 
62
            }
63
 
64
            i += 1
65
        }
23 efrain 66
 
31 efrain 67
        /*
23 efrain 68
        let dates = userNotificationDao.selectAllDistinctDateByUserUuid(userUuid: appData.userUuid)
69
 
70
 
71
 
72
        var i : Int = 0
73
        var d : Date
74
        var sDate : String
75
        while i < dates.count {
76
            sDate = dates[i]
24 efrain 77
            userNotificationGroupModel = UserNotificationGroupModel()
23 efrain 78
 
24 efrain 79
            switch sDate
80
            {
81
                case sToday :
82
                    userNotificationGroupModel.label = Config.LANG_COMMON_TODAY
83
                    break
84
 
85
                case sYesterday :
86
                    userNotificationGroupModel.label = Config.LANG_COMMON_YESTERDAY
87
                    break
88
 
89
                default :
90
                    d = dateFormatter.date(from: sDate) ?? Date()
91
                    userNotificationGroupModel.label = showFormatter.string(from: d)
92
                    break
93
 
94
            }
95
 
23 efrain 96
 
24 efrain 97
 
23 efrain 98
            userNotificationGroupModel.notifications = userNotificationDao.selectAllByUserUuidAndDate(userUuid: appData.userUuid, date: sDate)
99
 
100
            groups.append(userNotificationGroupModel)
101
 
102
            i += 1
103
 
104
        }
31 efrain 105
         */
1 efrain 106
    }
107
 
26 efrain 108
 
1 efrain 109
}