示例#1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (Reachability.IsHostReachable(Settings._baseDomain))
            {
                LoadingOverlay loadingOverlay = new LoadingOverlay(View.Frame);
                View.Add(loadingOverlay);
                Task.Run(() =>
                {
                    var image = HelperMethods.FromUrl(Settings.BanManProURL);
                    BeginInvokeOnMainThread(() =>
                    {
                        loadingOverlay.Hide();
                        BanManProImageView.Image = image;
                    });
                });
            }
            else
            {
                BanManProImageView.Image = UIImage.FromBundle("ad_placeholder.jpg");
            }

            tapGesture1 = new UITapGestureRecognizer(TapImageAction1);

            int currentIndex = this.DataObject.MagazinePageIndex;
            int totalPages   = this.DataObject.TotalPages;

            PageIndicator.SetIndicatorState(currentIndex, totalPages);
        }
        void RefreshButton_TouchUpInside(object sender, EventArgs e)
        {
            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>();

                Task.Run(async() =>
                {
                    foreach (var classification in Settings.GetFavoredClassifications())
                    {
                        Ad.DeleteAdsByClassification(classification);
                        //adList.AddRange(await Ad.GetAdsByClassificationAsync(classification));
                    }

                    BeginInvokeOnMainThread(() =>
                    {
                        loadingIndicator.Hide();
                    });

                    await LoadTable();
                });
            }
            else
            {
                HelperMethods.SendBasicAlert("Connect to a Network", "Please connect to a network to refresh these ads");
            }
        }
示例#3
0
        void TapImageAction1(UITapGestureRecognizer tap)
        {
            if (Reachability.IsHostReachable(Settings._baseDomain))
            {
                LoadingOverlay loadingOverlay = new LoadingOverlay(View.Frame);
                var            webView        = new UIWebView(View.Frame);


                webView.LoadFinished += (sender, e) =>
                {
                    loadingOverlay.Hide();
                };

                var banManProHREF = Settings.BanManProURL.Replace("Task=Get", "Task=Click");
                ;
                webView.LoadRequest(new NSUrlRequest(new NSUrl(banManProHREF)));

                UIView.BeginAnimations("fadeflag");
                UIView.Animate(1, () =>
                {
                    tap.View.Alpha = .5f;
                }, () =>
                {
                    View.AddSubview(webView);
                    View.AddSubview(loadingOverlay);

                    UIButton closeButton = new UIButton(new CGRect(View.Bounds.Width - 75, 0, 75, 50));
                    closeButton.SetImage(UIImage.FromBundle("close"), UIControlState.Normal);
                    closeButton.BackgroundColor = UIColor.White.ColorWithAlpha(.5f);
                    closeButton.TouchUpInside  += (sender, e) =>
                    {
                        try
                        {
                            webView.RemoveFromSuperview();
                            closeButton.RemoveFromSuperview();
                        }
                        finally
                        {
                            webView.Dispose();
                        }
                    };

                    UIImageView imageView = new UIImageView(new CGRect(View.Bounds.Width - 75, View.Bounds.Height / 2, 75, 50));
                    imageView.Image       = UIImage.FromBundle("swipe_left");
                    imageView.Alpha       = .5f;
                    webView.AddSubview(closeButton);
                    webView.AddSubview(imageView);

                    tap.View.Alpha = 1f;
                });

                UIView.CommitAnimations();
            }
            else
            {
                HelperMethods.SendBasicAlert("Connect to a Network", "Please connect to a network to view this ad");
            }
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            //register for events
            EditTableButton.TouchUpInside += EditTableButton_TouchUpInside;
            RefreshButton.TouchUpInside   += RefreshButton_TouchUpInside;
            LoadingOverlayProperty         = new LoadingOverlay(this.View.Frame, "Loading...");
            this.View.AddSubview(LoadingOverlayProperty);


            Task.Run(async() =>
            {
                await LoadTable();
            });
        }
