Now fonts are correct

This commit is contained in:
Vladimir Dubovik 2025-01-29 19:04:37 +03:00
parent 4ee81cf2ea
commit 06416138d9
17 changed files with 92 additions and 53 deletions

View File

@ -16,9 +16,9 @@ struct CreatedClassView: View {
HStack(spacing: 10) { HStack(spacing: 10) {
VStack { VStack {
Text(getTimeString(_class.starttime)) Text(getTimeString(_class.starttime))
.font(.system(size: 15, weight: .regular)) .font(.custom("Montserrat-Regular", size: 15))
Text(getTimeString(_class.endtime)) Text(getTimeString(_class.endtime))
.font(.system(size: 15, weight: .regular)) .font(.custom("Montserrat-Regular", size: 15))
} }
.padding(.top, 7) .padding(.top, 7)
.padding(.bottom, 7) .padding(.bottom, 7)
@ -30,7 +30,7 @@ struct CreatedClassView: View {
.padding(.bottom, 7) .padding(.bottom, 7)
.foregroundColor(_class.important ? Color("redForImportant") : onlineOrNot(_class.online)) .foregroundColor(_class.important ? Color("redForImportant") : onlineOrNot(_class.online))
Text(getSubjectName(_class.subject, _class.professor, _class.auditory)) Text(getSubjectName(_class.subject, _class.professor, _class.auditory))
.font(.system(size: 18, weight: .regular)) .font(.custom("Montserrat-Regular", size: 18))
.padding(.top, 7) .padding(.top, 7)
.padding(.bottom, 7) .padding(.bottom, 7)
Spacer() Spacer()

View File

@ -16,9 +16,9 @@ struct AuditoryFieldView: View {
Image(systemName: "mappin.and.ellipse") Image(systemName: "mappin.and.ellipse")
.foregroundColor(Color.gray) .foregroundColor(Color.gray)
.padding(.leading, 12) .padding(.leading, 12)
.padding(.trailing, 7) .padding(.trailing, 14)
TextField(labelForField, text: $text) TextField(labelForField, text: $text)
.font(.system(size: 18, weight: .regular)) .font(.custom("Montserrat-Regular", size: 18))
.disableAutocorrection(true) .disableAutocorrection(true)
.submitLabel(.done) .submitLabel(.done)
.focused($isFocused) .focused($isFocused)

View File

@ -14,6 +14,7 @@ struct CommentFieldView: View {
var body: some View { var body: some View {
HStack { HStack {
TextField("Комментарий", text: $textForComment) TextField("Комментарий", text: $textForComment)
.font(.custom("Montserrat-Regular", size: 18))
.submitLabel(.done) .submitLabel(.done)
.multilineTextAlignment(.leading) .multilineTextAlignment(.leading)
.focused($isFocused) .focused($isFocused)

View File

@ -18,7 +18,7 @@ struct ProfessorFieldView: View {
.padding(.leading, 12) .padding(.leading, 12)
.padding(.trailing, 7) .padding(.trailing, 7)
TextField(labelForField, text: $text) TextField(labelForField, text: $text)
.font(.system(size: 18, weight: .regular)) .font(.custom("Montserrat-Regular", size: 18))
.disableAutocorrection(true) .disableAutocorrection(true)
.submitLabel(.done) .submitLabel(.done)
.focused($isFocused) .focused($isFocused)

View File

@ -19,16 +19,17 @@ struct StartEndTimeFieldView: View {
Image(systemName: imageName) Image(systemName: imageName)
.foregroundColor(isIncorrectDate ? .red : Color("grayForFields")) .foregroundColor(isIncorrectDate ? .red : Color("grayForFields"))
.padding(.leading, 12) .padding(.leading, 12)
.padding(.trailing, 5)
if !isTimeSelected || isIncorrectDate { if !isTimeSelected || isIncorrectDate {
Text(text) Text(text)
.font(.system(size: 17, weight: .regular)) .font(.custom("Montserrat-Regular", size: 17))
.foregroundColor(.gray.opacity(0.5)) .foregroundColor(.gray.opacity(0.5))
} }
else { else {
Text("\(selectedTime, formatter: timeFormatter)") Text("\(selectedTime, formatter: timeFormatter)")
.foregroundColor(isIncorrectDate ? .red : .black) .foregroundColor(isIncorrectDate ? .red : .black)
.font(.system(size: 17, weight: .medium)) .font(.custom("Montserrat-Medium", size: 17))
.padding(.trailing, 10) .padding(.trailing, 10)
} }
Spacer() Spacer()

View File

@ -3,7 +3,7 @@
// Schedule ICTIS // Schedule ICTIS
// //
// Created by G412 on 16.12.2024. // Created by G412 on 16.12.2024.
// // КТбо2-6
import SwiftUI import SwiftUI
@ -17,9 +17,9 @@ struct SubjectFieldView: View {
Image(systemName: "book") Image(systemName: "book")
.foregroundColor(Color.gray) .foregroundColor(Color.gray)
.padding(.leading, 12) .padding(.leading, 12)
.padding(.trailing, 7) .padding(.trailing, 9)
TextField(labelForField, text: $text) TextField(labelForField, text: $text)
.font(.system(size: 18, weight: .regular)) .font(.custom("Montserrat-Regular", size: 18))
.disableAutocorrection(true) .disableAutocorrection(true)
.submitLabel(.done) .submitLabel(.done)
.focused($isFocused) .focused($isFocused)
@ -33,7 +33,7 @@ struct SubjectFieldView: View {
Group { Group {
if isShowingSubjectFieldRed { if isShowingSubjectFieldRed {
Text("Поле должно быть заполнено!") Text("Поле должно быть заполнено!")
.font(.system(size: 18, weight: .regular)) .font(.custom("Montserrat-Regular", size: 18))
.foregroundColor(.red) .foregroundColor(.red)
.frame(width: 290) .frame(width: 290)
.padding(.leading, -42) .padding(.leading, -42)

View File

@ -12,10 +12,16 @@ struct MainView: View {
@State private var isShowingMonthSlider: Bool = false @State private var isShowingMonthSlider: Bool = false
@ObservedObject var vm: ScheduleViewModel @ObservedObject var vm: ScheduleViewModel
@FocusState private var isFocusedSearchBar: Bool @FocusState private var isFocusedSearchBar: Bool
@State private var isScrolling: Bool = false
var body: some View { var body: some View {
VStack { VStack {
SearchBarView(text: $searchText, isFocused: _isFocusedSearchBar, vm: vm) 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) { if (vm.isFirstStartOffApp && vm.isLoading) {
LoadingView(isLoading: $vm.isLoading) LoadingView(isLoading: $vm.isLoading)
@ -25,7 +31,7 @@ struct MainView: View {
} }
else { else {
CurrentDateView() CurrentDateView()
ScheduleView(vm: vm) ScheduleView(vm: vm, isScrolling: $isScrolling)
} }
} }
.alert(isPresented: $vm.isShowingAlertForIncorrectGroup, error: vm.errorInNetwork) { error in .alert(isPresented: $vm.isShowingAlertForIncorrectGroup, error: vm.errorInNetwork) { error in
@ -45,14 +51,14 @@ struct MainView: View {
HStack { HStack {
VStack (alignment: .leading, spacing: 0) { VStack (alignment: .leading, spacing: 0) {
Text(vm.selectedDay.format("EEEE")) Text(vm.selectedDay.format("EEEE"))
.font(.system(size: 40, weight: .semibold)) .font(.custom("Montserrat-SemiBold", size: 40))
.foregroundStyle(.black) .foregroundStyle(.black)
HStack (spacing: 5) { HStack (spacing: 5) {
Text(vm.selectedDay.format("dd")) Text(vm.selectedDay.format("dd"))
.font(.system(size: 20, weight: .bold)) .font(.custom("Montserrat-Bold", size: 20))
.foregroundStyle(Color("grayForDate")) .foregroundStyle(Color("grayForDate"))
Text(vm.selectedDay.format("MMMM")) Text(vm.selectedDay.format("MMMM"))
.font(.system(size: 20, weight: .bold)) .font(.custom("Montserrat-Bold", size: 20))
.foregroundStyle(Color("grayForDate")) .foregroundStyle(Color("grayForDate"))
Spacer() Spacer()
Button(action: { Button(action: {
@ -62,7 +68,7 @@ struct MainView: View {
}) { }) {
HStack(spacing: 2) { HStack(spacing: 2) {
Text(isShowingMonthSlider ? "Свернуть" : "Развернуть") Text(isShowingMonthSlider ? "Свернуть" : "Развернуть")
.font(.system(size: 16, weight: .light)) .font(.custom("Montserrat-Light", size: 16))
.foregroundStyle(Color.blue) .foregroundStyle(Color.blue)
Image(isShowingMonthSlider ? "arrowup" : "arrowdown") Image(isShowingMonthSlider ? "arrowup" : "arrowdown")
.resizable() .resizable()

View File

@ -13,6 +13,7 @@ struct NoScheduleView: View {
ScrollView (showsIndicators: false) { ScrollView (showsIndicators: false) {
Text("Пока расписания нет") Text("Пока расписания нет")
.padding(.top, 20) .padding(.top, 20)
.font(.custom("Montserrat-Regular", size: 15))
} }
} }
} }

View File

@ -3,7 +3,7 @@
// Schedule ICTIS // Schedule ICTIS
// //
// Created by Mironov Egor on 05.12.2024. // Created by Mironov Egor on 05.12.2024.
// // ктбо2-6
import SwiftUI import SwiftUI
@ -11,6 +11,7 @@ struct ScheduleView: View {
@ObservedObject var vm: ScheduleViewModel @ObservedObject var vm: ScheduleViewModel
@FetchRequest(fetchRequest: ClassModel.all()) private var classes //Делаем запрос в CoreData и получаем список сохраненных пар @FetchRequest(fetchRequest: ClassModel.all()) private var classes //Делаем запрос в CoreData и получаем список сохраненных пар
@State private var selectedClass: ClassModel? = nil @State private var selectedClass: ClassModel? = nil
@Binding var isScrolling: Bool
var provider = ClassProvider.shared var provider = ClassProvider.shared
var body: some View { var body: some View {
if vm.isLoading { if vm.isLoading {
@ -30,9 +31,11 @@ struct ScheduleView: View {
HStack(spacing: 10) { HStack(spacing: 10) {
VStack { VStack {
Text(convertTimeString(vm.classes[1][lessonIndex])[0]) 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]) 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(.top, 7)
.padding(.bottom, 7) .padding(.bottom, 7)
@ -44,9 +47,10 @@ struct ScheduleView: View {
.padding(.bottom, 7) .padding(.bottom, 7)
.foregroundColor(getColorForClass(lesson)) .foregroundColor(getColorForClass(lesson))
Text(lesson) Text(lesson)
.font(.system(size: 18, weight: .regular)) .font(.custom("Montserrat-Regular", size: 17))
.padding(.top, 7) .lineSpacing(3)
.padding(.bottom, 7) .padding(.top, 9)
.padding(.bottom, 9)
Spacer() Spacer()
} }
.frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230) .frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230)
@ -70,6 +74,16 @@ struct ScheduleView: View {
.padding(.bottom, 100) .padding(.bottom, 100)
.padding(.top, 30) .padding(.top, 30)
} }
.onPreferenceChange(ViewOffsetKey.self) { offset in
if offset > 0 {
isScrolling = true
print("Сейчас скролл")
} else {
isScrolling = false
print("Scrolling ended")
}
}
.coordinateSpace(name: "scroll")
VStack { VStack {
LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.95), Color.white.opacity(0.1)]), startPoint: .top, endPoint: .bottom) 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 { #Preview {
ContentView() ContentView()
} }

View File

@ -31,6 +31,7 @@ struct CreateEditClassView: View {
.padding(.bottom, 10) .padding(.bottom, 10)
HStack { HStack {
Text("Тип") Text("Тип")
.font(.custom("Montserrat-Medium", size: 17))
Spacer() Spacer()
Picker("Тип", selection: $vm._class.online, content: { Picker("Тип", selection: $vm._class.online, content: {
ForEach(MockData.onlineOrOffline, id: \.self) { ForEach(MockData.onlineOrOffline, id: \.self) {
@ -72,14 +73,14 @@ struct CreateEditClassView: View {
Image(systemName: "calendar") Image(systemName: "calendar")
.foregroundColor(Color.gray) .foregroundColor(Color.gray)
.padding(.leading, 12) .padding(.leading, 12)
.padding(.trailing, 7) .padding(.trailing, 5)
Text("Дата") Text("Дата")
.foregroundColor(Color("grayForFields").opacity(0.5)) .foregroundColor(Color("grayForFields").opacity(0.5))
.font(.system(size: 18, weight: .regular)) .font(.custom("Montserrat-Regular", size: 18))
Spacer() Spacer()
Text("\(vm._class.day, formatter: dateFormatter)") Text("\(vm._class.day, formatter: dateFormatter)")
.foregroundColor(.black) .foregroundColor(.black)
.font(.system(size: 18, weight: .medium)) .font(.custom("Montserrat-Medium", size: 18))
.padding(.trailing, 20) .padding(.trailing, 20)
} }
.frame(height: 40) .frame(height: 40)
@ -127,6 +128,7 @@ struct CreateEditClassView: View {
.frame(height: 40) .frame(height: 40)
.padding(.bottom, 10) .padding(.bottom, 10)
Toggle("Пометить как важную", isOn: $vm._class.important) Toggle("Пометить как важную", isOn: $vm._class.important)
.font(.custom("Montserrat-Medium", size: 17))
.frame(height: 40) .frame(height: 40)
.padding(.horizontal) .padding(.horizontal)
.background( .background(
@ -137,6 +139,7 @@ struct CreateEditClassView: View {
HStack { HStack {
Text("Напоминанние") Text("Напоминанние")
.font(.custom("Montserrat-Medium", size: 17))
Spacer() Spacer()
Picker("Напоминание", selection: $vm._class.notification, content: { Picker("Напоминание", selection: $vm._class.notification, content: {
ForEach(MockData.notifications, id: \.self) { ForEach(MockData.notifications, id: \.self) {
@ -160,7 +163,7 @@ struct CreateEditClassView: View {
if !vm.isNew { if !vm.isNew {
Button { Button {
do { do {
try delete(vm._class) try provider.delete(vm._class, in: provider.viewContext)
dismiss() dismiss()
} catch { } catch {
print(error) print(error)
@ -170,7 +173,7 @@ struct CreateEditClassView: View {
Spacer() Spacer()
Image(systemName: "trash") Image(systemName: "trash")
Text("Удалить занятие") Text("Удалить занятие")
.font(.system(size: 17, weight: .medium)) .font(.custom("Montserrat-Medium", size: 17))
Spacer() Spacer()
} }
.frame(height: 40) .frame(height: 40)
@ -235,7 +238,6 @@ struct CreateEditClassView: View {
} }
if day > Calendar.current.startOfDay(for: Date()) { if day > Calendar.current.startOfDay(for: Date()) {
vm._class.day = day vm._class.day = day
print(34)
} }
} }
.onTapGesture { .onTapGesture {

View File

@ -18,7 +18,7 @@ struct MonthTabView: View {
HStack (spacing: 34) { HStack (spacing: 34) {
ForEach(MockData.daysOfWeek.indices, id: \.self) { index in ForEach(MockData.daysOfWeek.indices, id: \.self) { index in
Text(MockData.daysOfWeek[index]) Text(MockData.daysOfWeek[index])
.font(.system(size: 15, weight: .semibold)) .font(.custom("Montserrat-SemiBold", size: 15))
.foregroundColor(MockData.daysOfWeek[index] == "Вс" ? Color(.red) : Color("customGray2")) .foregroundColor(MockData.daysOfWeek[index] == "Вс" ? Color(.red) : Color("customGray2"))
.padding(.top, 13) .padding(.top, 13)
.foregroundColor(.gray) .foregroundColor(.gray)
@ -50,7 +50,6 @@ struct MonthTabView: View {
monthSlider.removeAll() monthSlider.removeAll()
currentMonthIndex = 1 currentMonthIndex = 1
updateMonthScreenViewForNewGroup() updateMonthScreenViewForNewGroup()
print(52)
vm.isNewGroup = false vm.isNewGroup = false
} }
} }

View File

@ -39,7 +39,6 @@ struct WeekTabView: View {
weekSlider.removeAll() weekSlider.removeAll()
currentWeekIndex = 1 currentWeekIndex = 1
updateWeekScreenViewForNewGroup() updateWeekScreenViewForNewGroup()
print(52)
vm.isNewGroup = false vm.isNewGroup = false
} }
} }

View File

@ -16,7 +16,7 @@ struct WeekViewForMonth: View {
ForEach(week) { day in ForEach(week) { day in
VStack { VStack {
Text(day.date.format("dd")) Text(day.date.format("dd"))
.font(.system(size: 15, weight: .bold)) .font(.custom("Montserrat-Medium", size: 15))
.foregroundStyle(getForegroundColor(day: day)) .foregroundStyle(getForegroundColor(day: day))
} }
.frame(width: 30, height: 30, alignment: .center) .frame(width: 30, height: 30, alignment: .center)

View File

@ -18,12 +18,12 @@ struct WeekViewForWeek: View {
ForEach(week) { day in ForEach(week) { day in
VStack (spacing: 1) { VStack (spacing: 1) {
Text(day.date.format("E")) 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")) .foregroundColor(day.date.format("E") == "Вс" ? Color(.red) : isSameDate(day.date, vm.selectedDay) ? Color("customGray1") : Color("customGray3"))
.padding(.top, 13) .padding(.top, 13)
.foregroundColor(.gray) .foregroundColor(.gray)
Text(day.date.format("dd")) 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) .foregroundStyle(isSameDate(day.date, vm.selectedDay) ? .white : .black)
.padding(.bottom, 13) .padding(.bottom, 13)
} }

View File

@ -47,7 +47,27 @@ final class ClassProvider {
fatalError("Unable to load store. Error: \(error)") 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()
}
} }
} }

View File

@ -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()
}
}
}
}

View File

@ -13,13 +13,16 @@ final class EditClassViewModel: ObservableObject {
let isNew: Bool let isNew: Bool
private let provider: ClassProvider
private let context: NSManagedObjectContext private let context: NSManagedObjectContext
init(provider: ClassProvider, _class: ClassModel? = nil) { init(provider: ClassProvider, _class: ClassModel? = nil) {
self.provider = provider
self.context = provider.newContext self.context = provider.newContext
if let _class, if let _class,
let existingClassCopy = try? context.existingObject(with: _class.objectID) as? ClassModel { let existingClassCopy = provider.exists(_class, in: context) {
self._class = existingClassCopy self._class = existingClassCopy
self.isNew = false self.isNew = false
} }
@ -30,8 +33,6 @@ final class EditClassViewModel: ObservableObject {
} }
func save() throws { func save() throws {
if context.hasChanges { try provider.persist(in: context)
try context.save()
}
} }
} }