コード例 #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);
            ListView               veiligheidMenu = FindViewById <ListView>(Resource.Id.ListView);
            LinearLayout           linearLayout   = FindViewById <LinearLayout>(Resource.Id.LinearLayout);
            VeiligheidAdapter      adapter;
            RelatieVeiligheidModel relatieVeiligheidModel = new RelatieVeiligheidModel();
            EditText               searchBar = FindViewById <EditText>(Resource.Id.searchBar);

            if (isFavoriteOption.Equals("1"))
            {
                List <Veiligheid> veiligheid = relatieVeiligheidModel.getFavorieten(userId);
                adapter = new VeiligheidAdapter(this, veiligheid, Resource.Layout.OtherMenuListview);
                veiligheidMenu.Adapter = adapter;

                searchBar.Visibility = Android.Views.ViewStates.Invisible;
            }
            else
            {
                List <Veiligheid> veiligheid = model.GetAllData();
                adapter = new VeiligheidAdapter(this, veiligheid, Resource.Layout.OtherMenuListview);
                veiligheidMenu.Adapter = adapter;
            }

            veiligheidMenu.ItemClick += (s, e) =>
            {
                Intent veiligheidActivity = new Intent(this, typeof(VeiligheidActivity));
                veiligheidActivity.PutExtra("id", adapter.GetVeiligheid(e.Position).id);
                veiligheidActivity.PutExtra("userId", userId);
                this.StartActivity(veiligheidActivity);
            };

            searchBar.TextChanged += searchBar_TextChanged;

            void searchBar_TextChanged(object sender, EventArgs e)
            {
                string            query            = searchBar.Text.ToLower();
                List <Veiligheid> searchVeiligheid = model.GetSearchData(query);

                adapter = new VeiligheidAdapter(this, searchVeiligheid, Resource.Layout.OtherMenuListview);
                veiligheidMenu.Adapter = adapter;
            };
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.PlannenView);
            RelatieVeiligheidModel relatieVeiligheidModel = new RelatieVeiligheidModel();

            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.VeiligheidModel model      = new Models.VeiligheidModel();
            Veiligheid             veiligheid = model.GetSingleData(id);

            titel.Text        = veiligheid.ongeval;
            beschrijving.Text = veiligheid.handeling;

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