protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.MenuView); string userId = Intent.GetStringExtra("userId"); string isFavoriteOption = Intent.GetStringExtra("isFavoriteOption"); ListView plannenMenu = FindViewById <ListView>(Resource.Id.ListView); LinearLayout linearLayout = FindViewById <LinearLayout>(Resource.Id.LinearLayout); PlannenAdapter adapter; RelatiePlannenModel relatiePlannenModel = new RelatiePlannenModel(); EditText searchBar = FindViewById <EditText>(Resource.Id.searchBar); if (isFavoriteOption.Equals("1")) { List <Plannen> plannen = relatiePlannenModel.getFavorieten(userId); adapter = new PlannenAdapter(this, plannen, Resource.Layout.ReceptMenuListview); plannenMenu.Adapter = adapter; searchBar.Visibility = Android.Views.ViewStates.Invisible; } else { List <Plannen> plannen = model.GetAllData(); adapter = new PlannenAdapter(this, plannen, Resource.Layout.ReceptMenuListview); plannenMenu.Adapter = adapter; } plannenMenu.ItemClick += (s, e) => { Intent plannenActivity = new Intent(this, typeof(PlannenActivity)); plannenActivity.PutExtra("id", adapter.GetPlannen(e.Position).id); plannenActivity.PutExtra("userId", userId); this.StartActivity(plannenActivity); }; searchBar.TextChanged += searchBar_TextChanged; void searchBar_TextChanged(object sender, EventArgs e) { string query = searchBar.Text.ToLower(); List <Plannen> searchPlannen = model.GetSearchData(query); adapter = new PlannenAdapter(this, searchPlannen, Resource.Layout.OtherMenuListview); plannenMenu.Adapter = adapter; }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.PlannenView); RelatiePlannenModel relatiePlannenModel = new RelatiePlannenModel(); string id = Intent.GetStringExtra("id"); string userId = Intent.GetStringExtra("userId"); TextView titel = FindViewById <TextView>(Resource.Id.txtReceptTitel); TextView beschrijving = FindViewById <TextView>(Resource.Id.txtReceptBeschrijving); ImageButton favorieten = FindViewById <ImageButton>(Resource.Id.favorietenReceptBtn); Models.PlannenModel model = new Models.PlannenModel(); Plannen plannen = model.GetSingleData(id); titel.Text = plannen.titel; beschrijving.Text = plannen.tip; favorieten.Click += delegate { if (string.IsNullOrEmpty(userId)) { messageHandler(3, null); } else { if (relatiePlannenModel.checkIfExists(userId, id)) { relatiePlannenModel.deleteFavoriet(userId, id); messageHandler(2, loginModel.requestUser(userId)); } else { relatiePlannenModel.setFavoriet(userId, id); messageHandler(1, loginModel.requestUser(userId)); } } }; void messageHandler(int switchId, Gebruiker gebruiker) { switch (switchId) { case 1: Android.App.AlertDialog.Builder popupMessage1 = new AlertDialog.Builder(this); AlertDialog alert1 = popupMessage1.Create(); alert1.SetTitle("Favoriet toegevoegd!"); alert1.SetMessage("Het plan is aan de favorieten toegevoegd van gebruiker " + gebruiker.gebruikersnaam + "."); alert1.SetButton("OK", (c, ev) => { }); alert1.Show(); break; case 2: Android.App.AlertDialog.Builder popupMessage2 = new AlertDialog.Builder(this); AlertDialog alert2 = popupMessage2.Create(); alert2.SetTitle("Favoriet verwijderd!"); alert2.SetMessage("Het plan is uit de favorieten gehaald van gebruiker " + gebruiker.gebruikersnaam + "."); alert2.SetButton("OK", (c, ev) => { }); alert2.Show(); break; case 3: Android.App.AlertDialog.Builder popupMessage3 = new AlertDialog.Builder(this); AlertDialog alert3 = popupMessage3.Create(); alert3.SetTitle("Favoriet toevoegen mislukt!"); alert3.SetMessage("U moet ingelogd zijn om gebruik te maken van deze functie."); alert3.SetButton("OK", (c, ev) => { }); alert3.Show(); break; } } }