Commit
This commit is contained in:
parent
57e241292f
commit
1de531abc8
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
|
"filename" : "ICTIS_logo.png",
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"platform" : "ios",
|
"platform" : "ios",
|
||||||
"size" : "1024x1024"
|
"size" : "1024x1024"
|
||||||
|
BIN
Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/ICTIS_logo.png
Normal file
BIN
Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/ICTIS_logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"color" : {
|
||||||
|
"color-space" : "srgb",
|
||||||
|
"components" : {
|
||||||
|
"alpha" : "1.000",
|
||||||
|
"blue" : "0xDE",
|
||||||
|
"green" : "0xE4",
|
||||||
|
"red" : "0x22"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"idiom" : "universal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"appearances" : [
|
||||||
|
{
|
||||||
|
"appearance" : "luminosity",
|
||||||
|
"value" : "dark"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"color" : {
|
||||||
|
"color-space" : "srgb",
|
||||||
|
"components" : {
|
||||||
|
"alpha" : "1.000",
|
||||||
|
"blue" : "0xDE",
|
||||||
|
"green" : "0xE4",
|
||||||
|
"red" : "0x22"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
@ -8,20 +8,33 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@State private var selectedTab: TabBarModel = .schedule
|
@State private var selectedTab: Int = 1
|
||||||
@StateObject var vm = ViewModel()
|
@StateObject var vm = ViewModel()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
TabView(selection: $selectedTab) {
|
||||||
switch selectedTab {
|
Text("Tasks")
|
||||||
case .schedule:
|
.tabItem {
|
||||||
MainView(vm: vm)
|
Image(systemName: "books.vertical")
|
||||||
case .tasks:
|
Text("Задания")
|
||||||
Text("Tasks")
|
}
|
||||||
case .settings:
|
.tag(0)
|
||||||
Text("Settings")
|
|
||||||
}
|
MainView(vm: vm)
|
||||||
TabBarView(selectedTab: $selectedTab)
|
.tabItem {
|
||||||
|
Image(systemName: "house")
|
||||||
|
Text("Расписание")
|
||||||
|
}
|
||||||
|
.tag(1)
|
||||||
|
|
||||||
|
Text("Settings")
|
||||||
|
.tabItem {
|
||||||
|
Image(systemName: "gear")
|
||||||
|
Text("Настройки")
|
||||||
|
}
|
||||||
|
.tag(2)
|
||||||
}
|
}
|
||||||
|
.accentColor(Color("blueColor"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,24 @@ extension Date {
|
|||||||
return month
|
return month
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createNextMonth() -> [MonthWeek] {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let startOfLastDate = calendar.startOfDay(for: self)
|
||||||
|
guard let nextDate = calendar.date(byAdding: .day, value: 1, to: startOfLastDate) else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return fetchMonth(nextDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createPreviousMonth() -> [MonthWeek] {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let startOfFirstDate = calendar.startOfDay(for: self)
|
||||||
|
guard let previousDate = calendar.date(byAdding: .month, value: -1, to: startOfFirstDate) else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return fetchMonth(previousDate)
|
||||||
|
}
|
||||||
|
|
||||||
func createNextWeek() -> [WeekDay] {
|
func createNextWeek() -> [WeekDay] {
|
||||||
let calendar = Calendar.current
|
let calendar = Calendar.current
|
||||||
let startOfLastDate = calendar.startOfDay(for: self)
|
let startOfLastDate = calendar.startOfDay(for: self)
|
||||||
|
@ -24,4 +24,50 @@ extension View {
|
|||||||
|
|
||||||
return currentMonth == dateMonth && currentYear == dateYear
|
return currentMonth == dateMonth && currentYear == dateYear
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isSameWeek(_ date1: Date, _ date2: Date) -> Bool {
|
||||||
|
return Calendar.current.compare(date1, to: date2, toGranularity: .weekOfYear) == .orderedSame
|
||||||
|
}
|
||||||
|
|
||||||
|
func weeksBetween(startDate: Date, endDate: Date) -> Int {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let startOfFirstDate = calendar.startOfDay(for: startDate)
|
||||||
|
let startOfEndDate = calendar.startOfDay(for: endDate)
|
||||||
|
|
||||||
|
let weekForDate1 = calendar.dateInterval(of: .weekOfMonth, for: startOfFirstDate)
|
||||||
|
let weekForDate2 = calendar.dateInterval(of: .weekOfMonth, for: startOfEndDate)
|
||||||
|
|
||||||
|
guard let startOfWeek1 = weekForDate1?.start else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let startOfWeek2 = weekForDate2?.start else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
let components = calendar.dateComponents([.day], from: startOfWeek1, to: startOfWeek2)
|
||||||
|
let daysDifference = components.day ?? 0
|
||||||
|
return Int(ceil(Double(abs(daysDifference)) / 7.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertTimeString(_ input: String) -> [String] {
|
||||||
|
let parts = input.split(separator: "-")
|
||||||
|
if let firstPart = parts.first, let lastPart = parts.last {
|
||||||
|
return [String(firstPart), String(lastPart)]
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getColorForClass(_ str: String) -> Color {
|
||||||
|
if (str.contains("LMS")) {
|
||||||
|
return Color("blueForOnline")
|
||||||
|
}
|
||||||
|
else if (str.contains("ВПК")) {
|
||||||
|
return Color("turquoise")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Color("greenForOffline")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
25
Schedule ICTIS/Main/LoadingView.swift
Normal file
25
Schedule ICTIS/Main/LoadingView.swift
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// LoadingView.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 11.12.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct LoadingView: View {
|
||||||
|
@Binding var isLoading: Bool
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
Color("background")
|
||||||
|
.ignoresSafeArea()
|
||||||
|
ProgressView()
|
||||||
|
.progressViewStyle(CircularProgressViewStyle(tint: .secondary))
|
||||||
|
.scaleEffect(1.5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
LoadingView(isLoading: .constant(true))
|
||||||
|
}
|
@ -9,10 +9,6 @@ import SwiftUI
|
|||||||
|
|
||||||
struct MainView: View {
|
struct MainView: View {
|
||||||
@State private var searchText: String = ""
|
@State private var searchText: String = ""
|
||||||
@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
|
@State private var isShowingMonthSlider: Bool = false
|
||||||
@State private var isFirstAppearence = true
|
@State private var isFirstAppearence = true
|
||||||
@ObservedObject var vm: ViewModel
|
@ObservedObject var vm: ViewModel
|
||||||
@ -20,7 +16,10 @@ struct MainView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
SearchBarView(text: $searchText, vm: vm)
|
SearchBarView(text: $searchText, vm: vm)
|
||||||
if (vm.isFirstStartOffApp) {
|
if (vm.isFirstStartOffApp && vm.isLoading) {
|
||||||
|
LoadingView(isLoading: $vm.isLoading)
|
||||||
|
}
|
||||||
|
else if (vm.isFirstStartOffApp) {
|
||||||
FirstLaunchScheduleView()
|
FirstLaunchScheduleView()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -34,23 +33,6 @@ struct MainView: View {
|
|||||||
Text(error.failureReason)
|
Text(error.failureReason)
|
||||||
}
|
}
|
||||||
.background(Color("background"))
|
.background(Color("background"))
|
||||||
.onAppear(perform: {
|
|
||||||
currentDate = vm.selectedDay
|
|
||||||
vm.updateSelectedDayIndex(currentDate)
|
|
||||||
if weekSlider.isEmpty {
|
|
||||||
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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
@ -58,14 +40,14 @@ struct MainView: View {
|
|||||||
VStack (alignment: .leading, spacing: 6) {
|
VStack (alignment: .leading, spacing: 6) {
|
||||||
HStack {
|
HStack {
|
||||||
VStack (alignment: .leading, spacing: 0) {
|
VStack (alignment: .leading, spacing: 0) {
|
||||||
Text(currentDate.format("EEEE"))
|
Text(vm.selectedDay.format("EEEE"))
|
||||||
.font(.system(size: 40, weight: .semibold))
|
.font(.system(size: 40, weight: .semibold))
|
||||||
.foregroundStyle(.black)
|
.foregroundStyle(.black)
|
||||||
HStack (spacing: 5) {
|
HStack (spacing: 5) {
|
||||||
Text(currentDate.format("dd"))
|
Text(vm.selectedDay.format("dd"))
|
||||||
.font(.system(size: 20, weight: .bold))
|
.font(.system(size: 20, weight: .bold))
|
||||||
.foregroundStyle(Color("grayForDate"))
|
.foregroundStyle(Color("grayForDate"))
|
||||||
Text(currentDate.format("MMMM"))
|
Text(vm.selectedDay.format("MMMM"))
|
||||||
.font(.system(size: 20, weight: .bold))
|
.font(.system(size: 20, weight: .bold))
|
||||||
.foregroundStyle(Color("grayForDate"))
|
.foregroundStyle(Color("grayForDate"))
|
||||||
Spacer()
|
Spacer()
|
||||||
@ -91,7 +73,7 @@ struct MainView: View {
|
|||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
if (!isShowingMonthSlider) {
|
if (!isShowingMonthSlider) {
|
||||||
WeekTabView(currentWeekIndex: $currentWeekIndex, weekSlider: $weekSlider, currentDate: $currentDate, vm: vm)
|
WeekTabView(vm: vm)
|
||||||
.transition(.opacity)
|
.transition(.opacity)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -10,75 +10,59 @@ import SwiftUI
|
|||||||
struct ScheduleView: View {
|
struct ScheduleView: View {
|
||||||
@ObservedObject var vm: ViewModel
|
@ObservedObject var vm: ViewModel
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack (alignment: .top) {
|
if vm.isLoading {
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
LoadingView(isLoading: $vm.isLoading)
|
||||||
VStack (spacing: 20) {
|
}
|
||||||
ForEach(vm.classes.indices, id: \.self) { index in
|
else {
|
||||||
if index != 0 && index != 1 && index == vm.selectedIndex {
|
ZStack (alignment: .top) {
|
||||||
let daySchedule = vm.classes[index] // Это массив строк для дня
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
ForEach(daySchedule.indices.dropFirst(), id: \.self) { lessonIndex in
|
VStack (spacing: 20) {
|
||||||
let lesson = daySchedule[lessonIndex] // Это строка с расписанием одной пары
|
ForEach(vm.classes.indices, id: \.self) { index in
|
||||||
if !lesson.isEmpty {
|
if index != 0 && index != 1 && index == vm.selectedIndex {
|
||||||
HStack(spacing: 10) {
|
let daySchedule = vm.classes[index] // Это массив строк для дня
|
||||||
VStack {
|
ForEach(daySchedule.indices.dropFirst(), id: \.self) { lessonIndex in
|
||||||
Text(convertTimeString(vm.classes[1][lessonIndex])[0])
|
let lesson = daySchedule[lessonIndex] // Это строка с расписанием одной пары
|
||||||
.font(.system(size: 15, weight: .regular))
|
if !lesson.isEmpty {
|
||||||
Text(convertTimeString(vm.classes[1][lessonIndex])[1])
|
HStack(spacing: 10) {
|
||||||
.font(.system(size: 15, weight: .regular))
|
VStack {
|
||||||
|
Text(convertTimeString(vm.classes[1][lessonIndex])[0])
|
||||||
|
.font(.system(size: 15, weight: .regular))
|
||||||
|
Text(convertTimeString(vm.classes[1][lessonIndex])[1])
|
||||||
|
.font(.system(size: 15, weight: .regular))
|
||||||
|
}
|
||||||
|
.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(.system(size: 18, weight: .regular))
|
||||||
|
.padding(.top, 7)
|
||||||
|
.padding(.bottom, 7)
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
.padding(.top, 7)
|
.frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230)
|
||||||
.padding(.bottom, 7)
|
.background(Color.white)
|
||||||
.padding(.leading, 10)
|
.cornerRadius(20)
|
||||||
Rectangle()
|
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
||||||
.frame(width: 2)
|
|
||||||
.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)
|
|
||||||
.cornerRadius(20)
|
|
||||||
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.frame(width: UIScreen.main.bounds.width)
|
||||||
|
.padding(.bottom, 100)
|
||||||
|
.padding(.top, 30)
|
||||||
}
|
}
|
||||||
.frame(width: UIScreen.main.bounds.width)
|
VStack {
|
||||||
.padding(.bottom, 100)
|
LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.9), Color("background").opacity(0.89)]), startPoint: .top, endPoint: .bottom)
|
||||||
.padding(.top, 30)
|
}
|
||||||
|
.frame(width: UIScreen.main.bounds.width, height: 15)
|
||||||
}
|
}
|
||||||
VStack {
|
|
||||||
LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.9), Color("background").opacity(0.89)]), startPoint: .top, endPoint: .bottom)
|
|
||||||
// Rectangle()
|
|
||||||
// .frame(width: UIScreen.main.bounds.width, height: 25)
|
|
||||||
// .foregroundColor(Color("background").opacity(0.9))
|
|
||||||
}
|
|
||||||
.frame(width: UIScreen.main.bounds.width, height: 15)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertTimeString(_ input: String) -> [String] {
|
|
||||||
let parts = input.split(separator: "-")
|
|
||||||
if let firstPart = parts.first, let lastPart = parts.last {
|
|
||||||
return [String(firstPart), String(lastPart)]
|
|
||||||
} else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func onlineOrOffline(_ str: String) -> Bool {
|
|
||||||
if (MockData.onlineClasses.contains(str)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ struct MonthTabView: View {
|
|||||||
@State private var currentMonthIndex: Int = 1
|
@State private var currentMonthIndex: Int = 1
|
||||||
@State private var monthSlider: [[Date.MonthWeek]] = []
|
@State private var monthSlider: [[Date.MonthWeek]] = []
|
||||||
@State private var createMonth: Bool = false
|
@State private var createMonth: Bool = false
|
||||||
@State private var currentDate: Date = .init()
|
|
||||||
@ObservedObject var vm: ViewModel
|
@ObservedObject var vm: ViewModel
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@ -39,32 +38,55 @@ struct MonthTabView: View {
|
|||||||
.tabViewStyle(.page(indexDisplayMode: .never))
|
.tabViewStyle(.page(indexDisplayMode: .never))
|
||||||
//.background(Color.green)
|
//.background(Color.green)
|
||||||
}
|
}
|
||||||
|
.onAppear(perform: {
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
|
if monthSlider.isEmpty {
|
||||||
|
let currentMonth = Date().fetchMonth(vm.selectedDay)
|
||||||
|
|
||||||
|
if let firstDate = currentMonth.first?.week[0].date {
|
||||||
|
monthSlider.append(firstDate.createPreviousMonth())
|
||||||
|
}
|
||||||
|
|
||||||
|
monthSlider.append(currentMonth)
|
||||||
|
|
||||||
|
if let lastDate = currentMonth.last?.week[6].date {
|
||||||
|
monthSlider.append(lastDate.createNextMonth())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
.onChange(of: currentMonthIndex, initial: false) { oldValue, newValue in
|
.onChange(of: currentMonthIndex, initial: false) { oldValue, newValue in
|
||||||
if newValue == 0 || newValue == (monthSlider.count - 1) {
|
if newValue == 0 || newValue == (monthSlider.count - 1) {
|
||||||
createMonth = true
|
createMonth = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear(perform: {
|
|
||||||
currentDate = vm.selectedDay
|
|
||||||
vm.updateSelectedDayIndex(currentDate)
|
|
||||||
if monthSlider.isEmpty {
|
|
||||||
let currentMonth = Date().fetchMonth(vm.selectedDay)
|
|
||||||
|
|
||||||
monthSlider.append(currentMonth)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func MonthView(_ month: [Date.MonthWeek]) -> some View {
|
func MonthView(_ month: [Date.MonthWeek]) -> some View {
|
||||||
VStack {
|
VStack (spacing: 10) {
|
||||||
ForEach(month.indices, id: \.self) { index in
|
ForEach(month.indices, id: \.self) { index in
|
||||||
let week = month[index].week
|
let week = month[index].week
|
||||||
WeekView(week)
|
WeekView(week)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.background {
|
||||||
|
GeometryReader {
|
||||||
|
let minX = $0.frame(in: .global).minX
|
||||||
|
|
||||||
|
Color.clear
|
||||||
|
.preference(key: OffsetKey.self, value: minX)
|
||||||
|
.onPreferenceChange(OffsetKey.self) { value in
|
||||||
|
if (abs(value.rounded()) - 20) < 5 && createMonth {
|
||||||
|
paginateMonth()
|
||||||
|
|
||||||
|
createMonth = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func WeekView(_ week: [Date.WeekDay]) -> some View {
|
func WeekView(_ week: [Date.WeekDay]) -> some View {
|
||||||
HStack (spacing: 23) {
|
HStack (spacing: 23) {
|
||||||
@ -72,18 +94,18 @@ struct MonthTabView: View {
|
|||||||
VStack {
|
VStack {
|
||||||
Text(day.date.format("dd"))
|
Text(day.date.format("dd"))
|
||||||
.font(.system(size: 15, weight: .bold))
|
.font(.system(size: 15, weight: .bold))
|
||||||
.foregroundStyle(isDateInCurrentMonth(day.date) ? isSameDate(day.date, currentDate) ? Color.white : Color.black: isSameDate(day.date, currentDate) ? Color.white : Color("greyForDaysInMonthTabView"))
|
.foregroundStyle(isDateInCurrentMonth(day.date) ? isSameDate(day.date, vm.selectedDay) ? Color.white : Color.black: isSameDate(day.date, vm.selectedDay) ? Color.white : Color("greyForDaysInMonthTabView"))
|
||||||
}
|
}
|
||||||
.frame(width: 30, height: 30, alignment: .center)
|
.frame(width: 30, height: 30, alignment: .center)
|
||||||
.background( content: {
|
.background( content: {
|
||||||
Group {
|
Group {
|
||||||
if isSameDate(day.date, currentDate) {
|
if isSameDate(day.date, vm.selectedDay) {
|
||||||
Color("blueColor")
|
Color("blueColor")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Color("background")
|
Color("background")
|
||||||
}
|
}
|
||||||
if isSameDate(day.date, currentDate) {
|
if isSameDate(day.date, vm.selectedDay) {
|
||||||
Color("blueColor")
|
Color("blueColor")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +113,7 @@ struct MonthTabView: View {
|
|||||||
)
|
)
|
||||||
.overlay (
|
.overlay (
|
||||||
Group {
|
Group {
|
||||||
if day.date.isToday && !isSameDate(day.date, currentDate) {
|
if day.date.isToday && !isSameDate(day.date, vm.selectedDay) {
|
||||||
RoundedRectangle(cornerRadius: 100)
|
RoundedRectangle(cornerRadius: 100)
|
||||||
.stroke(Color("blueColor"), lineWidth: 2)
|
.stroke(Color("blueColor"), lineWidth: 2)
|
||||||
}
|
}
|
||||||
@ -99,12 +121,60 @@ struct MonthTabView: View {
|
|||||||
)
|
)
|
||||||
.cornerRadius(15)
|
.cornerRadius(15)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
currentDate = day.date
|
if isSameWeek(day.date, vm.selectedDay) {
|
||||||
vm.updateSelectedDayIndex(currentDate)
|
print("На одной неделе")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var difBetweenWeeks = weeksBetween(startDate: vm.selectedDay, endDate: day.date)
|
||||||
|
if day.date < vm.selectedDay {
|
||||||
|
difBetweenWeeks = difBetweenWeeks * -1
|
||||||
|
}
|
||||||
|
print(difBetweenWeeks)
|
||||||
|
vm.fetchWeekSchedule("", difBetweenWeeks)
|
||||||
|
}
|
||||||
|
vm.selectedDay = day.date
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func paginateMonth() {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
if monthSlider.indices.contains(currentMonthIndex) {
|
||||||
|
if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date,
|
||||||
|
currentMonthIndex == 0 {
|
||||||
|
// switch (vm.numOfGroup) {
|
||||||
|
// case "":
|
||||||
|
// vm.week -= 1
|
||||||
|
// default:
|
||||||
|
// vm.fetchWeekSchedule("new week", -1)
|
||||||
|
// }
|
||||||
|
monthSlider.insert(firstDate.createPreviousMonth(), at: 0)
|
||||||
|
monthSlider.removeLast()
|
||||||
|
currentMonthIndex = 1
|
||||||
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
|
vm.fetchWeekSchedule("", -5)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let lastDate = monthSlider[currentMonthIndex].last?.week[6].date,
|
||||||
|
currentMonthIndex == (monthSlider.count - 1) {
|
||||||
|
// switch (vm.numOfGroup) {
|
||||||
|
// case "":
|
||||||
|
// vm.week += 1
|
||||||
|
// default:
|
||||||
|
// vm.fetchWeekSchedule("new week", 1)
|
||||||
|
// }
|
||||||
|
monthSlider.append(lastDate.createNextMonth())
|
||||||
|
monthSlider.removeFirst()
|
||||||
|
currentMonthIndex = monthSlider.count - 2
|
||||||
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
|
vm.fetchWeekSchedule("", 5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
@ -8,9 +8,8 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct WeekTabView: View {
|
struct WeekTabView: View {
|
||||||
@Binding var currentWeekIndex: Int
|
@State private var currentWeekIndex: Int = 1
|
||||||
@Binding var weekSlider: [[Date.WeekDay]]
|
@State private var weekSlider: [[Date.WeekDay]] = []
|
||||||
@Binding var currentDate: Date
|
|
||||||
@State private var createWeek: Bool = false
|
@State private var createWeek: Bool = false
|
||||||
@ObservedObject var vm: ViewModel
|
@ObservedObject var vm: ViewModel
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@ -27,6 +26,22 @@ struct WeekTabView: View {
|
|||||||
.tabViewStyle(.page(indexDisplayMode: .never))
|
.tabViewStyle(.page(indexDisplayMode: .never))
|
||||||
.frame(height: 90)
|
.frame(height: 90)
|
||||||
}
|
}
|
||||||
|
.onAppear(perform: {
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
|
if weekSlider.isEmpty {
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
.onChange(of: currentWeekIndex, initial: false) { oldValue, newValue in
|
.onChange(of: currentWeekIndex, initial: false) { oldValue, newValue in
|
||||||
if newValue == 0 || newValue == (weekSlider.count - 1) {
|
if newValue == 0 || newValue == (weekSlider.count - 1) {
|
||||||
createWeek = true
|
createWeek = true
|
||||||
@ -41,24 +56,24 @@ struct WeekTabView: View {
|
|||||||
VStack (spacing: 1) {
|
VStack (spacing: 1) {
|
||||||
Text(day.date.format("E"))
|
Text(day.date.format("E"))
|
||||||
.font(.system(size: 15, weight: .semibold))
|
.font(.system(size: 15, weight: .semibold))
|
||||||
.foregroundColor(day.date.format("E") == "Вс" ? Color(.red) : isSameDate(day.date, currentDate) ? 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(.system(size: 15, weight: .bold))
|
||||||
.foregroundStyle(isSameDate(day.date, currentDate) ? .white : .black)
|
.foregroundStyle(isSameDate(day.date, vm.selectedDay) ? .white : .black)
|
||||||
.padding(.bottom, 13)
|
.padding(.bottom, 13)
|
||||||
}
|
}
|
||||||
.frame(width: 43, height: 55, alignment: .center)
|
.frame(width: 43, height: 55, alignment: .center)
|
||||||
.background( content: {
|
.background( content: {
|
||||||
Group {
|
Group {
|
||||||
if isSameDate(day.date, currentDate) {
|
if isSameDate(day.date, vm.selectedDay) {
|
||||||
Color("blueColor")
|
Color("blueColor")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Color(.white)
|
Color(.white)
|
||||||
}
|
}
|
||||||
if isSameDate(day.date, currentDate) {
|
if isSameDate(day.date, vm.selectedDay) {
|
||||||
Color("blueColor")
|
Color("blueColor")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +81,7 @@ struct WeekTabView: View {
|
|||||||
)
|
)
|
||||||
.overlay (
|
.overlay (
|
||||||
Group {
|
Group {
|
||||||
if day.date.isToday && !isSameDate(day.date, currentDate) {
|
if day.date.isToday && !isSameDate(day.date, vm.selectedDay) {
|
||||||
RoundedRectangle(cornerRadius: 15)
|
RoundedRectangle(cornerRadius: 15)
|
||||||
.stroke(Color("blueColor"), lineWidth: 2)
|
.stroke(Color("blueColor"), lineWidth: 2)
|
||||||
}
|
}
|
||||||
@ -74,8 +89,8 @@ struct WeekTabView: View {
|
|||||||
)
|
)
|
||||||
.cornerRadius(15)
|
.cornerRadius(15)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
currentDate = day.date
|
vm.selectedDay = day.date
|
||||||
vm.updateSelectedDayIndex(currentDate)
|
vm.updateSelectedDayIndex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +126,7 @@ struct WeekTabView: View {
|
|||||||
weekSlider.removeLast()
|
weekSlider.removeLast()
|
||||||
currentWeekIndex = 1
|
currentWeekIndex = 1
|
||||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init()
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init()
|
||||||
currentDate = vm.selectedDay
|
vm.updateSelectedDayIndex()
|
||||||
}
|
}
|
||||||
|
|
||||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||||
@ -126,8 +141,7 @@ struct WeekTabView: View {
|
|||||||
weekSlider.removeFirst()
|
weekSlider.removeFirst()
|
||||||
currentWeekIndex = weekSlider.count - 2
|
currentWeekIndex = weekSlider.count - 2
|
||||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init()
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init()
|
||||||
currentDate = vm.selectedDay
|
vm.updateSelectedDayIndex()
|
||||||
print(currentDate)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,11 @@ final class ViewModel: ObservableObject {
|
|||||||
@Published var isFirstStartOffApp = true
|
@Published var isFirstStartOffApp = true
|
||||||
@Published var isShowingAlertForIncorrectGroup: Bool = false
|
@Published var isShowingAlertForIncorrectGroup: Bool = false
|
||||||
@Published var errorInNetwork: NetworkError?
|
@Published var errorInNetwork: NetworkError?
|
||||||
|
@Published var isLoading: Bool = false
|
||||||
|
|
||||||
//MARK: Methods
|
//MARK: Methods
|
||||||
func fetchWeekSchedule(_ group: String, _ num: Int = 0) {
|
func fetchWeekSchedule(_ group: String, _ num: Int = 0) {
|
||||||
|
isLoading = true
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
var schedule: Schedule
|
var schedule: Schedule
|
||||||
@ -45,6 +47,7 @@ final class ViewModel: ObservableObject {
|
|||||||
classes = weekSchedule.table
|
classes = weekSchedule.table
|
||||||
self.isFirstStartOffApp = false
|
self.isFirstStartOffApp = false
|
||||||
self.isShowingAlertForIncorrectGroup = false
|
self.isShowingAlertForIncorrectGroup = false
|
||||||
|
isLoading = false
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
if let error = error as? NetworkError {
|
if let error = error as? NetworkError {
|
||||||
@ -57,15 +60,15 @@ final class ViewModel: ObservableObject {
|
|||||||
default:
|
default:
|
||||||
print(2)
|
print(2)
|
||||||
}
|
}
|
||||||
|
isLoading = false
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSelectedDayIndex(_ date: Date) {
|
func updateSelectedDayIndex() {
|
||||||
selectedDay = date
|
switch selectedDay.format("E") {
|
||||||
switch date.format("E") {
|
|
||||||
case "Пн":
|
case "Пн":
|
||||||
selectedIndex = 2
|
selectedIndex = 2
|
||||||
case "Вт":
|
case "Вт":
|
||||||
@ -81,7 +84,6 @@ final class ViewModel: ObservableObject {
|
|||||||
default:
|
default:
|
||||||
selectedIndex = 8
|
selectedIndex = 8
|
||||||
}
|
}
|
||||||
print(selectedIndex)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user