Ejemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // set share icon
            btnShare.SetImage(UIImage.FromFile("share.png"), UIControlState.Normal);

            if (Reachability.IsHostReachable("www.laftrip.com"))
            {
                //get liked jokes from db
                likedPhotos = LikeProvider.GetLikedPhotos();

                //
                btnShare.TouchUpInside += (object sender, EventArgs e) => {
                    this.NavigationController.PushViewController(new JokesShareViewController(Laftrip.API.Enums.ItemType.Photo, currentphotoTitle, currentphotoDesc, currentphotoId), true);
                };

                btnLike.TouchUpInside += (object sender, EventArgs e) => {
                    if (!isLiked)
                    {
                        int        success    = -1;
                        Downloader downloader = new Downloader();

                        DisplayProgress("Liking Photo");

                        Task.Factory.StartNew(() => {
                            success = downloader.LikePhoto(currentphotoId);
                        }).ContinueWith(task3 => {
                            HideProgress();

                            //save liked joke to db
                            LikeProvider.SaveLikedPhoto(currentphotoId);

                            //add photoid to array
                            btnLike.SetImage(UIImage.FromFile("liked.png"), UIControlState.Normal);
                            isLiked = true;
                            likedPhotos.Add(currentphotoId);

                            return(success);
                        },
                                        TaskScheduler.FromCurrentSynchronizationContext());
                    }
                    else
                    {
                        //remove from db
                        LikeProvider.DeleteLikedPhoto(currentphotoId);
                        btnLike.SetImage(UIImage.FromFile("unliked.png"), UIControlState.Normal);
                        isLiked = false;
                        likedPhotos.Remove(currentphotoId);
                    }
                };

                //INITIAL DOWNLOAD
                DisplayProgress("Getting Photo");
                Download();


                NavigationController.SetNavigationBarHidden(true, true);

                //admob
                adView = new GADBannerView(size: GADAdSizeCons.Banner, origin: new PointF(0, 0))
                {
                    AdUnitID           = AdmobID,
                    RootViewController = this
                };

                adView.DidReceiveAd += (sender, args) => {
                    if (!viewOnScreen)
                    {
                        View.AddSubview(adView);
                    }
                    viewOnScreen = true;
                };

                adView.LoadRequest(GADRequest.Request);
            }
            else
            {
                connDelegate = new NoConnectionDelegate(this.NavigationController);

                new UIAlertView("No Internet Detected", "Internet Connection is required."
                                , connDelegate, "ok", null).Show();
            }
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //set share button image
            btnShare.SetImage(UIImage.FromFile("share.png"), UIControlState.Normal);

            if (Reachability.IsHostReachable("www.laftrip.com"))
            {
                this.ParentViewController.ParentViewController.NavigationItem.SetRightBarButtonItem(
                    new UIBarButtonItem(UIBarButtonSystemItem.Add, (sender, args) => {
                    this.TabBarController.NavigationController.PushViewController(new AddJokeView(), true);
                })
                    , true);

                //get liked jokes from db
                likedJokes = LikeProvider.GetLikedJokes();

                //
                btnShare.TouchUpInside += (object sender, EventArgs e) => {
                    this.TabBarController.NavigationController.PushViewController(new JokesShareViewController(Laftrip.API.Enums.ItemType.Joke, currentJokeTitle, currentJokeDesc, currentJokeId), true);
                };

                btnLike.TouchUpInside += (object sender, EventArgs e) => {
                    if (!isLiked)
                    {
                        int        success    = -1;
                        Downloader downloader = new Downloader();

                        DisplayProgress("Liking Joke");

                        Task.Factory.StartNew(() => {
                            success = downloader.LikeJoke(currentJokeId);
                        }).ContinueWith(task3 => {
                            HideProgress();
                            View.BackgroundColor = UIColor.White;

                            //save liked joke to db
                            LikeProvider.SaveLikedJoke(currentJokeId);

                            //add jokeid to array
                            btnLike.SetImage(UIImage.FromFile("liked.png"), UIControlState.Normal);
                            likedJokes.Add(currentJokeId);
                            isLiked = true;

                            return(success);
                        },
                                        TaskScheduler.FromCurrentSynchronizationContext());
                    }
                    else                       //already liked.  dislike.
                                               //remove from db
                    {
                        LikeProvider.DeleteLikedPhoto(currentJokeId);
                        btnLike.SetImage(UIImage.FromFile("unliked.png"), UIControlState.Normal);
                        likedJokes.Remove(currentJokeId);
                        isLiked = false;
                    }
                };

                //INITIAL DOWNLOAD
                DisplayProgress("Getting Jokes");
                Download();

                // previous
                swipeRight.AddTarget(() => {
                    jokeIndex--;


                    internalPage--;
                    swipeLeft.Enabled = true;

                    //if this is the first element in the internal list, download previous external page
                    if (internalPage == -1 && jokeIndex > 0)
                    {
                        DisplayProgress("Getting Jokes");
                        Download();
                        externalPage--;
                    }
                    else
                    {
                        txtJokeDesc.Text = filteredJokesBatch[internalPage].JokeDesc;
                        lblTitle.Text    = filteredJokesBatch[internalPage].Title;
                        currentJokeId    = filteredJokesBatch[internalPage].JokeID;
                        currentJokeTitle = filteredJokesBatch[internalPage].Title;
                        currentJokeDesc  = filteredJokesBatch[internalPage].JokeDesc;

                        checkLiked();
                    }


                    if (jokeIndex == 0)
                    {
                        swipeRight.Enabled = false;
                    }

                    lblPage.Text = (jokeIndex + 1) + " of " + jokeCount;
                });

                //next
                swipeLeft.AddTarget(() => {
                    jokeIndex++;

                    internalPage++;
                    swipeRight.Enabled = true;

                    //if this is the last element in the internal list, download next external page
                    if (internalPage == filteredJokesBatch.Count)
                    {
                        externalPage++;
                        DisplayProgress("Getting Jokes");
                        Download();
                    }
                    else
                    {
                        txtJokeDesc.Text = filteredJokesBatch [internalPage].JokeDesc;
                        lblTitle.Text    = filteredJokesBatch[internalPage].Title;
                        currentJokeId    = filteredJokesBatch[internalPage].JokeID;
                        currentJokeTitle = filteredJokesBatch[internalPage].Title;
                        currentJokeDesc  = filteredJokesBatch[internalPage].JokeDesc;

                        checkLiked();
                    }

                    if ((jokeIndex + 1) == jokeCount)
                    {
                        swipeLeft.Enabled = false;
                    }

                    lblPage.Text = (jokeIndex + 1) + " of " + jokeCount;
                });

                View.AddGestureRecognizer(swipeRight);
                View.AddGestureRecognizer(swipeLeft);



                NavigationController.SetNavigationBarHidden(true, true);

                //admob
                adView = new GADBannerView(size: GADAdSizeCons.Banner, origin: new PointF(0, 0))
                {
                    AdUnitID           = AdmobID,
                    RootViewController = this
                };

                adView.DidReceiveAd += (sender, args) => {
                    if (!viewOnScreen)
                    {
                        View.AddSubview(adView);
                    }
                    viewOnScreen = true;
                };

                adView.LoadRequest(GADRequest.Request);
            }
            else
            {
                connDelegate = new NoConnectionDelegate(this.NavigationController);

                new UIAlertView("No Internet Detected", "Internet Connection is required."
                                , connDelegate, "ok", null).Show();
            }
        }
Ejemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //set share button image
            btnShare.SetImage(UIImage.FromFile("share.png"), UIControlState.Normal);

            if (Reachability.IsHostReachable("www.laftrip.com"))
            {
                // Perform any additional setup after loading the view, typically from a nib.
                View.BackgroundColor = UIColor.Black;

                progressBar.Hidden = true;
                lblPercent.Hidden  = true;

                this.ParentViewController.ParentViewController.NavigationItem.SetRightBarButtonItem(
                    new UIBarButtonItem(UIBarButtonSystemItem.Add, (sender, args) => {
                    this.TabBarController.NavigationController.PushViewController(new AddPhotoView(), true);
                })
                    , true);


                //get liked jokes from db
                likedPhotos = LikeProvider.GetLikedPhotos();

                //
                btnShare.TouchUpInside += (object sender, EventArgs e) => {
                    this.TabBarController.NavigationController.PushViewController(new JokesShareViewController(Laftrip.API.Enums.ItemType.Photo, currentphotoTitle, currentphotoDesc, currentphotoId), true);
                };

                btnLike.TouchUpInside += (object sender, EventArgs e) => {
                    if (!isLiked)
                    {
                        int        success    = -1;
                        Downloader downloader = new Downloader();

                        DisplayProgress("Liking Photo");

                        Task.Factory.StartNew(() => {
                            success = downloader.LikePhoto(currentphotoId);
                        }).ContinueWith(task3 => {
                            HideProgress();

                            //save liked joke to db
                            LikeProvider.SaveLikedPhoto(currentphotoId);

                            //add photoid to array
                            btnLike.SetImage(UIImage.FromFile("liked.png"), UIControlState.Normal);
                            isLiked = true;
                            likedPhotos.Add(currentphotoId);

                            return(success);
                        },
                                        TaskScheduler.FromCurrentSynchronizationContext());
                    }
                    else
                    {
                        //remove from db
                        LikeProvider.DeleteLikedPhoto(currentphotoId);
                        btnLike.SetImage(UIImage.FromFile("unliked.png"), UIControlState.Normal);
                        isLiked = false;
                        likedPhotos.Remove(currentphotoId);
                    }
                };


                //INITIAL DOWNLOAD
                DisplayProgress("Getting Photos");
                Download();

                // previous
                swipeRight.AddTarget(() => {
                    photoIndex--;


                    internalPage--;
                    swipeLeft.Enabled = true;

                    //if this is the first element in the internal list, download previous external page
                    if (internalPage == -1 && photoIndex > 0)
                    {
                        DisplayProgress("Getting Photos");
                        Download();
                        externalPage--;
                    }
                    else
                    {
                        lblDescription.Text = filteredphotosBatch [internalPage].Description;
                        currentphotoId      = filteredphotosBatch [internalPage].PhotoId;
                        currentphotoTitle   = filteredphotosBatch [internalPage].Title;
                        currentphotoDesc    = filteredphotosBatch [internalPage].Description;

                        checkLiked();

                        ImageUrl = new NSUrl(filteredphotosBatch [internalPage].Url);

                        if (ImageUrl != null)
                        {
                            progressBar.Hidden = false;
                            lblPercent.Hidden  = false;
                            imgPhoto.SetImage(ImageUrl, null, SDWebImageOptions.ProgressiveDownload, ProgressHandler, CompletedHandler);
                        }
                    }


                    if (photoIndex == 0)
                    {
                        swipeRight.Enabled = false;
                    }

                    lblPage.Text = (photoIndex + 1) + " of " + photoCount;
                });

                //next
                swipeLeft.AddTarget(() => {
                    photoIndex++;

                    internalPage++;
                    swipeRight.Enabled = true;

                    //if this is the last element in the internal list, download next external page
                    if (internalPage == filteredphotosBatch.Count)
                    {
                        externalPage++;
                        DisplayProgress("Getting Photos");
                        Download();
                    }
                    else
                    {
                        lblDescription.Text = filteredphotosBatch [internalPage].Description;

                        ImageUrl = new NSUrl(filteredphotosBatch [internalPage].Url);

                        if (ImageUrl != null)
                        {
                            progressBar.Hidden = false;
                            lblPercent.Hidden  = false;
                            imgPhoto.SetImage(ImageUrl, null, SDWebImageOptions.ProgressiveDownload, ProgressHandler, CompletedHandler);
                        }
                        currentphotoId    = filteredphotosBatch [internalPage].PhotoId;
                        currentphotoTitle = filteredphotosBatch [internalPage].Title;
                        currentphotoDesc  = filteredphotosBatch [internalPage].Description;

                        checkLiked();
                    }

                    if ((photoIndex + 1) == photoCount)
                    {
                        swipeLeft.Enabled = false;
                    }

                    lblPage.Text = (photoIndex + 1) + " of " + photoCount;
                });

                View.AddGestureRecognizer(swipeRight);
                View.AddGestureRecognizer(swipeLeft);

                NavigationController.SetNavigationBarHidden(true, true);

                //admob
                adView = new GADBannerView(size: GADAdSizeCons.Banner, origin: new PointF(0, 0))
                {
                    AdUnitID           = AdmobID,
                    RootViewController = this
                };

                adView.DidReceiveAd += (sender, args) => {
                    if (!viewOnScreen)
                    {
                        View.AddSubview(adView);
                    }
                    viewOnScreen = true;
                };

                adView.LoadRequest(GADRequest.Request);
            }
            else
            {
                connDelegate = new NoConnectionDelegate(this.NavigationController);

                new UIAlertView("No Internet Detected", "Internet Connection is required."
                                , connDelegate, "ok", null).Show();
            }
        }