public ViewerPage(ProductCatalog fileItem)
        {
            NavigationPage.SetHasNavigationBar(this, true);

            //Title = fileItem.Name;

            FileItem = fileItem;

            // rendering of this page is done natively on each platform
        }
        public void DownloadData(ProductCatalog fileItem, Action<string> filePath = null)
        {
            var status = PSPDFStatusHUDItem.GetIndeterminateProgressHud ("Downloading");
            status.Push (true,null);

            var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
            var directoryname = Path.Combine (documents, "Downloads");
            Directory.CreateDirectory (directoryname);

            string localFilename = fileItem.FilePath.Substring (fileItem.FilePath.LastIndexOf ("/") + 1, fileItem.FilePath.Length - 1 - fileItem.FilePath.LastIndexOf ("/"));
            string localfilePath = Path.Combine (directoryname, localFilename);
            string localImagename = fileItem.ThumbPath.Substring (fileItem.ThumbPath.LastIndexOf ("/") + 1, fileItem.ThumbPath.Length - 1 - fileItem.ThumbPath.LastIndexOf ("/"));
            string localimagePath = Path.Combine (directoryname, localImagename);

            var imageClient = new WebClient ();
            imageClient.DownloadFileAsync(NSUrl.FromString (fileItem.ThumbPath), localimagePath);

            var webClient = new WebClient ();
            webClient.DownloadFileAsync (NSUrl.FromString (fileItem.FilePath), localfilePath);

            webClient.DownloadFileCompleted += (s, e) => {
                try {
                    status.Pop(true,null);
                    filePath.Invoke (localFilename);
                    status = null;
                } catch(Exception ex) {
                    new UIAlertView ("Error", "Download Failed", null, "OK", null).Show ();
                }
            };

            webClient.DownloadProgressChanged += (s,e) => {
                status.Progress = (float)e.ProgressPercentage;
            };

            imageClient.DownloadDataCompleted += (s, e) => {

            };
        }
        public DetailsPopup(ProductCatalog item, LibraryType type)
        {
            this.BackgroundImage = ImageConstants.backgroundImage;
            var thumb = new Image {
                WidthRequest = 150,
                HeightRequest = 200,
                Source = GetSource (item.ThumbPath),
                BackgroundColor = ColorConstants.SemiOpaqueBackground

            };

            downloadlabel =
                new Label {
                Text = item.DownloadDate == null ? "" : string.Format ("{0}", ((DateTime)item.DownloadDate).ToString ("d")),
                FontSize = (Device.Idiom == TargetIdiom.Phone)
                            ? Device.GetNamedSize (NamedSize.Small, typeof(Label))
                            : Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                TextColor = Color.White,
            };

            var publishedlabel = new StackLayout {
                HorizontalOptions = LayoutOptions.Start,
                //Padding = 20,
                Orientation = StackOrientation.Vertical,
                Children = {
                    new CustomLabel {
                        Text = "Publication Date:",
                        FontSize = (Device.Idiom == TargetIdiom.Phone)
                            ? Device.GetNamedSize (NamedSize.Small, typeof(Label))
                            : Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                        TextColor = Color.White,
                        FontAttributes = FontAttributes.Italic,
                    },
                    new CustomLabel {
                        Text = item.PublicationDate == null ? "" : string.Format ("{0}", ((DateTime)item.PublicationDate).ToString ("d")),
                        FontSize = (Device.Idiom == TargetIdiom.Phone)
                            ? Device.GetNamedSize (NamedSize.Small, typeof(Label))
                            : Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                        TextColor = Color.White,
                        FontAttributes = FontAttributes.Bold,
                    },
                }
            };

            var namelabel = new StackLayout {
                HorizontalOptions = LayoutOptions.Start,
                //Padding = 20,
                Orientation = StackOrientation.Vertical,
                Children = {
                    new CustomLabel {
                        Text = "File Name:",
                        FontSize = (Device.Idiom == TargetIdiom.Phone)
                            ? Device.GetNamedSize (NamedSize.Small, typeof(Label))
                            : Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                        TextColor = Color.White,
                        FontAttributes = FontAttributes.Italic,
                    },
                    new CustomLabel {
                        Text = item.FileName,
                        FontSize = (Device.Idiom == TargetIdiom.Phone)
                            ? Device.GetNamedSize (NamedSize.Small, typeof(Label))
                            : Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                        TextColor = Color.White,
                        FontAttributes = FontAttributes.Bold,
                    },
                }
            };

            var description = new StackLayout {
                HorizontalOptions = LayoutOptions.Start,
                //Padding = 20,
                Orientation = StackOrientation.Vertical,
                Children = {
                    new CustomLabel {
                        Text = "Description:",
                        FontSize = (Device.Idiom == TargetIdiom.Phone)
                            ? Device.GetNamedSize (NamedSize.Small, typeof(Label))
                            : Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                        TextColor = Color.White,
                        FontAttributes = FontAttributes.Italic,
                    },
                    new CustomLabel {
                        Text = item.Description,
                        FontSize = (Device.Idiom == TargetIdiom.Phone)
                            ? Device.GetNamedSize (NamedSize.Small, typeof(Label))
                            : Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                        TextColor = Color.White,
                        FontAttributes = FontAttributes.Bold,
                    },
                }
            };

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

            var download = new Button () {

                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromHex ("#006699"),
                TextColor = Color.White,
                HeightRequest = 40,
                WidthRequest = 140,
            };

            if (item.DownloadDate == null) {
                if (item.MimeType.StartsWith ("mp4")) {
                    readOnline.Text = Translation.Localize ("PlayOnlineText");
                } else {
                    readOnline.Text = Translation.Localize ("ReadOnlineText");
                }
                download.Text = Translation.Localize ("DownloadText");
            } else {
                if (item.MimeType.StartsWith ("mp4")) {
                    readOnline.Text = Translation.Localize ("PlayOfflineText");
                } else {
                    readOnline.Text = Translation.Localize ("ReadOfflineText");
                }
                download.Text = Translation.Localize ("DeleteText");
            }

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

                var btn = ((Button)sender);

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

                if (item.MimeType.StartsWith ("mp4")) {
                    var page = (Page)Activator.CreateInstance (typeof(VideoView), item);
                    this.ParentView.Navigation.PushAsync (page, true);
                } else {

                    pdfService.OpenPDF (type, item.FilePath, item.FileName, 0, null);
                }

            };

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

                var currentitem = db.GetCatalogsByID (item.Id);

                if (currentitem.DownloadDate == null) {

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

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

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

                    if (confirm) {

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

                        pdfService.DownloadData (currentitem, (string filePath) => {
                            if (filePath != "") {

                                currentitem.FilePath = filePath;
                                currentitem.ThumbPath = filePath.Replace (".pdf", ".jpeg").Replace (".mp4", ".jpeg");
                                db.InsertDownloadItem (currentitem);
                                if (currentitem.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");
                            }
                        });
                    }
                } else {

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

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

                    if (confirm) {

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

                        deleteService.DeleteFile (currentitem.FilePath, (bool completed) => {
                            if (completed == true) {
                                db.DeleteDownloadItem (currentitem.Id);
                                if (item.MimeType.StartsWith ("mp4"))
                                    readOnline.Text = Translation.Localize ("PlayOnlineText");
                                else
                                    readOnline.Text = Translation.Localize ("ReadOnlineText");

                                download.Text = Translation.Localize ("DownloadText");

                                downloadlabel.Text = "";
                            }
                        });
                    }
                }

            };

            var leftheader = new StackLayout {
                HorizontalOptions = LayoutOptions.Start,
                Orientation = StackOrientation.Vertical,
                Children = {
                    thumb,
                    downloadlabel,
                }
            };

            var rightheader = new StackLayout {
                HorizontalOptions = LayoutOptions.Center,
                Orientation = StackOrientation.Vertical,
                Padding = new Thickness (0, 10, 0, 20),
                Children = {
                    //publicationlabel,
                    readOnline,
                    download
                }
            };

            var headerView = new StackLayout {
                Padding = 10,
                HorizontalOptions = LayoutOptions.Start,
                Orientation = StackOrientation.Horizontal,
                Children = {
                    leftheader,
                    rightheader,
                }
            };

            var detailsView = new StackLayout {
                Padding = 10,
                HorizontalOptions = LayoutOptions.Start,
                Orientation = StackOrientation.Vertical,
                Children = {
                    publishedlabel, namelabel, description
                }
            };

            scrollView = new ScrollView ();
            scrollView.Content = new StackLayout {
                BackgroundColor = Color.FromRgba (255, 255, 255, 0.1),
                Padding = 0,
                Children = { headerView, detailsView }
            };

            Content = scrollView;
        }
 public VideoView(ProductCatalog fileItem)
 {
     NavigationPage.SetHasNavigationBar(this, false);
     FileItem = fileItem;
 }
 public void InsertDownloadItem(ProductCatalog download)
 {
     var item = new Downloads {
         Id = download.Id,
         ProductID = download.ProductID,
         AppCode = download.AppCode,
         CategoryCode = download.CategoryCode,
         Language = download.Language,
         FileName = download.FileName,
         Description = download.Description,
         MimeType = download.MimeType,
         PublicationDate = download.PublicationDate,
         FilePath = download.FilePath,
         ThumbPath = download.ThumbPath,
         DownloadDate = DateTime.Now,
         SearchKeywords = download.SearchKeywords,
     };
     _connection.Insert (item);
 }
        public AndroidVideoPlayer(ProductCatalog fileItem)
        {
            player = new VideoPlayerView ();
            NavigationPage.SetBackButtonTitle (this, Translation.Localize ("BackButton"));
            //			this.ToolbarItems.Add (new ToolbarItem {
            //				Order = ToolbarItemOrder.Secondary,
            //				Text = "Controller",
            //				Command = new Command( () => {
            //					this.player.VideoPlayer.AddVideoController = !this.player.VideoPlayer.AddVideoController;
            //				})
            //			});
            //
            //			this.ToolbarItems.Add (new ToolbarItem {
            //				Order = ToolbarItemOrder.Secondary,
            //				Text = "Full Screen",
            //				Command = new Command( () => {
            //
            //					// resize the Content for full screen mode
            //					this.player.VideoPlayer.FullScreen = !this.player.VideoPlayer.FullScreen;
            //					if (this.player.VideoPlayer.FullScreen)
            //					{
            //						this.player.HeightRequest = -1;
            //						this.Content.VerticalOptions = LayoutOptions.FillAndExpand;
            //						player.VideoPlayer.FullScreen = true;
            //					}
            //					else
            //					{
            //						this.player.HeightRequest = 200;
            //						this.Content.VerticalOptions = LayoutOptions.StartAndExpand;
            //						player.VideoPlayer.FullScreen = false;
            //					}
            //				})
            //			});
            //
            //			this.ToolbarItems.Add (new ToolbarItem {
            //				Order = ToolbarItemOrder.Secondary,
            //				Text = "Play",
            //				Command = new Command( () => {
            //					this.player.VideoPlayer.PlayerAction = VideoState.PLAY;
            //				})
            //			});
            //
            //			this.ToolbarItems.Add (new ToolbarItem {
            //				Order = ToolbarItemOrder.Secondary,
            //				Text = "Stop",
            //				Command = new Command( () => {
            //					this.player.VideoPlayer.PlayerAction = VideoState.STOP;
            //				})
            //			});
            //
            //			this.ToolbarItems.Add (new ToolbarItem {
            //				Order = ToolbarItemOrder.Secondary,
            //				Text = "Pause",
            //				Command = new Command( () => {
            //					this.player.VideoPlayer.PlayerAction = VideoState.PAUSE;
            //				})
            //			});
            //
            //			this.ToolbarItems.Add (new ToolbarItem {
            //				Order = ToolbarItemOrder.Secondary,
            //				Text = "Restart",
            //				Command = new Command( () => {
            //					this.player.VideoPlayer.PlayerAction = VideoState.RESTART;
            //				})
            //			});

            //			// heightRequest must be set it not full screen
            //			player.HeightRequest = 200;
            //			player.VideoPlayer.AddVideoController = false;

            this.player.HeightRequest = (App.ScreenHeight - 100) / 2;
            //this.Content.VerticalOptions = LayoutOptions.FillAndExpand;
            player.VideoPlayer.FullScreen = false;
            player.VideoPlayer.AddVideoController = true;

            // location in Assets folder.  file marked as Asset, NOT Resource
            player.VideoPlayer.FileSource = fileItem.FilePath;

            // autoplay video
            player.VideoPlayer.AutoPlay = true;

            //			TapGestureRecognizer tapAutoHide = new TapGestureRecognizer ();
            //			tapAutoHide.Tapped += (sender, args) => {
            //				this.player.VideoPlayer.ActionBarHide = !this.player.VideoPlayer.ActionBarHide;
            //			};
            //			player.VideoPlayer.GestureRecognizers.Add (tapAutoHide);

            this.Content = new StackLayout {
                VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    player
                }
            };
        }