示例#5
0
        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();
        }
        async void CompleteRegistrationButton_TouchUpInside(object sender, EventArgs e)
        {
            if (Reachability.IsHostReachable(Settings._baseDomain))
            {
                LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame, "Loading ...");
                this.View.AddSubview(loadingIndicator);
                //Attempt to register in the API
                var response = await MagAppRegisterResponse.RegisterAsync();

                if (response.Status == "Success")
                {
                    Settings.IsRegistered = true;

                    var alert = UIAlertController.Create("Congratulations!", "You have successfully registered.", UIAlertControllerStyle.Alert);

                    alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                    {
                    }));

                    PresentViewController(alert, animated: true, completionHandler: () =>
                    {
                        RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;

                        var loginVC = registrationVC.PresentingViewController as LoginViewController;
                        registrationVC.DismissViewController(true, null);
                        if (loginVC != null)
                        {
                            loginVC.PerformSegue("LoadTabBarControllerSeque", loginVC);
                        }
                    });
                }
                else
                {
                    loadingIndicator.Hide();
                    HelperMethods.SendBasicAlert("Oops.", "There was a problem registering. Please try again.");
                }
            }
            else
            {
                HelperMethods.SendBasicAlert("Please connect to the internet", "Internet access is required.");
            }
        }
示例#7
0
        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);
                });
            });
        }
