From c08f07d61f2bb066e98e0bcebaf71413838d0946 Mon Sep 17 00:00:00 2001 From: Yuliya Raikova Date: Tue, 7 May 2024 17:27:54 +0300 Subject: [PATCH 1/5] [FIX] Bugs with chart and refresh token --- .../RoundedListView/RoundedListView.cs | 10 +++++++--- source/EduCATS/EduCATS.csproj | 1 - source/EduCATS/Networking/RequestController.cs | 4 ++-- .../Login/ViewModels/LoginPageViewModel.cs | 7 ++++++- .../Base/ViewModels/StatsPageViewModel.cs | 12 ++++++------ .../Statistics/Base/Views/StatsPageView.cs | 1 - .../Base/ViewModels/TodayPageViewModel.cs | 18 ++++++++++-------- .../Pages/Today/Base/Views/TodayPageView.cs | 6 +++--- 8 files changed, 34 insertions(+), 25 deletions(-) diff --git a/source/EduCATS/Controls/RoundedListView/RoundedListView.cs b/source/EduCATS/Controls/RoundedListView/RoundedListView.cs index e87b00b8..13ae33e9 100644 --- a/source/EduCATS/Controls/RoundedListView/RoundedListView.cs +++ b/source/EduCATS/Controls/RoundedListView/RoundedListView.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Runtime.CompilerServices; using EduCATS.Controls.RoundedListView.Selectors; +using EduCATS.Helpers.Forms; using EduCATS.Helpers.Forms.Styles; using EduCATS.Pages.Today.Base.Views.ViewCells; using EduCATS.Themes; @@ -54,10 +55,13 @@ public class RoundedListView : ListView View header = null, double headerTopPadding = 0, double footerBottomPadding = 0, - Func func = null) + Func func = null, + IPlatformServices services = null) { - if (type == typeof(SubjectPageViewCell) || type == typeof(CalendarSubjectsViewCell)) HasUnevenRows = false; - else HasUnevenRows = true; + HasUnevenRows = true; + + if ((type == typeof(SubjectPageViewCell) || type == typeof(CalendarSubjectsViewCell)) && services is not null && services.Preferences.IsLargeFont) HasUnevenRows = false; + ItemTemplate = func == null ? new RoundedListTemplateSelector(type, checkbox) : new RoundedListTemplateSelector(func, checkbox); diff --git a/source/EduCATS/EduCATS.csproj b/source/EduCATS/EduCATS.csproj index f369ad26..40d99c9f 100644 --- a/source/EduCATS/EduCATS.csproj +++ b/source/EduCATS/EduCATS.csproj @@ -65,7 +65,6 @@ - diff --git a/source/EduCATS/Networking/RequestController.cs b/source/EduCATS/Networking/RequestController.cs index fdc38c76..d28f3d69 100644 --- a/source/EduCATS/Networking/RequestController.cs +++ b/source/EduCATS/Networking/RequestController.cs @@ -119,7 +119,7 @@ async Task get() var response = await _client.GetAsync(Uri); if (!response.IsSuccessStatusCode) { - _services.Preferences.AccessToken = ((LoginPageViewModel)(new LoginPageView().BindingContext)).RefreshToken(); + _services.Preferences.AccessToken = await ((LoginPageViewModel)(new LoginPageView().BindingContext)).RefreshToken(); _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(_services.Preferences.AccessToken); return await _client.GetAsync(Uri); } @@ -155,7 +155,7 @@ async Task post() var response = await _client.PostAsync(Uri, _postContent); if (!response.IsSuccessStatusCode) { - _services.Preferences.AccessToken = ((LoginPageViewModel)(new LoginPageView().BindingContext)).RefreshToken(); + _services.Preferences.AccessToken = await ((LoginPageViewModel)(new LoginPageView().BindingContext)).RefreshToken(); _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(_services.Preferences.AccessToken); return await _client.PostAsync(Uri, _postContent); } diff --git a/source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs b/source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs index c874cddc..44a5867c 100644 --- a/source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs +++ b/source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs @@ -230,8 +230,13 @@ protected async Task openParental() /// Implements refresh token. /// /// Access token string on success, null otherwise. - public string RefreshToken() + public async Task RefreshToken() { + if (DataAccess.Username == string.Empty || DataAccess.Password == string.Empty) + { + await loginRequest(); + } + Username = DataAccess.Username; Password = DataAccess.Password; diff --git a/source/EduCATS/Pages/Statistics/Base/ViewModels/StatsPageViewModel.cs b/source/EduCATS/Pages/Statistics/Base/ViewModels/StatsPageViewModel.cs index 0fab16ba..c7277f56 100644 --- a/source/EduCATS/Pages/Statistics/Base/ViewModels/StatsPageViewModel.cs +++ b/source/EduCATS/Pages/Statistics/Base/ViewModels/StatsPageViewModel.cs @@ -430,9 +430,9 @@ protected virtual async Task getAndSetStatistics() } } - averages[0] /= countOfGroups; - averages[1] /= countOfGroups; - averages[2] /= countOfGroups; + averages[0] /= countOfGroups == 0? 1 : countOfGroups; + averages[1] /= countOfGroups == 0? 1 : countOfGroups; + averages[2] /= countOfGroups == 0 ? 1 : countOfGroups; setChartData(currentStudentStatistics, new LabsVisitingList(), null, averages); } @@ -559,7 +559,7 @@ List calculateChartData(StatsStudentModel stats, LabsVisitingList studen countOfPractStudents++; } - avgPract /= countOfPractStudents; + avgPract /= countOfPractStudents == 0 ? 1 : countOfPractStudents; @@ -573,9 +573,9 @@ List calculateChartData(StatsStudentModel stats, LabsVisitingList studen avgTests += double.Parse(student.TestMark, CultureInfo.InvariantCulture); } - avgLabs /= countOfStudents; + avgLabs /= countOfStudents == 0 ? 1 : countOfStudents; - avgTests /= countOfStudents; + avgTests /= countOfStudents == 0 ? 1 : countOfStudents; } else { diff --git a/source/EduCATS/Pages/Statistics/Base/Views/StatsPageView.cs b/source/EduCATS/Pages/Statistics/Base/Views/StatsPageView.cs index 4ff4c1ea..cd99c1da 100644 --- a/source/EduCATS/Pages/Statistics/Base/Views/StatsPageView.cs +++ b/source/EduCATS/Pages/Statistics/Base/Views/StatsPageView.cs @@ -64,7 +64,6 @@ StackLayout createHeaderView() { var subjectsView = new SubjectsPickerView(); var radarChartView = createFrameWithChartView(); - radarChartView.SetBinding(IsVisibleProperty, "IsStudent"); return new StackLayout { diff --git a/source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs b/source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs index 819a6cee..984c1169 100644 --- a/source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs +++ b/source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs @@ -27,11 +27,13 @@ public class TodayPageViewModel : ViewModel readonly double _subjectHeight; readonly double _subjectsFooterHeight; readonly double _subjectsHeaderHeight = 71; + readonly double _subjectsHeightToSubtract; + readonly bool _isLargeFont; const int _minimumCalendarPosition = 0; const int _maximumCalendarPosition = 2; - const double _subjectsHeightToAdd = 55; - const double _emptySubjectsHeight = 110; + const double _emptySubjectsHeight = 120; + const double _emptySubjectsHeightLarge = 130; // bool _isCreation = true; bool _isManualSelectedCalendarDay; @@ -40,8 +42,10 @@ public class TodayPageViewModel : ViewModel public TodayPageViewModel(double subjectHeight, double subjectsHeaderHeight, IPlatformServices services) { - _subjectHeight = subjectHeight; + _subjectHeight = services.Preferences.IsLargeFont ? (subjectHeight + 90) : subjectHeight; + _subjectsHeightToSubtract = services.Preferences.IsLargeFont ? 95 : 85; _subjectsFooterHeight = subjectsHeaderHeight; + _isLargeFont = services.Preferences.IsLargeFont; _services = services; initSetup(); @@ -492,8 +496,7 @@ void setupSubjectsHeight() } CalendarSubjectsHeight = - (_subjectHeight * CalendarSubjects.Count) + - (_subjectsHeaderHeight * 2) + _subjectsHeightToAdd; + _subjectHeight * CalendarSubjects.Count; } catch (Exception ex) { AppLogs.Log(ex); } @@ -505,13 +508,12 @@ void setupNewsSubjectsHeight() { if (NewsSubjectList.Count == 0) { - CalendarSubjectsHeight = _emptySubjectsHeight; + CalendarSubjectsHeight = _isLargeFont ? _emptySubjectsHeightLarge : _emptySubjectsHeight; return; } CalendarSubjectsHeight = - (_subjectHeight * (NewsSubjectList.Count) /** 2*/) + - _subjectsHeaderHeight + _subjectsFooterHeight + _subjectsHeightToAdd; + _subjectHeight * NewsSubjectList.Count - _subjectsHeightToSubtract * (NewsSubjectList.Count - 1); } catch (Exception ex) { diff --git a/source/EduCATS/Pages/Today/Base/Views/TodayPageView.cs b/source/EduCATS/Pages/Today/Base/Views/TodayPageView.cs index 1afc9a8c..2112ecf1 100644 --- a/source/EduCATS/Pages/Today/Base/Views/TodayPageView.cs +++ b/source/EduCATS/Pages/Today/Base/Views/TodayPageView.cs @@ -20,7 +20,7 @@ public class TodayPageView : ContentPage const double _calendarDaysOfWeekCollectionHeight = 50; const string _calendarCollectionDataBinding = "."; - double _subjectRowHeight = 80; + double _subjectRowHeight = 170; double _subjectDetailedRowHeight = 80; static Thickness _newsLabelMagin = new Thickness(10); @@ -170,7 +170,7 @@ ListView createSubjectsList() if (Networking.Servers.Current == Networking.Servers.EduCatsByAddress) { - subjectsListView = new RoundedListView(typeof(SubjectPageViewCell), header: subjectsLabel) + subjectsListView = new RoundedListView(typeof(SubjectPageViewCell), header: subjectsLabel, services: _services) { RowHeight = (int)_subjectDetailedRowHeight, IsEnabled = false, @@ -181,7 +181,7 @@ ListView createSubjectsList() } else { - subjectsListView = new RoundedListView(typeof(CalendarSubjectsViewCell), header: subjectsLabel) { + subjectsListView = new RoundedListView(typeof(CalendarSubjectsViewCell), header: subjectsLabel, services: _services) { RowHeight = (int)_subjectRowHeight, IsEnabled = false, Margin = _subjectsMargin, From ea25dd4443d1287d6e5b4984c178ce47ac40d786 Mon Sep 17 00:00:00 2001 From: Yuliya Raikova Date: Wed, 8 May 2024 08:41:53 +0300 Subject: [PATCH 2/5] [FIX] Fixed the logic of refresh token on re-login --- source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs b/source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs index 44a5867c..68c8c7ae 100644 --- a/source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs +++ b/source/EduCATS/Pages/Login/ViewModels/LoginPageViewModel.cs @@ -232,7 +232,7 @@ protected async Task openParental() /// Access token string on success, null otherwise. public async Task RefreshToken() { - if (DataAccess.Username == string.Empty || DataAccess.Password == string.Empty) + if (_services.Preferences.AccessToken == string.Empty) { await loginRequest(); } From 0daeef5a56d277eab2b65e625aac44b7c04e16c0 Mon Sep 17 00:00:00 2001 From: Yuliya Raikova Date: Wed, 8 May 2024 08:47:54 +0300 Subject: [PATCH 3/5] [FIX] Updated unit test for refresh token to work --- source/EduCATS.UnitTests/Registration/RegistrationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/EduCATS.UnitTests/Registration/RegistrationTests.cs b/source/EduCATS.UnitTests/Registration/RegistrationTests.cs index 0a92c32e..86bdd574 100644 --- a/source/EduCATS.UnitTests/Registration/RegistrationTests.cs +++ b/source/EduCATS.UnitTests/Registration/RegistrationTests.cs @@ -24,7 +24,7 @@ public class RegistrationTests { [TestCase("TestLecturer5", "TestLecturer5")] [Test] - public void RefreshToken_Test(string username, string password) + public async void RefreshToken_Test(string username, string password) { try { @@ -34,7 +34,7 @@ public void RefreshToken_Test(string username, string password) var mockedLoginPageView = new Mock(mockedServices).Object; mockedLoginPageView.Username = username; mockedLoginPageView.Password = password; - var actual = mockedLoginPageView.RefreshToken(); + var actual = await mockedLoginPageView.RefreshToken(); Assert.IsNotEmpty(actual); } catch (Exception ex) From 2ea1528d92a6344611b8cecdbfaf9ab2d9ada6a1 Mon Sep 17 00:00:00 2001 From: Yuliya Raikova Date: Wed, 8 May 2024 08:53:19 +0300 Subject: [PATCH 4/5] [FIX] Another fix to unit test --- source/EduCATS.UnitTests/Registration/RegistrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/EduCATS.UnitTests/Registration/RegistrationTests.cs b/source/EduCATS.UnitTests/Registration/RegistrationTests.cs index 86bdd574..07513edb 100644 --- a/source/EduCATS.UnitTests/Registration/RegistrationTests.cs +++ b/source/EduCATS.UnitTests/Registration/RegistrationTests.cs @@ -24,7 +24,7 @@ public class RegistrationTests { [TestCase("TestLecturer5", "TestLecturer5")] [Test] - public async void RefreshToken_Test(string username, string password) + public async Task RefreshToken_Test(string username, string password) { try { From 278afb681a0eb89f666b85fcd1fc6a710ca5a133 Mon Sep 17 00:00:00 2001 From: Ilya Lehchylin Date: Thu, 6 Jun 2024 23:28:16 +0300 Subject: [PATCH 5/5] [FIX] Variable duplicate --- source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs b/source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs index 926d5251..b0bacf97 100644 --- a/source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs +++ b/source/EduCATS/Pages/Today/Base/ViewModels/TodayPageViewModel.cs @@ -28,7 +28,6 @@ public class TodayPageViewModel : ViewModel readonly double _subjectsHeightToSubtract; readonly double _subjectsFooterHeight; readonly double _subjectsHeaderHeight = 71; - readonly double _subjectsHeightToSubtract; readonly bool _isLargeFont; const int _minimumCalendarPosition = 0;