Skip to content

Commit

Permalink
重写判断 lessonIndex 的代码,新增对是否正在上课的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Mar 24, 2024
1 parent eff774d commit ce3e89b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 25 deletions.
7 changes: 5 additions & 2 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<ScrollViewer Name="ScrollViewerShowingCurriculum" PanningMode="VerticalOnly">
<TextBlock x:Name="textBlockCurriculum" TextWrapping="Wrap" Margin="16"
<ScrollViewer Name="ScrollViewerShowCurriculum" PanningMode="VerticalOnly">
<Grid Margin="16">
<TextBlock Visibility="Collapsed" Name="textBlockCurriculum" TextWrapping="Wrap"
Text="语文&#10;数学&#10;英语&#10;物理&#10;化学&#10;生物&#10;历史&#10;政治&#10;地理&#10;活动&#10;体育"
FontSize="28" Foreground="{DynamicResource ForegroundColor}" TextAlignment="Center"/>
<ui:SimpleStackPanel Name="StackPanelShowTimetable"/>
</Grid>
</ScrollViewer>
<ScrollViewer x:Name="scrollViewerCurriculum" Visibility="Collapsed" PanningMode="VerticalOnly">
<ui:SimpleStackPanel Spacing="8" Margin="24">
Expand Down
99 changes: 76 additions & 23 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,14 @@ private void LoadTimetableorCurriculum()
if (Settings.TimetableSettings.IsTimetableEnabled)
{
LoadTimetable();
textBlockCurriculum.Visibility = Visibility.Collapsed;
StackPanelShowTimetable.Visibility = Visibility.Visible;
}
else
{
LoadCurriculum();
textBlockCurriculum.Visibility = Visibility.Visible;
StackPanelShowTimetable.Visibility = Visibility.Collapsed;
}
}

