Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 8 additions & 44 deletions Controls/Components/NextClassDisplayComponent.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using System.Linq;
using ClassIsland.Shared.ComponentModels;
using Avalonia.Interactivity;
using ClassIsland.Core.Abstractions.Controls;
Expand All @@ -22,8 +21,6 @@ public partial class NextClassDisplayComponent : ComponentBase<NextClassDisplayS
private const string NoMoreClassesText = "接下来已无课程";

private readonly ILessonsService _lessonsService;
private readonly IProfileService _profileService;
private readonly IExactTimeService _exactTimeService;

private string _subjectName = string.Empty;
private string _teacherName = string.Empty;
Expand Down Expand Up @@ -94,11 +91,9 @@ private set

public new event PropertyChangedEventHandler? PropertyChanged;

public NextClassDisplayComponent(ILessonsService lessonsService, IProfileService profileService, IExactTimeService exactTimeService)
public NextClassDisplayComponent(ILessonsService lessonsService)
{
_lessonsService = lessonsService;
_profileService = profileService;
_exactTimeService = exactTimeService;
InitializeComponent();
}

Expand Down Expand Up @@ -140,49 +135,18 @@ private void OnLessonsServicePropertyChanged(object? sender, PropertyChangedEven

private void UpdateDisplay()
{
var classPlan = _lessonsService.CurrentClassPlan;
if (classPlan?.TimeLayout == null)
var nextSubject = _lessonsService.NextClassSubject;
var nextTimeLayoutItem = _lessonsService.NextClassTimeLayoutItem;
if (nextSubject == null || nextTimeLayoutItem == null || nextSubject == Subject.Fallback || nextTimeLayoutItem.TimeType != 0)
{
ApplyNoMoreClasses();
return;
}

var now = _exactTimeService.GetCurrentLocalDateTime().TimeOfDay;
var validLessonSlots = classPlan.TimeLayout.Layouts
.Where(x => x.TimeType == 0)
.ToList();

foreach (var candidateTime in validLessonSlots)
{
if (candidateTime.StartTime <= now)
{
continue;
}

var candidateClassInfo = classPlan.Classes.FirstOrDefault(x => ReferenceEquals(x.CurrentTimeLayoutItem, candidateTime));
if (candidateClassInfo == null)
{
continue;
}

if (!candidateClassInfo.IsEnabled)
{
continue;
}

if (!_profileService.Profile.Subjects.TryGetValue(candidateClassInfo.SubjectId, out var subject))
{
continue;
}

HasNextClass = true;
SubjectName = subject.Name;
TimeRangeText = $"{candidateTime.StartTime:hh\\:mm}-{candidateTime.EndTime:hh\\:mm}";
TeacherName = string.IsNullOrWhiteSpace(subject.TeacherName) ? string.Empty : subject.TeacherName;
return;
}

ApplyNoMoreClasses();
HasNextClass = true;
SubjectName = nextSubject.Name;
TimeRangeText = $"{nextTimeLayoutItem.StartTime:hh\\:mm}-{nextTimeLayoutItem.EndTime:hh\\:mm}";
TeacherName = string.IsNullOrWhiteSpace(nextSubject.TeacherName) ? string.Empty : nextSubject.TeacherName;
}

private void ApplyNoMoreClasses()
Expand Down
Loading