Beispiel #1
0
 /// <summary>
 /// Confirms the cancel download.
 /// Invoked when user click confirm button of cancel download alert view
 /// </summary>
 /// <param name="publication">Publication.</param>
 /// <param name="publicationView">Publication view.</param>
 private void ConfirmCancelDownload(Publication publication, PublicationView publicationView)
 {
     publicationView.DownloadCancelTokenSource.Cancel();
     //UpdatePublicationViewInScrollView (publication, publicationView);
     publicationView.P = publication;
     //ShowAlert ("Download Failed");
 }
Beispiel #2
0
        /// <summary>
        /// Shows the confirm cancel download.
        /// When user click download progress view
        /// </summary>
        /// <param name="publication">Publication.</param>
        /// <param name="publicationView">Publication view.</param>
        private void ShowConfirmCancelDownload(Publication publication, PublicationView publicationView)
        {
            var confirmCancelDownload = UIAlertController.Create("Cancel Download", "Are you sure you want to cancel the download of this LexisNexis Red publication?", UIAlertControllerStyle.Alert);

            confirmCancelDownload.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
            confirmCancelDownload.AddAction(UIAlertAction.Create("Confirm", UIAlertActionStyle.Default, alert => ConfirmCancelDownload(publication, publicationView)));

            PresentViewController(confirmCancelDownload, true, null);
        }
Beispiel #3
0
        public static PublicationView CreatePublicationView(Publication publication, DoPublicationDownload startDownload, ShowAlert cancelDownloadAlert, float zoomRate = 1.0f)
        {
            PublicationView publicationView = new PublicationView();

            publicationView.ZoomRate          = zoomRate;
            publicationView.StartDownload     = startDownload;
            publicationView.ShowDownloadAlert = cancelDownloadAlert;

            PublicationCover cover = CreatePublicationCover(publication);

            publicationView.AddCover(cover);
            publicationView.DrawPublicationActionView();

            publicationView.P = publication;

            return(publicationView);
        }
Beispiel #4
0
        /// <summary>
        /// Updates the publication view in scroll view.
        /// Invoked when publication has been download or some other occasion
        /// </summary>
        /// <param name="publication">Publication.</param>
        /// <param name="publicationView">Publication view.</param>
        private void UpdatePublicationViewInScrollView(Publication publication, PublicationView publicationView)
        {
            publicationList = PublicationUtil.Instance.GetPublicationOffline();
            foreach (var p in publicationList)
            {
                if (p.BookId == publication.BookId)
                {
                    publication = p;
                    break;
                }
            }
            PublicationView updatePublicationView = PublicationViewFactory.CreatePublicationView(publication, StartDownload, ShowConfirmCancelDownload);

            publicationView.RemoveFromSuperview();
            publicationView = null;
            publicationViewScrollContainer.AddSubview(updatePublicationView);
        }
