Esempio n. 1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = new ListView(this.Activity);

            Console.WriteLine("Max Listings: " + MaxListings + ", Weeks Old: " + WeeksOld);
            feedClient = new CLFeedClient(Query, MaxListings, WeeksOld);
            var connected = feedClient.GetAllPostingsAsync();

            if (!connected)
            {
                var builder = new Android.Support.V7.App.AlertDialog.Builder(this.Activity);

                builder.SetTitle("No internet connection")
                .SetMessage("Please connect and try again")
                .SetPositiveButton("Ok", delegate
                {
                    this.FragmentManager.PopBackStack();
                });

                builder.Create().Show();
            }
            else
            {
                var progressDialog = ProgressDialog.Show(this.Activity, "Please wait...", "Loading listings...", true);
                progressDialog.SetCancelable(true);
                progressDialog.SetCanceledOnTouchOutside(false);
                progressDialog.SetOnCancelListener(this);

                new Thread(new ThreadStart(delegate
                {
                    //HIDE PROGRESS DIALOG
                    feedClient.asyncLoadingComplete += (object sender, EventArgs e) =>
                    {
                        this.Activity.RunOnUiThread(() =>
                        {
                            progressDialog.Hide();
                        });
                        Console.WriteLine("NUM POSTINGS: " + feedClient.postings.Count);
                        feedAdapter = new FeedResultsAdapter(this.Activity, new System.Collections.ObjectModel.ObservableCollection <Models.Posting>(feedClient.postings));
                        this.Activity.RunOnUiThread(() =>
                        {
                            view.Adapter = feedAdapter;
                        });
                    };

                    feedClient.emptyPostingComplete += (object sender, EventArgs e) =>
                    {
                        this.Activity.RunOnUiThread(() => progressDialog.Hide());

                        var builder = new Android.Support.V7.App.AlertDialog.Builder(this.Activity);
                        builder.SetTitle("Error loading listings");
                        builder.SetMessage(String.Format("No listings found.{0}Try a different search", System.Environment.NewLine));
                        builder.SetPositiveButton("Ok", delegate
                        {
                            this.FragmentManager.PopBackStack();
                        });

                        this.Activity.RunOnUiThread(() =>
                        {
                            builder.Create().Show();
                        });
                    };
                })).Start();
            }

            view.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
            {
                var transaction = this.Activity.SupportFragmentManager.BeginTransaction();
                PostingDetailsFragment postingDetailsFragment = new PostingDetailsFragment();
                postingDetailsFragment.Posting = feedClient.postings[e.Position];
                transaction.Replace(Resource.Id.frameLayout, postingDetailsFragment);
                transaction.AddToBackStack(null);
                transaction.Commit();
            };

            return(view);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Console.WriteLine(Query);

            this.Title = "Search Results";

            var bounds = UIScreen.MainScreen.Bounds; // portrait bounds

            if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight)
            {
                bounds.Size = new CGSize(bounds.Size.Height, bounds.Size.Width);
            }
            // show the loading overlay on the UI thread using the correct orientation sizing
            this._loadingOverlay = new LoadingOverlay(bounds);
            this.View.Add(this._loadingOverlay);

            feedClient = new CLFeedClient(Query, MaxListings, WeeksOld);
            var result = feedClient.GetAllPostingsAsync();

            if (!result)
            {
                this._loadingOverlay.Hide();
                UIAlertView alert = new UIAlertView();
                alert.Message = String.Format("No network connection.{0}Please check your settings", Environment.NewLine);
                alert.AddButton("OK");
                alert.Clicked += (s, ev) =>
                {
                    this.InvokeOnMainThread(() => this.NavigationController.PopViewController(true));
                };
                this.InvokeOnMainThread(() => alert.Show());
            }

            tableSource = new FeedResultTableSource(this, feedClient);

            feedResultTable.Source         = tableSource;
            feedResultTable.SeparatorStyle = UITableViewCellSeparatorStyle.None;

            refreshControl = new UIRefreshControl();
            feedResultTable.AddSubview(refreshControl);
            refreshControl.ValueChanged += (object sender, EventArgs e) =>
            {
                feedClient.GetAllPostingsAsync();
            };

            feedClient.asyncLoadingComplete       += feedClient_LoadingComplete;
            feedClient.asyncLoadingPartlyComplete += feedClient_LoadingComplete;
            feedClient.emptyPostingComplete       += (object sender, EventArgs e) =>
            {
                if (!this._loadingOverlay.AlreadyHidden)
                {
                    this._loadingOverlay.Hide();
                }

                refreshControl.EndRefreshing();
                UIAlertView alert = new UIAlertView();
                alert.Message = String.Format("No listings found.{0}Try another search", Environment.NewLine);
                alert.AddButton("OK");
                alert.Clicked += (s, ev) =>
                {
                    this.InvokeOnMainThread(() => this.NavigationController.PopViewController(true));
                };
                this.InvokeOnMainThread(() => alert.Show());
            };

            ads.AdLoaded += (object sender, EventArgs e) =>
            {
                AddAdBanner(true);
            };
        }
Esempio n. 3
0
 public FeedResultTableSource(UIViewController owner, CLFeedClient client)
 {
     this.owner      = owner;
     this.feedClient = client;
 }