Commit
This commit is contained in:
parent
13de6fa302
commit
15fbe5895c
@ -36,15 +36,23 @@ struct ContentView: View {
|
||||
}
|
||||
.accentColor(Color("blueColor"))
|
||||
.onAppear {
|
||||
let group = UserDefaults.standard.string(forKey: "group")
|
||||
if let nameGroup = group {
|
||||
vm.group = nameGroup
|
||||
vm.fetchWeekSchedule(group: nameGroup)
|
||||
let group1 = UserDefaults.standard.string(forKey: "group")
|
||||
let group2 = UserDefaults.standard.string(forKey: "group2")
|
||||
let group3 = UserDefaults.standard.string(forKey: "group3")
|
||||
if let nameGroup1 = group1, nameGroup1 != "" {
|
||||
vm.nameGroups.append(nameGroup1)
|
||||
}
|
||||
if let nameGroup2 = group2, nameGroup2 != "" {
|
||||
vm.nameGroups.append(nameGroup2)
|
||||
}
|
||||
if let nameGroup3 = group3, nameGroup3 != "" {
|
||||
vm.nameGroups.append(nameGroup3)
|
||||
}
|
||||
print("\(group1) - \(group2) - \(group3)")
|
||||
vm.fetchWeekSchedule()
|
||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||
vm.fetchWeekVPK(vpk: vpkStr)
|
||||
}
|
||||
print(vm.vpks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,6 @@ struct ScheduleView: View {
|
||||
@State private var isShowingMyPairs = false
|
||||
@Binding var isScrolling: Bool
|
||||
var provider = ClassProvider.shared
|
||||
var hasLessons: Bool {
|
||||
return vm.classes.indices.contains(vm.selectedIndex) &&
|
||||
vm.classes[vm.selectedIndex].dropFirst().contains { !$0.isEmpty }
|
||||
}
|
||||
var hasVPK: Bool {
|
||||
return vm.vpks.indices.contains(vm.selectedIndex) && vm.vpks[vm.selectedIndex].dropFirst().contains { !$0.isEmpty }
|
||||
}
|
||||
@ -32,23 +28,20 @@ struct ScheduleView: View {
|
||||
ZStack (alignment: .top) {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack (spacing: 30) {
|
||||
VStack (alignment: .leading, spacing: 20 ) {
|
||||
if hasLessons {
|
||||
Text("Учебное расписание")
|
||||
.font(.custom("Montserrat-Bold", fixedSize: 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 {
|
||||
VStack (alignment: .leading, spacing: 10) {
|
||||
ForEach(0..<vm.classesGroups.count, id: \.self) { dayIndex in
|
||||
if dayIndex == vm.selectedIndex {
|
||||
ForEach(vm.classesGroups[dayIndex]) { info in
|
||||
VStack (alignment: .trailing) {
|
||||
Text(info.group)
|
||||
.font(.custom("Montserrat-Regular", fixedSize: 11))
|
||||
.foregroundColor(Color("grayForNameGroup"))
|
||||
HStack(spacing: 15) {
|
||||
VStack {
|
||||
Text(convertTimeString(vm.classes[1][lessonIndex])[0])
|
||||
Text(convertTimeString(info.time)[0])
|
||||
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
||||
.padding(.bottom, 1)
|
||||
Text(convertTimeString(vm.classes[1][lessonIndex])[1])
|
||||
Text(convertTimeString(info.time)[1])
|
||||
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
||||
.padding(.top, 1)
|
||||
}
|
||||
@ -61,8 +54,8 @@ struct ScheduleView: View {
|
||||
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
.foregroundColor(getColorForClass(lesson))
|
||||
Text(lesson)
|
||||
.foregroundColor(getColorForClass(info.subject))
|
||||
Text(info.subject)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 16))
|
||||
.lineSpacing(3)
|
||||
.padding(.top, 9)
|
||||
@ -92,54 +85,6 @@ struct ScheduleView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||
VStack (alignment: .leading, spacing: 20 ) {
|
||||
if hasVPK {
|
||||
Text("ВПК")
|
||||
.font(.custom("Montserrat-Bold", fixedSize: 20))
|
||||
}
|
||||
ForEach(vm.vpks.indices, id: \.self) { index in
|
||||
if index != 0 && index != 1 && index == vm.selectedIndex {
|
||||
let dayVPK = vm.vpks[index] // Это массив строк для дня
|
||||
ForEach(dayVPK.indices.dropFirst(), id: \.self) { lessonIndex in
|
||||
let lesson = dayVPK[lessonIndex] // Это строка с расписанием одной пары
|
||||
if !lesson.isEmpty {
|
||||
HStack(spacing: 15) {
|
||||
VStack {
|
||||
Text(convertTimeString(vm.vpks[1][lessonIndex])[0])
|
||||
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
||||
.padding(.bottom, 1)
|
||||
Text(convertTimeString(vm.vpks[1][lessonIndex])[1])
|
||||
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
||||
.padding(.top, 1)
|
||||
}
|
||||
.frame(width: 48)
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
.padding(.leading, 10)
|
||||
Rectangle()
|
||||
.frame(width: 2)
|
||||
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
.foregroundColor(getColorForClass(lesson))
|
||||
Text(lesson)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 16))
|
||||
.lineSpacing(3)
|
||||
.padding(.top, 9)
|
||||
.padding(.bottom, 9)
|
||||
Spacer()
|
||||
}
|
||||
.frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230)
|
||||
.background(Color.white)
|
||||
.cornerRadius(20)
|
||||
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: UIScreen.main.bounds.width)
|
||||
.padding(.bottom, 100)
|
||||
|
@ -29,7 +29,7 @@ struct SearchBarView: View {
|
||||
.onSubmit {
|
||||
self.isFocused = false
|
||||
if (!text.isEmpty) {
|
||||
vm.fetchWeekSchedule(group: text)
|
||||
//vm.fetchWeekSchedule(group: text)
|
||||
}
|
||||
self.text = ""
|
||||
}
|
||||
|
@ -21,3 +21,10 @@ struct Table: Decodable {
|
||||
let table: [[String]]
|
||||
let link: String
|
||||
}
|
||||
|
||||
struct ClassInfo: Identifiable {
|
||||
let id = UUID()
|
||||
let subject: String
|
||||
let group: String
|
||||
let time: String
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0x89",
|
||||
"green" : "0x89",
|
||||
"red" : "0x89"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0x89",
|
||||
"green" : "0x89",
|
||||
"red" : "0x89"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
95
Schedule ICTIS/Settings/FavGroupsView.swift
Normal file
95
Schedule ICTIS/Settings/FavGroupsView.swift
Normal file
@ -0,0 +1,95 @@
|
||||
//
|
||||
// FavGroupsView.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by G412 on 05.03.2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FavGroupsView: View {
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
var firstFavGroup = (UserDefaults.standard.string(forKey: "group") ?? "")
|
||||
var secondFavGroup = (UserDefaults.standard.string(forKey: "group2") ?? "")
|
||||
var thirdFavGroup = (UserDefaults.standard.string(forKey: "group3") ?? "")
|
||||
var body: some View {
|
||||
VStack {
|
||||
List {
|
||||
if firstFavGroup != "" {
|
||||
HStack {
|
||||
Text(firstFavGroup)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
Spacer()
|
||||
}
|
||||
.background(Color.white)
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
UserDefaults.standard.set("", forKey: "group")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
if secondFavGroup != "" {
|
||||
HStack {
|
||||
Text(secondFavGroup)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
Spacer()
|
||||
}
|
||||
.background(Color.white)
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
UserDefaults.standard.set("", forKey: "group2")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
if thirdFavGroup != "" {
|
||||
HStack {
|
||||
Text(thirdFavGroup)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
Spacer()
|
||||
}
|
||||
.background(Color.white)
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
UserDefaults.standard.set("", forKey: "group3")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if firstFavGroup == "" || secondFavGroup == "" || thirdFavGroup == "" {
|
||||
NavigationLink(destination: SelectingGroupView(vm: vm, firstFavGroup: firstFavGroup, secondFavGroup: secondFavGroup, thirdFavGroup: thirdFavGroup)) {
|
||||
HStack {
|
||||
Image(systemName: "plus")
|
||||
.foregroundColor(.white)
|
||||
.font(.system(size: 22))
|
||||
.padding(EdgeInsets(top: 15, leading: 130, bottom: 15, trailing: 130))
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.background(Color("blueColor"))
|
||||
.cornerRadius(10)
|
||||
.padding(.bottom, 40)
|
||||
}
|
||||
}
|
||||
}
|
||||
.background(Color("background"))
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
@Previewable @StateObject var vm = ScheduleViewModel()
|
||||
FavGroupsView(vm: vm)
|
||||
}
|
@ -8,20 +8,15 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ScheduleGroupSettings: View {
|
||||
@AppStorage("group") private var favGroup = ""
|
||||
@AppStorage("vpk") private var favVPK = ""
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
var body: some View {
|
||||
VStack {
|
||||
NavigationLink(destination: SelectingGroupView(vm: vm)) {
|
||||
NavigationLink(destination: FavGroupsView(vm: vm)) {
|
||||
HStack {
|
||||
Text("Избранное расписание")
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
.foregroundColor(.black)
|
||||
Spacer()
|
||||
Text(favGroup)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
.foregroundColor(Color("customGray3"))
|
||||
Image("arrowRight")
|
||||
}
|
||||
.padding(.horizontal)
|
||||
@ -38,9 +33,6 @@ struct ScheduleGroupSettings: View {
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
.foregroundColor(.black)
|
||||
Spacer()
|
||||
Text(favVPK)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
.foregroundColor(Color("customGray3"))
|
||||
Image("arrowRight")
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
@ -14,142 +14,132 @@ struct SelectingGroupView: View {
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
@State private var isLoading = false
|
||||
@State private var searchTask: DispatchWorkItem?
|
||||
@AppStorage("group") private var favGroup = ""
|
||||
@StateObject private var serchGroupsVM = SearchGroupsViewModel()
|
||||
var firstFavGroup: String
|
||||
var secondFavGroup: String
|
||||
var thirdFavGroup: String
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
HStack (spacing: 0) {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.foregroundColor(Color.gray)
|
||||
.padding(.leading, 12)
|
||||
.padding(.trailing, 7)
|
||||
TextField("Поиск группы", text: $text)
|
||||
.disableAutocorrection(true)
|
||||
.focused($isFocused)
|
||||
.onChange(of: text) { oldValue, newValue in
|
||||
searchTask?.cancel()
|
||||
let task = DispatchWorkItem {
|
||||
if !text.isEmpty {
|
||||
vm.fetchGroups(group: text)
|
||||
VStack {
|
||||
HStack (spacing: 0) {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.foregroundColor(Color.gray)
|
||||
.padding(.leading, 12)
|
||||
.padding(.trailing, 7)
|
||||
TextField("Поиск группы", text: $text)
|
||||
.disableAutocorrection(true)
|
||||
.focused($isFocused)
|
||||
.onChange(of: text) { oldValue, newValue in
|
||||
searchTask?.cancel()
|
||||
let task = DispatchWorkItem {
|
||||
if !text.isEmpty {
|
||||
serchGroupsVM.fetchGroups(group: text)
|
||||
}
|
||||
else {
|
||||
serchGroupsVM.fetchGroups(group: "кт")
|
||||
}
|
||||
}
|
||||
searchTask = task
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: task)
|
||||
}
|
||||
.onSubmit {
|
||||
self.isFocused = false
|
||||
if (!text.isEmpty) {
|
||||
vm.fetchWeekSchedule(isOtherWeek: false)
|
||||
self.isLoading = true
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
self.isLoading = false
|
||||
if vm.errorInNetwork == .noError {
|
||||
vm.errorInNetwork = nil
|
||||
print("Зашел")
|
||||
if firstFavGroup == "" {
|
||||
UserDefaults.standard.set(text, forKey: "group")
|
||||
} else if secondFavGroup == "" {
|
||||
UserDefaults.standard.set(text, forKey: "group2")
|
||||
} else {
|
||||
UserDefaults.standard.set(text, forKey: "group3")
|
||||
}
|
||||
vm.nameGroups.append(text)
|
||||
self.text = ""
|
||||
dismiss()
|
||||
}
|
||||
else {
|
||||
vm.fetchGroups(group: "кт")
|
||||
}
|
||||
}
|
||||
searchTask = task
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: task)
|
||||
}
|
||||
.onSubmit {
|
||||
self.isFocused = false
|
||||
if (!text.isEmpty) {
|
||||
vm.fetchWeekSchedule(group: text)
|
||||
self.isLoading = true
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
self.isLoading = false
|
||||
if vm.errorInNetwork == .noError {
|
||||
vm.errorInNetwork = nil
|
||||
print("Зашел")
|
||||
UserDefaults.standard.set(text, forKey: "group")
|
||||
vm.group = text
|
||||
self.text = ""
|
||||
dismiss()
|
||||
}
|
||||
else {
|
||||
vm.isShowingAlertForIncorrectGroup = true
|
||||
vm.errorInNetwork = .invalidResponse
|
||||
}
|
||||
vm.isShowingAlertForIncorrectGroup = true
|
||||
vm.errorInNetwork = .invalidResponse
|
||||
}
|
||||
}
|
||||
}
|
||||
.submitLabel(.done)
|
||||
if isFocused {
|
||||
Button {
|
||||
self.text = ""
|
||||
self.isFocused = false
|
||||
} label: {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
.padding(.trailing, 20)
|
||||
.offset(x: 10)
|
||||
.foregroundColor(.gray)
|
||||
.background(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: 40)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 15)
|
||||
.fill(.white)
|
||||
)
|
||||
Spacer()
|
||||
if isLoading {
|
||||
LoadingView(isLoading: $isLoading)
|
||||
}
|
||||
.submitLabel(.done)
|
||||
if isFocused {
|
||||
ScrollView(.vertical, showsIndicators: true) {
|
||||
ForEach(vm.groups) { item in
|
||||
if item.name.starts(with: "КТ") { //Отображаем только группы(без аудиторий и преподавателей)
|
||||
VStack {
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(Color("customGray1"))
|
||||
.padding(.horizontal, 10)
|
||||
HStack {
|
||||
Text(item.name)
|
||||
.foregroundColor(.black)
|
||||
.font(.custom("Montserrat-SemiBold", fixedSize: 15))
|
||||
Spacer()
|
||||
}
|
||||
Button {
|
||||
self.text = ""
|
||||
self.isFocused = false
|
||||
} label: {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
.padding(.trailing, 20)
|
||||
.offset(x: 10)
|
||||
.foregroundColor(.gray)
|
||||
.background(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: 40)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 15)
|
||||
.fill(.white)
|
||||
)
|
||||
Spacer()
|
||||
if isLoading {
|
||||
LoadingView(isLoading: $isLoading)
|
||||
}
|
||||
if isFocused {
|
||||
ScrollView(.vertical, showsIndicators: true) {
|
||||
ForEach(serchGroupsVM.groups) { item in
|
||||
if item.name.starts(with: "КТ") { //Отображаем только группы(без аудиторий и преподавателей)
|
||||
VStack {
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(Color("customGray1"))
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.top, 2)
|
||||
.padding(.bottom, 2)
|
||||
.frame(width: UIScreen.main.bounds.width, height: 30)
|
||||
.background(Color("background"))
|
||||
.onTapGesture {
|
||||
HStack {
|
||||
Text(item.name)
|
||||
.foregroundColor(.black)
|
||||
.font(.custom("Montserrat-SemiBold", fixedSize: 15))
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.top, 2)
|
||||
.padding(.bottom, 2)
|
||||
.frame(width: UIScreen.main.bounds.width, height: 30)
|
||||
.background(Color("background"))
|
||||
.onTapGesture {
|
||||
if firstFavGroup == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "group")
|
||||
vm.group = item.name
|
||||
vm.fetchWeekSchedule(group: item.name)
|
||||
dismiss()
|
||||
} else if secondFavGroup == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "group2")
|
||||
} else {
|
||||
UserDefaults.standard.set(item.name, forKey: "group3")
|
||||
}
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if favGroup != "" {
|
||||
Button {
|
||||
UserDefaults.standard.removeObject(forKey: "group")
|
||||
vm.classes.removeAll()
|
||||
vm.group = ""
|
||||
vm.numOfGroup = ""
|
||||
dismiss()
|
||||
} label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Image(systemName: "trash")
|
||||
Text("Удалить группу")
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
Spacer()
|
||||
}
|
||||
.frame(height: 40)
|
||||
.background(Color.white)
|
||||
.foregroundColor(Color.red)
|
||||
.cornerRadius(10)
|
||||
.padding(.bottom, 50)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
.background(Color("background"))
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
.background(Color("background"))
|
||||
.onAppear {
|
||||
vm.fetchGroups(group: "кт")
|
||||
serchGroupsVM.fetchGroups(group: "кт")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
@Previewable @StateObject var vm = ScheduleViewModel()
|
||||
SelectingGroupView(vm: vm)
|
||||
SelectingGroupView(vm: vm, firstFavGroup: "", secondFavGroup: "", thirdFavGroup: "")
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ struct SelectingVPKView: View {
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
@State private var isLoading = false
|
||||
@State private var searchTask: DispatchWorkItem?
|
||||
@StateObject private var serchGroupsVM = SearchGroupsViewModel()
|
||||
@AppStorage("vpk") private var favVPK = ""
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
@ -30,10 +31,10 @@ struct SelectingVPKView: View {
|
||||
searchTask?.cancel()
|
||||
let task = DispatchWorkItem {
|
||||
if !text.isEmpty {
|
||||
vm.fetchGroups(group: text)
|
||||
serchGroupsVM.fetchGroups(group: text)
|
||||
}
|
||||
else {
|
||||
vm.fetchGroups(group: "впк")
|
||||
serchGroupsVM.fetchGroups(group: "впк")
|
||||
}
|
||||
}
|
||||
searchTask = task
|
||||
@ -50,7 +51,7 @@ struct SelectingVPKView: View {
|
||||
vm.errorInNetwork = nil
|
||||
print("Зашел")
|
||||
UserDefaults.standard.set(text, forKey: "vpk")
|
||||
vm.group = text
|
||||
//vm.group = text
|
||||
self.text = ""
|
||||
dismiss()
|
||||
}
|
||||
@ -87,7 +88,7 @@ struct SelectingVPKView: View {
|
||||
}
|
||||
if isFocused {
|
||||
ScrollView(.vertical, showsIndicators: true) {
|
||||
ForEach(vm.groups) { item in
|
||||
ForEach(serchGroupsVM.groups) { item in
|
||||
if item.name.starts(with: "ВП") || item.name.starts(with: "мВ") {
|
||||
VStack {
|
||||
Rectangle()
|
||||
@ -145,7 +146,7 @@ struct SelectingVPKView: View {
|
||||
.background(Color("background"))
|
||||
}
|
||||
.onAppear {
|
||||
vm.fetchGroups(group: "впк")
|
||||
serchGroupsVM.fetchGroups(group: "впк")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
28
Schedule ICTIS/Settings/TestingView.swift
Normal file
28
Schedule ICTIS/Settings/TestingView.swift
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// TestingView.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by G412 on 05.03.2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct TestingView: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("Hello")
|
||||
Text("Hello")
|
||||
Text("Hello")
|
||||
Text("Hello")
|
||||
Text("Hello")
|
||||
Text("Hello")
|
||||
Text("Hello")
|
||||
Text("Hello")
|
||||
Text("Hello")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
TestingView()
|
||||
}
|
@ -187,11 +187,11 @@ extension WeekViewForWeek {
|
||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||
currentWeekIndex == 0 {
|
||||
vm.week -= 1
|
||||
if vm.group != "" {
|
||||
if !vm.nameGroups.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||
vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
||||
//vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
||||
}
|
||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||
weekSlider.removeLast()
|
||||
@ -203,7 +203,7 @@ extension WeekViewForWeek {
|
||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||
currentWeekIndex == (weekSlider.count - 1) {
|
||||
vm.week += 1
|
||||
if vm.group != "" {
|
||||
if !vm.nameGroups.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||
@ -252,11 +252,11 @@ extension WeekViewForMonth {
|
||||
}
|
||||
print(difBetweenWeeks)
|
||||
vm.week += difBetweenWeeks
|
||||
if vm.group != "" {
|
||||
if !vm.nameGroups.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||
vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
||||
//vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
||||
}
|
||||
}
|
||||
vm.selectedDay = day.date
|
||||
@ -293,7 +293,7 @@ extension MonthTabView {
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week -= 5
|
||||
if vm.group != "" {
|
||||
if !vm.nameGroups.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||
@ -309,7 +309,7 @@ extension MonthTabView {
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week += 5
|
||||
if vm.group != "" {
|
||||
if !vm.nameGroups.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||
|
@ -6,10 +6,16 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUICore
|
||||
|
||||
@MainActor
|
||||
final class ScheduleViewModel: ObservableObject {
|
||||
//MARK: Properties
|
||||
|
||||
@Published var nameGroups: [String] = []
|
||||
@Published var numbersNTMLGroups: [String] = []
|
||||
@Published var classesGroups: [[ClassInfo]] = []
|
||||
|
||||
//Schedule
|
||||
@Published var weekScheduleGroup: Table = Table(
|
||||
type: "",
|
||||
@ -21,14 +27,12 @@ final class ScheduleViewModel: ObservableObject {
|
||||
)
|
||||
@Published var selectedDay: Date = .init()
|
||||
@Published var selectedIndex: Int = 1
|
||||
@Published var classes: [[String]] = []
|
||||
@Published var week: Int = 0
|
||||
@Published var numOfGroup: String = ""
|
||||
|
||||
@Published var isFirstStartOffApp = true
|
||||
@Published var isShowingAlertForIncorrectGroup: Bool = false
|
||||
@Published var errorInNetwork: NetworkError?
|
||||
@Published var isLoading: Bool = false
|
||||
@Published var group: String = ""
|
||||
@Published var isNewGroup: Bool = false
|
||||
|
||||
//Groups
|
||||
@ -46,39 +50,64 @@ final class ScheduleViewModel: ObservableObject {
|
||||
link: ""
|
||||
)
|
||||
|
||||
|
||||
//MARK: Methods
|
||||
func fetchWeekSchedule(group: String = "default", isOtherWeek: Bool = false) {
|
||||
func fetchWeekSchedule(isOtherWeek: Bool = false) {
|
||||
isLoading = true
|
||||
Task {
|
||||
do {
|
||||
var schedule: Schedule
|
||||
// В этот if мы заходим только если пользователь перелистывает недели и нам ИЗВЕСТНЫ номер группы(в html формате) и номер недели, которая показывается пользователю
|
||||
if (isOtherWeek || !isFirstStartOffApp) && (group == "default") {
|
||||
schedule = try await NetworkManager.shared.getScheduleForOtherWeek(self.week, self.numOfGroup)
|
||||
var updatedClassesGroups: [[ClassInfo]] = Array(repeating: [], count: 6) // 6 дней (пн-сб)
|
||||
|
||||
if isOtherWeek {
|
||||
for groupHTML in numbersNTMLGroups {
|
||||
let schedule = try await NetworkManager.shared.getScheduleForOtherWeek(self.week, groupHTML)
|
||||
let table = schedule.table.table
|
||||
let nameOfGroup = schedule.table.name
|
||||
|
||||
// Преобразуем данные в формат ClassInfo
|
||||
for (dayIndex, day) in table[2...].enumerated() { // Пропускаем первые две строки (заголовки)
|
||||
for (timeIndex, subject) in day.enumerated() {
|
||||
if !subject.isEmpty && timeIndex > 0 { // Пропускаем первый столбец (день и дату)
|
||||
let time = table[1][timeIndex] // Время берем из второй строки
|
||||
let classInfo = ClassInfo(subject: subject, group: nameOfGroup, time: time)
|
||||
updatedClassesGroups[dayIndex].append(classInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for groupName in nameGroups {
|
||||
let schedule = try await NetworkManager.shared.getSchedule(groupName)
|
||||
let numberHTML = schedule.table.group
|
||||
self.numbersNTMLGroups.append(numberHTML)
|
||||
let table = schedule.table.table
|
||||
let nameOfGroup = schedule.table.name
|
||||
self.week = schedule.table.week
|
||||
|
||||
// Преобразуем данные в формат ClassInfo
|
||||
for (dayIndex, day) in table[2...].enumerated() { // Пропускаем первые две строки (заголовки)
|
||||
for (timeIndex, subject) in day.enumerated() {
|
||||
if !subject.isEmpty && timeIndex > 0 { // Пропускаем первый столбец (день и дату)
|
||||
let time = table[1][timeIndex] // Время берем из второй строки
|
||||
let classInfo = ClassInfo(subject: subject, group: groupName, time: time)
|
||||
updatedClassesGroups[dayIndex].append(classInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// В else мы заходим в том случае, если НЕ знаем номер недели, которую нужно отобразить и номер группы(в html формате)
|
||||
else {
|
||||
print("Отладка 1")
|
||||
schedule = try await NetworkManager.shared.getSchedule(group)
|
||||
print("Отладка 2")
|
||||
self.group = group
|
||||
self.isNewGroup = true
|
||||
self.selectedDay = .init()
|
||||
}
|
||||
self.weekScheduleGroup = schedule.table
|
||||
self.week = weekScheduleGroup.week
|
||||
self.numOfGroup = weekScheduleGroup.group
|
||||
self.classes = weekScheduleGroup.table
|
||||
|
||||
// Обновляем данные
|
||||
self.classesGroups = updatedClassesGroups
|
||||
self.isFirstStartOffApp = false
|
||||
self.isShowingAlertForIncorrectGroup = false
|
||||
self.isLoading = false
|
||||
self.errorInNetwork = .noError
|
||||
print("Отладка 4")
|
||||
}
|
||||
catch {
|
||||
|
||||
// Сортируем по времени
|
||||
self.sortClassesByTime()
|
||||
} catch {
|
||||
if let error = error as? NetworkError {
|
||||
switch (error) {
|
||||
switch error {
|
||||
case .invalidResponse:
|
||||
errorInNetwork = .invalidResponse
|
||||
case .invalidData:
|
||||
@ -135,46 +164,68 @@ final class ScheduleViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func fetchGroups(group: String) {
|
||||
Task {
|
||||
do {
|
||||
var groups: Welcome
|
||||
groups = try await NetworkManager.shared.getGroups(group: group)
|
||||
self.groups = groups.choices
|
||||
|
||||
}
|
||||
catch {
|
||||
if let error = error as? NetworkError {
|
||||
switch (error) {
|
||||
case .invalidData:
|
||||
self.groups.removeAll()
|
||||
default:
|
||||
self.groups.removeAll()
|
||||
print("Неизвестная ошибка: \(error)")
|
||||
}
|
||||
print("Есть ошибка: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateSelectedDayIndex() {
|
||||
switch selectedDay.format("E") {
|
||||
case "Пн":
|
||||
selectedIndex = 2
|
||||
selectedIndex = 0
|
||||
case "Вт":
|
||||
selectedIndex = 3
|
||||
selectedIndex = 1
|
||||
case "Ср":
|
||||
selectedIndex = 4
|
||||
selectedIndex = 2
|
||||
case "Чт":
|
||||
selectedIndex = 5
|
||||
selectedIndex = 3
|
||||
case "Пт":
|
||||
selectedIndex = 6
|
||||
selectedIndex = 4
|
||||
case "Сб":
|
||||
selectedIndex = 7
|
||||
selectedIndex = 5
|
||||
default:
|
||||
selectedIndex = 8
|
||||
selectedIndex = 6
|
||||
}
|
||||
}
|
||||
|
||||
private func parseTime(_ timeString: String) -> Int {
|
||||
// Разделяем строку по дефису и берем первую часть (время начала)
|
||||
let startTimeString = timeString.components(separatedBy: "-").first ?? ""
|
||||
|
||||
// Разделяем время на часы и минуты
|
||||
let components = startTimeString.components(separatedBy: ":")
|
||||
guard components.count == 2,
|
||||
let hours = Int(components[0]),
|
||||
let minutes = Int(components[1]) else {
|
||||
return 0 // В случае ошибки возвращаем 0
|
||||
}
|
||||
|
||||
// Преобразуем время в минуты с начала дня
|
||||
return hours * 60 + minutes
|
||||
}
|
||||
|
||||
// Method for sorting classes by time
|
||||
private func sortClassesByTime() {
|
||||
// Проходим по каждому дню (подмассиву) в classesGroups
|
||||
for dayIndex in 0..<classesGroups.count {
|
||||
// Сортируем подмассив по времени начала пары
|
||||
classesGroups[dayIndex].sort { class1, class2 in
|
||||
let time1 = parseTime(class1.time) // Время начала первой пары
|
||||
let time2 = parseTime(class2.time) // Время начала второй пары
|
||||
return time1 < time2 // Сортируем по возрастанию
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateArrayOfGroups() {
|
||||
self.nameGroups.removeAll()
|
||||
self.numbersNTMLGroups.removeAll()
|
||||
let group1 = UserDefaults.standard.string(forKey: "group")
|
||||
let group2 = UserDefaults.standard.string(forKey: "group2")
|
||||
let group3 = UserDefaults.standard.string(forKey: "group3")
|
||||
if let nameGroup1 = group1, nameGroup1 != "" {
|
||||
self.nameGroups.append(nameGroup1)
|
||||
}
|
||||
if let nameGroup2 = group2, nameGroup2 != "" {
|
||||
self.nameGroups.append(nameGroup2)
|
||||
}
|
||||
if let nameGroup3 = group3, nameGroup3 != "" {
|
||||
self.nameGroups.append(nameGroup3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
Schedule ICTIS/ViewModel/SearchGroupsViewModel.swift
Normal file
36
Schedule ICTIS/ViewModel/SearchGroupsViewModel.swift
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// SearchGroupsViewModel.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by G412 on 06.03.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@MainActor
|
||||
final class SearchGroupsViewModel: ObservableObject {
|
||||
@Published var groups: [Choice] = []
|
||||
|
||||
func fetchGroups(group: String) {
|
||||
Task {
|
||||
do {
|
||||
var groups: Welcome
|
||||
groups = try await NetworkManager.shared.getGroups(group: group)
|
||||
self.groups = groups.choices
|
||||
|
||||
}
|
||||
catch {
|
||||
if let error = error as? NetworkError {
|
||||
switch (error) {
|
||||
case .invalidData:
|
||||
self.groups.removeAll()
|
||||
default:
|
||||
self.groups.removeAll()
|
||||
print("Неизвестная ошибка: \(error)")
|
||||
}
|
||||
print("Есть ошибка: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user