-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentCoursePage.xaml.cs
More file actions
90 lines (73 loc) · 2.76 KB
/
StudentCoursePage.xaml.cs
File metadata and controls
90 lines (73 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using MyMauiApp.Models;
using MyMauiApp.Services;
using System.Collections.ObjectModel;
using Microsoft.Maui.ApplicationModel; // для Launcher
namespace MyMauiApp;
public partial class StudentCoursePage : ContentPage
{
private readonly Guid _courseId;
private Course _course;
private Enrollment? _enrollment;
public ObservableCollection<MaterialItem> Materials { get; } = new();
public StudentCoursePage(Guid courseId)
{
InitializeComponent();
_courseId = courseId;
BindingContext = this;
}
protected override void OnAppearing()
{
base.OnAppearing();
var data = AppData.Instance;
var current = data.CurrentUser!;
_course = data.Courses.First(c => c.Id == _courseId);
// обеспечиваем наличие записи о зачислении
_enrollment = data.EnsureEnrollment(_courseId, current.Id);
Materials.Clear();
foreach (var m in _course.Materials)
Materials.Add(m);
CourseTitleLabel.Text = _course.Title;
LessonsInfoLabel.Text = $"Wykład {Materials.Count} z {_course.LessonsCount}";
UpdateProgress();
}
private void UpdateProgress()
{
if (_enrollment == null) return;
var percent = AppData.Instance.GetProgressPercent(_courseId, _enrollment.StudentId);
ProgressPercentLabel.Text = $"{percent:0}%";
}
// 👉 здесь открываем материал
private async void OnMaterialTapped(object sender, TappedEventArgs e)
{
if (e.Parameter is not MaterialItem material || _enrollment == null)
return;
// 1. переключаем "выполнено/не выполнено"
AppData.Instance.ToggleMaterialCompleted(material.CourseId, material.Id, _enrollment.StudentId);
UpdateProgress();
// 2. пробуем открыть сам материал
if (!string.IsNullOrWhiteSpace(material.Url))
{
try
{
// если это http/https — откроется в браузере
await Launcher.OpenAsync(material.Url);
}
catch
{
await DisplayAlert("Błąd", "Nie można otworzyć materiału (link jest nieprawidłowy).", "OK");
}
}
else
{
// если ссылки нет — показать инфу
var text = string.IsNullOrWhiteSpace(material.Description)
? "Brak dodatkowych informacji."
: material.Description;
await DisplayAlert(material.Title, text, "OK");
}
}
private async void OnBackTapped(object sender, EventArgs e)
{
await Navigation.PopAsync();
}
}