Expand Down Expand Up @@ -924,7 +928,7 @@ private void editCurriculumButton_Click(object sender, RoutedEventArgs e)
}
else
{
ScrollViewerShowingCurriculum.Visibility = Visibility.Collapsed;
ScrollViewerShowCurriculum.Visibility = Visibility.Collapsed;
editCurriculumButton.Visibility = Visibility.Collapsed;

saveCurriculumButton.Visibility = Visibility.Visible;
Expand All @@ -936,7 +940,7 @@ private void saveCurriculumButton_Click(object sender, RoutedEventArgs e)
{
SaveCurriculum();

ScrollViewerShowingCurriculum.Visibility = Visibility.Visible;
ScrollViewerShowCurriculum.Visibility = Visibility.Visible;
editCurriculumButton.Visibility = Visibility.Visible;

saveCurriculumButton.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -964,42 +968,58 @@ private void LoadTimetable()
}

string day = DateTime.Today.DayOfWeek.ToString();
List<Lesson> timetableToday = new List<Lesson>();

if (!ToggleSwitchTempTimetable.IsOn)
{
switch (day)
{
case "Monday":
textBlockCurriculum.Text = Timetable.ToCurriculums(Timetable.Monday);
timetableToday = Timetable.Monday;
break;
case "Tuesday":
textBlockCurriculum.Text = Timetable.ToCurriculums(Timetable.Tuesday);
timetableToday = Timetable.Tuesday;
break;
case "Wednesday":
textBlockCurriculum.Text = Timetable.ToCurriculums(Timetable.Wednesday);
timetableToday = Timetable.Wednesday;
break;
case "Thursday":
textBlockCurriculum.Text = Timetable.ToCurriculums(Timetable.Thursday);
timetableToday = Timetable.Thursday;
break;
case "Friday":
textBlockCurriculum.Text = Timetable.ToCurriculums(Timetable.Friday);
timetableToday = Timetable.Friday;
break;
case "Saturday":
textBlockCurriculum.Text = Timetable.ToCurriculums(Timetable.Saturday);
timetableToday = Timetable.Saturday;
break;
case "Sunday":
textBlockCurriculum.Text = Timetable.ToCurriculums(Timetable.Sunday);
timetableToday = Timetable.Sunday;
break;
}
}
else
{
textBlockCurriculum.Text = Timetable.ToCurriculums(Timetable.Temp);
timetableToday = Timetable.Temp;
}

StackPanelShowTimetable.Children.Clear();
foreach (Lesson lesson in timetableToday)
{
TextBlock textBlock = new TextBlock()
{
FontSize = 28,
HorizontalAlignment = HorizontalAlignment.Center,
Foreground = (SolidColorBrush)FindResource("ForegroundColor"),
Text = lesson.Subject
};

StackPanelShowTimetable.Children.Add(textBlock);
}

lessonIndex = -1;
}
private int lessonIndex = -1;
private int lessonIndex = -1; // 第几节课
private bool isInClass = false; // 是否是上课时段
private void CheckTimetable(object sender, EventArgs e)
{
timetableTimer.Stop();
Expand Down Expand Up @@ -1042,27 +1062,60 @@ private void CheckTimetable(object sender, EventArgs e)

if (today != null)
{
for (int i = 0; i < today.Count; i++)
// 获取上课状态 lessonIndex 和 isInClass
foreach (var lesson in today)
{
Lesson lesson = today[i];
if (currentTime >= lesson.StartTime)
if (currentTime >= lesson.StartTime) // 在这节课开始后
{
lessonIndex = i;
if (currentTime == lesson.EndTime)
if (today.IndexOf(lesson) + 1 < today.Count) // 不是最后一节课
{
if (lessonIndex + 1 < today.Count) ShowClassOverNotification(today, lessonIndex);
else ShowLastClassOverNotification();
if (currentTime < today[today.IndexOf(lesson) + 1].StartTime) // 在下一节课上课前
{
lessonIndex = today.IndexOf(lesson);
isInClass = currentTime < lesson.EndTime;
break;
}
}
else // 是最后一节课
{
lessonIndex = today.Count - 1;
isInClass = currentTime < lesson.EndTime;
break;
}
}
if (lessonIndex + 1 < today.Count)
else if (today.IndexOf(lesson) == 0) // 在第一节课开始前
{
lessonIndex = -1;
isInClass = false;
break;
}
}

// 弹出上下课提醒
if (Settings.TimetableSettings.IsTimetableNotificationEnabled)
{
if (lessonIndex != -1 && currentTime == today[lessonIndex].EndTime) // 下课时
{
if (currentTime == today[lessonIndex + 1].StartTime - TimeSpan.FromSeconds(10))
if (lessonIndex + 1 < today.Count) // 不是最后一节课
{
if (lessonIndex + 1 < today.Count) ShowClassBeginPreNotification(today, lessonIndex);
ShowClassOverNotification(today, lessonIndex);
}
else ShowLastClassOverNotification();
}
if (lessonIndex + 1 < today.Count && !isInClass && currentTime == today[lessonIndex + 1].StartTime - TimeSpan.FromSeconds(10)) // 有下一节课,在下一节课开始的数秒前
{
ShowClassBeginPreNotification(today, lessonIndex);
}
if (currentTime < lesson.EndTime) break;
}

// 在界面中高亮当前课程或下一节课
if (isInClass) //上课时,高亮当前课程
{

}
else if (lessonIndex + 1 < today.Count) // 在课间,高亮下一节课
{

}
}

Expand Down Expand Up @@ -1104,7 +1157,7 @@ private void ShowLastClassOverNotification()
{
if (Settings.TimetableSettings.IsTimetableNotificationEnabled)
{
ShowNotificationBNS("课堂结束", "这是最后一节课", 3, false);
ShowNotificationBNS("课堂结束", "", 3, false);
}
}
#endregion
Expand Down

0 comments on commit ce3e89b

Please sign in to comment.