And the winner is... Stylet!

This commit is contained in:
SpoinkyNL committed 2017-12-27 16:50:34 +01:00
1 parent 73241793b8
commit 418b3adea7
24 files changed
+299 -370

No files matched your search

@@ -0,0 +1,23 @@
using System;
using System.Diagnostics;
using Artemis.UI.ViewModels.Interfaces;
using Stylet;
namespace Artemis.UI.ViewModels
{
public class HomeViewModel : Screen, IMainViewModel
{
public string Title => "Home";
public void OpenUrl(string url)
{
// Don't open anything but valid URIs
if (Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
Process.Start(url);
}
}
public interface IMainViewModel : IArtemisViewModel
{
}
}
@@ -1,10 +1,7 @@
using ReactiveUI;
namespace Artemis.UI.ViewModels.Interfaces
namespace Artemis.UI.ViewModels.Interfaces
{
public interface IArtemisViewModel : IRoutableViewModel
public interface IArtemisViewModel
{
string Title { get; }
string Icon { get; }
}
}
@@ -1,36 +0,0 @@
using System.Diagnostics;
using System.Threading.Tasks;
using Artemis.UI.ViewModels.Interfaces;
using ReactiveUI;
namespace Artemis.UI.ViewModels
{
public class MainViewModel : ReactiveObject, IMainViewModel
{
public MainViewModel(IScreen screen, ISidebarViewModel sidebarViewModel)
{
HostScreen = screen;
OpenUrl = ReactiveCommand.CreateFromTask<string>(OpenUrlAsync);
// Add this view as a menu item
sidebarViewModel.MenuItems.Add(this);
}
public IScreen HostScreen { get; }
public string UrlPathSegment => Title.ToLower();
public string Title => "Home";
public string Icon => "Home";
public ReactiveCommand OpenUrl { get; }
private async Task OpenUrlAsync(string url)
{
await Task.Run(() => Process.Start(url));
}
}
public interface IMainViewModel : IArtemisViewModel
{
ReactiveCommand OpenUrl { get; }
}
}
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.UI.ViewModels.Interfaces;
using Stylet;
namespace Artemis.UI.ViewModels
{
public class RootViewModel : Conductor<IArtemisViewModel>.Collection.OneActive
{
public RootViewModel(ICollection<IArtemisViewModel> artemisViewModels)
{
// Add the built-in items
Items.AddRange(artemisViewModels);
// Activate the home item
ActiveItem = artemisViewModels.First(v => v.GetType() == typeof(HomeViewModel));
}
}
}
@@ -1,23 +0,0 @@
using System.Collections.ObjectModel;
using Artemis.UI.ViewModels.Interfaces;
using ReactiveUI;
namespace Artemis.UI.ViewModels
{
public class SidebarViewModel : ReactiveObject, ISidebarViewModel
{
public SidebarViewModel(IScreen screen)
{
HostScreen = screen;
MenuItems = new ObservableCollection<IArtemisViewModel>();
}
public IScreen HostScreen { get; }
public ObservableCollection<IArtemisViewModel> MenuItems { get; set; }
}
public interface ISidebarViewModel
{
ObservableCollection<IArtemisViewModel> MenuItems { get; set; }
}
}