示例#9
0
        public static void LoadWebViewWithAd(UITapGestureRecognizer tap, Ad ad, UIView mainView)
        {
            if (Reachability.IsHostReachable(Settings._baseDomain))
            {
                LoadingOverlay loadingOverlay = new LoadingOverlay(mainView.Frame);

                var frame   = new CGRect(0, 0, mainView.Bounds.Width, mainView.Bounds.Height);
                var webView = new UIWebView(frame);


                webView.LoadFinished += (sender, e) =>
                {
                    loadingOverlay.Hide();
                };


                var url = ad.AircraftForSaleURL;
                //commenting to test banmanpro
                //var url = "https://www.globalair.com/banmanpro/ad.aspx?ZoneID=94&Task=Get&Mode=HTML&SiteID=1&PageID=78751";
                webView.LoadRequest(new NSUrlRequest(new NSUrl(url)));

                UIView.BeginAnimations("fadeflag");
                UIView.Animate(1, () =>
                {
                    tap.View.Alpha = .5f;
                }, () =>
                {
                    mainView.AddSubview(webView);
                    mainView.AddSubview(loadingOverlay);

                    UIButton closeButton = new UIButton(new CGRect(mainView.Bounds.Width - 75, 0, 75, 50));
                    closeButton.SetImage(UIImage.FromBundle("close"), UIControlState.Normal);
                    closeButton.BackgroundColor = UIColor.Black;
                    closeButton.TouchUpInside  += (sender, e) =>
                    {
                        try
                        {
                            webView.RemoveFromSuperview();
                            closeButton.RemoveFromSuperview();
                        }
                        finally
                        {
                            webView.Dispose();
                        }
                    };

                    int width, height;

                    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        width  = 110;
                        height = 75;
                    }
                    else
                    {
                        width  = 60;
                        height = 40;
                    }

                    UIImageView imageView            = new UIImageView(new CGRect(mainView.Bounds.Width - width, mainView.Bounds.Height / 2, width, height));
                    imageView.Image                  = UIImage.FromBundle("swipe_left");
                    imageView.Alpha                  = .5f;
                    imageView.UserInteractionEnabled = true;
                    imageView.BackgroundColor        = UIColor.Gray;
                    imageView.ContentMode            = UIViewContentMode.ScaleAspectFit;
                    imageView.Layer.CornerRadius     = 20;

                    //imageView.MultipleTouchEnabled = true;

                    webView.AddSubview(imageView);
                    webView.AddSubview(closeButton);

                    tap.View.Alpha = 1f;
                });

                UIView.CommitAnimations();
            }
            else
            {
                SendBasicAlert("Connect to a Network", "Please connect to a network to view this ad");
            }
        }
        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 RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = tableView.CellAt(indexPath);


            if (Reachability.IsHostReachable(Settings._baseDomain))
            {
                var ad = Owner.FavoritesAdList[indexPath.Row];
                var statusBarHeight = UIApplication.SharedApplication.StatusBarFrame.Height;
                var tabBarHeight    = Owner.TabBarController.TabBar.Bounds.Height;

                var frame   = new CGRect(0, statusBarHeight, Owner.View.Bounds.Width, Owner.View.Bounds.Height - (statusBarHeight + tabBarHeight));
                var webView = new UIWebView(frame);

                LoadingOverlay loadingOverlay = new LoadingOverlay(Owner.View.Frame);

                webView.LoadFinished += (sender, e) =>
                {
                    loadingOverlay.Hide();
                };


                var url = ad.AircraftForSaleURL;
                webView.LoadRequest(new NSUrlRequest(new NSUrl(url)));

                UIView.BeginAnimations("fadeflag");
                UIView.Animate(1, () =>
                {
                    cell.Alpha = .5f;
                }, () =>
                {
                    Owner.View.AddSubview(webView);
                    Owner.View.AddSubview(loadingOverlay);

                    UIButton closeButton = new UIButton(new CGRect(Owner.View.Bounds.Width - 50, 0, 50, 50));
                    closeButton.SetImage(UIImage.FromBundle("close"), UIControlState.Normal);
                    closeButton.BackgroundColor = UIColor.Black;
                    closeButton.TouchUpInside  += (sender, e) =>
                    {
                        try
                        {
                            webView.RemoveFromSuperview();
                            closeButton.RemoveFromSuperview();
                        }
                        finally
                        {
                            webView.Dispose();
                        }
                    };
                    //Owner.View.AddSubview(closeButton);
                    webView.AddSubview(closeButton);

                    cell.Alpha = 1f;
                });

                UIView.CommitAnimations();
                //}
            }
            else
            {
                HelperMethods.SendBasicAlert("Connect to a Network", "Please connect to a network to view this ad");
            }



            tableView.DeselectRow(indexPath, true);
        }
        async void SubmitButton_TouchUpInside(object sender, EventArgs e)
        {
            UsernameTextField.Enabled = false;
            PasswordTextField.Enabled = false;

            string username = UsernameTextField.Text;
            string password = PasswordTextField.Text;



            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                if (!HelperMethods.IsValidPassword(password))
                {
                    HelperMethods.SendBasicAlert("Validation", "Passwords should contain letters and numbers and be at least 6 characters.");
                    PasswordTextField.Layer.BorderColor = UIColor.Red.CGColor;
                    PasswordTextField.Layer.BorderWidth = 1f;
                    UsernameTextField.Enabled           = true;
                    PasswordTextField.Enabled           = true;
                    return;
                }
                //Save username/password to settings

                Settings.Username = username;
                Settings.Password = password;



                LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame, "Loading ...");
                this.View.AddSubview(loadingIndicator);

                //AuthResponse

                BlobCache.LocalMachine.InvalidateObject <AuthResponse>(AuthResponse.getAuthResponse);

                AuthResponse response = await AuthResponse.GetAuthResponseAsync(0, Settings.Username, Settings.Password);

                Settings.AppID     = response.AppId;
                Settings.AuthToken = response.AuthToken;

                APIManager manager = new APIManager();

                {
                    //LoginResponse authResponse = await manager.loginUser(Settings.AppID, Settings.Username, Settings.Password, Settings.AuthToken);
                    LoginResponse authResponse = await manager.loginUser(Settings.AppID, Settings.Username, Settings.Password, Settings.AuthToken);

                    if (authResponse.AuthToken != null)
                    {
                        Settings.AppID     = authResponse.AppId;
                        Settings.UserID    = authResponse.MagAppUserId;
                        Settings.AuthToken = authResponse.AuthToken;
                    }
                    else
                    {
                        loadingIndicator.Hide();
                        String responseMessage = "";
                        if (authResponse.ResponseMsg != null && authResponse.ResponseMsg != string.Empty)
                        {
                            responseMessage = authResponse.ResponseMsg;
                        }
                        else
                        {
                            responseMessage = "Unable to authenticate user.";
                        }

                        if (responseMessage == "Incorrect Password")
                        {
                            MessageViewController messageViewController = (MessageViewController)Storyboard.InstantiateViewController("MessageViewController");
                            this.PresentViewController(messageViewController, true, null);
                        }
                        else
                        {
                            HelperMethods.SendBasicAlert("Login", responseMessage);
                        }
                        UsernameTextField.Enabled = true;
                        PasswordTextField.Enabled = true;
                        return;
                    }


                    try
                    {
                        var responseProfile = await manager.getUserProfile(Settings.AppID, Settings.Username, Settings.AuthToken, Settings.Password);

                        Settings.IsAmphibian    = responseProfile.C1 == 1;
                        Settings.IsCommercial   = responseProfile.C2 == 1;
                        Settings.IsExperimental = responseProfile.C3 == 1;
                        Settings.IsHelicopter   = responseProfile.C4 == 1;
                        Settings.IsJets         = responseProfile.C5 == 1;
                        Settings.IsSingles      = responseProfile.C7 == 1;
                        Settings.IsSingleEngine = responseProfile.C6 == 1;
                        Settings.IsTwinPistons  = responseProfile.C8 == 1;
                        Settings.IsTwinTurbines = responseProfile.C9 == 1;
                        Settings.IsVintage      = responseProfile.C10 == 1;
                        Settings.IsWarbirds     = responseProfile.C11 == 1;
                        Settings.IsLightSport   = responseProfile.C12 == 1;

                        Settings.Email = Settings.Username;

                        Settings.FirstName = responseProfile.FirstName;
                        Settings.LastName  = responseProfile.LastName;
                        Settings.Phone     = responseProfile.CellPhone;

                        Settings.Company                  = responseProfile.Company;
                        Settings.Hours                    = responseProfile.HourPerMonth;
                        Settings.ManufacturerId           = responseProfile.DesignationId;
                        Settings.LocationPickerSelectedId = responseProfile.CountryId;
                        Settings.Phone                    = responseProfile.CellPhone;
                        Settings.DesignationId            = responseProfile.DesignationId;
                        Settings.PurposeId                = responseProfile.FlyingPurposeId;
                        Settings.HomeAirport              = responseProfile.HomeAirport;
                        Settings.Password                 = responseProfile.Password;
                        Settings.PilotStatusId            = responseProfile.PilotStatusId;
                        Settings.PilotTypeId              = responseProfile.PilotTypeId;
                        Settings.PurchaseTimeFrame        = responseProfile.PurchaseTimeFrame;

                        loadingIndicator.Hide();
                        this.PerformSegue("LoadTabBarControllerSeque", this);
                    }
                    catch (Exception exe)
                    {
                        loadingIndicator.Hide();
                        HelperMethods.SendBasicAlert("Login", "Login Failed");
                    }
                }



                PasswordTextField.Layer.BorderColor = UIColor.Clear.CGColor;
                PasswordTextField.Layer.BorderWidth = 0f;

                UsernameTextField.Layer.BorderColor = UIColor.Clear.CGColor;
                UsernameTextField.Layer.BorderWidth = 0f;
            }
            else
            {
                //Update UI to reflect invalid username or password

                if (string.IsNullOrEmpty(username))
                {
                    UsernameTextField.Layer.BorderColor = UIColor.Red.CGColor;
                    UsernameTextField.Layer.BorderWidth = 1f;
                }
                else
                {
                    UsernameTextField.Layer.BorderColor = UIColor.Clear.CGColor;
                    UsernameTextField.Layer.BorderWidth = 0f;
                }

                if (string.IsNullOrEmpty(password))
                {
                    PasswordTextField.Layer.BorderColor = UIColor.Red.CGColor;
                    PasswordTextField.Layer.BorderWidth = 1f;
                }
                else
                {
                    PasswordTextField.Layer.BorderColor = UIColor.Clear.CGColor;
                    PasswordTextField.Layer.BorderWidth = 0f;
                }
            }

            UsernameTextField.Enabled = true;
            PasswordTextField.Enabled = true;
        }
