예제 #1
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Resource.Id.action_clear_history:
                var suggestions = new SearchRecentSuggestions(this, SuggestionProvider.Authority, SuggestionProvider.Mode);
                var builder     = new AlertDialog.Builder(this);
                builder.SetMessage(Resource.String.confirm_clear).SetTitle(Resource.String.action_clear_history);
                builder.SetPositiveButton(Resource.String.yes, delegate {
                    suggestions.ClearHistory();
                    Toast.MakeText(this, Resource.String.clear_successful, ToastLength.Short).Show();
                });
                builder.SetNegativeButton(Resource.String.cancel, CancelClicked);
                var alert = builder.Create();
                alert.Show();
                return(true);

            case Resource.Id.action_settings:
                var reg = storage.Get(PropertyRegID);
                Toast.MakeText(this, reg, ToastLength.Long).Show();
                Console.WriteLine("From storage: " + reg);
                Console.WriteLine("From local: " + RegID);
                return(true);

            case Resource.Id.action_refresh:
                pubs.RefreshTable();
                return(true);
            }
            return(DrawerToggle.OnOptionsItemSelected(item) || base.OnOptionsItemSelected(item));
        }
예제 #2
0
        void HandleIntent(Intent intent)
        {
            if (Intent.ActionSearch.Equals(intent.Action))
            {
                var query       = intent.GetStringExtra(SearchManager.Query);
                var suggestions = new SearchRecentSuggestions(this, SuggestionProvider.Authority, SuggestionProvider.Mode);
                suggestions.SaveRecentQuery(query, null);
                var parser = new PublicationsParser();
                SetTitle(Resource.String.search_results);
                mDrawerList.SetItemChecked(0, false);
                var publicationsList = FindViewById <ListView> (Resource.Id.Publications);
                SetProgressBarIndeterminateVisibility(true);
                LoadingView = FindViewById <LinearLayout> (Resource.Id.load_status);
                publicationsList.Visibility = ViewStates.Gone;
                LoadingView.Visibility      = ViewStates.Visible;
                if (cnHelper.NetworkAvailable())
                {
                    parser.SendSearchParameters(publications => RunOnUiThread(() => {
                        var adapter = new PublicationsListAdapter(this.LayoutInflater, publications);
                        publicationsList.Adapter    = adapter;
                        publicationsList.ItemClick += (sender, e) => {
                            var pub      = adapter.Publications [e.Position];
                            var myIntent = new Intent(this, typeof(PublicationActivity));
                            myIntent.PutExtra("remote_id", pub.RemoteId);
                            StartActivity(myIntent);
                        };
                        SetProgressBarIndeterminateVisibility(false);
                        LoadingView.Visibility      = ViewStates.Gone;
                        publicationsList.Visibility = ViewStates.Visible;
                    }), query, state => RunOnUiThread(() => {
                        var builder = new AlertDialog.Builder(this);
                        builder.SetMessage(Resource.String.connection_error).SetTitle(Resource.String.error);
                        builder.SetPositiveButton(Resource.String.ok, delegate {
                            LoadingView.Visibility      = ViewStates.Gone;
                            publicationsList.Visibility = ViewStates.Visible;
                            FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, pubs).Commit();
                            SetProgressBarIndeterminateVisibility(false);
                        });
                        var alert = builder.Create();
                        alert.Show();
                        //Toast.MakeText (this, Resource.String.connection_error, ToastLength.Short).Show ();
                    }));
                }
                else
                {
                    parser.LocalSearch(publications => RunOnUiThread(() => {
                        var adapter          = ((PublicationsListAdapter)publicationsList.Adapter);
                        adapter.Publications = publications;
                        adapter.NotifyDataSetChanged();
                        publicationsList.ItemClick += (sender, e) => {
                            var pub      = adapter.Publications [e.Position];
                            var myIntent = new Intent(this, typeof(PublicationActivity));
                            myIntent.PutExtra("pub_id", pub.Id);
                            StartActivity(myIntent);
                        };
//						FrameView.Visibility = ViewStates.Visible;
                        LoadingView.Visibility = ViewStates.Gone;
                    }), query);
                }
            }
        }