Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 9 | Rev 17 | 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
//  GridSlideView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 2/17/22.
6
//
7
 
8
import SwiftUI
9
 
10
 
11
struct GridSlideView: View {
12
 
8 efrain 13
    @EnvironmentObject private var networkMonitor : NetworkMonitor
1 efrain 14
    @EnvironmentObject private var appNavigation : AppNavigation
15
    @State private var scrollToIndex : Int = 0
16
 
9 efrain 17
    private let appDao = AppDao.sharedInstance
1 efrain 18
    private let capsuleDao : CapsuleDao = CapsuleDao.sharedInstance
19
 
20
    private var capsuleModel : CapsuleModel = CapsuleModel()
21
    private var viewModel : SlideGridViewModel = SlideGridViewModel()
22
    private var capsuleTitle : String = ""
23
 
24
    private let config = [
25
        GridItem(.fixed(Constants.CARD_WIDTH)),
26
        GridItem(.fixed(Constants.CARD_WIDTH))
27
    ]
28
 
29
 
30
 
31
    //init(capsuleUuid : String)
32
    init()
33
    {
11 efrain 34
        let appData = appDao.selectOne()
1 efrain 35
        self.capsuleModel = capsuleDao.selectByUuid(uuid: appData.capsuleUuidActive)
36
        viewModel.fetch(capsuleUuid: self.capsuleModel.uuid, userUuid: appData.userUuid)
37
 
38
        if self.capsuleModel.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {
39
            capsuleTitle = String(Array(self.capsuleModel.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."
40
        } else {
41
            capsuleTitle = self.capsuleModel.name
42
        }
43
    }
44
 
45
    var body: some View {
46
 
47
            VStack(spacing: 0) {
48
                HStack {
49
                    Button(action: {
8 efrain 50
 
11 efrain 51
                        var appData = appDao.selectOne()
52
                        if appNavigation.subPageSource == .mycapsules {
8 efrain 53
                            appData.topicUuidActive = ""
54
                            appData.capsuleUuidActive = ""
55
 
11 efrain 56
                            print("update query : 10")
57
                            appDao.update(model: appData)
58
 
8 efrain 59
                            withAnimation {
60
                                appNavigation.subpageActive = .mycapsules
61
                            }
62
                        } else {
63
                            appData.slideUuidActive = ""
64
 
11 efrain 65
                            print("update query : 11")
66
                            appDao.update(model: appData)
67
 
8 efrain 68
                            withAnimation {
69
                                appNavigation.subpageActive = .capsules
70
                            }
71
                        }
1 efrain 72
 
8 efrain 73
 
1 efrain 74
                    }, label: {
75
 
76
 
77
                        Image(systemName: "chevron.backward")
78
                        .frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
79
                        .aspectRatio(contentMode: .fit)
8 efrain 80
                            .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
1 efrain 81
                    })
82
                    .padding(.leading, 16)
83
 
8 efrain 84
                    Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : capsuleTitle)
1 efrain 85
                    .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
8 efrain 86
                     .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
1 efrain 87
                        .padding(.leading, 4)
88
 
89
                    Spacer()
90
                }
91
                .edgesIgnoringSafeArea(.top)
92
                .frame(height: 50)
8 efrain 93
                .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
94
 
95
 
96
                Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
97
 
1 efrain 98
 
99
                Divider()
100
 
101
                ScrollView() {
102
                    ScrollViewReader { proxy in
103
                        LazyVGrid(columns: config, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, pinnedViews: /*@START_MENU_TOKEN@*/[]/*@END_MENU_TOKEN@*/, content: {
104
 
105
                            ForEach(0..<self.viewModel.slides.count) { index in
106
                                CardSlideView(
107
                                    slideUuid: self.viewModel.slides[index].uuid,
108
                                    position: index
109
                                )
110
                                .environmentObject(appNavigation)
111
                                .frame(
112
                                    width: Constants.CARD_WIDTH,
113
                                    height: Constants.CARD_HEIGHT,
114
                                    alignment: .center
115
                                )
116
                                .id(index)
117
 
118
                            }
119
                            /*}.onChange(of:  scrollToIndex, perform: { value in
11 efrain 120
                                //print("onChange")
1 efrain 121
                                proxy.scrollTo(value, anchor: nil)
122
                            })*/
123
                        })
124
                    }
125
 
126
                }
127
                /*.onAppear {
128
                    var i : Int = 0
129
                    while i < self.viewModel.slides.count {
130
                        if appData.slideUuidActive == self.viewModel.slides[i].uuid {
131
                            self.scrollToIndex = i
132
                        }
133
                        i += 1
134
                    }
135
 
136
                }*/
137
                .padding(.top, 5)
138
 
139
 
140
 
141
 
142
        }
143
    }
144
}
145
 
146
struct GridSlideView_Previews: PreviewProvider {
147
    static var previews: some View {
148
        //GridSlideView(capsuleUuid: "C123")
149
        GridSlideView()
150
    }
151
}
152
 
153