LotsOfChanges
This commit is contained in:
28
Schedule ICTIS/Main/FirstLaunchScheduleView.swift
Normal file
28
Schedule ICTIS/Main/FirstLaunchScheduleView.swift
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// FirstLaunchScheduleView.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by G412 on 06.12.2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FirstLaunchScheduleView: View {
|
||||
var body: some View {
|
||||
VStack (alignment: .center) {
|
||||
Spacer()
|
||||
HStack {
|
||||
Image(systemName: "pencil")
|
||||
.font(.title)
|
||||
Text("Введите свою группу")
|
||||
.font(.system(size: 20, weight: .bold, design: .default))
|
||||
}
|
||||
.foregroundColor(Color("blueColor"))
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
FirstLaunchScheduleView()
|
||||
}
|
@ -9,40 +9,47 @@ import SwiftUI
|
||||
|
||||
struct MainView: View {
|
||||
@State private var searchText: String = ""
|
||||
@State private var currentDate: Date = .init()
|
||||
@State private var currentDate: Date = Date()
|
||||
@State private var weekSlider: [[Date.WeekDay]] = []
|
||||
@State private var currentWeekIndex: Int = 1
|
||||
@State private var createWeek: Bool = false
|
||||
@State private var isShowingMonthSlider: Bool = false
|
||||
@StateObject var vm = ViewModel()
|
||||
@State private var isFirstAppearence = true
|
||||
@ObservedObject var vm: ViewModel
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
SearchBarView(text: $searchText, vm: vm)
|
||||
HeaderView()
|
||||
ScheduleView(vm: vm)
|
||||
CurrentDateView()
|
||||
if (vm.isFirstStartOffApp) {
|
||||
FirstLaunchScheduleView()
|
||||
}
|
||||
else {
|
||||
ScheduleView(vm: vm)
|
||||
}
|
||||
}
|
||||
.background(Color("background"))
|
||||
.onAppear(perform: {
|
||||
currentDate = vm.selectedDay
|
||||
vm.updateSelectedDayIndex(currentDate)
|
||||
if weekSlider.isEmpty {
|
||||
let currentWeek = Date().fetchWeek()
|
||||
|
||||
|
||||
if let firstDate = currentWeek.first?.date {
|
||||
weekSlider.append(firstDate.createPrevioustWeek())
|
||||
}
|
||||
|
||||
|
||||
weekSlider.append(currentWeek)
|
||||
|
||||
|
||||
if let lastDate = currentWeek.last?.date {
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
}
|
||||
}
|
||||
vm.updateSelectedDayIndex(currentDate)
|
||||
})
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func HeaderView() -> some View {
|
||||
func CurrentDateView() -> some View {
|
||||
VStack (alignment: .leading, spacing: 6) {
|
||||
HStack {
|
||||
VStack (alignment: .leading, spacing: 0) {
|
||||
@ -147,6 +154,7 @@ struct MainView: View {
|
||||
.onPreferenceChange(OffsetKey.self) { value in
|
||||
if value.rounded() == 15 && createWeek {
|
||||
paginateWeek()
|
||||
|
||||
createWeek = false
|
||||
}
|
||||
}
|
||||
@ -158,6 +166,7 @@ struct MainView: View {
|
||||
if weekSlider.indices.contains(currentWeekIndex) {
|
||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||
currentWeekIndex == 0 {
|
||||
vm.fetchWeekSchedule("new week", -1)
|
||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||
weekSlider.removeLast()
|
||||
currentWeekIndex = 1
|
||||
@ -165,6 +174,7 @@ struct MainView: View {
|
||||
|
||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||
currentWeekIndex == (weekSlider.count - 1) {
|
||||
vm.fetchWeekSchedule("new week", 1)
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
weekSlider.removeFirst()
|
||||
currentWeekIndex = weekSlider.count - 2
|
||||
@ -174,5 +184,5 @@ struct MainView: View {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
MainView()
|
||||
ContentView()
|
||||
}
|
||||
|
@ -11,34 +11,48 @@ struct ScheduleView: View {
|
||||
@ObservedObject var vm: ViewModel
|
||||
var body: some View {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack (spacing: 12) {
|
||||
VStack (spacing: 20) {
|
||||
ForEach(vm.classes.indices, id: \.self) { index in
|
||||
if index != 0 && index != 1 && index == vm.selectedIndex {
|
||||
let daySchedule = vm.classes[index] // Это массив строк для дня
|
||||
ForEach(daySchedule.indices.dropFirst(), id: \.self) { lessonIndex in
|
||||
let lesson = daySchedule[lessonIndex] // Это строка с расписанием одной пары
|
||||
if !lesson.isEmpty {
|
||||
HStack(spacing: 6) {
|
||||
HStack(spacing: 10) {
|
||||
VStack {
|
||||
Text(convertTimeString(vm.classes[1][lessonIndex])[0])
|
||||
.font(.system(size: 15, weight: .light))
|
||||
.font(.system(size: 15, weight: .regular))
|
||||
Text(convertTimeString(vm.classes[1][lessonIndex])[1])
|
||||
.font(.system(size: 15, weight: .light))
|
||||
.font(.system(size: 15, weight: .regular))
|
||||
}
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
.padding(.leading, 10)
|
||||
Rectangle()
|
||||
.frame(width: 2)
|
||||
.frame(maxHeight: 100)
|
||||
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
.foregroundColor(onlineOrOffline(lesson) ? Color("greenForOffline") : Color("blueForOnline"))
|
||||
Text(lesson)
|
||||
.font(.system(size: 18, weight: .regular))
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
Spacer()
|
||||
}
|
||||
.frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230)
|
||||
.background(Color.white)
|
||||
.padding(.horizontal)
|
||||
.cornerRadius(20)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.bottom, 100)
|
||||
.padding(.top, 10)
|
||||
}
|
||||
}
|
||||
//ктбо2-6
|
||||
|
||||
func convertTimeString(_ input: String) -> [String] {
|
||||
let parts = input.split(separator: "-")
|
||||
@ -48,8 +62,17 @@ struct ScheduleView: View {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
func onlineOrOffline(_ str: String) -> Bool {
|
||||
if (MockData.onlineClasses.contains(str)) {
|
||||
return false
|
||||
}
|
||||
else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
MainView()
|
||||
ContentView()
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ struct SearchBarView: View {
|
||||
.onSubmit {
|
||||
isEditing = false
|
||||
if (!text.isEmpty) {
|
||||
vm.isFirstStartOffApp = false
|
||||
vm.fetchWeekSchedule(text)
|
||||
}
|
||||
}
|
||||
@ -76,5 +77,5 @@ struct SearchBarView: View {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
MainView()
|
||||
ContentView()
|
||||
}
|
||||
|
Reference in New Issue
Block a user