public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, Foundation.NSIndexPath indexPath) { switch (editingStyle) { case UITableViewCellEditingStyle.Delete: //set isliked to false on root ad Ad item = Owner.FavoritesAdList[indexPath.Row]; item.IsLiked = false; // remove the item from the underlying data source Owner.FavoritesAdList.RemoveAt(indexPath.Row); // delete the row from the table tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade); //attempt to change like status in the database Task.Run(async() => { AdLikeResponse adLikeResponse = await new AdLikeResponse().RecordAdLike(int.Parse(item.ID), false); if (adLikeResponse.Status != "Success") { InvokeOnMainThread(() => { HelperMethods.SendBasicAlert("Oops", adLikeResponse.ResponseMsg); item.IsLiked = true; // remove the item from the underlying data source Owner.FavoritesAdList.Insert(indexPath.Row, item); // delete the row from the table tableView.InsertRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade); }); } else { var allAdsByClassification = (await Ad.GetAdsByClassificationAsync(item.Classification)).ToList(); var thisItem = allAdsByClassification.FirstOrDefault(row => row.ID == item.ID); thisItem.IsLiked = false; Ad.SaveAdsByClassification(allAdsByClassification, item.Classification); } }); break; case UITableViewCellEditingStyle.None: Console.WriteLine("CommitEditingStyle:None called"); break; } }
public async void NavigateToAdd(string classification, string adId) { var vc = Window.RootViewController; while (vc.PresentedViewController != null) { vc = vc.PresentedViewController; } LoadingOverlay loadingIndicator = new LoadingOverlay(vc.View.Frame, "Loading ...", false); if (vc is MainTabBarController) { vc.View.AddSubview(loadingIndicator); //remove cache //Ad.DeleteAdsByClassification(classification); //Retrieve highlighted ad var adsByClassification = await Ad.GetAdsByClassificationAsync(classification); var highlightedAd = adsByClassification.Where(row => row.ID == adId).First(); var maintTabBarController = vc as MainTabBarController; var magNavVC = maintTabBarController.ViewControllers.FirstOrDefault(row => row is MagazineNavigationViewController); if (magNavVC != null) { maintTabBarController.SelectedIndex = 0; var chooseClassVC = (magNavVC as MagazineNavigationViewController).ViewControllers.FirstOrDefault(row => row is ChooseClassificationCollectionViewController); if (chooseClassVC != null) { var chooseClassificationViewController = chooseClassVC as ChooseClassificationCollectionViewController; var storyboard = UIStoryboard.FromName("Main_ipad", NSBundle.MainBundle); MagazineFlipBoardViewController flipboardVC = storyboard.InstantiateViewController("MagazineFlipBoardViewController") as MagazineFlipBoardViewController; flipboardVC.Title = classification; flipboardVC.SelectedClassification = classification; flipboardVC.NavigateDirectlyToAdId = adId; chooseClassificationViewController.NavigationController.PopToRootViewController(false); chooseClassificationViewController.ShowViewController(flipboardVC, this); } } } loadingIndicator.Hide(); }
public ModelController(String selectedClassification) { Task.Run(async() => { var adListEnumerable = (await Ad.GetAdsByClassificationAsync(selectedClassification)).OrderByDescending(r => r.IsFeatured); switch (Settings.SortOptions) { case "No Preference": { adList = adListEnumerable.ToList(); break; } case "Recently Updated": { adList = adListEnumerable.OrderByDescending(row => DateTime.Parse(row.LastUpdated)).ThenByDescending(r => r.IsFeatured).ToList(); break; } case "Price": { adList = adListEnumerable.OrderBy(row => row.Price == null || row.Price == string.Empty || row.Price == "N/A" ? 999999999 : double.Parse(row.Price, NumberStyles.Currency)).ThenByDescending(r => r.IsFeatured).ToList(); break; } case "Total Time": { adList = adListEnumerable.OrderBy(row => double.Parse(row.TotalTime)).ThenByDescending(r => r.IsFeatured).ToList(); break; } default: { adList = adListEnumerable.ToList(); break; } } }).Wait(); LoadModalController(adList, selectedClassification); }
public async Task PerformBackgroundDataFetchFromBuyplaneAPI(System.Action completionHandler, List <Ad> adListOverride = null) { //NSUrlSession session = ConfigureBackgroundSession(); List <Ad> adList = new List <Ad>(); if (adListOverride == null) { if (Settings.IsRegistered) { var favoredClassificationsList = Settings.GetFavoredClassifications(); foreach (var fClass in favoredClassificationsList) { //remove current data in the database Ad.DeleteAdsByClassification(fClass); adList.AddRange(await Ad.GetAdsByClassificationAsync(fClass)); } } else { //preload Jets Settings.IsJets = true; Settings.IsSingleEngine = true; Settings.IsTwinTurbines = true; List <string> preloadJetsAndOtherClassificationsIfSetSettingsTrueAbove = Settings.GetFavoredClassifications(); foreach (var fClass in preloadJetsAndOtherClassificationsIfSetSettingsTrueAbove) { //remove current data in the database Ad.DeleteAdsByClassification(fClass); adList.AddRange(await Ad.GetAdsByClassificationAsync(fClass)); } } } else { adList = adListOverride; } //filter out previously cached int adsAlreadyInCacheCount = 0; int adCount = 0; foreach (var ad in adList) { SDImageCache.SharedImageCache.DiskImageExists(ad.ImageURL, (isInCache) => { adCount++; if (!isInCache) { FetchImage(ad.ImageURL); } else { adsAlreadyInCacheCount++; } if (adsAlreadyInCacheCount == adList.Count) { completionHandler.Invoke(); } if (adCount == adList.Count) { completionHandler.Invoke(); } }); } }
void AdSortButton_TouchUpInside(object sender, EventArgs e) { if (!Settings.IsRegistered) { if (sender == Ad1NameButton || sender == Ad2NameButton || sender == Ad3NameButton || sender == Ad4NameButton) { HelperMethods.MakeModelRegistrationRequiredPrompt(this, sender as UIButton); } if (sender == Ad1BrokerButton || sender == Ad2BrokerButton || sender == Ad3BrokerButton || sender == Ad4BrokerButton) { HelperMethods.SellerRegistrationRequiredPrompt(this, sender as UIButton); } return; } Ad ad = new Ad(); bool isAdNameSort = false; if (sender == Ad1NameButton) { ad = DataObject.Ads[0]; isAdNameSort = true; } if (sender == Ad2NameButton) { ad = DataObject.Ads[1]; isAdNameSort = true; } if (sender == Ad3NameButton) { ad = DataObject.Ads[2]; isAdNameSort = true; } if (sender == Ad4NameButton) { ad = DataObject.Ads[3]; isAdNameSort = true; } if (sender == Ad1BrokerButton) { ad = DataObject.Ads[0]; isAdNameSort = false; } if (sender == Ad2BrokerButton) { ad = DataObject.Ads[1]; isAdNameSort = false; } if (sender == Ad3BrokerButton) { ad = DataObject.Ads[2]; isAdNameSort = false; } if (sender == Ad4BrokerButton) { ad = DataObject.Ads[3]; isAdNameSort = false; } LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame, isAdNameSort ? "Loading Aircraft by Selected Type" : "Loading Aircraft by Selected Broker"); this.View.AddSubview(loadingIndicator); var pageViewController = this.ParentViewController as UIPageViewController; var magFlipBoardViewController = pageViewController.ParentViewController as MagazineFlipBoardViewController; var modelController = magFlipBoardViewController.ModelController; List <Ad> adList = new List <Ad>(); Task.Run(async() => { adList = (await Ad.GetAdsByClassificationAsync(DataObject.SelectedClassification)).ToList(); //get ads with this name and move them to the from of the list List <Ad> similarAdList = new List <Ad>(); if (isAdNameSort) { similarAdList = adList.Where(row => row.Name == ad.Name).ToList(); } else { similarAdList = adList.Where(row => row.BrokerName == ad.BrokerName).ToList(); } for (int i = 0; i < similarAdList.Count(); i++) { adList.Remove(similarAdList[i]); adList.Insert(0, similarAdList[i]); } InvokeOnMainThread(() => { modelController.LoadModalController(adList, DataObject.SelectedClassification); loadingIndicator.Hide(); var startingViewController = modelController.GetViewController(0, false); var viewControllers = new UIViewController[] { startingViewController }; pageViewController.SetViewControllers(viewControllers, UIPageViewControllerNavigationDirection.Forward, true, null); HelperMethods.SendBasicAlert("", "Aircraft arranged by " + (isAdNameSort? ad.Name:ad.BrokerName)); }); }); }
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) { var classification = classifications[(int)indexPath.Item]; LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame, "Loading Aircraft..."); this.View.AddSubview(loadingIndicator); //Clay Martin 1/1/18: Change app name to BuyPlane string magazineTitle = "GlobalAir.com BuyPlane (" + classification.Name + ")"; NavigationItem.BackBarButtonItem = new UIBarButtonItem("Back to BuyPlane", UIBarButtonItemStyle.Plain, null); Task.Run(async() => { List <Ad> ads; if (!Settings.IsRegistered) { ads = (await Ad.GetAdsByClassificationAsync(classification.Name)).OrderByDescending(r => r.IsFeatured).ToList(); } else { IEnumerable <Ad> adListEnumerable = await Ad.GetAdsByClassificationAsync(classification.Name); switch (Settings.SortOptions) { case "No Preference": { ads = adListEnumerable.OrderByDescending(r => r.IsFeatured).ToList(); break; } case "Recently Updated": { ads = adListEnumerable.OrderByDescending(row => DateTime.Parse(row.LastUpdated)).ThenByDescending(r => r.IsFeatured).ToList(); break; } case "Price": { ads = adListEnumerable.OrderBy(row => row.Price == null || row.Price == string.Empty || row.Price == "N/A" ? 999999999 : double.Parse(row.Price, NumberStyles.Currency)).ThenByDescending(r => r.IsFeatured).ToList(); break; } case "Total Time": { ads = adListEnumerable.OrderBy(row => double.Parse(row.TotalTime)).ThenByDescending(r => r.IsFeatured).ToList(); break; } default: { ads = adListEnumerable.OrderByDescending(r => r.IsFeatured).ToList(); break; } } } var appDelegate = UIApplication.SharedApplication.Delegate as AppDelegate; await appDelegate.PerformBackgroundDataFetchFromBuyplaneAPI(() => Console.WriteLine("Background Fetch for ads chosen from ChooseClassificationCollention complete"), ads); //AppDelegate.PerformBackgroundDataFetchFromBuyplaneAPI((obj) => Console.WriteLine("Background Fetch for ads chosen from ChooseClassificationCollention complete", ads); }).ContinueWith((task) => { InvokeOnMainThread(() => { loadingIndicator.Hide(); MagazineFlipBoardViewController flipboardVC = this.Storyboard.InstantiateViewController("MagazineFlipBoardViewController") as MagazineFlipBoardViewController; flipboardVC.Title = magazineTitle; flipboardVC.SelectedClassification = classification.Name; //flipboardVC.TabBarController.HidesBottomBarWhenPushed = true; this.ShowViewController(flipboardVC, this); //NavigationController.PushViewController(flipboardVC, true); }); }); }
void AdSortButton_TouchUpInside(object sender, EventArgs e) { //Get current view controller var window = UIApplication.SharedApplication.KeyWindow; var vc = window.RootViewController; while (vc.PresentedViewController != null) { vc = vc.PresentedViewController; } if (!Settings.IsRegistered) { HelperMethods.SellerRegistrationRequiredSmallPrompt(vc, sender as UIButton); return; } bool isAdNameSort = false; LoadingOverlay loadingIndicator = new LoadingOverlay(vc.View.Frame, isAdNameSort ? "Loading Aircraft by Selected Type" : "Loading Aircraft by Selected Broker"); vc.View.AddSubview(loadingIndicator); //var pageViewController = vc.ParentViewController as UIPageViewController; var magazineNavigationViewController = vc.ChildViewControllers.First(row => row is MagazineNavigationViewController); var flipboardVC = magazineNavigationViewController.ChildViewControllers.First(row => row is MagazineFlipBoardViewController); //var magFlipBoardViewController = pageViewController.ParentViewController as MagazineFlipBoardViewController; var magFlipBoardViewController = flipboardVC as MagazineFlipBoardViewController; var pageViewController = magFlipBoardViewController.ChildViewControllers.First(row => row is UIPageViewController) as UIPageViewController; var modelController = magFlipBoardViewController.ModelController; List <Ad> adList = new List <Ad>(); Task.Run(async() => { adList = (await Ad.GetAdsByClassificationAsync(ad.Classification)).ToList(); //get ads with this name and move them to the from of the list List <Ad> similarAdList = new List <Ad>(); if (isAdNameSort) { similarAdList = adList.Where(row => row.Name == ad.Name).OrderBy(r => r.IsFeatured).ToList(); } else { similarAdList = adList.Where(row => row.BrokerName == ad.BrokerName).OrderBy(r => r.IsFeatured).ToList(); } for (int i = 0; i < similarAdList.Count(); i++) { adList.Remove(similarAdList[i]); adList.Insert(0, similarAdList[i]); } InvokeOnMainThread(() => { modelController.LoadModalController(adList, ad.Classification); loadingIndicator.Hide(); var startingViewController = modelController.GetViewController(0, false); var viewControllers = new UIViewController[] { startingViewController }; pageViewController.SetViewControllers(viewControllers, UIPageViewControllerNavigationDirection.Forward, true, null); HelperMethods.SendBasicAlert("", "Aircraft arranged by " + (isAdNameSort ? ad.Name : ad.BrokerName)); }); }); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); // This screen name value will remain set on the tracker and sent with // hits until it is set to a new value or to null. Gai.SharedInstance.DefaultTracker.Set(GaiConstants.ScreenName, "MagazineFlip View"); Gai.SharedInstance.DefaultTracker.Send(DictionaryBuilder.CreateScreenView().Build()); if (NavigateDirectlyToAdId != null && NavigateDirectlyToAdId != string.Empty) { var pageViewController = this.PageViewController; var magFlipBoardViewController = this; Ad ad = new Ad(); var adList = ModelController.adList; ad = adList.FirstOrDefault(row => row.ID == NavigateDirectlyToAdId); NavigateDirectlyToAdId = null; if (ad != null && ad.ID != string.Empty) { //this.View.AddSubview(loadingIndicator); var modelController = this.ModelController; List <Ad> searchAddList = new List <Ad>(); Task.Run(async() => { searchAddList = (await Ad.GetAdsByClassificationAsync(ad.Classification)).ToList(); //get ads with this name and move them to the from of the liste List <Ad> similarAdList = new List <Ad>(); similarAdList = searchAddList.Where(row => row.Name == ad.Name).OrderBy(r => r.IsFeatured).ToList(); //similarAdList.Remove(ad); for (int i = 0; i < similarAdList.Count(); i++) { searchAddList.Remove(similarAdList[i]); searchAddList.Insert(0, similarAdList[i]); } //similarAdList.Remove(ad); //searchAddList.Insert(0, ad); var index = searchAddList.FindIndex(x => x.ID == ad.ID); var item = searchAddList[index]; searchAddList[index] = searchAddList[0]; searchAddList[0] = item; InvokeOnMainThread(() => { modelController.LoadModalController(searchAddList, ad.Classification); var initialViewController = modelController.GetViewController(0, false); var searchViewControllers = new UIViewController[] { initialViewController }; pageViewController.SetViewControllers(searchViewControllers, UIPageViewControllerNavigationDirection.Forward, true, (finished) => { if (LoadingIndicator != null) { LoadingIndicator.Hide(); } }); //HelperMethods.SendBasicAlert("", "Aircraft arranged based on search selection"); }); }); } else { if (LoadingIndicator != null) { LoadingIndicator.Hide(); } } } ; }
public override void ViewDidLoad() { base.ViewDidLoad(); if (this.TabBarController != null) { this.TabBarController.TabBar.Hidden = true; } //Ensure database refresh //this.NavigationItem.SetRightBarButtonItem( var refreshButton = new UIBarButtonItem(UIBarButtonSystemItem.Refresh, async(sender, args) => { if (Reachability.IsHostReachable(Settings._baseDomain)) { LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame); this.View.AddSubview(loadingIndicator); // button was clicked List <Ad> adList = new List <Ad>(); Ad.DeleteAdsByClassification(SelectedClassification); adList = (await Ad.GetAdsByClassificationAsync(SelectedClassification)).ToList(); this.ModelController.LoadModalController(adList, SelectedClassification); var firstViewController = ModelController.GetViewController(0, false); var viewControllerArray = new UIViewController[] { firstViewController }; PageViewController.SetViewControllers(viewControllerArray, UIPageViewControllerNavigationDirection.Forward, true, null); loadingIndicator.Hide(); } else { HelperMethods.SendBasicAlert("Connect to a Network", "Please connect to a network to refresh these ads"); } }); //, true); //start implementing search feature var searchButton = new UIBarButtonItem(UIBarButtonSystemItem.Search, (sender, e) => { var errorMessage = ""; if (ModelController != null && ModelController.adList != null && ModelController.adList.Count > 0) { var adList = ModelController.adList; SearchResultsViewController searchResultsViewController = new SearchResultsViewController(); searchResultsViewController.SearchResultsAdList = adList; searchResultsViewController.Classification = SelectedClassification; searchResultsViewController.AdSelectedAction = delegate { var pageViewController = this.PageViewController; var magFlipBoardViewController = this; Ad ad = new Ad(); ad = searchResultsViewController.SelectedAd; LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame, "Loading Aircraft"); this.View.AddSubview(loadingIndicator); var modelController = this.ModelController; List <Ad> searchAddList = new List <Ad>(); Task.Run(async() => { searchAddList = (await Ad.GetAdsByClassificationAsync(ad.Classification)).ToList(); //get ads with this name and move them to the from of the liste List <Ad> similarAdList = new List <Ad>(); similarAdList = searchAddList.Where(row => row.Name == ad.Name).OrderBy(r => r.IsFeatured).ToList(); //similarAdList.Remove(ad); for (int i = 0; i < similarAdList.Count(); i++) { searchAddList.Remove(similarAdList[i]); searchAddList.Insert(0, similarAdList[i]); } //similarAdList.Remove(ad); //searchAddList.Insert(0, ad); var index = searchAddList.FindIndex(x => x.ID == ad.ID); var item = searchAddList[index]; searchAddList[index] = searchAddList[0]; searchAddList[0] = item; InvokeOnMainThread(() => { modelController.LoadModalController(searchAddList, ad.Classification); loadingIndicator.Hide(); var initialViewController = modelController.GetViewController(0, false); var searchViewControllers = new UIViewController[] { initialViewController }; pageViewController.SetViewControllers(searchViewControllers, UIPageViewControllerNavigationDirection.Forward, true, null); HelperMethods.SendBasicAlert("", "Aircraft arranged based on search selection"); }); }); }; this.PresentViewController(searchResultsViewController, true, null); } else { errorMessage = "Oops... There was a problem. Aircraft ads are not yet loaded."; } if (errorMessage != string.Empty) { HelperMethods.SendBasicAlert("Alert", errorMessage); } }); List <UIBarButtonItem> navButtonList = new List <UIBarButtonItem>(); navButtonList.Add(searchButton); navButtonList.Add(refreshButton); this.NavigationItem.SetRightBarButtonItems(navButtonList.ToArray(), true); ModelController = new ModelController(SelectedClassification); // Configure the page view controller and add it as a child view controller. //UIPageViewControllerSpineLocation.Min PageViewController = new UIPageViewController(UIPageViewControllerTransitionStyle.PageCurl, UIPageViewControllerNavigationOrientation.Horizontal, UIPageViewControllerSpineLocation.Min); PageViewController.WeakDelegate = this; var startingViewController = ModelController.GetViewController(0, false); var viewControllers = new UIViewController[] { startingViewController }; PageViewController.SetViewControllers(viewControllers, UIPageViewControllerNavigationDirection.Forward, false, null); PageViewController.WeakDataSource = ModelController; AddChildViewController(PageViewController); View.AddSubview(PageViewController.View); UINavigationController magazineNavigationController = (UINavigationController)Storyboard.InstantiateViewController("MagazineNavigationViewController"); float heightTopNavBar = (float)magazineNavigationController.NavigationBar.Frame.Size.Height; float statusBarHeight = (float)UIApplication.SharedApplication.StatusBarFrame.Height; float totalStatusBarHeight = heightTopNavBar + statusBarHeight; var pageViewRect = new CGRect(0, totalStatusBarHeight, View.Bounds.Width, View.Bounds.Height - totalStatusBarHeight); PageViewController.View.Frame = pageViewRect; PageViewController.DidMoveToParentViewController(this); // Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily. //View.GestureRecognizers = PageViewController.GestureRecognizers; if (NavigateDirectlyToAdId != null && NavigateDirectlyToAdId != string.Empty) { LoadingIndicator = new LoadingOverlay(this.View.Frame, "Loading Aircraft", false); this.View.AddSubview(LoadingIndicator); } }
public override void ViewDidDisappear(bool animated) { //unregister from events EditTableButton.TouchUpInside -= EditTableButton_TouchUpInside; RefreshButton.TouchUpInside -= RefreshButton_TouchUpInside; return; var localModifiedAdList = FavoritesAdList.Where(row => row.IsModified).ToList(); //Save modifications made to ads while browsing a magazine if (localModifiedAdList != null && localModifiedAdList.Count > 0) { var classifications = localModifiedAdList.Select(row => row.Classification).Distinct(); //var classifications = Settings.GetFavoredClassifications(); if (classifications.Count() > 0) { Task.Run(async() => { foreach (var classification in classifications) { var modifiedAdsByClassification = localModifiedAdList.Where(row => row.Classification == classification); var allAdsByClassification = (await Ad.GetAdsByClassificationAsync(classification)).ToList(); //remove favorite ads from all ads list //int sequence = 0; foreach (var modifiedAd in modifiedAdsByClassification) { var adWithSameAdID = allAdsByClassification.FirstOrDefault(row => row.ID == modifiedAd.ID); if (adWithSameAdID != null) { allAdsByClassification.Remove(adWithSameAdID); } //if ad local doesn't exist, create it and set values var adLocal = await AdLocal.GetAdLocalByAdID(modifiedAd.ID); if (adLocal == null || string.IsNullOrEmpty(adLocal.AdID)) { adLocal = new AdLocal(); adLocal.AdID = modifiedAd.ID; } adLocal.Sequence = modifiedAd.ClientFavoritesSortOrder; adLocal.Notes = modifiedAd.Notes; AdLocal.SaveAdLocalByAdID(adLocal, modifiedAd.ID); modifiedAd.IsModified = false; } //add favorite ads back into all ads list allAdsByClassification.AddRange(modifiedAdsByClassification); Ad.SaveAdsByClassification(allAdsByClassification, classification); } }); } } FavoritesAdList = null; base.ViewDidDisappear(animated); }