Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 57 | Rev 61 | 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
//  NotificationListView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 7/31/22.
6
//
7
 
8
import SwiftUI
55 efrain 9
import SafariServices
1 efrain 10
 
11
struct NotificationListView: View {
8 efrain 12
    @EnvironmentObject private var networkMonitor : NetworkMonitor
13
    @EnvironmentObject private var appNavigation : AppNavigation
1 efrain 14
 
44 efrain 15
    @ObservedObject var viewModel :NotificationListViewModel
55 efrain 16
 
17
    @State private var sheetURL: String = ""
18
    @State private var sheetShow = false
19
 
25 efrain 20
    private let appData = AppData.sharedInstance
1 efrain 21
 
44 efrain 22
    init() {
23
 
24
        let userNotificationDao = UserNotificationDao.sharedInstance
25
 
26
        userNotificationDao.removeExpired(userUuid:appData.userUuid)
27
 
28
        viewModel = NotificationListViewModel()
29
    }
25 efrain 30
 
1 efrain 31
    var body: some View {
32
        VStack(spacing: 0) {
33
            HStack {
34
                Image("logo")
35
                .resizable()
36
                .frame(width: 32, height: 32, alignment: .center)
37
                .aspectRatio(contentMode: .fit)
8 efrain 38
                    .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
1 efrain 39
                .padding(.leading, 16)
40
 
8 efrain 41
                Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : Config.LANG_TAB_BAR_BUTTON_NOTIFICATIONS)
1 efrain 42
                .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
8 efrain 43
                    .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
1 efrain 44
                .padding(.leading, 4)
45
 
46
                Spacer()
47
 
48
 
49
            }
50
            .edgesIgnoringSafeArea(.top)
51
            .frame(height: 50)
8 efrain 52
            .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
53
 
54
            Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
1 efrain 55
 
56
            ScrollView {
22 efrain 57
 
31 efrain 58
                if self.viewModel.notifications.count == 0  {
22 efrain 59
                    NotificationListItemEmptyView()
1 efrain 60
 
22 efrain 61
                } else {
62
 
63
 
64
 
65
                    LazyVStack  {
1 efrain 66
 
23 efrain 67
 
31 efrain 68
 
24 efrain 69
 
44 efrain 70
                        ForEach(self.viewModel.notifications) { notificationItem  in
23 efrain 71
 
44 efrain 72
                            //let notificationItem = self.viewModel.notifications[index]
24 efrain 73
 
25 efrain 74
                                NotificationListItemView(notification: notificationItem,onExecute: {
75
 
76
                                    if notificationItem.command == Constants.NOTIFICATION_COMMAND_REFRESH_CONTENT && notificationItem.viewed == 0 {
77
 
44 efrain 78
                                        let notificationDao = UserNotificationDao.sharedInstance
79
                                        notificationDao.markViewedAllPendingByUserUuidAndCommand(userUuid: appData.userUuid, command: Constants.NOTIFICATION_COMMAND_REFRESH_CONTENT)
25 efrain 80
 
81
                                        appData.refreshContentActionRequired = true
82
                                        appData.save()
83
 
84
                                        withAnimation {
85
                                            appNavigation.subpageActive = .topics
86
                                        }
87
 
88
 
89
                                    } else if notificationItem.command == Constants.NOTIFICATION_COMMAND_OPEN_URL &&
90
                                        !notificationItem.url.isEmpty  &&
91
                                        notificationItem.viewed == 0  {
92
 
55 efrain 93
 
44 efrain 94
                                        let notificationDao = UserNotificationDao.sharedInstance
95
                                        notificationDao.markViewed(id: notificationItem.id)
25 efrain 96
 
44 efrain 97
                                        self.viewModel.fetchAll()
98
 
55 efrain 99
                                        self.sheetURL =  notificationItem.url
100
                                        self.sheetShow = true
101
 
25 efrain 102
                                    }
103
 
104
                                }) {
44 efrain 105
 
106
                                    DispatchQueue.main.async {
107
                                        let notificationDao = UserNotificationDao.sharedInstance
108
                                        notificationDao.remove(id: notificationItem.id)
109
 
110
                                        self.viewModel.fetchAll()
111
                                    }
23 efrain 112
                                }
25 efrain 113
 
22 efrain 114
                            }
31 efrain 115
 
1 efrain 116
                    }
117
                }
8 efrain 118
            }.padding(.top, 5)
26 efrain 119
        }.onAppear {
120
            viewModel.fetchAll()
57 efrain 121
        }.popover(isPresented: self.$sheetShow, content: {
55 efrain 122
 
58 efrain 123
 
55 efrain 124
 
58 efrain 125
            SafariView(sURL: self.sheetURL)
57 efrain 126
 
55 efrain 127
 
56 efrain 128
        })    }
1 efrain 129
}
130
 
131
struct NotificationListView_Previews: PreviewProvider {
132
    static var previews: some View {
133
        NotificationListView()
134
    }
135
}