Beispiel #5
0
        /// <summary>
        /// Starts the download.
        /// </summary>
        /// <param name="publication">Publication.</param>
        /// <param name="publicationView">Publication view.</param>
        /// <param name="checkNetLimitation">If set to <c>true</c> check net limitation.</param>
        private async void StartDownload(Publication publication, PublicationView publicationView, bool checkNetLimitation = true)
        {
            string prevInfoStr       = publicationView.StatusLabel.Text;
            string downloadFailedMsg = "";

            if (publication.PublicationStatus == PublicationStatusEnum.NotDownloaded)
            {
                downloadFailedMsg = "Download Failed";
            }
            if (publication.PublicationStatus == PublicationStatusEnum.RequireUpdate)
            {
                downloadFailedMsg = "Update Failed";
            }

            publicationView.StatusLabel.Text = "Downloading";



            var pView = AppDisplayUtil.Instance.AppDelegateInstance.PublicationViewList.Find(pv => pv.P.BookId == publication.BookId);

            if (pView != null && pView != publicationView)
            {
                pView.RightTopView.ShowDownloadProgressView();
            }

            DownloadResult downloadResult = await PublicationUtil.Instance.DownloadPublicationByBookId(publication.BookId, publicationView.DownloadCancelTokenSource.Token, delegate(int downloadedProgress, long downloadSize) {
                //更新publication对应的所有view的下载进度及状态
                publicationView.UpdateDownloadProgress(downloadedProgress, downloadSize);
                if (pView != null && pView != publicationView)
                {
                    pView.UpdateDownloadProgress(downloadedProgress, downloadSize);
                }
            }, checkNetLimitation);

            switch (downloadResult.DownloadStatus)
            {
            case DownLoadEnum.OverLimitation:
                var overLimitationAlert = UIAlertController.Create("Download Over 20MB", "This Digital Looseleaf title is over 20MB. We recommend you connect to a Wi-Fi network to download it.", UIAlertControllerStyle.Alert);
                overLimitationAlert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
                overLimitationAlert.AddAction(UIAlertAction.Create("Download", UIAlertActionStyle.Default, alert => StartDownload(publication, publicationView, false)));
                PresentViewController(overLimitationAlert, true, null);
                break;

            case DownLoadEnum.Canceled:
                publicationView.StatusLabel.Text = downloadFailedMsg;
                if (pView != null && pView != publicationView)
                {
                    pView.P = publication;
                    pView.StatusLabel.Text = downloadFailedMsg;
                }
                break;

            case DownLoadEnum.Failure:
                publicationView.StatusLabel.Text = downloadFailedMsg;
                publicationView.RightTopView.RemoveActionSubview();
                publicationView.RightTopView.ShowDownloadActionView(publication, StartDownload, ShowConfirmCancelDownload, true);
                ShowAlert(downloadFailedMsg);
                break;

            case DownLoadEnum.NetDisconnected:
                publicationView.StatusLabel.Text = downloadFailedMsg;
                publicationView.RightTopView.RemoveActionSubview();
                publicationView.RightTopView.ShowDownloadActionView(publication, StartDownload, ShowConfirmCancelDownload, true);
                ShowAlert("Missing connection", "Sorry, there appears to be no Internet connection. A connection is required to complete this task.");
                break;

            case DownLoadEnum.Success:
                //update publication view after publication has been download(download date, practice area, subcategory etc)
                //UpdatePublicationViewInScrollView (publication, publicationView);
                publicationList = PublicationUtil.Instance.GetPublicationOffline();
                publication     = publicationList.Find(p => p.BookId == publication.BookId);             //Get latest publication meta data after it has been downloaded
                publication.PublicationStatus = PublicationStatusEnum.Downloaded;
                publicationView.P             = publication;
                if (pView != null && pView != publicationView)
                {
                    pView.P = publication;
                }
                break;
            }
        }
        private void ShowPublicationCoverAndActionButton()
        {
            var pvInList = AppDisplayUtil.Instance.AppDelegateInstance.PublicationViewList.Find(item => item.P.BookId == curPublication.BookId);

            PublicationView pv = PublicationViewFactory.CreatePublicationView(curPublication, pvInList.StartDownload, pvInList.ShowDownloadAlert, 0.85f);

            pv.ZoomInOrOut(0.85f);
            PublicationCoverContainer.AddSubview(pv);

            PublicationNameLabel.Text = curPublication.Name;
            CGSize publicationNameLabelSize = TextDisplayUtil.GetStringBoundRect(curPublication.Name, UIFont.SystemFontOfSize(ViewConstant.INFO_NAME_LABEL_FONT_SIZE), new CGSize(ViewConstant.INFO_AUTHOR_LABEL_WIDTH, 600));
            nfloat expectedNameLabelHeight  = publicationNameLabelSize.Height > 26 ? publicationNameLabelSize.Height : 26;

            ChangeViewHeightConstraint(PublicationNameLabel, expectedNameLabelHeight);

            PublicationAuthorLabel.Text = curPublication.Author;
            CGSize publicationAuthorLabelSize = TextDisplayUtil.GetStringBoundRect(curPublication.Author, UIFont.SystemFontOfSize(ViewConstant.INFO_AUTHOR_LABEL_FONT_SIZE), new CGSize(ViewConstant.INFO_AUTHOR_LABEL_WIDTH, 600));
            nfloat expectedAuthorLabelHeight  = publicationAuthorLabelSize.Height < ViewConstant.INFO_AUTHOR_LABEL_MIN_HEIGHT ? ViewConstant.INFO_AUTHOR_LABEL_MIN_HEIGHT : publicationAuthorLabelSize.Height;

            ChangeViewHeightConstraint(PublicationAuthorLabel, expectedAuthorLabelHeight);

            ActionButton.Layer.BorderWidth  = 1.0f;
            ActionButton.Layer.CornerRadius = 5;

            if (curPublication.DaysRemaining < 0)
            {
                ActionButton.Layer.BorderColor = UIColor.Red.CGColor;
                ActionButton.SetTitleColor(UIColor.Red, UIControlState.Normal);
            }
            else
            {
                ActionButton.Layer.BorderColor = UIColor.FromRGB(22, 132, 250).CGColor;
                ActionButton.SetTitleColor(UIColor.FromRGB(22, 132, 250), UIControlState.Normal);
            }

            if (curPublication.IsLoan)
            {
                LoanTagLabel.Layer.CornerRadius  = 8;
                LoanTagLabel.Layer.MasksToBounds = true;

                ChangeViewWidthConstraint(LoanTagLabel, ViewConstant.INFO_LOAN_TAG_LABEL_WIDTH);
                ChangeViewWidthConstraint(TagSpaceLabel, 10);
            }
            else
            {
                ChangeViewWidthConstraint(LoanTagLabel, 0);
                ChangeViewWidthConstraint(TagSpaceLabel, 0);
            }

            if (curPublication.IsFTC)
            {
                PlusCaseTagLabel.Layer.CornerRadius  = 8;
                PlusCaseTagLabel.Layer.MasksToBounds = true;
                PlusCaseTagLabel.Hidden = false;
            }
            else
            {
                PlusCaseTagLabel.Hidden = true;
            }

            nfloat expectedTitleAuthorScrollViewContentHeight = expectedAuthorLabelHeight + expectedNameLabelHeight + 34;

            if (expectedTitleAuthorScrollViewContentHeight > ViewConstant.INFO_NAME_AUTHOR_SCROLL_VIEW_MAX_HEIGHT)
            {
                ChangeViewHeightConstraint(TitleAuthorScrollView, ViewConstant.INFO_NAME_AUTHOR_SCROLL_VIEW_MAX_HEIGHT);
                TitleAuthorScrollView.ScrollEnabled = true;
            }
            else
            {
                ChangeViewHeightConstraint(TitleAuthorScrollView, expectedTitleAuthorScrollViewContentHeight);
                TitleAuthorScrollView.ScrollEnabled = false;
            }
            TitleAuthorScrollView.ContentSize = new CGSize(ViewConstant.INFO_AUTHOR_LABEL_WIDTH, expectedTitleAuthorScrollViewContentHeight);
            TitleAuthorScrollView.SetContentOffset(new CGPoint(0, 0), false);
        }
Beispiel #7
0
 public void AddPublicationView(PublicationView pv)
 {
     AppDelegateInstance.PublicationViewList.Add(pv);
 }