public NewsLetterCellTemplate()
        {
            var publishLabel = new Label () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.StartAndExpand,
            };
            publishLabel.SetBinding (Label.TextProperty, new Binding ("PublicationDate", converter: new DateConverter ()));

            var nameLabel = new CustomLabel () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                FontAttributes = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions = LayoutOptions.StartAndExpand,
                //LineBreakMode = LineBreakMode.TailTruncation,
            };
            nameLabel.SetBinding (Label.TextProperty, "FileName");

            var descriptionLabel = new CustomLabel () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions = LayoutOptions.StartAndExpand,
                //LineBreakMode = LineBreakMode.TailTruncation,
            };
            descriptionLabel.SetBinding (Label.TextProperty, "Description");

            Device.OnPlatform (iOS: () => {
                nameLabel.LineBreakMode = LineBreakMode.TailTruncation;
                descriptionLabel.LineBreakMode = LineBreakMode.TailTruncation;
            });

            var thumbnailImage = new CachedImage () {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions = LayoutOptions.StartAndExpand,
                HeightRequest = UIConstants.GetThumbnailHeight (),
                WidthRequest = UIConstants.GetThumbnailWidth (),
                BackgroundColor = ColorConstants.SemiOpaqueBackground,

                CacheDuration = TimeSpan.FromDays (30),
                DownsampleHeight = UIConstants.GetThumbnailHeight () - 100,
                RetryCount = 3,
                RetryDelay = 250,
                TransparencyEnabled = false,
                ErrorPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png"),
                LoadingPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png")

            };

            thumbnailImage.SetBinding (CachedImage.SourceProperty, new Binding ("ThumbPath", converter: new NoCacheConverter ()));

            var downloadLabel = new Label () {
                FontSize = (Device.Idiom == TargetIdiom.Phone)
                    ? Device.GetNamedSize (NamedSize.Small, typeof(Label))
                    : Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.StartAndExpand,
            };
            downloadLabel.SetBinding (Label.TextProperty, new Binding ("DownloadDate", converter: new DownloadDateConverter ()));

            //Read Online Button
            var readOnline = new Button () {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromHex ("#006699"),
                TextColor = Color.White,
                HeightRequest = UIConstants.GetButtonHeight (),
                WidthRequest = UIConstants.GetButtonWidth (),
            };
            readOnline.SetBinding (Button.TextProperty, new Binding ("ButtonText"));
            readOnline.SetBinding (Button.CommandParameterProperty, new Binding ("."));

            readOnline.Clicked += (sender, e) => {

                var btn = ((Button)sender);
                var ViewModel = (NewsLetterViewModel)this.Parent.BindingContext;
                var currentItem = (ProductCatalog)btn.CommandParameter;
                var fileItem = ViewModel.Files.ToList ().FirstOrDefault (i => i.Id == currentItem.Id);

                var pdfService = DependencyService.Get<IPdfService> ();
                if (pdfService == null)
                    return;

                if (fileItem.CategoryCode == "newsletter") {
                    pdfService.OpenPDF (LibraryType.NewsLetter, fileItem.FilePath, fileItem.FileName, 0, null);
                } else {
                    pdfService.OpenPDF (LibraryType.All, fileItem.FilePath, fileItem.FileName, 0, null);

                }

            };

            //Download Button
            var download = new Button () {
                Text = Translation.Localize ("DownloadText"),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromHex ("#006699"),
                TextColor = Color.White,
                HeightRequest = UIConstants.GetButtonHeight (),
                WidthRequest = UIConstants.GetButtonWidth (),
            };
            download.SetBinding (Button.TextProperty, new Binding ("DownloadDate", converter: new DownloadTextConverter ()));
            download.SetBinding (Button.CommandParameterProperty, new Binding ("."));

            download.Clicked += async (sender, e) => {

                var btn = ((Button)sender);
                var currentItem = (ProductCatalog)btn.CommandParameter;

                var ViewModel = (NewsLetterViewModel)this.Parent.BindingContext;
                var parent = (NewsletterView)this.ParentView.ParentView.Parent;

                var fileItem = ViewModel.Files.ToList ().FirstOrDefault (i => i.Id == currentItem.Id);
                if (fileItem.DownloadDate == null) {

                    if (GlobalVariables.WifiDownloadOnly) {
                        if (!App.IsWifiReachable ()) {
                            await parent.DisplayAlert ("", GlobalVariables.WifiConnectionOnlyAlert, Translation.Localize ("Ok"));
                            return;
                        }
                    }

                    var textToDisplay =
                        currentItem.MimeType.StartsWith ("mp4")
                        ? Translation.Localize ("DownloadVideoMessage")
                        : Translation.Localize ("DownloadDocumentMessage");

                    var confirm = await parent.DisplayAlert ("", textToDisplay, Translation.Localize ("Yes"), Translation.Localize ("No"));

                    if (confirm) {
                        var pdfService = DependencyService.Get<IDownloadService> ();
                        if (pdfService == null)
                            return;

                        pdfService.DownloadData (fileItem, (string filePath) => {
                            if (filePath != "") {
                                fileItem.FilePath = filePath;
                                fileItem.ThumbPath = filePath.Replace (".pdf", ".jpeg").Replace (".mp4", ".jpeg");
                                if (fileItem.MimeType.StartsWith ("mp4"))
                                    readOnline.Text = Translation.Localize ("PlayOfflineText");
                                else
                                    readOnline.Text = Translation.Localize ("ReadOfflineText");
                                //
                                download.Text = Translation.Localize ("DeleteText");
                                downloadLabel.Text = DateTime.Now.ToString ("d");
                                ViewModel.fileItem = fileItem;
                                ViewModel.InsertDocumentsCommand.Execute (null);
                            }
                        });
                    }
                } else {
                    var textToDisplay = currentItem.MimeType.StartsWith ("mp4")
                        ? Translation.Localize ("DeleteVideoMessage")
                        : Translation.Localize ("DeleteDocumentMessage");
                    var confirm = await parent.DisplayAlert ("", textToDisplay, Translation.Localize ("Yes"), Translation.Localize ("No"));
                    if (confirm) {
                        var deleteService = DependencyService.Get<IDeleteService> ();
                        if (deleteService == null)
                            return;

                        deleteService.DeleteFile (fileItem.FilePath, (bool completed) => {
                            if (completed == true) {

                                if (fileItem.MimeType.StartsWith ("mp4"))
                                    readOnline.Text = Translation.Localize ("PlayOnlineText");
                                else
                                    readOnline.Text = Translation.Localize ("ReadOnlineText");
                                //
                                download.Text = Translation.Localize ("DownloadText");
                                downloadLabel.Text = "";
                                ViewModel.DocFileID = fileItem.Id;
                                ViewModel.DeleteDocumentsCommand.Execute (null);
                            }
                        });
                    }
                }

            };

            Grid details = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Start,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },

                }
            };

            details.Children.Add (publishLabel, 0, 0);
            details.Children.Add (nameLabel, 0, 1);
            details.Children.Add (descriptionLabel, 0, 2);
            details.Children.Add (readOnline, 0, 3);
            details.Children.Add (download, 0, 4);

            Grid leftdetails = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
                }
            };

            leftdetails.Children.Add (thumbnailImage, 0, 0);
            leftdetails.Children.Add (downloadLabel, 0, 1);

            Grid grid = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Center,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = GridLength.Auto },
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
                }
            };
            grid.Children.Add (leftdetails, 0, 0);
            grid.Children.Add (details, 1, 0);

            var frame = new Frame {
                OutlineColor = Color.FromRgba (255, 255, 255, 0.5),
                HasShadow = true,
                HorizontalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromRgba (255, 255, 255, 0.1),
                VerticalOptions = LayoutOptions.StartAndExpand,
                Padding = 5
            };

            Device.OnPlatform (
                iOS: () => {
                    frame.Content = new StackLayout {
                        Padding = 0,
                        Children = {
                            grid
                        }
                    };
                },
                Android: () => {
                    frame.Content = new AbsoluteLayout {
                        Padding = 0,
                        Children = {
                            grid
                        }
                    };
                }
            );
            this.View = frame;
        }
        public DocumentsCellTemplate()
        {
            var publishLabel = new Label () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.StartAndExpand,
            };
            publishLabel.SetBinding (Label.TextProperty, new Binding ("PublicationDate", converter: new DateConverter ()));

            var nameLabel = new CustomLabel () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                FontAttributes = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions = LayoutOptions.StartAndExpand,
            };
            nameLabel.SetBinding (Label.TextProperty, "FileName");

            var descriptionLabel = new CustomLabel2 () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions = LayoutOptions.StartAndExpand,
            };
            descriptionLabel.SetBinding (Label.TextProperty, "Description");

            Device.OnPlatform (iOS: () => {
                nameLabel.LineBreakMode = LineBreakMode.TailTruncation;
                descriptionLabel.LineBreakMode = LineBreakMode.TailTruncation;
            });

            var thumbnailImage = new CachedImage () {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions = LayoutOptions.StartAndExpand,
                HeightRequest = UIConstants.GetThumbnailHeight (),
                WidthRequest = UIConstants.GetThumbnailWidth (),
                BackgroundColor = ColorConstants.SemiOpaqueBackground,

                CacheDuration = TimeSpan.FromDays (30),
                DownsampleHeight = UIConstants.GetThumbnailHeight () - 100,
                RetryCount = 3,
                RetryDelay = 250,
                TransparencyEnabled = false,
                ErrorPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png"),
                LoadingPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png")

            };

            thumbnailImage.SetBinding (CachedImage.SourceProperty, new Binding ("ThumbPath", converter: new NoCacheConverter ()));

            var downloadLabel = new Label () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.StartAndExpand,
            };
            downloadLabel.SetBinding (Label.TextProperty, new Binding ("DownloadDate", converter: new DownloadDateConverter ()));

            //Read Online Button
            var readOnline = new Button () {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromHex ("#006699"),
                TextColor = Color.White,
                HeightRequest = UIConstants.GetButtonHeight (),
                WidthRequest = UIConstants.GetButtonWidth (),
            };

            readOnline.SetBinding (Button.TextProperty, new Binding ("CategoryCode", converter: new OfflineTextConverter ()));
            readOnline.SetBinding (Button.CommandParameterProperty, new Binding ("."));

            readOnline.Clicked += (sender, e) => {

                var btn = ((Button)sender);

                var fileItem = (Downloads)btn.CommandParameter;

                if (fileItem.MimeType.StartsWith ("mp4")) {
                    Device.OnPlatform (
                        iOS: () => {
                            var page = (Page)Activator.CreateInstance (typeof(DownloadViewer), fileItem);
                            this.ParentView.Navigation.PushAsync (page, true);
                        },
                        Android: () => {
                            var page = (Page)Activator.CreateInstance (typeof(AndroidVideoPlayer), fileItem);
                            this.ParentView.Navigation.PushAsync (page, true);
                        }
                    );
                } else {
                    var pdfService = DependencyService.Get<IPdfService> ();
                    if (pdfService == null)
                        return;

                    pdfService.OpenPDF (LibraryType.MyDocuments, fileItem.FilePath, fileItem.FileName, 0, null);
                }

            };

            //Download Button
            var download = new Button () {
                Text = Translation.Localize ("DeleteText"),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromHex ("#006699"),
                TextColor = Color.White,
                HeightRequest = UIConstants.GetButtonHeight (),
                WidthRequest = UIConstants.GetButtonWidth (),
            };
            download.SetBinding (Button.CommandParameterProperty, new Binding ("."));

            download.Clicked += async (sender, e) => {

                var btn = ((Button)sender);
                //download.IsEnabled = false;
                var fileItem = (Downloads)btn.CommandParameter;
                var parent = (MyDocumentsView)this.ParentView.ParentView.Parent;

                var textToDisplay =
                    fileItem.MimeType.StartsWith ("mp4")
                    ? Translation.Localize ("DeleteVideoMessage")
                    : Translation.Localize ("DeleteDocumentMessage");

                var confirm = await parent.DisplayAlert ("", textToDisplay, Translation.Localize ("Yes"), Translation.Localize ("No"));

                if (confirm) {
                    var deleteService = DependencyService.Get<IDeleteService> ();
                    if (deleteService == null)
                        return;

                    deleteService.DeleteFile (fileItem.FilePath, (bool completed) => {
                        if (completed == true) {
                            var ViewModel = (MyDocumentsViewModel)this.Parent.BindingContext;
                            ViewModel.DocFileID = fileItem.Id;
                            ViewModel.DeleteDocumentsCommand.Execute (null);
                        }
                    });

                }
            };

            Grid grid = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Center,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = GridLength.Auto },
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
                }
            };

            Grid details = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Start,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },

                }
            };

            details.Children.Add (publishLabel, 0, 0);
            details.Children.Add (nameLabel, 0, 1);
            details.Children.Add (descriptionLabel, 0, 2);
            details.Children.Add (readOnline, 0, 3);
            details.Children.Add (download, 0, 4);

            Grid leftdetails = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
                }
            };

            leftdetails.Children.Add (thumbnailImage, 0, 0);
            leftdetails.Children.Add (downloadLabel, 0, 1);

            grid.Children.Add (leftdetails, 0, 0);
            grid.Children.Add (details, 1, 0);

            var frame = new Frame {
                OutlineColor = Color.FromRgba (255, 255, 255, 0.5),
                HasShadow = true,
                HorizontalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromRgba (255, 255, 255, 0.1),
                VerticalOptions = LayoutOptions.Center,
                Padding = 5,
            };

            Device.OnPlatform (
                iOS: () => {
                    frame.Content = new StackLayout {
                        Padding = 0,
                        Children = {
                            grid
                        }
                    };
                },
                Android: () => {
                    frame.Content = new AbsoluteLayout {
                        Padding = 0,
                        Children = {
                            grid
                        }
                    };
                }
            );

            this.View = frame;
        }