Files
wgu-c971/WguApp/Views/TestPage.xaml.cs

120 lines
4.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plugin.LocalNotification;
using WguApp.Services;
namespace WguApp.Views;
public partial class TestPage : ContentPage
{
public TestPage()
{
InitializeComponent();
}
private async void TestBtn_OnClicked(object? sender, EventArgs e)
{
if (await LocalNotificationCenter.Current.AreNotificationsEnabled() == false)
{
await LocalNotificationCenter.Current.RequestNotificationPermission();
}
var notification = new NotificationRequest
{
NotificationId = 1,
Title = "Notification Test",
Description = "Success!",
Schedule =
{
NotifyTime = DateTime.Now.AddSeconds(30),
RepeatType = NotificationRepeat.No
}
};
await LocalNotificationCenter.Current.Show(notification);
await DisplayAlert("Info", "A test notification should appear in 30 seconds", "ok");
}
private async void AddData_OnCLicked(object? sender, EventArgs e)
{
var result = await DisplayAlert("Load Sample Data", "Do you really want to load DB sample data? This will delete ALL data from the database. This action cannot be undone.", "Yes", "No");
if (!result) return;
await DatabaseService.LoadSampleData();
var terms = await DatabaseService.GetAllTerms();
var courses = await DatabaseService.GetAllCourses();
var assessments = await DatabaseService.GetAllAssessments();
await DisplayAlert("Info", $"Tried to load sample db data, there are now {terms.Count} Terms, {courses.Count} Courses, and {assessments.Count} Assessments", "Ok");
}
private async void Delete_OnClicked(object? sender, EventArgs e)
{
var terms = await DatabaseService.GetAllTerms();
var courses = await DatabaseService.GetAllCourses();
var assessments = await DatabaseService.GetAllAssessments();
var result = await DisplayAlert("Delete DB Data", $"Do you really want to delete the DB data? This will delete ALL data from the database. This action cannot be undone.\nThere are currently {terms.Count} Terms, {courses.Count} Courses, and {assessments.Count} Assessments", "Yes", "No");
if (!result) return;
await DatabaseService.ClearDbData();
terms = await DatabaseService.GetAllTerms();
courses = await DatabaseService.GetAllCourses();
assessments = await DatabaseService.GetAllAssessments();
await DisplayAlert("Info", $"Tried to delete db data, there are now {terms.Count} Terms, {courses.Count} Courses, and {assessments.Count} Assessments", "Ok");
}
private async void ShareButton_OnClick(object? sender, EventArgs e)
{
await Share.Default.RequestAsync(new ShareTextRequest
{
Text = "Test Share Text",
Title = "Share Text"
});
}
private async void ListNotifs_Clicked(object? sender, EventArgs e)
{
var pendingNotifs = await LocalNotificationCenter.Current.GetPendingNotificationList();
var message = pendingNotifs.Aggregate($"-- Scheduled notifications ({pendingNotifs.Count}) --\n",
(current, notif) => current + $"{notif.Title} : {notif.Schedule.NotifyTime}\n");
await DisplayAlert("Info", message, "Ok");
}
private void TestLogger_Clicked(object? sender, EventArgs e)
{
LoggerService.LogToFile("Test");
}
private async void ClearAllNotifs_Clicked(object? sender, EventArgs e)
{
var pendingNotifs = await LocalNotificationCenter.Current.GetPendingNotificationList();
foreach (var notificationRequest in pendingNotifs)
{
await LocalNotificationService.CancelNotification(notificationRequest.NotificationId);
}
}
private async void ShowLog_Clicked(object? sender, EventArgs e)
{
var logFilePath = Path.Combine(FileSystem.AppDataDirectory, "log.txt");
await DisplayAlert("Log", await File.ReadAllTextAsync(logFilePath), "Ok");
}
private void ClearLog_Clicked(object? sender, EventArgs e)
{
var logFilePath = Path.Combine(FileSystem.AppDataDirectory, "log.txt");
File.WriteAllText(logFilePath, "");
}
}