示例#13
0
        public override void ViewDidLoad()
        {
            NavigationItem.Title = "Registration";

            NavigationItem.BackBarButtonItem = new UIBarButtonItem("Back", UIBarButtonItemStyle.Plain, null);

            HideKeyboardGesture = new UITapGestureRecognizer(() =>
            {
                View.EndEditing(true);
            });

            var finishButton = new UIBarButtonItem("Finish", UIBarButtonItemStyle.Plain, async(sender, args) =>
            {
                if (Reachability.IsHostReachable(Settings._baseDomain))
                {
                    LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame, "Loading ...");
                    this.View.AddSubview(loadingIndicator);
                    //Attempt to register in the API
                    var response = await MagAppRegisterResponse.RegisterAsync();

                    if (response.Status == "Success")
                    {
                        loadingIndicator.Hide();
                        Settings.IsRegistered = true;

                        //var registrationStoryboard = UIStoryboard.FromName("Main_ipad", NSBundle.MainBundle);
                        //PushNotificationPromptViewController pushNotificationPromptViewController = (PushNotificationPromptViewController)registrationStoryboard.InstantiateViewController("PushNotificationPromptViewController");
                        //pushNotificationPromptViewController.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
                        //PresentViewController(pushNotificationPromptViewController, true, () =>
                        //{
                        var alert = UIAlertController.Create("Congratulations!", "You have successfully registered.", UIAlertControllerStyle.Alert);

                        alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                        {
                            this.DismissViewController(true, null);
                            var loginViewController = this.PresentingViewController as LoginViewController;
                            this.NavigationController.DismissViewController(true, null);
                            if (loginViewController != null)
                            {
                                loginViewController.PerformSegue("LoadTabBarControllerSeque", loginViewController);
                            }
                        }));

                        PresentViewController(alert, animated: true, completionHandler: () =>
                        {
                        });
                        //});
                    }
                    else
                    {
                        loadingIndicator.Hide();
                        HelperMethods.SendBasicAlert("Oops.", response.ResponseMsg);
                    }
                }
                else
                {
                    HelperMethods.SendBasicAlert("Please connect to the internet", "Internet access is required.");
                }
            });
            UITextAttributes icoFontAttribute = new UITextAttributes();

            icoFontAttribute.Font      = UIFont.BoldSystemFontOfSize(20);
            icoFontAttribute.TextColor = UIColor.White;

            finishButton.SetTitleTextAttributes(icoFontAttribute, UIControlState.Normal);

            this.NavigationItem.SetRightBarButtonItem(finishButton, true);

            var orderByPicker = new UIPickerView();

            orderByPicker.Model = new SortOptionsViewModel();
            orderByPicker.ShowSelectionIndicator = true;

            UIToolbar orderByToolbar = new UIToolbar();

            orderByToolbar.BarStyle    = UIBarStyle.Black;
            orderByToolbar.Translucent = true;
            orderByToolbar.SizeToFit();

            UIBarButtonItem orderByDoneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (s, e) =>
            {
                UITextField textview = OrderByTextField;

                textview.Text = Settings.SortOptions;
                textview.ResignFirstResponder();
            });

            orderByToolbar.SetItems(new UIBarButtonItem[] { orderByDoneButton }, true);


            OrderByTextField.InputView          = orderByPicker;
            OrderByTextField.InputAccessoryView = orderByToolbar;

            var timeframePicker = new UIPickerView();

            timeframePicker.Model = new TimeframeViewModel();
            timeframePicker.ShowSelectionIndicator = true;

            UIToolbar timeframeToolbar = new UIToolbar();

            timeframeToolbar.BarStyle    = UIBarStyle.Black;
            timeframeToolbar.Translucent = true;
            timeframeToolbar.SizeToFit();

            UIBarButtonItem timeframeDoneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (s, e) =>
            {
                UITextField textview = TimeFrameTextField;

                textview.Text = Settings.PurchaseTimeFrame + " months";
                textview.ResignFirstResponder();
            });

            timeframeToolbar.SetItems(new UIBarButtonItem[] { timeframeDoneButton }, true);


            TimeFrameTextField.InputView          = timeframePicker;
            TimeFrameTextField.InputAccessoryView = timeframeToolbar;

            var whyFlyPicker = new UIPickerView();

            whyFlyPicker.Model = new PurposeViewModel();
            whyFlyPicker.ShowSelectionIndicator = true;

            UIToolbar whyFlyToolbar = new UIToolbar();

            whyFlyToolbar.BarStyle    = UIBarStyle.Black;
            whyFlyToolbar.Translucent = true;
            whyFlyToolbar.SizeToFit();

            UIBarButtonItem whyFlyDoneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (s, e) =>
            {
                UITextField textview = WhyFlyTextField;

                //var selected = Settings.LocationResponse.PurposeForFlying.FirstOrDefault(row => row.FlyingPurposeId == Settings.PurposeId);

                textview.Text = Settings.PurposeString;
                textview.ResignFirstResponder();
            });

            whyFlyToolbar.SetItems(new UIBarButtonItem[] { whyFlyDoneButton }, true);


            WhyFlyTextField.InputView          = whyFlyPicker;
            WhyFlyTextField.InputAccessoryView = whyFlyToolbar;


            var borderFrameHeight     = WhyFlyTextField.Frame.Size.Height - 1;
            var borderFrameWidth      = this.View.Bounds.Width - 20;
            var borderBackgroundColor = UIColor.Gray.CGColor;

            // create CALayer
            var bottomBorder1 = new CALayer();

            bottomBorder1.Frame           = new CGRect(0.0f, borderFrameHeight, borderFrameWidth, 1.0f);
            bottomBorder1.BackgroundColor = borderBackgroundColor;

            var bottomBorder2 = new CALayer();

            bottomBorder2.Frame           = new CGRect(0.0f, borderFrameHeight, borderFrameWidth, 1.0f);
            bottomBorder2.BackgroundColor = borderBackgroundColor;

            var bottomBorder3 = new CALayer();

            bottomBorder3.Frame           = new CGRect(0.0f, borderFrameHeight, borderFrameWidth, 1.0f);
            bottomBorder3.BackgroundColor = borderBackgroundColor;

            var bottomBorder4 = new CALayer();

            bottomBorder4.Frame           = new CGRect(0.0f, borderFrameHeight, borderFrameWidth, 1.0f);
            bottomBorder4.BackgroundColor = borderBackgroundColor;

            var fontSize   = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 22.0f : 16.0f;
            var fontObject = UIFont.SystemFontOfSize(fontSize);

            WhyFlyTextField.Layer.AddSublayer(bottomBorder2);
            WhyFlyTextField.Layer.MasksToBounds   = true;
            WhyFlyTextField.AttributedPlaceholder = new NSAttributedString(
                "Select from list",
                font: fontObject,
                foregroundColor: UIColor.DarkGray
                );
            WhyFlyTextField.Font = fontObject;
            WhyFlyTextField.Text = Settings.PurposeString ?? string.Empty;

            TimeFrameTextField.Layer.AddSublayer(bottomBorder3);
            TimeFrameTextField.Layer.MasksToBounds   = true;
            TimeFrameTextField.AttributedPlaceholder = new NSAttributedString(
                "Select from list",
                font: fontObject,
                foregroundColor: UIColor.DarkGray
                );
            TimeFrameTextField.Font = fontObject;
            TimeFrameTextField.Text = Settings.PurchaseTimeFrame != 0 ? Settings.PurchaseTimeFrame + " months" : string.Empty;

            OrderByTextField.Layer.AddSublayer(bottomBorder4);
            OrderByTextField.Layer.MasksToBounds   = true;
            OrderByTextField.AttributedPlaceholder = new NSAttributedString(
                "Select from list",
                font: fontObject,
                foregroundColor: UIColor.DarkGray
                );
            OrderByTextField.Font = fontObject;
            OrderByTextField.Text = Settings.SortOptions ?? string.Empty;


            // add to UITextField
            HoursTextView.Layer.AddSublayer(bottomBorder1);
            HoursTextView.Layer.MasksToBounds = true;
            HoursTextView.Font           = fontObject;
            HoursTextView.KeyboardType   = UIKeyboardType.NumberPad;
            HoursTextView.EditingDidEnd += (sender, e) => {
                if (HoursTextView.Text != string.Empty)
                {
                    int hours = 0;
                    if (int.TryParse(HoursTextView.Text, out hours) && hours > 0)
                    {
                        Settings.Hours = hours;
                    }
                }
            };
            HoursTextView.Text = Settings.Hours != 0 ? Settings.Hours.ToString() : string.Empty;
        }