Пример #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_search);
            _requestSender = new RequestSender();
            _allBooks      = _requestSender.SendGetBooksRequest();

            //-------------Fill list of books------------------------------
            _allBooks                 = _allBooks.OrderByDescending(b => b.BookInfo.Popularity).ToList();
            _allBooksListView         = FindViewById <ListView>(Resource.Id.lstSearch);
            _allBooksListAdapter      = new ListAdapterLibrary(this, _allBooks);
            _allBooksListView.Adapter = _allBooksListAdapter;


            //---------Spinner------------------------------
            _spinner               = FindViewById <Spinner>(Resource.Id.spinner);
            _spinner.Prompt        = "Search by";
            _spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
            _adapter               = ArrayAdapter.CreateFromResource(this, Resource.Array.Counter, Android.Resource.Layout.SimpleSpinnerItem);
            _adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            _spinner.Adapter = _adapter;
            _spinner1Choose  = "Popularity";

            //---------Spinner2--------------------------------
            _spinner2               = FindViewById <Spinner>(Resource.Id.spinner2);
            _spinner2.Prompt        = "Choose filter option";
            _spinner2.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner2_ItemSelected);
            _adapter2               = ArrayAdapter.CreateFromResource(this, Resource.Array.ByPopularity, Android.Resource.Layout.SimpleSpinnerItem);
            _adapter2.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            _spinner2.Adapter = _adapter2;
        }
Пример #2
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            Intent intent;

            switch (item.ItemId)
            {
            case Resource.Id.menu_search:
            {
                intent = new Intent(this, typeof(SearchActivity));
                StartActivity(intent);
                break;
            }

            case Resource.Id.menu_top_books:
            {
                string userinfo = JsonConvert.SerializeObject(user);
                intent = new Intent(this, typeof(TopBooksActivity));
                intent.PutExtra("user", userinfo);
                StartActivity(intent);
                break;
            }

            case Resource.Id.menu_logout:
            {
                intent = new Intent(this, typeof(LoginActivity));
                StartActivity(intent);
                break;
            }

            case Resource.Id.menu_delete:
            {
                RequestSender rSender = new RequestSender();
                if (user.BorrowedBooks.Count == 0)
                {
                    AlertDialog.Builder builder     = new AlertDialog.Builder(this);
                    AlertDialog         alertDialog = builder.Create();

                    alertDialog.Show();

                    new AlertDialog.Builder(this)
                    .SetPositiveButton("Yes", (sent, args) =>
                        {
                            if (rSender.SendDeleteUser(user.UserInfo.Id))
                            {
                                intent = new Intent(this, typeof(MainActivity));
                                StartActivity(intent);
                            }
                            else
                            {
                                Toast.MakeText(this, "Unable to delete account", ToastLength.Long).Show();
                            }
                        })
                    .SetNegativeButton("No", (sent, args) => { })
                    .SetMessage("Are you sure you want to delete your account?")
                    .SetTitle("DELETE ACCOUNT")
                    .SetCancelable(false)
                    .Show();
                }
                else
                {
                    Toast.MakeText(this, "Please return all your books first!", ToastLength.Long).Show();
                }
                break;
            }
            }
            return(base.OnOptionsItemSelected(item));
        }