-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from sahin-a/19-settings-tab-avalonia
19 settings tab avalonia
- Loading branch information
Showing
24 changed files
with
355 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using ReactiveUI; | ||
using SteamAccountManager.AvaloniaUI.ViewModels; | ||
using SteamAccountManager.AvaloniaUI.Views; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SteamAccountManager.AvaloniaUI | ||
{ | ||
public class AppViewLocator : IViewLocator | ||
{ | ||
public IViewFor? ResolveView<T>(T viewModel, string? contract = null) | ||
{ | ||
string? viewPath = viewModel?.GetType().FullName? | ||
.Replace("ViewModels", "Views") | ||
.Replace("ViewModel", "View"); | ||
|
||
switch (viewPath) | ||
{ | ||
case not null: | ||
return createInstanceFromPath(viewPath); | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
private IViewFor createInstanceFromPath(string path) | ||
{ | ||
Type classType = Type.GetType(path, true) ?? throw new Exception("Couldn't resolve type from path"); | ||
return Activator.CreateInstance(classType) as IViewFor ?? throw new Exception("Type isn't of type IViewFor!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Autofac; | ||
using ReactiveUI; | ||
using SteamAccountManager.Domain.Common.CodeExtensions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SteamAccountManager.AvaloniaUI.Common | ||
{ | ||
internal class ViewModelStore | ||
{ | ||
private readonly Dictionary<Type, IRoutableViewModel> _viewModels = new Dictionary<Type, IRoutableViewModel>(); | ||
|
||
public IRoutableViewModel Get<T>(IScreen screen) where T : class, IRoutableViewModel | ||
{ | ||
var viewModel = _viewModels.GetOrNull(typeof(T)); | ||
if (viewModel is null) | ||
{ | ||
viewModel = CreateViewModel<T>(screen); | ||
Register(viewModel); | ||
} | ||
|
||
return viewModel; | ||
} | ||
|
||
public void Register(IRoutableViewModel viewModel) => _viewModels.Add(viewModel.GetType(), viewModel); | ||
|
||
private IRoutableViewModel CreateViewModel<T>(IScreen screen) where T : class, IRoutableViewModel | ||
=> Dependencies.Container?.Resolve<T>(new TypedParameter(typeof(IScreen), screen)) ?? throw new Exception("Failed to resolve AccountSwitcherViewModel"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
SteamAccountManager.AvaloniaUI/SteamAccountSwitcherStyles.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Styles xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
<Style Selector="Window"> | ||
<Setter Property="Background" Value="#1c1b1b" /> | ||
<Setter Property="Icon" Value="/Assets/sam.ico" /> | ||
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" /> | ||
</Style> | ||
|
||
<Style Selector="Grid.NavBar"> | ||
<Setter Property="Background" Value="#1c1b1b" /> | ||
</Style> | ||
<Style Selector="Button.NavTab"> | ||
<Setter Property="HorizontalContentAlignment" Value="Center" /> | ||
<Setter Property="VerticalContentAlignment" Value="Center" /> | ||
<Setter Property="HorizontalAlignment" Value="Stretch" /> | ||
<Setter Property="VerticalAlignment" Value="Stretch" /> | ||
<Setter Property="Background" Value="Transparent" /> | ||
<Setter Property="Padding" Value="12" /> | ||
<Setter Property="Margin" Value="0" /> | ||
</Style> | ||
|
||
<Style Selector="Grid.ButtonBar"> | ||
<Setter Property="Background" Value="#1c1b1b" /> | ||
</Style> | ||
<Style Selector="Button.BarItem"> | ||
<Setter Property="FontSize" Value="25" /> | ||
<Setter Property="HorizontalContentAlignment" Value="Center" /> | ||
<Setter Property="VerticalContentAlignment" Value="Center" /> | ||
<Setter Property="HorizontalAlignment" Value="Stretch" /> | ||
<Setter Property="VerticalAlignment" Value="Stretch" /> | ||
<Setter Property="Background" Value="Transparent" /> | ||
<Setter Property="Padding" Value="12" /> | ||
<Setter Property="Margin" Value="0" /> | ||
</Style> | ||
</Styles> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 66 additions & 3 deletions
69
SteamAccountManager.AvaloniaUI/ViewModels/MainWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,71 @@ | ||
namespace SteamAccountManager.AvaloniaUI.ViewModels | ||
using ReactiveUI; | ||
using SteamAccountManager.AvaloniaUI.Common; | ||
using SteamAccountManager.AvaloniaUI.ViewModels.Commands; | ||
using System.Reactive; | ||
|
||
namespace SteamAccountManager.AvaloniaUI.ViewModels | ||
{ | ||
public class MainWindowViewModel | ||
public class NavigationTarget | ||
{ | ||
public string Title { get; set; } | ||
public string HintText { get; set; } | ||
public QuickCommand NavigateCommand { get; set; } | ||
|
||
public NavigationTarget(string title, string hintText, QuickCommand navigateCommand) | ||
{ | ||
Title = title; | ||
HintText = hintText; | ||
NavigateCommand = navigateCommand; | ||
} | ||
} | ||
|
||
public class MainWindowViewModel : ReactiveObject, IScreen | ||
{ | ||
public string Greeting => "Welcome to Avalonia!"; | ||
// The Router associated with this Screen. | ||
// Required by the IScreen interface. | ||
public RoutingState Router { get; } = new RoutingState(); | ||
|
||
public AdvancedObservableCollection<NavigationTarget> NavigationTargets { get; } = new(); | ||
|
||
private readonly ViewModelStore _viewModelStore = new ViewModelStore(); | ||
|
||
public MainWindowViewModel() | ||
{ | ||
// Manage the routing state. Use the Router.Navigate.Execute | ||
// command to navigate to different view models. | ||
// | ||
// Note, that the Navigate.Execute method accepts an instance | ||
// of a view model, this allows you to pass parameters to | ||
// your view models, or to reuse existing view models. | ||
// | ||
NavigationTargets.Add( | ||
new NavigationTarget | ||
( | ||
title: "Accounts", | ||
hintText: "Show Accounts", | ||
new QuickCommand(() => NavigateTo(_viewModelStore.Get<AccountSwitcherViewModel>(this))) | ||
) | ||
); | ||
NavigationTargets.Add( | ||
new NavigationTarget | ||
( | ||
title: "Settings", | ||
hintText: "Show Settings", | ||
new QuickCommand(() => NavigateTo(_viewModelStore.Get<SettingsViewModel>(this))) | ||
) | ||
); | ||
|
||
NavigateTo(_viewModelStore.Get<AccountSwitcherViewModel>(this)); | ||
} | ||
|
||
private void NavigateTo(IRoutableViewModel viewModel) | ||
{ | ||
if (IsViewAlreadyVisible(viewModel)) | ||
return; | ||
|
||
Router.Navigate.Execute(viewModel); | ||
} | ||
|
||
public bool IsViewAlreadyVisible(IRoutableViewModel viewModel) => viewModel == Router.GetCurrentViewModel(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using ReactiveUI; | ||
using SteamAccountManager.AvaloniaUI.ViewModels.Commands; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
|
||
namespace SteamAccountManager.AvaloniaUI.ViewModels | ||
{ | ||
public class SettingsViewModel : RoutableViewModel | ||
{ | ||
public SettingsViewModel(IScreen screen) : base(screen) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
using ReactiveUI; | ||
using System; | ||
using System.Windows.Input; | ||
|
||
namespace SteamAccountManager.AvaloniaUI.ViewModels | ||
{ | ||
public class ViewModelBase : ReactiveObject | ||
public abstract class ViewModelBase : ReactiveObject | ||
{ | ||
} | ||
|
||
public abstract class RoutableViewModel : ViewModelBase, IRoutableViewModel | ||
{ | ||
public ICommand NavigateBackCommand { get; } | ||
|
||
public string? UrlPathSegment => Guid.NewGuid().ToString().Substring(0, 5); | ||
public IScreen HostScreen { get; } | ||
|
||
public RoutableViewModel(IScreen screen) | ||
{ | ||
NavigateBackCommand = ReactiveCommand.Create(NavigateBack); | ||
HostScreen = screen; | ||
} | ||
|
||
protected void NavigateBack() | ||
{ | ||
HostScreen.Router.NavigateBack.Execute(); | ||
} | ||
} | ||
} |
Oops, something went wrong.