summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/AppLinkPageGallery.cs
blob: bc765dd965ad3d81f8f604be56975d9aaa66ea0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;

namespace Xamarin.Forms.Controls
{
	public class AppLinkPageGallery  : ContentPage
	{
		public AppLinkPageGallery ()
		{
			_linkEntry = GetEntry ();
			_lbl = new Label {
				Text = "You are on a demo page via app url", IsVisible = ShowLabel 
			};

			var btnRegister = new Button { Text = "Index this Page", 
				Command = new Command (() => Application.Current.AppLinks.RegisterLink (LinkEntry))
			};
			var btnRemove = new Button { Text = "Remove this Page from index", 
				Command = new Command (() => Application.Current.AppLinks.DeregisterLink (LinkEntry))
			};

			var btnClearAll = new Button { Text = "Clear All Indexed Data", 
			//	Command = new Command (() => Application.Current.AppLinks.DeregisterAll ())
			};

			Content = new StackLayout { Children = { _lbl, btnRegister, btnRemove, btnClearAll } };
		}

		protected override void OnAppearing ()
		{
			LinkEntry.IsLinkActive = true;
		}

		protected override void OnDisappearing ()
		{
			LinkEntry.IsLinkActive = false;
		}

		public bool ShowLabel {
			get { 
				return _showlabel;
			}
			set { 
				_showlabel = value;
				_lbl.IsVisible = _showlabel;
			}
		}

		internal IAppLinkEntry LinkEntry {
			get { 
				return _linkEntry;
			}
		}

		bool _showlabel;
		IAppLinkEntry _linkEntry;
		Label _lbl;

		AppLinkEntry GetEntry ()
		{
			if (string.IsNullOrEmpty (Title))
				Title = "App Link Page Gallery";
	
			var type = GetType ().ToString ();
			var entry = new AppLinkEntry {
				Title = Title,
				Description =$"This is the page {Title} \nof Xamarin Forms Gallery",
				AppLinkUri = new Uri ($"http://{App.AppName}/gallery/{type}", UriKind.RelativeOrAbsolute),
				IsLinkActive = true,
				Thumbnail = ImageSource.FromFile ("seth.png")
			};

			entry.KeyValues.Add ("contentType", "GalleryPage");
			entry.KeyValues.Add ("appName",  App.AppName);
			entry.KeyValues.Add ("companyName", "Xamarin");

			return entry;
		}
	}
}