From 06416138d969ccf5e8940fd34ff1dbe161df57b8 Mon Sep 17 00:00:00 2001 From: Vladimir Dubovik Date: Wed, 29 Jan 2025 19:04:37 +0300 Subject: [PATCH] Now fonts are correct --- .../Main/Views/CreatedClassView.swift | 6 ++-- .../Main/Views/Fields/AuditoryFieldView.swift | 4 +-- .../Main/Views/Fields/CommentFieldView.swift | 1 + .../Views/Fields/ProfessorFieldView.swift | 2 +- .../Views/Fields/StartEndTimeFieldView.swift | 5 +-- .../Main/Views/Fields/SubjectFieldView.swift | 8 ++--- Schedule ICTIS/Main/Views/MainView.swift | 16 ++++++--- .../Main/Views/NoScheduleView.swift | 1 + Schedule ICTIS/Main/Views/ScheduleView.swift | 34 +++++++++++++++---- .../Views/Sheets/CreateEditClassView.swift | 14 ++++---- .../Main/Views/TabViews/MonthTabView.swift | 3 +- .../Main/Views/TabViews/WeekTabView.swift | 1 - .../Views/TabViews/WeekViewForMonth.swift | 2 +- .../Main/Views/TabViews/WeekViewForWeek.swift | 4 +-- Schedule ICTIS/Provider/ClassProvider.swift | 22 +++++++++++- .../Extensions/View+Extensions.swift | 13 ------- .../ViewModel/EditClassViewModel.swift | 9 ++--- 17 files changed, 92 insertions(+), 53 deletions(-) diff --git a/Schedule ICTIS/Main/Views/CreatedClassView.swift b/Schedule ICTIS/Main/Views/CreatedClassView.swift index e36cd8b..e58f960 100644 --- a/Schedule ICTIS/Main/Views/CreatedClassView.swift +++ b/Schedule ICTIS/Main/Views/CreatedClassView.swift @@ -16,9 +16,9 @@ struct CreatedClassView: View { HStack(spacing: 10) { VStack { Text(getTimeString(_class.starttime)) - .font(.system(size: 15, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 15)) Text(getTimeString(_class.endtime)) - .font(.system(size: 15, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 15)) } .padding(.top, 7) .padding(.bottom, 7) @@ -30,7 +30,7 @@ struct CreatedClassView: View { .padding(.bottom, 7) .foregroundColor(_class.important ? Color("redForImportant") : onlineOrNot(_class.online)) Text(getSubjectName(_class.subject, _class.professor, _class.auditory)) - .font(.system(size: 18, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 18)) .padding(.top, 7) .padding(.bottom, 7) Spacer() diff --git a/Schedule ICTIS/Main/Views/Fields/AuditoryFieldView.swift b/Schedule ICTIS/Main/Views/Fields/AuditoryFieldView.swift index 0037a22..098b59a 100644 --- a/Schedule ICTIS/Main/Views/Fields/AuditoryFieldView.swift +++ b/Schedule ICTIS/Main/Views/Fields/AuditoryFieldView.swift @@ -16,9 +16,9 @@ struct AuditoryFieldView: View { Image(systemName: "mappin.and.ellipse") .foregroundColor(Color.gray) .padding(.leading, 12) - .padding(.trailing, 7) + .padding(.trailing, 14) TextField(labelForField, text: $text) - .font(.system(size: 18, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 18)) .disableAutocorrection(true) .submitLabel(.done) .focused($isFocused) diff --git a/Schedule ICTIS/Main/Views/Fields/CommentFieldView.swift b/Schedule ICTIS/Main/Views/Fields/CommentFieldView.swift index 2c0a4a2..98228fd 100644 --- a/Schedule ICTIS/Main/Views/Fields/CommentFieldView.swift +++ b/Schedule ICTIS/Main/Views/Fields/CommentFieldView.swift @@ -14,6 +14,7 @@ struct CommentFieldView: View { var body: some View { HStack { TextField("Комментарий", text: $textForComment) + .font(.custom("Montserrat-Regular", size: 18)) .submitLabel(.done) .multilineTextAlignment(.leading) .focused($isFocused) diff --git a/Schedule ICTIS/Main/Views/Fields/ProfessorFieldView.swift b/Schedule ICTIS/Main/Views/Fields/ProfessorFieldView.swift index ff2d048..240d83c 100644 --- a/Schedule ICTIS/Main/Views/Fields/ProfessorFieldView.swift +++ b/Schedule ICTIS/Main/Views/Fields/ProfessorFieldView.swift @@ -18,7 +18,7 @@ struct ProfessorFieldView: View { .padding(.leading, 12) .padding(.trailing, 7) TextField(labelForField, text: $text) - .font(.system(size: 18, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 18)) .disableAutocorrection(true) .submitLabel(.done) .focused($isFocused) diff --git a/Schedule ICTIS/Main/Views/Fields/StartEndTimeFieldView.swift b/Schedule ICTIS/Main/Views/Fields/StartEndTimeFieldView.swift index 9b70a98..751b0bc 100644 --- a/Schedule ICTIS/Main/Views/Fields/StartEndTimeFieldView.swift +++ b/Schedule ICTIS/Main/Views/Fields/StartEndTimeFieldView.swift @@ -19,16 +19,17 @@ struct StartEndTimeFieldView: View { Image(systemName: imageName) .foregroundColor(isIncorrectDate ? .red : Color("grayForFields")) .padding(.leading, 12) + .padding(.trailing, 5) if !isTimeSelected || isIncorrectDate { Text(text) - .font(.system(size: 17, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 17)) .foregroundColor(.gray.opacity(0.5)) } else { Text("\(selectedTime, formatter: timeFormatter)") .foregroundColor(isIncorrectDate ? .red : .black) - .font(.system(size: 17, weight: .medium)) + .font(.custom("Montserrat-Medium", size: 17)) .padding(.trailing, 10) } Spacer() diff --git a/Schedule ICTIS/Main/Views/Fields/SubjectFieldView.swift b/Schedule ICTIS/Main/Views/Fields/SubjectFieldView.swift index 10f1b22..c799acf 100644 --- a/Schedule ICTIS/Main/Views/Fields/SubjectFieldView.swift +++ b/Schedule ICTIS/Main/Views/Fields/SubjectFieldView.swift @@ -3,7 +3,7 @@ // Schedule ICTIS // // Created by G412 on 16.12.2024. -// +// КТбо2-6 import SwiftUI @@ -17,9 +17,9 @@ struct SubjectFieldView: View { Image(systemName: "book") .foregroundColor(Color.gray) .padding(.leading, 12) - .padding(.trailing, 7) + .padding(.trailing, 9) TextField(labelForField, text: $text) - .font(.system(size: 18, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 18)) .disableAutocorrection(true) .submitLabel(.done) .focused($isFocused) @@ -33,7 +33,7 @@ struct SubjectFieldView: View { Group { if isShowingSubjectFieldRed { Text("Поле должно быть заполнено!") - .font(.system(size: 18, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 18)) .foregroundColor(.red) .frame(width: 290) .padding(.leading, -42) diff --git a/Schedule ICTIS/Main/Views/MainView.swift b/Schedule ICTIS/Main/Views/MainView.swift index e45e675..31e8755 100644 --- a/Schedule ICTIS/Main/Views/MainView.swift +++ b/Schedule ICTIS/Main/Views/MainView.swift @@ -12,10 +12,16 @@ struct MainView: View { @State private var isShowingMonthSlider: Bool = false @ObservedObject var vm: ScheduleViewModel @FocusState private var isFocusedSearchBar: Bool + @State private var isScrolling: Bool = false var body: some View { VStack { SearchBarView(text: $searchText, isFocused: _isFocusedSearchBar, vm: vm) + .onChange(of: isScrolling, initial: false) { oldValue, newValue in + if newValue && isScrolling { + isFocusedSearchBar = false + } + } if (vm.isFirstStartOffApp && vm.isLoading) { LoadingView(isLoading: $vm.isLoading) @@ -25,7 +31,7 @@ struct MainView: View { } else { CurrentDateView() - ScheduleView(vm: vm) + ScheduleView(vm: vm, isScrolling: $isScrolling) } } .alert(isPresented: $vm.isShowingAlertForIncorrectGroup, error: vm.errorInNetwork) { error in @@ -45,14 +51,14 @@ struct MainView: View { HStack { VStack (alignment: .leading, spacing: 0) { Text(vm.selectedDay.format("EEEE")) - .font(.system(size: 40, weight: .semibold)) + .font(.custom("Montserrat-SemiBold", size: 40)) .foregroundStyle(.black) HStack (spacing: 5) { Text(vm.selectedDay.format("dd")) - .font(.system(size: 20, weight: .bold)) + .font(.custom("Montserrat-Bold", size: 20)) .foregroundStyle(Color("grayForDate")) Text(vm.selectedDay.format("MMMM")) - .font(.system(size: 20, weight: .bold)) + .font(.custom("Montserrat-Bold", size: 20)) .foregroundStyle(Color("grayForDate")) Spacer() Button(action: { @@ -62,7 +68,7 @@ struct MainView: View { }) { HStack(spacing: 2) { Text(isShowingMonthSlider ? "Свернуть" : "Развернуть") - .font(.system(size: 16, weight: .light)) + .font(.custom("Montserrat-Light", size: 16)) .foregroundStyle(Color.blue) Image(isShowingMonthSlider ? "arrowup" : "arrowdown") .resizable() diff --git a/Schedule ICTIS/Main/Views/NoScheduleView.swift b/Schedule ICTIS/Main/Views/NoScheduleView.swift index 384e2be..0a1e2aa 100644 --- a/Schedule ICTIS/Main/Views/NoScheduleView.swift +++ b/Schedule ICTIS/Main/Views/NoScheduleView.swift @@ -13,6 +13,7 @@ struct NoScheduleView: View { ScrollView (showsIndicators: false) { Text("Пока расписания нет") .padding(.top, 20) + .font(.custom("Montserrat-Regular", size: 15)) } } } diff --git a/Schedule ICTIS/Main/Views/ScheduleView.swift b/Schedule ICTIS/Main/Views/ScheduleView.swift index 318bc63..c263b06 100644 --- a/Schedule ICTIS/Main/Views/ScheduleView.swift +++ b/Schedule ICTIS/Main/Views/ScheduleView.swift @@ -3,7 +3,7 @@ // Schedule ICTIS // // Created by Mironov Egor on 05.12.2024. -// +// ктбо2-6 import SwiftUI @@ -11,6 +11,7 @@ struct ScheduleView: View { @ObservedObject var vm: ScheduleViewModel @FetchRequest(fetchRequest: ClassModel.all()) private var classes //Делаем запрос в CoreData и получаем список сохраненных пар @State private var selectedClass: ClassModel? = nil + @Binding var isScrolling: Bool var provider = ClassProvider.shared var body: some View { if vm.isLoading { @@ -30,9 +31,11 @@ struct ScheduleView: View { HStack(spacing: 10) { VStack { Text(convertTimeString(vm.classes[1][lessonIndex])[0]) - .font(.system(size: 15, weight: .regular)) + .font(.custom("Montserrat-Medium", size: 15)) + .padding(.bottom, 1) Text(convertTimeString(vm.classes[1][lessonIndex])[1]) - .font(.system(size: 15, weight: .regular)) + .font(.custom("Montserrat-Medium", size: 15)) + .padding(.top, 1) } .padding(.top, 7) .padding(.bottom, 7) @@ -44,9 +47,10 @@ struct ScheduleView: View { .padding(.bottom, 7) .foregroundColor(getColorForClass(lesson)) Text(lesson) - .font(.system(size: 18, weight: .regular)) - .padding(.top, 7) - .padding(.bottom, 7) + .font(.custom("Montserrat-Regular", size: 17)) + .lineSpacing(3) + .padding(.top, 9) + .padding(.bottom, 9) Spacer() } .frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230) @@ -70,6 +74,16 @@ struct ScheduleView: View { .padding(.bottom, 100) .padding(.top, 30) } + .onPreferenceChange(ViewOffsetKey.self) { offset in + if offset > 0 { + isScrolling = true + print("Сейчас скролл") + } else { + isScrolling = false + print("Scrolling ended") + } + } + .coordinateSpace(name: "scroll") VStack { LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.95), Color.white.opacity(0.1)]), startPoint: .top, endPoint: .bottom) } @@ -91,6 +105,14 @@ struct ScheduleView: View { } } +struct ViewOffsetKey: PreferenceKey { + typealias Value = CGFloat + static var defaultValue = CGFloat.zero + static func reduce(value: inout Value, nextValue: () -> Value) { + value += nextValue() + } +} + #Preview { ContentView() } diff --git a/Schedule ICTIS/Main/Views/Sheets/CreateEditClassView.swift b/Schedule ICTIS/Main/Views/Sheets/CreateEditClassView.swift index 0691a4b..242f411 100644 --- a/Schedule ICTIS/Main/Views/Sheets/CreateEditClassView.swift +++ b/Schedule ICTIS/Main/Views/Sheets/CreateEditClassView.swift @@ -31,6 +31,7 @@ struct CreateEditClassView: View { .padding(.bottom, 10) HStack { Text("Тип") + .font(.custom("Montserrat-Medium", size: 17)) Spacer() Picker("Тип", selection: $vm._class.online, content: { ForEach(MockData.onlineOrOffline, id: \.self) { @@ -72,14 +73,14 @@ struct CreateEditClassView: View { Image(systemName: "calendar") .foregroundColor(Color.gray) .padding(.leading, 12) - .padding(.trailing, 7) + .padding(.trailing, 5) Text("Дата") .foregroundColor(Color("grayForFields").opacity(0.5)) - .font(.system(size: 18, weight: .regular)) + .font(.custom("Montserrat-Regular", size: 18)) Spacer() Text("\(vm._class.day, formatter: dateFormatter)") .foregroundColor(.black) - .font(.system(size: 18, weight: .medium)) + .font(.custom("Montserrat-Medium", size: 18)) .padding(.trailing, 20) } .frame(height: 40) @@ -127,6 +128,7 @@ struct CreateEditClassView: View { .frame(height: 40) .padding(.bottom, 10) Toggle("Пометить как важную", isOn: $vm._class.important) + .font(.custom("Montserrat-Medium", size: 17)) .frame(height: 40) .padding(.horizontal) .background( @@ -137,6 +139,7 @@ struct CreateEditClassView: View { HStack { Text("Напоминанние") + .font(.custom("Montserrat-Medium", size: 17)) Spacer() Picker("Напоминание", selection: $vm._class.notification, content: { ForEach(MockData.notifications, id: \.self) { @@ -160,7 +163,7 @@ struct CreateEditClassView: View { if !vm.isNew { Button { do { - try delete(vm._class) + try provider.delete(vm._class, in: provider.viewContext) dismiss() } catch { print(error) @@ -170,7 +173,7 @@ struct CreateEditClassView: View { Spacer() Image(systemName: "trash") Text("Удалить занятие") - .font(.system(size: 17, weight: .medium)) + .font(.custom("Montserrat-Medium", size: 17)) Spacer() } .frame(height: 40) @@ -235,7 +238,6 @@ struct CreateEditClassView: View { } if day > Calendar.current.startOfDay(for: Date()) { vm._class.day = day - print(34) } } .onTapGesture { diff --git a/Schedule ICTIS/Main/Views/TabViews/MonthTabView.swift b/Schedule ICTIS/Main/Views/TabViews/MonthTabView.swift index f9d0f54..8fe0419 100644 --- a/Schedule ICTIS/Main/Views/TabViews/MonthTabView.swift +++ b/Schedule ICTIS/Main/Views/TabViews/MonthTabView.swift @@ -18,7 +18,7 @@ struct MonthTabView: View { HStack (spacing: 34) { ForEach(MockData.daysOfWeek.indices, id: \.self) { index in Text(MockData.daysOfWeek[index]) - .font(.system(size: 15, weight: .semibold)) + .font(.custom("Montserrat-SemiBold", size: 15)) .foregroundColor(MockData.daysOfWeek[index] == "Вс" ? Color(.red) : Color("customGray2")) .padding(.top, 13) .foregroundColor(.gray) @@ -50,7 +50,6 @@ struct MonthTabView: View { monthSlider.removeAll() currentMonthIndex = 1 updateMonthScreenViewForNewGroup() - print(52) vm.isNewGroup = false } } diff --git a/Schedule ICTIS/Main/Views/TabViews/WeekTabView.swift b/Schedule ICTIS/Main/Views/TabViews/WeekTabView.swift index 31e967d..9308fe5 100644 --- a/Schedule ICTIS/Main/Views/TabViews/WeekTabView.swift +++ b/Schedule ICTIS/Main/Views/TabViews/WeekTabView.swift @@ -39,7 +39,6 @@ struct WeekTabView: View { weekSlider.removeAll() currentWeekIndex = 1 updateWeekScreenViewForNewGroup() - print(52) vm.isNewGroup = false } } diff --git a/Schedule ICTIS/Main/Views/TabViews/WeekViewForMonth.swift b/Schedule ICTIS/Main/Views/TabViews/WeekViewForMonth.swift index ed493d7..4179b49 100644 --- a/Schedule ICTIS/Main/Views/TabViews/WeekViewForMonth.swift +++ b/Schedule ICTIS/Main/Views/TabViews/WeekViewForMonth.swift @@ -16,7 +16,7 @@ struct WeekViewForMonth: View { ForEach(week) { day in VStack { Text(day.date.format("dd")) - .font(.system(size: 15, weight: .bold)) + .font(.custom("Montserrat-Medium", size: 15)) .foregroundStyle(getForegroundColor(day: day)) } .frame(width: 30, height: 30, alignment: .center) diff --git a/Schedule ICTIS/Main/Views/TabViews/WeekViewForWeek.swift b/Schedule ICTIS/Main/Views/TabViews/WeekViewForWeek.swift index 2617ce9..648bab4 100644 --- a/Schedule ICTIS/Main/Views/TabViews/WeekViewForWeek.swift +++ b/Schedule ICTIS/Main/Views/TabViews/WeekViewForWeek.swift @@ -18,12 +18,12 @@ struct WeekViewForWeek: View { ForEach(week) { day in VStack (spacing: 1) { Text(day.date.format("E")) - .font(.system(size: 15, weight: .semibold)) + .font(.custom("Montserrat-Medium", size: 16)) .foregroundColor(day.date.format("E") == "Вс" ? Color(.red) : isSameDate(day.date, vm.selectedDay) ? Color("customGray1") : Color("customGray3")) .padding(.top, 13) .foregroundColor(.gray) Text(day.date.format("dd")) - .font(.system(size: 15, weight: .bold)) + .font(.custom("Montserrat-Medium", size: 15)) .foregroundStyle(isSameDate(day.date, vm.selectedDay) ? .white : .black) .padding(.bottom, 13) } diff --git a/Schedule ICTIS/Provider/ClassProvider.swift b/Schedule ICTIS/Provider/ClassProvider.swift index 7221797..5e7f4a2 100644 --- a/Schedule ICTIS/Provider/ClassProvider.swift +++ b/Schedule ICTIS/Provider/ClassProvider.swift @@ -47,7 +47,27 @@ final class ClassProvider { fatalError("Unable to load store. Error: \(error)") } } - + } + + func exists(_ lesson: ClassModel, in context: NSManagedObjectContext) -> ClassModel? { + try? context.existingObject(with: lesson.objectID) as? ClassModel + } + + func delete(_ lesson: ClassModel, in context: NSManagedObjectContext) throws { + if let existingClass = exists(lesson, in: context) { + context.delete(existingClass) + Task(priority: .background) { + try await context.perform { + try context.save() + } + } + } + } + + func persist(in context: NSManagedObjectContext) throws { + if context.hasChanges { + try context.save() + } } } diff --git a/Schedule ICTIS/Utilities/Extensions/View+Extensions.swift b/Schedule ICTIS/Utilities/Extensions/View+Extensions.swift index 0de3a0c..889c578 100644 --- a/Schedule ICTIS/Utilities/Extensions/View+Extensions.swift +++ b/Schedule ICTIS/Utilities/Extensions/View+Extensions.swift @@ -160,16 +160,3 @@ extension View { } } } - -extension CreateEditClassView { - func delete(_ _class: ClassModel) throws { - let context = provider.viewContext - let existingClass = try context.existingObject(with: _class.objectID) - context.delete(existingClass) - Task (priority: .background) { - try await context.perform { - try context.save() - } - } - } -} diff --git a/Schedule ICTIS/ViewModel/EditClassViewModel.swift b/Schedule ICTIS/ViewModel/EditClassViewModel.swift index dabab4d..1706c1f 100644 --- a/Schedule ICTIS/ViewModel/EditClassViewModel.swift +++ b/Schedule ICTIS/ViewModel/EditClassViewModel.swift @@ -13,13 +13,16 @@ final class EditClassViewModel: ObservableObject { let isNew: Bool + private let provider: ClassProvider + private let context: NSManagedObjectContext init(provider: ClassProvider, _class: ClassModel? = nil) { + self.provider = provider self.context = provider.newContext if let _class, - let existingClassCopy = try? context.existingObject(with: _class.objectID) as? ClassModel { + let existingClassCopy = provider.exists(_class, in: context) { self._class = existingClassCopy self.isNew = false } @@ -30,8 +33,6 @@ final class EditClassViewModel: ObservableObject { } func save() throws { - if context.hasChanges { - try context.save() - } + try provider.persist(in: context) } }