Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 22 | Rev 24 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 22 Rev 23
Línea 7... Línea 7...
7
 
7
 
8
import Foundation
8
import Foundation
Línea -... Línea 9...
-
 
9
import SwiftUI
-
 
10
 
-
 
11
 
-
 
12
struct UserNotificationGroupModel :Identifiable {
-
 
13
    var id : String = UUID().uuidString
-
 
14
    var label : String =  ""
-
 
15
    var notifications = [UserNotificationModel]()
-
 
16
}
9
import SwiftUI
17
 
10
 
18
 
11
 
19
 
-
 
20
class NotificationListViewModel: ObservableObject
-
 
21
{
Línea 12... Línea 22...
12
class NotificationListViewModel: ObservableObject
22
    @Published public var groups = [UserNotificationGroupModel]()
Línea 13... Línea 23...
13
{
23
    private let appData = AppData.sharedInstance
14
    @Published public var notifications = [UserNotificationModel]()
24
    
Línea 15... Línea 25...
15
    
25
    
16
    init() {
26
    init() {
-
 
27
 
-
 
28
        fetchAll()
-
 
29
    }
-
 
30
 
-
 
31
    func fetchAll()
-
 
32
    {
-
 
33
        let now = Date()
-
 
34
        let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: now)!
-
 
35
        
-
 
36
        
-
 
37
        let dateFormatter = DateFormatter()
-
 
38
        dateFormatter.dateFormat = Constants.FORMAT_DATE_YMD
-
 
39
        
-
 
40
        let sNow = dateFormatter.string(from: now)
-
 
41
        let sYesterday = dateFormatter.string(from: yesterday)
-
 
42
        
-
 
43
        let showFormatter = DateFormatter()
-
 
44
        showFormatter.dateFormat = Constants.FORMAT_DATE_DMY
-
 
45
        
17
 
46
        
-
 
47
        
-
 
48
        
-
 
49
        groups.removeAll()
-
 
50
        
-
 
51
        var userNotificationGroupModel : UserNotificationGroupModel
-
 
52
        let userNotificationDao = UserNotificationDao.sharedInstance
-
 
53
        let dates = userNotificationDao.selectAllDistinctDateByUserUuid(userUuid: appData.userUuid)
-
 
54
        
-
 
55
        
-
 
56
 
-
 
57
        var i : Int = 0
-
 
58
        var d : Date
-
 
59
        var sDate : String
18
        fetchAll()
60
        while i < dates.count {
-
 
61
            sDate = dates[i]
-
 
62
            d = dateFormatter.date(from: sDate) ?? Date()
-
 
63
            
-
 
64
            
-
 
65
            
-
 
66
            userNotificationGroupModel = UserNotificationGroupModel()
-
 
67
            userNotificationGroupModel.label = showFormatter.string(from: d)
-
 
68
            userNotificationGroupModel.notifications = userNotificationDao.selectAllByUserUuidAndDate(userUuid: appData.userUuid, date: sDate)
19
    }
69
            
Línea 20... Línea 70...
20
 
70
            groups.append(userNotificationGroupModel)
21
    func fetchAll()
71
            
22
    {
72
            i += 1
-
 
73
            
-
 
74
        }
-
 
75
    }
23
        let userNotificationDao = UserNotificationDao.sharedInstance
76
    
-
 
77
    public func removeItem(id: Int) {
-
 
78
        let userNotificationDao = UserNotificationDao.sharedInstance
-
 
79
        userNotificationDao.remove(id: id)
-
 
80
        
-
 
81
        var i : Int = 0
24
        notifications = userNotificationDao.selectAll();
82
        while i < groups.count {
Línea 25... Línea 83...
25
    }
83
            groups[i].notifications.remove(at:  groups[i].notifications.firstIndex(where: {  $0.id == id })!)