Ejemplo n.º 1
0
 public void updateChapterScroll(UISecondScrollView scrollView)
 {
     if (scrollView.moveToLeft)
     {
         if (this.currentPage == 0)
         {
             return;
         }
         else
         {
             this.currentPage--;
             this.pageControl.CurrentPage = this.currentPage;
             this.currentChapter          = this.chaptersController[this.currentPage];
             drawCurrentChapter();
             scrollView.moveToLeft = false;
         }
     }
     else if (scrollView.moveToRight)
     {
         if (this.currentPage == this.chaptersController.Count - 1)
         {
             return;
         }
         else
         {
             this.currentPage++;
             this.pageControl.CurrentPage = this.currentPage;
             this.currentChapter          = this.chaptersController[this.currentPage];
             drawCurrentChapter();
             scrollView.moveToRight = false;
         }
     }
 }
Ejemplo n.º 2
0
        public bool updateCurrentChapter()
        {
            int chapter = (int)Math.Round(this.chapterScroll.ContentOffset.X / this.chapterScroll.Frame.Width);

            if (chapter >= this.chaptersController.Count || chapter < 0)
            {
                chapterChanged = false;
                return(chapterChanged);
            }

            if (chapter != this.currentPage)
            {
                this.currentPage             = chapter;
                this.currentChapter          = this.chaptersController[this.currentPage];
                this.pageControl.CurrentPage = this.currentPage;

                this.secondScroll.currentChapter = this.currentPage;

                secondScrollIsScrolling = false;

                chapterChanged = true;
            }
            else
            {
                chapterChanged = false;
            }

            return(chapterChanged);
        }
Ejemplo n.º 3
0
        public void setCurrentChapterController(ChapterController currentChapterController)
        {
            this.currentChapterController = currentChapterController;
            this.currentChapter           = currentChapterController.indexInBook;

            CGSize contentSize = this.ContentSize;

            contentSize.Width = this.currentChapterController.pagesFinishX - this.currentChapterController.pagesStartX;
            this.ContentSize  = contentSize;
        }
