Compare commits
2 Commits
0f8dcea0a6
...
955c7d9066
Author | SHA1 | Date | |
---|---|---|---|
|
955c7d9066 | ||
|
e7510aef68 |
@ -0,0 +1,38 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0xFF",
|
||||
"green" : "0x7A",
|
||||
"red" : "0x00"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0xFF",
|
||||
"green" : "0xFF",
|
||||
"red" : "0xFF"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0x0A",
|
||||
"green" : "0x97",
|
||||
"red" : "0x00"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0xFF",
|
||||
"green" : "0xFF",
|
||||
"red" : "0xFF"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
@ -9,11 +9,12 @@ import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@State private var selectedTab: TabBarModel = .schedule
|
||||
@StateObject var vm = ViewModel()
|
||||
var body: some View {
|
||||
ZStack {
|
||||
switch selectedTab {
|
||||
case .schedule:
|
||||
MainView()
|
||||
MainView(vm: vm)
|
||||
case .tasks:
|
||||
Text("Tasks")
|
||||
case .settings:
|
||||
|
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,52 @@ 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)
|
||||
if (vm.isFirstStartOffApp) {
|
||||
FirstLaunchScheduleView()
|
||||
}
|
||||
else {
|
||||
CurrentDateView()
|
||||
ScheduleView(vm: vm)
|
||||
}
|
||||
}
|
||||
.alert(isPresented: $vm.isShowingAlertForIncorrectGroup, error: vm.errorInNetwork) { error in
|
||||
|
||||
} message: { error in
|
||||
Text(error.failureReason)
|
||||
}
|
||||
.background(Color("background"))
|
||||
.onAppear(perform: {
|
||||
currentDate = vm.selectedDay
|
||||
vm.updateSelectedDayIndex(currentDate)
|
||||
if weekSlider.isEmpty {
|
||||
let currentWeek = Date().fetchWeek()
|
||||
|
||||
let currentWeek = Date().fetchWeek(vm.selectedDay)
|
||||
|
||||
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 +159,7 @@ struct MainView: View {
|
||||
.onPreferenceChange(OffsetKey.self) { value in
|
||||
if value.rounded() == 15 && createWeek {
|
||||
paginateWeek()
|
||||
|
||||
createWeek = false
|
||||
}
|
||||
}
|
||||
@ -155,24 +168,42 @@ struct MainView: View {
|
||||
}
|
||||
|
||||
func paginateWeek() {
|
||||
let calendar = Calendar.current
|
||||
if weekSlider.indices.contains(currentWeekIndex) {
|
||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||
currentWeekIndex == 0 {
|
||||
switch (vm.numOfGroup) {
|
||||
case "":
|
||||
vm.week -= 1
|
||||
default:
|
||||
vm.fetchWeekSchedule("new week", -1)
|
||||
}
|
||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||
weekSlider.removeLast()
|
||||
currentWeekIndex = 1
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init()
|
||||
currentDate = vm.selectedDay
|
||||
}
|
||||
|
||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||
currentWeekIndex == (weekSlider.count - 1) {
|
||||
switch (vm.numOfGroup) {
|
||||
case "":
|
||||
vm.week += 1
|
||||
default:
|
||||
vm.fetchWeekSchedule("new week", 1)
|
||||
}
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
weekSlider.removeFirst()
|
||||
currentWeekIndex = weekSlider.count - 2
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init()
|
||||
currentDate = vm.selectedDay
|
||||
print(currentDate)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
MainView()
|
||||
ContentView()
|
||||
}
|
||||
|
@ -11,32 +11,47 @@ 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)
|
||||
.shadow(color: .black.opacity(0.25), radius: 4, x: 4, y: 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: UIScreen.main.bounds.width)
|
||||
.padding(.bottom, 100)
|
||||
.padding(.top, 10)
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,8 +63,17 @@ struct ScheduleView: View {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
func onlineOrOffline(_ str: String) -> Bool {
|
||||
if (MockData.onlineClasses.contains(str)) {
|
||||
return false
|
||||
}
|
||||
else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
MainView()
|
||||
ContentView()
|
||||
}
|
||||
|
@ -22,13 +22,14 @@ struct SearchBarView: View {
|
||||
TextField("Поиск группы", text: $text)
|
||||
.disableAutocorrection(true)
|
||||
.onTapGesture {
|
||||
isEditing = true
|
||||
self.isEditing = true
|
||||
}
|
||||
.onSubmit {
|
||||
isEditing = false
|
||||
self.isEditing = false
|
||||
if (!text.isEmpty) {
|
||||
vm.fetchWeekSchedule(text)
|
||||
}
|
||||
self.text = ""
|
||||
}
|
||||
.submitLabel(.search)
|
||||
if isEditing {
|
||||
@ -52,19 +53,20 @@ struct SearchBarView: View {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.white)
|
||||
)
|
||||
Button {
|
||||
|
||||
} label: {
|
||||
ZStack {
|
||||
Rectangle()
|
||||
.frame(width: 40, height: 40)
|
||||
.foregroundStyle(Color("blueColor"))
|
||||
.cornerRadius(15)
|
||||
Image(systemName: "plus")
|
||||
.resizable()
|
||||
.foregroundStyle(.white)
|
||||
.scaledToFit()
|
||||
.frame(width: 16)
|
||||
if (!vm.isFirstStartOffApp && !vm.isShowingAlertForIncorrectGroup) {
|
||||
Button {
|
||||
} label: {
|
||||
ZStack {
|
||||
Rectangle()
|
||||
.frame(width: 40, height: 40)
|
||||
.foregroundStyle(Color("blueColor"))
|
||||
.cornerRadius(15)
|
||||
Image(systemName: "plus")
|
||||
.resizable()
|
||||
.foregroundStyle(.white)
|
||||
.scaledToFit()
|
||||
.frame(width: 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,5 +78,5 @@ struct SearchBarView: View {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
MainView()
|
||||
ContentView()
|
||||
}
|
||||
|
21
Schedule ICTIS/MockData.swift
Normal file
21
Schedule ICTIS/MockData.swift
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// MockData.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by G412 on 06.12.2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
struct MockData {
|
||||
static let onlineClasses: [String] = [
|
||||
"пр.Академический курс иностранного языка Янкаускас Е. С. LMS",
|
||||
"пр.Академический курс иностранного языка Янкаускас Е. С. LMS-3",
|
||||
"пр.Введение в инженерную деятельность 1 п/г Михайлова В. Д. LMS 2 п/г Романенко К. С. 3 п/г Козловский А. В. 4 п/г Компаниец В. С. 5 п/г Олейников К. А. 6 п/г Прудников В. А. 7 п/г Петров Д. А. 8 п/г Григорян К. С.",
|
||||
"пр.Иностранный язык Иностранный язык LMS",
|
||||
"лек.Операционные системы 1 п/г Шкурко А. Н. Г-309 АКТРУ 2 п/г Дроздов С. Н. Г-333 3 п/г Нужнов Е. В. Г-301 Operating systems(Операционные системы) 4 п/г Самойлов А. Н. LMS",
|
||||
"пр.Введение в инженерную деятельность 1 п/г Плёнкин А. П. LMS-1 2 п/г Кучеров С. А. 3 п/г Шкурко А. Н. 4 п/г Механцев Б. Е.",
|
||||
"лек.Операционные системы 1 п/г Шкурко А. Н. Г-309 АКТРУ 2 п/г Дроздов С. Н. Г-333 3 п/г Нужнов Е. В. Г-301 Operating systems(Операционные системы) 4 п/г Самойлов А. Н. LMS"
|
||||
]
|
||||
}
|
@ -7,8 +7,35 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
enum NetworkError: String, Error {
|
||||
case invalidUrl = "Invalid URL"
|
||||
case invalidResponse = "Invalid response form the server"
|
||||
case invalidData = "Data received from the server is invalid"
|
||||
enum NetworkError: String, Error, LocalizedError {
|
||||
case invalidUrl
|
||||
case invalidResponse
|
||||
case invalidData
|
||||
case noNetwork
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .invalidUrl:
|
||||
"InvalidUrl"
|
||||
case .invalidResponse:
|
||||
"InvalidResponse"
|
||||
case .invalidData:
|
||||
"Проверьте номер группы"
|
||||
case .noNetwork:
|
||||
"No network connection"
|
||||
}
|
||||
}
|
||||
|
||||
var failureReason: String {
|
||||
switch self {
|
||||
case .invalidUrl:
|
||||
"Похоже не удалось составить ссылку для api"
|
||||
case .invalidResponse:
|
||||
"Для этой недели расписания еще нет"
|
||||
case .invalidData:
|
||||
"Похоже такой группы не существует"
|
||||
case .noNetwork:
|
||||
"Проверьте подключение к интернету и попробуйте заново"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,15 +8,12 @@
|
||||
import Foundation
|
||||
|
||||
final class NetworkManager {
|
||||
|
||||
//"https://webictis.sfedu.ru/schedule-api/?group=51.html&week=15"
|
||||
//MARK: Properties
|
||||
static let shared = NetworkManager()
|
||||
private let decoder = JSONDecoder()
|
||||
private let urlForGroup = "https://webictis.sfedu.ru/schedule-api/?query="
|
||||
private let urlForWeek = "https://webictis.sfedu.ru/schedule-api/?group=51.html&week=15"
|
||||
private var groupString: String = ""
|
||||
private var numOfGroup: String = ""
|
||||
private var numOfWeek: String = ""
|
||||
private let urlForWeek = "https://webictis.sfedu.ru/schedule-api/?group="
|
||||
|
||||
//MARK: Initializer
|
||||
private init() {
|
||||
@ -24,12 +21,16 @@ final class NetworkManager {
|
||||
}
|
||||
|
||||
//MARK: Methods
|
||||
func makeURL(_ group: String) -> String {
|
||||
func makeUrlForGroup(_ group: String) -> String {
|
||||
return urlForGroup + group
|
||||
}
|
||||
|
||||
func makeUrlForWeek(_ numOfWeek: Int, _ htmlNameOfGroup: String) -> String {
|
||||
return urlForWeek + htmlNameOfGroup + "&week=" + String(numOfWeek)
|
||||
}
|
||||
|
||||
func getSchedule(_ group: String) async throws -> Schedule {
|
||||
let newUrlForGroup = makeURL(group)
|
||||
let newUrlForGroup = makeUrlForGroup(group)
|
||||
guard let url = URL(string: newUrlForGroup) else {throw NetworkError.invalidUrl}
|
||||
let (data, response) = try await URLSession.shared.data(from: url)
|
||||
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {throw NetworkError.invalidResponse}
|
||||
@ -41,4 +42,19 @@ final class NetworkManager {
|
||||
throw NetworkError.invalidData
|
||||
}
|
||||
}
|
||||
|
||||
func getScheduleForOtherWeek(_ numOfWeek: Int, _ htmlNameOfGroup: String) async throws -> Schedule {
|
||||
let newUrlForWeek = makeUrlForWeek(numOfWeek, htmlNameOfGroup)
|
||||
print(newUrlForWeek)
|
||||
guard let url = URL(string: newUrlForWeek) else {throw NetworkError.invalidUrl}
|
||||
let (data, response) = try await URLSession.shared.data(from: url)
|
||||
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {throw NetworkError.invalidResponse}
|
||||
|
||||
do {
|
||||
return try decoder.decode(Schedule.self, from: data)
|
||||
}
|
||||
catch {
|
||||
throw NetworkError.invalidData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,26 +18,45 @@ final class ViewModel: ObservableObject {
|
||||
table: [[]],
|
||||
link: ""
|
||||
)
|
||||
@Published var selectedDay: Date = Date()
|
||||
@Published var selectedDay: Date = .init()
|
||||
@Published var selectedIndex: Int = 1
|
||||
@Published var classes: [[String]] = []
|
||||
|
||||
init() {
|
||||
|
||||
}
|
||||
|
||||
@Published var week: Int = 0
|
||||
@Published var numOfGroup: String = ""
|
||||
@Published var isFirstStartOffApp = true
|
||||
@Published var isShowingAlertForIncorrectGroup: Bool = false
|
||||
@Published var errorInNetwork: NetworkError?
|
||||
|
||||
//MARK: Methods
|
||||
func fetchWeekSchedule(_ group: String) {
|
||||
func fetchWeekSchedule(_ group: String, _ num: Int = 0) {
|
||||
Task {
|
||||
do {
|
||||
let schedule = try await NetworkManager.shared.getSchedule(group)
|
||||
var schedule: Schedule
|
||||
if (num != 0) {
|
||||
week += num
|
||||
schedule = try await NetworkManager.shared.getScheduleForOtherWeek(week, numOfGroup)
|
||||
}
|
||||
else{
|
||||
schedule = try await NetworkManager.shared.getSchedule(group)
|
||||
}
|
||||
weekSchedule = schedule.table
|
||||
week = weekSchedule.week
|
||||
numOfGroup = weekSchedule.group
|
||||
classes = weekSchedule.table
|
||||
print(weekSchedule.week)
|
||||
self.isFirstStartOffApp = false
|
||||
self.isShowingAlertForIncorrectGroup = false
|
||||
}
|
||||
catch {
|
||||
if let error = error as? NetworkError {
|
||||
switch (error) {
|
||||
case .invalidResponse:
|
||||
print(4)
|
||||
case .invalidData:
|
||||
errorInNetwork = .invalidData
|
||||
self.isShowingAlertForIncorrectGroup = true
|
||||
default:
|
||||
print(2)
|
||||
}
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
@ -45,6 +64,7 @@ final class ViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
func updateSelectedDayIndex(_ date: Date) {
|
||||
selectedDay = date
|
||||
switch date.format("E") {
|
||||
case "Пн":
|
||||
selectedIndex = 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user