void Initialize() { Adapter = adapter = new FeedResultsAdapter(_context, new ObservableCollection <Posting>(MainActivity.databaseConnection.GetAllPostingsAsync().Result)); ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { var transaction = ((MainActivity)_context).SupportFragmentManager.BeginTransaction(); PostingDetailsFragment postingDetailsFragment = new PostingDetailsFragment(); postingDetailsFragment.Posting = adapter.Postings[e.Position]; transaction.Replace(Resource.Id.frameLayout, postingDetailsFragment); transaction.AddToBackStack(null); transaction.Commit(); }; if (_deleteable) { ItemLongClick += (sender, e) => { PopupMenu menu = new PopupMenu(_context, GetChildAt(e.Position)); menu.Inflate(Resource.Menu.DeleteMenu); menu.Show(); menu.MenuItemClick += (se, args) => { Console.WriteLine("Deleting posting index: " + e.Position); lock (adapter.Postings) { var del = MainActivity.databaseConnection.DeletePostingAsync(adapter.Postings[e.Position]).Result; ((Activity)_context).RunOnUiThread(() => adapter.Postings.RemoveAt(e.Position)); adapter.NotifyDataSetChanged(); } Console.WriteLine(MainActivity.databaseConnection.StatusMessage); }; }; } ; }
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); }