Ejemplo n.º 4
0
        public void loadPropertiesFile()
        {
            string documentsPath = "load.txt";

            Dictionary <string, object> dict = (Dictionary <string, object>)Plist.readPlist(documentsPath);

            foreach (var content in dict)
            {
                List <object> root         = (List <object>)content.Value;
                int           pageNumber   = 0;
                int           chapterIndex = 0;

                foreach (var arrayElement in root)
                {
                    Dictionary <string, object> bookContent = (Dictionary <string, object>)arrayElement;
                    string imagesPath       = "Images/";
                    string chapterImageName = "";
                    foreach (var chapterContent in bookContent)
                    {
                        if (chapterContent.Key.Equals("ChapterImage"))
                        {
                            chapterImageName += imagesPath + (string)chapterContent.Value;
                        }
                        else if (chapterContent.Key.Equals("Pages"))
                        {
                            List <object> pName      = (List <object>)chapterContent.Value;
                            List <string> pagesNames = new List <string> ();
                            foreach (var page in pName)
                            {
                                pagesNames.Add(imagesPath + (string)page);
                            }
                            pagesNames.Insert(0, chapterImageName);

                            List <PageController> pagesController = new List <PageController> ();
                            for (int page = 0; page < pagesNames.Count; page++)
                            {
                                PageInformation pi = new PageInformation();
                                pi.indexInChapter = page;
                                pi.indexInBook    = pageNumber;
                                pi.chapter        = chapterIndex;
                                Console.WriteLine("page number " + page);
                                PageController pc = new PageController(pi, pagesNames[page], pagesNames[page], null);
                                pagesController.Add(pc);
                                pageNumber++;
                            }

                            ChapterController chapter = new ChapterController(pagesController, chapterImageName, chapterIndex);
                            chaptersController.Add(chapter);
                            chapterIndex++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            try
            {
                chaptersController = new List <ChapterController> ();

                //loadPropertiesFile ();
                loadPropertiesFileFromPList();


                chapterChanged                = false;
                setOffsetForChange            = false;
                secondScrollIsScrolling       = false;
                canBeginGestures              = true;
                isPossibleBigToSmallAnimation = true;

                List <PageController> allPagesController = new List <PageController> ();
                foreach (ChapterController chapter in this.chaptersController)
                {
                    foreach (PageController page in chapter.pagesController)
                    {
                        page.gesturesDelegate = this;
                        allPagesController.Add(page);
                    }
                }

                this.secondScroll = new UISecondScrollView(allPagesController);

                this.chapterScroll.Frame = new CGRect(Constants.MAIN_ORIGIN_X, Constants.MAIN_ORIGIN_Y,
                                                      Constants.MAIN_WIDTH, Constants.MAIN_HEIGHT);

                this.secondScroll.Frame = new RectangleF(Constants.SECOND_ORIGIN_X, Constants.SECOND_ORIGIN_Y,
                                                         Constants.SECOND_WIDTH, Constants.SECOND_HEIGHT);

                this.pageControl.Pages       = this.chaptersController.Count;
                this.currentPage             = 0;
                this.pageControl.CurrentPage = this.currentPage;
                this.currentChapter          = this.chaptersController[this.currentPage];

                //initial properties for second scroll
                this.secondScroll.currentChapter       = this.currentPage;
                this.chapterScroll.WeakDelegate        = this;
                this.secondScroll.secondScrollDelegate = this;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("file bookInfo.plist could not be opened");
            }
        }
Ejemplo n.º 6
0
        public void initChapterViewController(PageController page)
        {
            if (chapterVC == null)
            {
                //initial chapterVC
                ChapterViewController.pages = secondScroll.pagesController;
                chapterVC                     = new UIPageViewController(UIPageViewControllerTransitionStyle.Scroll, UIPageViewControllerNavigationOrientation.Horizontal, UIPageViewControllerSpineLocation.Min);
                chapterVC.DataSource          = new ChapterViewController.ChapterVCDataSource();
                chapterVC.View.Frame          = Constants.mainFrame;
                chapterVC.DidFinishAnimating += (sender, e) => {
                    if (e.Finished)
                    {
                        if (e.Completed)
                        {
                            foreach (ChapterViewController c in e.PreviousViewControllers)
                            {
                                this.secondScroll.view.AddSubview(c.currentPage.smallImage);
                                c.currentPage.smallImageToPosition(secondScroll, this.currentChapter.pagesStartX);
                                var currentVC = (ChapterViewController)chapterVC.ViewControllers [chapterVC.ViewControllers.Length - 1];
                                currentVC.currentPage.smallImage.Hidden = true;
                                Console.WriteLine("current + " + currentVC.currentPage.pageInfo.chapter + "   prev " + c.currentPage.pageInfo.chapter);
                                if (currentVC.currentPage.pageInfo.chapter != c.currentPage.pageInfo.chapter)
                                {
                                    Console.WriteLine("chapterchanged");
                                    int chapter = currentVC.currentPage.pageInfo.chapter;
                                    this.currentPage    = chapter;
                                    this.currentChapter = this.chaptersController [chapter];
                                    this.drawCurrentChapter();
                                }

                                fixSecondScrollPosition(currentVC.currentPage);
                            }
                        }
                    }
                };
            }

            ChapterViewController contentViewController = new ChapterViewController(page);

            var viewControllers = new List <ChapterViewController>();

            viewControllers.Add(contentViewController);
            chapterVC.SetViewControllers(viewControllers.ToArray(), UIPageViewControllerNavigationDirection.Forward, false, null);

            this.AddChildViewController(this.chapterVC);
            chapterVC.DidMoveToParentViewController(this);
            this.View.AddSubview(chapterVC.View);
            this.chapterScroll.UserInteractionEnabled = false;
            this.secondScroll.UserInteractionEnabled  = false;
        }
Ejemplo n.º 7
0
        public void updateChaptersControllerXPositions()
        {
            ChapterController prev = this.chaptersController[0];

            prev.pagesStartX  = 0;
            prev.pagesFinishX = Constants.SECOND_IMAGE_WIDTH * prev.pagesController.Count;

            for (int i = 1; i < this.chaptersController.Count; i++)
            {
                ChapterController tmp = this.chaptersController[i];
                tmp.pagesStartX  = prev.pagesFinishX;
                tmp.pagesFinishX = tmp.pagesStartX + Constants.SECOND_IMAGE_WIDTH * tmp.pagesController.Count;
                prev             = tmp;
            }
        }
Ejemplo n.º 8
0
        public void moveToChapter(ChapterController chapter)
        {
            this.setCurrentChapterController(chapter);
            CGRect f = this.view.Frame;

            f.X = -chapter.pagesStartX;

            UIView.Animate(
                duration: 0.25,
                delay: 0,
                options: UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.BeginFromCurrentState,
                animation: () => {
                this.view.Frame = f;
                this.SetContentOffset(new PointF(0, 0), false);
            },
                completion: () => {
            }
                );
        }
Ejemplo n.º 9
0
        void  createBooksFromDictionary(NSDictionary dic)
        {
            foreach (var pair in dic)
            {
                //this.setAttibute(key, dic.ObjectForKey(key), book);
                if (pair.Key.ToString().Equals("IdBook"))
                {
                    book.idBook = Int32.Parse((pair.Value as NSString).ToString());
                }

                if (pair.Key.ToString().Equals("NameBook"))
                {
                    book.nameBook = pair.Value as NSString;
                }
            }


            NSArray array = dic.ObjectForKey(new NSString("ChapterList")) as NSArray;

            for (nuint i = 0; i < array.Count; i++)
            {
                NSDictionary chapterDic = array.GetItem <NSDictionary> (i);

                Chapter chapter = new Chapter();
                foreach (var pair in chapterDic)
                {
                    //[self setAttibute:key Value:[chapterDic objectForKey:key] Object:chapter];
                    if (pair.Key.ToString().Equals("IdChapter"))
                    {
                        chapter.idChapter = Int32.Parse((pair.Value as NSString).ToString());
                    }
                    else if (pair.Key.ToString().Equals("NameChapter"))
                    {
                        chapter.nameChapter = pair.Value as NSString;
                    }
                }
                book.addChapter(chapter);
                initWithBookModel(chapter, i);
            }


            int pageNumber   = 0;
            int chapterIndex = 0;

            List <PageController> pagesController = new List <PageController> ();

            for (int idChapter = 0; idChapter < book.chapters.Count; idChapter++)
            {
                Chapter chapter = book.chapters [idChapter];

                for (int page = 0; page < chapter.pages.Count; page++)
                {
                    PageModel pageModel = chapter.pages [page];

                    PageInformation pi = new PageInformation();
                    pi.indexInChapter = page;
                    pi.indexInBook    = pageNumber;
                    pi.chapter        = chapterIndex;
                    Console.WriteLine("page number " + page);
                    PageController pc = new PageController(pi, pageModel.portThumbContent, pageModel.portLargeTempContent, pageModel);
                    pagesController.Add(pc);
                    pageNumber++;
                }
                ChapterController chc = new ChapterController(pagesController, book.chapters [idChapter].portLargeContent, chapterIndex);
                chaptersController.Add(chc);
                chapterIndex++;
            }
        }