Exemple #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            string userId           = Intent.GetStringExtra("userId");
            string isFavoriteOption = Intent.GetStringExtra("isFavoriteOption");

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.MenuView);
            RelatieReceptModel relatieReceptModel = new RelatieReceptModel();
            ListView           receptenMenu       = FindViewById <ListView>(Resource.Id.ListView);
            LinearLayout       linearLayout       = FindViewById <LinearLayout>(Resource.Id.LinearLayout);

            ReceptenAdapter adapter;

            EditText searchBar = FindViewById <EditText>(Resource.Id.searchBar);

            if (isFavoriteOption.Equals("1"))
            {
                List <Recept> recepten = relatieReceptModel.getFavorieten(userId);
                adapter = new ReceptenAdapter(this, recepten, Resource.Layout.ReceptMenuListview);
                receptenMenu.Adapter = adapter;

                searchBar.Visibility = Android.Views.ViewStates.Invisible;
            }
            else
            {
                List <Recept> recepten = model.GetAllData();
                adapter = new ReceptenAdapter(this, recepten, Resource.Layout.ReceptMenuListview);
                receptenMenu.Adapter = adapter;
            }

            receptenMenu.ItemClick += (s, e) =>
            {
                Intent receptActivity = new Intent(this, typeof(ReceptenActivity));
                receptActivity.PutExtra("id", adapter.GetRecept(e.Position).id);
                receptActivity.PutExtra("userId", userId);
                this.StartActivity(receptActivity);
            };

            searchBar.TextChanged += searchBar_TextChanged;

            void searchBar_TextChanged(object sender, EventArgs e)
            {
                string query = searchBar.Text.ToLower();

                List <Recept> searchRecepten = model.GetSearchData(query);

                adapter = new ReceptenAdapter(this, searchRecepten, Resource.Layout.ReceptMenuListview);
                receptenMenu.Adapter = adapter;
            };
        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ReceptView);
            RelatieReceptModel relatieReceptModel = new RelatieReceptModel();
            string             id     = Intent.GetStringExtra("id");
            string             userId = Intent.GetStringExtra("userId");

            TextView    titel           = FindViewById <TextView>(Resource.Id.txtReceptTitel);
            TextView    beschrijving    = FindViewById <TextView>(Resource.Id.txtReceptBeschrijving);
            TextView    bereidingstijd  = FindViewById <TextView>(Resource.Id.txtReceptBereidingstijd);
            TextView    ingredienten    = FindViewById <TextView>(Resource.Id.txtReceptIngredienten);
            TextView    voorbereiding   = FindViewById <TextView>(Resource.Id.txtReceptVoorbereiding);
            TextView    bereidingswijze = FindViewById <TextView>(Resource.Id.txtReceptBereidingswijze);
            TextView    kosten          = FindViewById <TextView>(Resource.Id.txtReceptKosten);
            ImageButton favorieten      = FindViewById <ImageButton>(Resource.Id.favorietenReceptBtn);

            Models.ReceptModel model  = new Models.ReceptModel();
            Recept             recept = model.GetSingleData(id);

            titel.Text           = recept.naam;
            beschrijving.Text    = recept.beschrijving;
            bereidingstijd.Text  = recept.bereidingstijd;
            ingredienten.Text    = recept.ingredienten;
            voorbereiding.Text   = recept.voorbereiding;
            bereidingswijze.Text = recept.bereidingswijze;
            kosten.Text          = recept.kosten;

            favorieten.Click += delegate
            {
                if (string.IsNullOrEmpty(userId))
                {
                    messageHandler(3, null);
                }
                else
                {
                    if (relatieReceptModel.checkIfExists(userId, id))
                    {
                        relatieReceptModel.deleteFavoriet(userId, id);
                        messageHandler(2, loginModel.requestUser(userId));
                    }
                    else
                    {
                        relatieReceptModel.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 recept 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 recept 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;
                }
            }
        }