Skip to content
Snippets Groups Projects
Commit 1e839c8c authored by Philipp Müller's avatar Philipp Müller
Browse files

refactoring

parent 41951031
No related branches found
No related tags found
1 merge request!51Refactoring session screens + Mascot animation screen kinda fixed i guess idk
......@@ -40,7 +40,7 @@
</StackPanel>
<!-- <header:HeaderTemplate VerticalAlignment="Center" Height="534"/> -->
<Button Margin="0,100,150,10" Width="40" Height="40" HorizontalAlignment="Right" VerticalAlignment="Top" Background="Transparent" BorderBrush="Transparent" Click="discardSession_Click">
<Button Margin="0,100,150,10" Width="40" Height="40" HorizontalAlignment="Right" VerticalAlignment="Top" Background="Transparent" BorderBrush="Transparent" Click="DiscardSession_Click">
<Grid >
<Line X1="5" Y1="5" X2="35" Y2="35" Stroke="Gray" StrokeThickness="5" />
<Line X1="5" Y1="35" X2="35" Y2="5" Stroke="Gray" StrokeThickness="5" />
......
......@@ -65,7 +65,7 @@ namespace InnoLabProjektDektopApp
this.sessions = cycles;
timer = new Timer(timertick, null, 0, 1000); //A background timer calls timertick every second
timer = new Timer(Timertick, null, 0, 1000); //A background timer calls timertick every second
//StageText.Text = ProcessMonitor.tmpStage.ToString();
......@@ -74,15 +74,15 @@ namespace InnoLabProjektDektopApp
processMonitor.StartMonitoring();
CreateCycleIndicators(); // Kreise erstellen
updateTexts();
UpdateTexts();
}
private void timertick(object state)
private void Timertick(object state)
{
Dispatcher.Invoke(() =>
{
seconds += step; // Reduziere Zeit, wenn der Timer läuft
updateTexts(); // Aktualisiere die UI
UpdateTexts(); // Aktualisiere die UI
// Fortschrittsanzeige nur während der Fokusperiode aktualisieren
......@@ -91,7 +91,7 @@ namespace InnoLabProjektDektopApp
if (seconds <= 0) // Wenn die Zeit abgelaufen ist
{
stopTimer(); // Timer stoppen
StopTimer(); // Timer stoppen
if (currentSession >= sessions) // Wenn alle Zyklen abgeschlossen sind
{
......@@ -117,7 +117,7 @@ namespace InnoLabProjektDektopApp
}
startTimer(); // Starte den Timer für die nächste Periode
StartTimer(); // Starte den Timer für die nächste Periode
} else
{
if(isBreakPeriod)
......@@ -129,7 +129,7 @@ namespace InnoLabProjektDektopApp
}
public void startTimer()
public void StartTimer()
{
if (seconds <= 0) return; // Prevent starting if time is zero
step = -1; // Set step to countdown
......@@ -137,22 +137,22 @@ namespace InnoLabProjektDektopApp
processMonitor.EndPause();
}
public void stopTimer()
public void StopTimer()
{
step = 0; // Stop counting down
PlayPauseButton.Content = "Start"; // Update button text
processMonitor.StartPause();
}
public void setTime(int minutes, int seconds)
public void SetTime(int minutes, int seconds)
{
if (minutes < 0 || minutes > maxTime / 60 || seconds < 0 || seconds > maxTime % 60) return;
seconds = minutes * 60 + seconds;
updateTexts();
this.seconds = minutes * 60 + seconds;
UpdateTexts();
}
private void updateTexts()
private void UpdateTexts()
{
Clock.Text = seconds / 60 + ":" + (seconds % 60 < 10 ? "0" : "") + seconds % 60;
......@@ -181,12 +181,12 @@ namespace InnoLabProjektDektopApp
}
else
{
stopTimer();
StopTimer();
}
}
else
{
startTimer();
StartTimer();
}
}
......@@ -228,7 +228,7 @@ namespace InnoLabProjektDektopApp
{
Width = 50, // Gleiche Breite wie der Hintergrund
Height = 20, // Gleiche Höhe wie der Hintergrund
Fill = GradientGenerator.generateTwoColorBrush(
Fill = GradientGenerator.GenerateTwoColorBrush(
Color.FromRgb(72, 98, 132),
Color.FromRgb(222, 222, 222),
1 - (seconds / (double)maxTime)
......@@ -258,10 +258,10 @@ namespace InnoLabProjektDektopApp
}
}
private void discardSession_Click(object sender, RoutedEventArgs e)
private void DiscardSession_Click(object sender, RoutedEventArgs e)
{
// Neues Fenster für die Auswahl des Abbruchgrunds erstellen
Window reasonWindow = new Window
Window reasonWindow = new()
{
Title = "Warum beenden Sie die Sitzung?",
Width = 600,
......@@ -271,17 +271,17 @@ namespace InnoLabProjektDektopApp
};
// Haupt-StackPanel für die Radiobuttons und den OK-Button
StackPanel stackPanel = new StackPanel
StackPanel stackPanel = new()
{
Margin = new Thickness(10)
};
// Radiobuttons für die Gründe
RadioButton reason1 = new RadioButton { Content = "Ich habe mich dazu entschieden, frühzeitig zu beenden (wird in die Statistik mit aufgenommen).", Margin = new Thickness(5), IsChecked = true };
RadioButton reason2 = new RadioButton { Content = "Mir ist etwas sehr Wichtiges dazwischengekommen, was ich nicht verschieben konnte.", Margin = new Thickness(5) };
RadioButton reason1 = new() { Content = "Ich habe mich dazu entschieden, frühzeitig zu beenden (wird in die Statistik mit aufgenommen).", Margin = new Thickness(5), IsChecked = true };
RadioButton reason2 = new() { Content = "Mir ist etwas sehr Wichtiges dazwischengekommen, was ich nicht verschieben konnte.", Margin = new Thickness(5) };
// OK-Button
Button okButton = new Button
Button okButton = new()
{
Content = "Ok",
Margin = new Thickness(5),
......@@ -313,7 +313,7 @@ namespace InnoLabProjektDektopApp
reasonWindow.Show();
}
public DateTime timeLeft()
public DateTime TimeLeft()
{
return DateTime.Now.AddSeconds(maxTime - seconds);
}
......@@ -385,18 +385,21 @@ namespace InnoLabProjektDektopApp
public static class GradientGenerator
{
public static Brush generateTwoColorBrush(Color color1, Color color2, double ratio)
public static Brush GenerateTwoColorBrush(Color color1, Color color2, double ratio)
{
GradientStopCollection collection = new GradientStopCollection();
GradientStopCollection collection =
[
new GradientStop(color1, 0),
new GradientStop(color1, ratio),
new GradientStop(color2, ratio),
new GradientStop(color2, 1.0),
];
collection.Add(new GradientStop(color1, 0));
collection.Add(new GradientStop(color1, ratio));
collection.Add(new GradientStop(color2, ratio));
collection.Add(new GradientStop(color2, 1.0));
LinearGradientBrush brush = new LinearGradientBrush(collection);
brush.StartPoint = new Point(0, 0);
brush.EndPoint = new Point(1, 0);
LinearGradientBrush brush = new(collection)
{
StartPoint = new Point(0, 0),
EndPoint = new Point(1, 0)
};
return brush;
}
......
......@@ -64,7 +64,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
Application.Current.Dispatcher.Invoke(() =>
{
DateTime timeLeft = Overview.getSessionInstance().timeLeft();
DateTime timeLeft = Overview.getSessionInstance().TimeLeft();
int processMonitorStage = processMonitor.CalculateCurrentDistractionStage(DateTime.Now);
......@@ -137,7 +137,8 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
//MascottImage.Source = new BitmapImage(new Uri($"pack://application:,,,/Assets/MascottAnimation/Down/{animation}/frame{frame_}.png"));
MascottImage.Source = new BitmapImage(new Uri(framePath));
}
catch (Exception e) {
catch (Exception)
{
return false;
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using InnoLabProjektDektopApp.Services;
using LiveChartsCore;
using System.Collections.Generic;
using LiveChartsCore.SkiaSharpView.Extensions;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
using Newtonsoft.Json.Linq;
using InnoLabProjektDektopApp.Services;
using System.IO;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace InnoLabProjektDektopApp.Screens.Regulaer
{
......@@ -35,13 +23,13 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
TimeSpan pausedTotal = new();
TimeSpan productiveTotal;
int final_stage = 0;
int offset = 130;
readonly int offset = 130;
public IEnumerable<ISeries> Series { get; set; }
public IEnumerable<ISeries> Series { get; set; } = [];
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;
private BitmapImage _centerImageSource;
private BitmapImage _centerImageSource = new();
public BitmapImage CenterImageSource
{
get => _centerImageSource;
......@@ -57,7 +45,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public SessionStatistics(string sessionDataJsonPath = "C:\\Users\\Phil\\Source\\Repos\\CoFlow\\InnoLabProjektDektopApp\\InnoLabProjektDektopApp\\bin\\Debug\\net8.0-windows\\Assets\\sessionData\\2025\\3\\4\\4.json")
public SessionStatistics(string sessionDataJsonPath)
{
DataContext = this;
InitializeComponent();
......@@ -96,7 +84,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
TimeSpan cycleDuration = cycleEndTime - cycleStartTime;
// Draw the entire cycle in green
Rectangle cycleSegment = new Rectangle
Rectangle cycleSegment = new()
{
Width = bar_width,
Height = bar_height,
......@@ -108,7 +96,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
chartCanvas.Children.Add(cycleSegment);
// Add cycle number text
TextBlock cycleText = new TextBlock
TextBlock cycleText = new()
{
Text = $"Cycle {cycle.Key}",
Foreground = Brushes.Black,
......@@ -239,7 +227,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
var legendItem = legendItems[i];
// Draw legend color box
Rectangle colorBox = new Rectangle
Rectangle colorBox = new()
{
Width = 20,
Height = 20,
......@@ -250,7 +238,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
chartCanvas.Children.Add(colorBox);
// Draw legend text
TextBlock legendText = new TextBlock
TextBlock legendText = new()
{
Text = legendItem.Text,
Foreground = Brushes.Black,
......@@ -280,8 +268,8 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
string productiveTimeFormatted = FormatTimeSpan(productiveTime);
// Update the series values
Series = new List<ISeries>
{
Series =
[
new PieSeries<double> {
Name = $"Distractions:",
Values = distractedTime.TotalSeconds > 1 ? [distractedTime.TotalMinutes] : new List<double>(),
......@@ -291,26 +279,26 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
},
new PieSeries<double> {
Name = $"Breaks:",
Values = breakTime.TotalMinutes > 0 ? [breakTime.TotalMinutes] : new List<double>(),
Values = breakTime.TotalSeconds > 1 ? [breakTime.TotalMinutes] : new List<double>(),
MaxRadialColumnWidth = 50,
Fill = new SolidColorPaint(SKColors.Blue),
ToolTipLabelFormatter = value => $"{breakTimeFormatted} minutes"
},
new PieSeries<double> {
Name = $"Manually paused:",
Values = pausedTime.TotalMinutes > 0 ? [pausedTime.TotalMinutes] : new List<double>(),
Values = pausedTime.TotalSeconds > 1 ? [pausedTime.TotalMinutes] : new List<double>(),
MaxRadialColumnWidth = 50,
Fill = new SolidColorPaint(SKColors.LightBlue),
ToolTipLabelFormatter = value => $"{pausedTimeFormatted} minutes"
},
new PieSeries<double> {
Name = $"Productive:",
Values = productiveTime.TotalMinutes > 0 ? [productiveTime.TotalMinutes] : new List<double>(),
Values = productiveTime.TotalSeconds > 1 ? [productiveTime.TotalMinutes] : new List<double>(),
MaxRadialColumnWidth = 50,
Fill = new SolidColorPaint(SKColors.Green),
ToolTipLabelFormatter = value => $"{productiveTimeFormatted} minutes"
}
};
];
CenterImageSource = new BitmapImage(new Uri($"pack://application:,,,/Assets/MascottAnimation/Up/{final_stage}/frame0.png"));
......@@ -320,7 +308,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer
}
// Helper method to format TimeSpan as "mm:ss"
private string FormatTimeSpan(TimeSpan timeSpan)
private static string FormatTimeSpan(TimeSpan timeSpan)
{
return $"{(int)timeSpan.TotalMinutes}:{timeSpan.Seconds:D2}";
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment