#region License
// Разработано: Коротенко Владимиром Николаевичем (Vladimir N. Korotenko)
// email: koroten@ya.ru
// skype:vladimir-korotenko
// https://vkorotenko.ru
// Создано: 08.04.2019 12:20
#endregion
using SpecialForcesDirectory.Models;
using SpecialForcesDirectory.ViewModels;
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace SpecialForcesDirectory.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ItemsPage : ContentPage
{
ItemsViewModel _vm;
public ItemsPage()
{
InitializeComponent();
BindingContext = _vm = new ItemsViewModel();
_vm.ErrorLoadDatAction += () => { DisplayAlert("Ошибка", "Данные не загружены", "ОК"); };
/// Перехватываем сообщение от страницы категорий.
MessagingCenter.Subscribe<GlobalCategoryPage, CategoryItem>(this, "NavSelected", async (obj, ci) =>
{
var newItem = ci as CategoryItem;
await PushPage(ci);
});
}
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
{
var item = args.SelectedItem as CategoryItem;
if (item == null)
return;
item.BackgroundColor = AppColor.SelectedColor;
await PushPage(item);
// Manually deselect categoryItem.
ItemsListView.SelectedItem = null;
item.BackgroundColor = AppColor.NormalColor;
}
private async Task PushPage(CategoryItem item)
{
if (item.IsContent)
{
_vm.IsBusy = true;
var model = new ShowContentViewModel(item);
_vm.IsBusy = false;
await Navigation.PushAsync(new ShowContentPage(model));
}
else
{
await Navigation.PushAsync(new PodcatPage(new PodcatPageViewModel(item)));
}
}
protected override void OnAppearing()
{
App.Height = RootStackLayout.Height;
base.OnAppearing();
if (_vm.Items.Count == 0)
_vm.LoadItemsCommand.Execute(null);
}
private void Button_OnClicked(object sender, EventArgs e)
{
_vm.NoInternet = false;
_vm.LoadItemsCommand.Execute(null);
}
}
}
return option.price * this.calc[option.multiplier]