1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-11-02 00:16:07 +00:00

NavigateToLink command

This commit is contained in:
Yan Maniez 2018-08-05 18:51:40 +02:00
parent 2e2aef66c8
commit 2d75cb2c67
6 changed files with 43 additions and 8 deletions

View file

@ -11,10 +11,11 @@
using Extensions; using Extensions;
using Markdig; using Markdig;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
public class MarkdownView : ContentView public class MarkdownView : ContentView
{ {
public Func<string, Task> NavigateToLink { get; set; } = async(s) => Device.OpenUri(new Uri(s)); //public Func<string, Task> NavigateToLink { get; set; } = async(s) => Device.OpenUri(new Uri(s));
public static MarkdownTheme Global = new LightMarkdownTheme(); public static MarkdownTheme Global = new LightMarkdownTheme();
@ -42,6 +43,17 @@
public static readonly BindableProperty ThemeProperty = BindableProperty.Create(nameof(Theme), typeof(MarkdownTheme), typeof(MarkdownView), Global, propertyChanged: OnMarkdownChanged); public static readonly BindableProperty ThemeProperty = BindableProperty.Create(nameof(Theme), typeof(MarkdownTheme), typeof(MarkdownView), Global, propertyChanged: OnMarkdownChanged);
public ICommand NavigateToLinkCommand
{
get { return (ICommand)GetValue(NavigateToLinkCommandProperty); }
set { SetValue(NavigateToLinkCommandProperty, value); }
}
public static readonly BindableProperty NavigateToLinkCommandProperty = BindableProperty.Create(nameof(NavigateToLinkCommand), typeof(ICommand), typeof(MarkdownView)); //, Global, propertyChanged: OnMarkdownChanged);
private bool isQuoted; private bool isQuoted;
private List<View> queuedViews = new List<View>(); private List<View> queuedViews = new List<View>();
@ -101,11 +113,13 @@
{ {
var result = await Application.Current.MainPage.DisplayActionSheet("Ouvrir le lien", "Annuler", null, blockLinks.Select(x => x.Key).ToArray()); var result = await Application.Current.MainPage.DisplayActionSheet("Ouvrir le lien", "Annuler", null, blockLinks.Select(x => x.Key).ToArray());
var link = blockLinks.FirstOrDefault(x => x.Key == result); var link = blockLinks.FirstOrDefault(x => x.Key == result);
await NavigateToLink(link.Value); //await NavigateToLink(link.Value);
NavigateToLinkCommand?.Execute(link.Value);
} }
else else
{ {
await NavigateToLink(blockLinks.First().Value); //await NavigateToLink(blockLinks.First().Value);
NavigateToLinkCommand?.Execute(blockLinks.First().Value);
} }
} }
catch (Exception) { } catch (Exception) { }

View file

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms; using Xamarin.Forms;
namespace AideDeJeu.ViewModels namespace AideDeJeu.ViewModels
@ -52,6 +53,14 @@ namespace AideDeJeu.ViewModels
await Navigation.PushAsync(new FilteredItemsPage(itemsVM)); await Navigation.PushAsync(new FilteredItemsPage(itemsVM));
} }
private ICommand _NavigateToLinkCommand = null;
public ICommand NavigateToLinkCommand
{
get
{
return _NavigateToLinkCommand ?? (_NavigateToLinkCommand = new Command<string>(async(s) => await NavigateToLinkAsync(s)));
}
}
public async Task NavigateToLinkAsync(string s) public async Task NavigateToLinkAsync(string s)
{ {

View file

@ -4,7 +4,8 @@
xmlns:tools="clr-namespace:AideDeJeu.Tools" xmlns:tools="clr-namespace:AideDeJeu.Tools"
xmlns:mdview="clr-namespace:Xam.Forms.Markdown" xmlns:mdview="clr-namespace:Xam.Forms.Markdown"
x:Class="AideDeJeu.Views.ItemDetailPage" x:Class="AideDeJeu.Views.ItemDetailPage"
Title="{Binding Title}"> Title="{Binding Title}"
x:Name="This">
<ContentPage.Resources> <ContentPage.Resources>
<ResourceDictionary> <ResourceDictionary>
<tools:MonsterMarkdownTheme x:Key="MonsterMarkdownTheme" /> <tools:MonsterMarkdownTheme x:Key="MonsterMarkdownTheme" />
@ -15,6 +16,11 @@
<ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding Main.AboutCommand}" /> <ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding Main.AboutCommand}" />
</ContentPage.ToolbarItems> </ContentPage.ToolbarItems>
<ScrollView Orientation="Vertical" BackgroundColor="#fdf1dc"> <ScrollView Orientation="Vertical" BackgroundColor="#fdf1dc">
<mdview:MarkdownView x:Name="mdMarkdown" Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding Item.Markdown}" /> <mdview:MarkdownView
x:Name="mdMarkdown"
Theme="{StaticResource MonsterMarkdownTheme}"
Markdown="{Binding Item.Markdown}"
NavigateToLinkCommand="{Binding BindingContext.Main.Navigator.NavigateToLinkCommand, Source={x:Reference This}}"
/>
</ScrollView> </ScrollView>
</ContentPage> </ContentPage>

View file

@ -19,7 +19,8 @@ namespace AideDeJeu.Views
BindingContext = this.viewModel = itemVM; BindingContext = this.viewModel = itemVM;
mdMarkdown.NavigateToLink = async (s) => await viewModel.Main.Navigator.NavigateToLinkAsync(s);
//mdMarkdown.NavigateToLink = async (s) => await viewModel.Main.Navigator.NavigateToLinkAsync(s);
} }
public ItemDetailPage() public ItemDetailPage()

View file

@ -19,7 +19,12 @@
</ContentPage.ToolbarItems> </ContentPage.ToolbarItems>
<ListView BackgroundColor="{StaticResource bgtan}" x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped"> <ListView BackgroundColor="{StaticResource bgtan}" x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped">
<ListView.Header> <ListView.Header>
<mdview:MarkdownView x:Name="mdMarkdown" Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding BindingContext.Items.Header, Source={x:Reference This}}" /> <mdview:MarkdownView
x:Name="mdMarkdown"
Theme="{StaticResource MonsterMarkdownTheme}"
Markdown="{Binding BindingContext.Items.Header, Source={x:Reference This}}"
NavigateToLinkCommand="{Binding BindingContext.Main.Navigation.NavigateToLinkCommand, Source={x:Reference This}}"
/>
</ListView.Header> </ListView.Header>
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>

View file

@ -31,7 +31,7 @@ namespace AideDeJeu.Views
BindingContext = _ItemsViewModel = itemsViewModel; BindingContext = _ItemsViewModel = itemsViewModel;
mdMarkdown.NavigateToLink = async (s) => await itemsViewModel.Main.Navigator.NavigateToLinkAsync(s); //mdMarkdown.NavigateToLink = async (s) => await itemsViewModel.Main.Navigator.NavigateToLinkAsync(s);
} }
public ItemsPage() public ItemsPage()
{ {