mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 14:35:45 +00:00
Nettoyage, suppression d'une couche dans le MVVM
This commit is contained in:
parent
fc19a60f70
commit
1585525519
24 changed files with 28 additions and 581 deletions
|
|
@ -50,7 +50,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.1.444934" />
|
||||
<PackageReference Include="Xamarin.Android.Support.Design" Version="25.4.0.2" />
|
||||
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="25.4.0.2" />
|
||||
<PackageReference Include="Xamarin.Android.Support.v4" Version="25.4.0.2" />
|
||||
|
|
|
|||
|
|
@ -165,8 +165,8 @@
|
|||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.0.1" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.1.444934" />
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AideDeJeu\AideDeJeu.csproj">
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@
|
|||
<Reference Include="Xamarin.iOS" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.1.444934" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BundleResource Include="Resources\tab_about.png" />
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.1.444934" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -32,19 +32,15 @@
|
|||
<Compile Update="Views\SpellDetailPage.xaml.cs">
|
||||
<DependentUpon>SpellDetailPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Views\ItemDetailPage.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="Views\ItemsPage.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="Views\SpellsPage.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
<DependentUpon>SpellsPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Views\NewItemPage.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace AideDeJeu.Models
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Text { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AideDeJeu.Services
|
||||
{
|
||||
public interface IDataStore<T>
|
||||
{
|
||||
Task<bool> AddItemAsync(T item);
|
||||
Task<bool> UpdateItemAsync(T item);
|
||||
Task<bool> DeleteItemAsync(T item);
|
||||
Task<T> GetItemAsync(string id);
|
||||
Task<IEnumerable<T>> GetItemsAsync(bool forceRefresh = false);
|
||||
Task<IEnumerable<T>> GetItemsAsync(string classe, int niveauMin, int niveauMax, string ecole, string rituel, string source);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Spells;
|
||||
|
||||
[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.Services.MockDataStore))]
|
||||
namespace AideDeJeu.Services
|
||||
{
|
||||
public class MockDataStore : IDataStore<Item>
|
||||
{
|
||||
List<Item> items;
|
||||
|
||||
public MockDataStore()
|
||||
{
|
||||
items = new List<Item>();
|
||||
var mockItems = new List<Item>
|
||||
{
|
||||
new Item { Id = Guid.NewGuid().ToString(), Text = "First item", Description="This is an item description." },
|
||||
new Item { Id = Guid.NewGuid().ToString(), Text = "Second item", Description="This is an item description." },
|
||||
new Item { Id = Guid.NewGuid().ToString(), Text = "Third item", Description="This is an item description." },
|
||||
new Item { Id = Guid.NewGuid().ToString(), Text = "Fourth item", Description="This is an item description." },
|
||||
new Item { Id = Guid.NewGuid().ToString(), Text = "Fifth item", Description="This is an item description." },
|
||||
new Item { Id = Guid.NewGuid().ToString(), Text = "Sixth item", Description="This is an item description." },
|
||||
};
|
||||
|
||||
foreach (var item in mockItems)
|
||||
{
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> AddItemAsync(Item item)
|
||||
{
|
||||
items.Add(item);
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateItemAsync(Item item)
|
||||
{
|
||||
var _item = items.Where((Item arg) => arg.Id == item.Id).FirstOrDefault();
|
||||
items.Remove(_item);
|
||||
items.Add(item);
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteItemAsync(Item item)
|
||||
{
|
||||
var _item = items.Where((Item arg) => arg.Id == item.Id).FirstOrDefault();
|
||||
items.Remove(_item);
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task<Item> GetItemAsync(string id)
|
||||
{
|
||||
return await Task.FromResult(items.FirstOrDefault(s => s.Id == id));
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Item>> GetItemsAsync(bool forceRefresh = false)
|
||||
{
|
||||
var scrapper = new SpellsScrappers();
|
||||
var spells = await scrapper.GetSpells(await scrapper.GetSpellIds("c"));
|
||||
items = spells.Select(spell => new Item() { Text = spell.Title, Description = spell.DescriptionText }).ToList();
|
||||
return await Task.FromResult(items);
|
||||
}
|
||||
public async Task<IEnumerable<Item>> GetItemsAsync(string classe, int minLevel, int maxLevel, string ecole, string rituel, string source)
|
||||
{
|
||||
return await GetItemsAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
|
||||
[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.Services.SpellDataStore))]
|
||||
namespace AideDeJeu.Services
|
||||
{
|
||||
//public class MonsterDataStore : IDataStore<Monster>
|
||||
//{
|
||||
// List<Spell> items;
|
||||
|
||||
// public MonsterDataStore()
|
||||
// {
|
||||
// items = new List<Spell>();
|
||||
// var mockItems = new List<Spell>
|
||||
// {
|
||||
// };
|
||||
|
||||
// foreach (var item in mockItems)
|
||||
// {
|
||||
// items.Add(item);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public async Task<bool> AddItemAsync(Spell item)
|
||||
// {
|
||||
// items.Add(item);
|
||||
|
||||
// return await Task.FromResult(true);
|
||||
// }
|
||||
|
||||
// public async Task<bool> UpdateItemAsync(Spell item)
|
||||
// {
|
||||
// var _item = items.Where((Spell arg) => arg.Id == item.Id).FirstOrDefault();
|
||||
// items.Remove(_item);
|
||||
// items.Add(item);
|
||||
|
||||
// return await Task.FromResult(true);
|
||||
// }
|
||||
|
||||
// public async Task<bool> DeleteItemAsync(Spell item)
|
||||
// {
|
||||
// var _item = items.Where((Spell arg) => arg.Id == item.Id).FirstOrDefault();
|
||||
// items.Remove(_item);
|
||||
|
||||
// return await Task.FromResult(true);
|
||||
// }
|
||||
|
||||
// public async Task<Spell> GetItemAsync(string id)
|
||||
// {
|
||||
// return await Task.FromResult(items.FirstOrDefault(s => s.Id == id));
|
||||
// }
|
||||
|
||||
// public async Task<IEnumerable<Monster>> GetItemsAsync(bool forceRefresh = false)
|
||||
// {
|
||||
// var scrapper = new MonstersScrappers();
|
||||
// //items = (await scrapper.GetSpells(await scrapper.GetSpellIds(""))).ToList();
|
||||
// items = (await scrapper.GetMonsters()).ToList();
|
||||
|
||||
// //items = spells.Select(spell => new Item() { Text = spell.Title, Description = spell.DescriptionText }).ToList();
|
||||
// return await Task.FromResult(items);
|
||||
// }
|
||||
|
||||
// public async Task<IEnumerable<Monster>> GetItemsAsync(string classe, int niveauMin, int niveauMax, string ecole, string rituel, string source)
|
||||
// {
|
||||
// var scrapper = new MonstersScrappers();
|
||||
// items = (await scrapper.GetMonsters(classe: classe, niveauMin: niveauMin, niveauMax: niveauMax, ecole: ecole, rituel: rituel, source: source)).ToList();
|
||||
|
||||
// return await Task.FromResult(items);
|
||||
// }
|
||||
|
||||
//}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Spells;
|
||||
|
||||
[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.Services.SpellDataStore))]
|
||||
namespace AideDeJeu.Services
|
||||
{
|
||||
public class SpellDataStore : IDataStore<Spell>
|
||||
{
|
||||
List<Spell> items;
|
||||
|
||||
public SpellDataStore()
|
||||
{
|
||||
items = new List<Spell>();
|
||||
var mockItems = new List<Spell>
|
||||
{
|
||||
};
|
||||
|
||||
foreach (var item in mockItems)
|
||||
{
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> AddItemAsync(Spell item)
|
||||
{
|
||||
items.Add(item);
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateItemAsync(Spell item)
|
||||
{
|
||||
var _item = items.Where((Spell arg) => arg.Id == item.Id).FirstOrDefault();
|
||||
items.Remove(_item);
|
||||
items.Add(item);
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteItemAsync(Spell item)
|
||||
{
|
||||
var _item = items.Where((Spell arg) => arg.Id == item.Id).FirstOrDefault();
|
||||
items.Remove(_item);
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task<Spell> GetItemAsync(string id)
|
||||
{
|
||||
return await Task.FromResult(items.FirstOrDefault(s => s.Id == id));
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Spell>> GetItemsAsync(bool forceRefresh = false)
|
||||
{
|
||||
var scrapper = new SpellsScrappers();
|
||||
//items = (await scrapper.GetSpells(await scrapper.GetSpellIds(""))).ToList();
|
||||
items = (await scrapper.GetSpells()).ToList();
|
||||
|
||||
//items = spells.Select(spell => new Item() { Text = spell.Title, Description = spell.DescriptionText }).ToList();
|
||||
return await Task.FromResult(items);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Spell>> GetItemsAsync(string classe, int niveauMin, int niveauMax, string ecole, string rituel, string source)
|
||||
{
|
||||
var scrapper = new SpellsScrappers();
|
||||
items = (await scrapper.GetSpells(classe: classe, niveauMin: niveauMin, niveauMax: niveauMax, ecole: ecole, rituel: rituel, source: source)).ToList();
|
||||
|
||||
return await Task.FromResult(items);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -5,17 +5,17 @@ using System.Runtime.CompilerServices;
|
|||
|
||||
using Xamarin.Forms;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeu.Services;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Spells;
|
||||
using AideDeJeuLib.Monsters;
|
||||
|
||||
namespace AideDeJeu.ViewModels
|
||||
{
|
||||
public class BaseViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public IDataStore<Item> DataStore => DependencyService.Get<IDataStore<Item>>() ?? new MockDataStore();
|
||||
public IDataStore<Spell> SpellDataStore => DependencyService.Get<IDataStore<Spell>>() ?? new SpellDataStore();
|
||||
//public IDataStore<Item> DataStore => DependencyService.Get<IDataStore<Item>>() ?? new MockDataStore();
|
||||
//public IDataStore<Spell> SpellDataStore => DependencyService.Get<IDataStore<Spell>>() ?? new SpellDataStore();
|
||||
public SpellsScrappers SpellsScrappers => DependencyService.Get<SpellsScrappers>() ?? new SpellsScrappers();
|
||||
public MonstersScrappers MonsterScrappers => DependencyService.Get<MonstersScrappers>() ?? new MonstersScrappers();
|
||||
|
||||
bool isBusy = false;
|
||||
public bool IsBusy
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
using System;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
|
||||
namespace AideDeJeu.ViewModels
|
||||
{
|
||||
public class ItemDetailViewModel : BaseViewModel
|
||||
{
|
||||
public Item Item { get; set; }
|
||||
public ItemDetailViewModel(Item item = null)
|
||||
{
|
||||
Title = item?.Text;
|
||||
Item = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Xamarin.Forms;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeu.Views;
|
||||
|
||||
namespace AideDeJeu.ViewModels
|
||||
{
|
||||
public class ItemsViewModel : BaseViewModel
|
||||
{
|
||||
public ObservableCollection<Item> Items { get; set; }
|
||||
public Command LoadItemsCommand { get; set; }
|
||||
|
||||
public ItemsViewModel()
|
||||
{
|
||||
Title = "Browse";
|
||||
Items = new ObservableCollection<Item>();
|
||||
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
|
||||
|
||||
MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
|
||||
{
|
||||
var _item = item as Item;
|
||||
Items.Add(_item);
|
||||
await DataStore.AddItemAsync(_item);
|
||||
});
|
||||
}
|
||||
|
||||
async Task ExecuteLoadItemsCommand()
|
||||
{
|
||||
if (IsBusy)
|
||||
return;
|
||||
|
||||
IsBusy = true;
|
||||
|
||||
try
|
||||
{
|
||||
Items.Clear();
|
||||
var items = await DataStore.GetItemsAsync(true);
|
||||
foreach (var item in items)
|
||||
{
|
||||
Items.Add(item);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,10 +5,6 @@ using System.Threading.Tasks;
|
|||
|
||||
using Xamarin.Forms;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeu.Views;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System.Collections.Generic;
|
||||
using AideDeJeuLib.Monsters;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@ using System.Threading.Tasks;
|
|||
|
||||
using Xamarin.Forms;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeu.Views;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
@ -194,7 +191,7 @@ namespace AideDeJeu.ViewModels
|
|||
//<option value="k">Sorcier</option>
|
||||
|
||||
Items.Clear();
|
||||
var items = await SpellDataStore.GetItemsAsync(classe: Classes[Classe].Key, niveauMin: NiveauMin, niveauMax: NiveauMax, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
|
||||
var items = await SpellsScrappers.GetSpells(classe: Classes[Classe].Key, niveauMin: NiveauMin, niveauMax: NiveauMax, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
|
||||
foreach (var item in items)
|
||||
{
|
||||
Items.Add(item);
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="AideDeJeu.Views.ItemDetailPage"
|
||||
Title="{Binding Title}">
|
||||
<StackLayout Spacing="20" Padding="15">
|
||||
<Label Text="{Binding Item.Text}" Style="{StaticResource Key=section}" />
|
||||
<Label Text="{Binding Item.Description}" Style="{StaticResource Key=subsection}" />
|
||||
</StackLayout>
|
||||
</ContentPage>
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeu.ViewModels;
|
||||
|
||||
namespace AideDeJeu.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class ItemDetailPage : ContentPage
|
||||
{
|
||||
ItemDetailViewModel viewModel;
|
||||
|
||||
public ItemDetailPage(ItemDetailViewModel viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = this.viewModel = viewModel;
|
||||
}
|
||||
|
||||
public ItemDetailPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var item = new Item
|
||||
{
|
||||
Text = "Item 1",
|
||||
Description = "This is an item description."
|
||||
};
|
||||
|
||||
viewModel = new ItemDetailViewModel(item);
|
||||
BindingContext = viewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="AideDeJeu.Views.ItemsPage"
|
||||
Title="{Binding Title}"
|
||||
x:Name="BrowseItemsPage">
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Text="Add" Clicked="AddItem_Clicked" />
|
||||
</ContentPage.ToolbarItems>
|
||||
<ContentPage.Content>
|
||||
<StackLayout>
|
||||
<ListView x:Name="ItemsListView"
|
||||
ItemsSource="{Binding Items}"
|
||||
VerticalOptions="FillAndExpand"
|
||||
HasUnevenRows="true"
|
||||
RefreshCommand="{Binding LoadItemsCommand}"
|
||||
IsPullToRefreshEnabled="true"
|
||||
IsRefreshing="{Binding IsBusy, Mode=OneWay}"
|
||||
CachingStrategy="RecycleElement"
|
||||
ItemSelected="OnItemSelected">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<StackLayout Padding="10">
|
||||
<Label Text="{Binding Text}"
|
||||
LineBreakMode="NoWrap"
|
||||
Style="{DynamicResource ListItemTextStyle}"
|
||||
FontSize="16" />
|
||||
<Label Text="{Binding Description}"
|
||||
LineBreakMode="NoWrap"
|
||||
Style="{DynamicResource ListItemDetailTextStyle}"
|
||||
FontSize="13" />
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeu.Views;
|
||||
using AideDeJeu.ViewModels;
|
||||
|
||||
namespace AideDeJeu.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class ItemsPage : ContentPage
|
||||
{
|
||||
ItemsViewModel viewModel;
|
||||
|
||||
public ItemsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = viewModel = new ItemsViewModel();
|
||||
}
|
||||
|
||||
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
|
||||
{
|
||||
var item = args.SelectedItem as Item;
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
await Navigation.PushAsync(new ItemDetailPage(new ItemDetailViewModel(item)));
|
||||
|
||||
// Manually deselect item.
|
||||
ItemsListView.SelectedItem = null;
|
||||
}
|
||||
|
||||
async void AddItem_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
await Navigation.PushModalAsync(new NavigationPage(new NewItemPage()));
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
if (viewModel.Items.Count == 0)
|
||||
viewModel.LoadItemsCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,12 @@
|
|||
using System;
|
||||
|
||||
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Spells;
|
||||
using AideDeJeuLib.Monsters;
|
||||
|
||||
namespace AideDeJeu.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class MonsterDetailPage : ContentPage
|
||||
{
|
||||
MonsterDetailViewModel viewModel;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
using AideDeJeu.Models;
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System;
|
||||
|
||||
using Xamarin.Forms;
|
||||
|
|
@ -10,7 +7,7 @@ using Xamarin.Forms.Xaml;
|
|||
|
||||
namespace AideDeJeu.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class MonstersPage : MasterDetailPage //TabbedPage
|
||||
{
|
||||
MonstersViewModel viewModel;
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="AideDeJeu.Views.NewItemPage"
|
||||
Title="New Item">
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Text="Save" Clicked="Save_Clicked" />
|
||||
</ContentPage.ToolbarItems>
|
||||
<ContentPage.Content>
|
||||
<StackLayout Spacing="20" Padding="15">
|
||||
<Label Text="Text" FontSize="Medium" />
|
||||
<Entry Text="{Binding Item.Text}" FontSize="Small" />
|
||||
<Label Text="Description" FontSize="Medium" />
|
||||
<Editor Text="{Binding Item.Description}" FontSize="Small" Margin="0" />
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
|
||||
namespace AideDeJeu.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class NewItemPage : ContentPage
|
||||
{
|
||||
public Item Item { get; set; }
|
||||
|
||||
public NewItemPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Item = new Item
|
||||
{
|
||||
Text = "Item name",
|
||||
Description = "This is an item description."
|
||||
};
|
||||
|
||||
BindingContext = this;
|
||||
}
|
||||
|
||||
async void Save_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
MessagingCenter.Send(this, "AddItem", Item);
|
||||
await Navigation.PopModalAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,12 @@
|
|||
using System;
|
||||
|
||||
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib.Spells;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using AideDeJeu.Models;
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Spells;
|
||||
|
||||
namespace AideDeJeu.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class SpellDetailPage : ContentPage
|
||||
{
|
||||
SpellDetailViewModel viewModel;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using AideDeJeu.Models;
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System;
|
||||
|
||||
|
|
@ -9,7 +7,7 @@ using Xamarin.Forms.Xaml;
|
|||
|
||||
namespace AideDeJeu.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class SpellsPage : MasterDetailPage //TabbedPage
|
||||
{
|
||||
SpellsViewModel viewModel;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue