2025-08-14 10:34:58 +02:00

181 lines
5.5 KiB
C#

using CommunityToolkit.Maui.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using gehGassiApp.ViewModels.Popups;
using gehGassiApp.Views.Popups;
using gehGassiApp.Resources;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gehGassiApp.ViewModels.Onboarding
{
public partial class OnboardingViewModel : ObservableObject
{
public ObservableCollection<OnboardingItemViewModel> OnboardingItems { get; set; } = [];
public ObservableCollection<OnboardingStepViewModel> OnboardingSteps { get; set; } = [];
[ObservableProperty]
private OnboardingItemViewModel _currentItem;
[ObservableProperty]
private int _currentPosition;
[ObservableProperty]
private bool _canGoBack;
[ObservableProperty]
private bool _isLastPage;
[ObservableProperty]
private bool _isNotLastPage = true;
[ObservableProperty]
private string _nextButtonText;
public OnboardingViewModel()
{
InitializeOnboarding();
}
private void InitializeOnboarding()
{
// Erstelle alle Onboarding-Items
OnboardingItems = new ObservableCollection<OnboardingItemViewModel>
{
new OnboardingItemViewModel
{
Title = "Unsere Services",
Subtitle = "Ob Business-Trip, Spontanmeeting oder Notfall",
ImageUrl = Text.Onboarding_Img_01
},
new OnboardingItemViewModel
{
Title = "Top-Feature",
Subtitle = "ÖFFENTLICHE ANFRAGE\nFür Sichere Matches in Minuten!",
ImageUrl = Text.Onboarding_Img_02
},
new OnboardingItemViewModel
{
Title = "Gemacht. Gebucht. Bezahlt.",
Subtitle = "Mit ID-Check und deiner\nFreigabe vor jeder Auszahlung!",
ImageUrl = Text.Onboarding_Img_03
}
};
// Erstelle die Schritt-Indikatoren
OnboardingSteps = new ObservableCollection<OnboardingStepViewModel>();
for (int i = 0; i < OnboardingItems.Count; i++)
{
OnboardingSteps.Add(new OnboardingStepViewModel
{
StepNumber = i + 1,
IsActive = i == 0,
IsCompleted = false,
HasNextStep = i < OnboardingItems.Count - 1
});
}
CurrentPosition = 0;
UpdateState();
}
partial void OnCurrentPositionChanged(int value)
{
// Aktualisiere die Schrittindikatoren - Zurücksetzen aller Indikatoren und dann korrekte Zustände setzen
for (int i = 0; i < OnboardingSteps.Count; i++)
{
// Explizites Zurücksetzen beider Zustände
OnboardingSteps[i].IsActive = false;
OnboardingSteps[i].IsCompleted = false;
// Dann die korrekten Zustände setzen
if (i == value)
{
OnboardingSteps[i].IsActive = true;
}
else if (i < value)
{
OnboardingSteps[i].IsCompleted = true;
}
}
UpdateState();
// Die automatische Navigation wurde entfernt
}
private void UpdateState()
{
CanGoBack = CurrentPosition > 0;
IsLastPage = CurrentPosition == OnboardingItems.Count - 1;
IsNotLastPage = !IsLastPage;
}
[RelayCommand]
private void NextStep()
{
if (CurrentPosition < OnboardingItems.Count - 1)
{
CurrentPosition++;
}
else if (CurrentPosition == OnboardingItems.Count - 1)
{
// Wenn wir auf der letzten Seite sind und der Weiter-Button geklickt wird,
// starten wir die CompleteOnboarding-Methode
CompleteOnboardingCommand.Execute(null);
}
}
[RelayCommand]
private void PreviousStep()
{
if (CurrentPosition > 0)
{
CurrentPosition--;
}
}
[RelayCommand]
private async Task CompleteOnboarding()
{
// Speichern, dass Onboarding abgeschlossen wurde
Preferences.Default.Set("OnboardingCompleted", true);
await Shell.Current.GoToAsync("//LoadingView"); // Navigiere zur Hauptseite
// Zur Hauptseite navigieren
//await ShowSubscriptionOfferAfterRegistration();
//await ShowSubscriptionSuccessPopup();
//await CheckAGBStatus();
}
}
public class OnboardingItemViewModel
{
public string Title { get; set; }
public string Subtitle { get; set; }
public string ImageUrl { get; set; }
}
public partial class OnboardingStepViewModel : ObservableObject
{
[ObservableProperty]
private int _stepNumber;
[ObservableProperty]
private bool _isActive;
[ObservableProperty]
private bool _isCompleted;
[ObservableProperty]
private bool _hasNextStep;
}
}