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 FeedResultTableSource(UIViewController owner, CLFeedClient client) { this.owner = owner; this.feedClient = client; }