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(); } }
public override void ViewDidLoad() { base.ViewDidLoad(); //set share icon btnShare.SetImage(UIImage.FromFile("share.png"), UIControlState.Normal); if (Reachability.IsHostReachable("www.laftrip.com")) { this.NavigationItem.SetRightBarButtonItem( new UIBarButtonItem(UIBarButtonSystemItem.Add, (sender, args) => { this.NavigationController.PushViewController(new AddJokeView(), true); }) , true); likedJokes = LikeProvider.GetLikedJokes(); // btnShare.TouchUpInside += (object sender, EventArgs e) => { this.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); isLiked = true; likedJokes.Add(currentJokeId); return(success); }, TaskScheduler.FromCurrentSynchronizationContext()); } else //already liked. dislike. //remove from db { LikeProvider.DeleteLikedJoke(currentJokeId); btnLike.SetImage(UIImage.FromFile("unliked.png"), UIControlState.Normal); isLiked = false; likedJokes.Remove(currentJokeId); } }; //INITIAL DOWNLOAD DisplayProgress("Getting Joke"); 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(); } }