Ejemplo n.º 1
0
        public void PerformSearch(string searchQuery, int searchCategory, TpbQueryOrder searchOrder)
        {
            if (MainActivity.Instance.IsConnected == true)
            {
                System.Threading.Thread thread = new System.Threading.Thread(() =>
                {
                    UserDialogs.Instance.ShowLoading("Searching, Please Wait …", MaskType.Black);
                    MainActivity.Instance.torrents = Tpb.Search(new TpbQuery(searchQuery, 0, searchOrder, searchCategory));
                    if (MainActivity.Instance.torrents.Count == 0)
                    {
                        MainActivity.Instance.RunOnUiThread(() => Toast.MakeText(Application.Context, "No results found for " + searchQuery, ToastLength.Short).Show());
                    }
                    else
                    {
                        //listViewAnimShow.Duration = 200;

                        lvResults.StartAnimation(listViewAnimShow);

                        //MainActivity.Instance.RunOnUiThread(() => listView.Visibility = ViewStates.Visible);
                        MainActivity.Instance.RunOnUiThread(() => lvResults.Adapter = new TorListAdapter(MainActivity.Instance, MainActivity.Instance.torrents));
                    };

                    UserDialogs.Instance.HideLoading();
                });;
                thread.Start();
                //torSearchView.ClearFocus();

                //torSearchView.SetQuery("", false);
                //MenuItemCompat.CollapseActionView(item);
                //tvStatusText.Text = "Search results for: " + e.NewText.ToString();
                //tvStatusText.Text = MaterialIcons.md_dis;
                //layoutWelcome.Visibility = ViewStates.Gone;

                //e.Handled = true;
            }
            else
            {
                //torSearchView.ClearFocus();
                Toast.MakeText(Application.Context, "No internet connection detected!", ToastLength.Long).Show();
            };
        }
Ejemplo n.º 2
0
        public override bool OnCreateOptionsMenu(IMenu menu)
        {
            MenuInflater.Inflate(Resource.Menu.toolmenu, menu);
            var item       = menu.FindItem(Resource.Id.menu_search);
            var searchItem = MenuItemCompat.GetActionView(item);

            torSearchView = searchItem.JavaCast <Android.Support.V7.Widget.SearchView>();
            torSearchView.SetIconifiedByDefault(false);
            torSearchView.QueryHint = "Torrent Search...";
            //torSearchView.SubmitButtonEnabled = true;
            var simgid         = torSearchView.Context.Resources.GetIdentifier("search_mag_icon", "id", PackageName);
            var id             = torSearchView.Context.Resources.GetIdentifier("search_src_text", "id", PackageName);
            var searchEditText = torSearchView.FindViewById <EditText>(id);
            var searchIcon     = torSearchView.FindViewById <ImageView>(simgid);

            searchIcon.SetColorFilter(Android.Graphics.Color.White);
            searchEditText.SetTextColor(Android.Graphics.Color.White);
            searchEditText.SetHintTextColor(Android.Graphics.Color.White);



            torSearchView.QueryTextSubmit += (s, e) =>
            {
                if (IsConnected == true)
                {
                    string query = e.NewText.ToString();
                    rlStatusLayout.Visibility = ViewStates.Gone;
                    listView.Visibility       = ViewStates.Gone;
                    System.Threading.Thread thread = new System.Threading.Thread(() =>
                    {
                        UserDialogs.Instance.ShowLoading("Searching, Please Wait …", MaskType.Black);
                        torrents = Tpb.Search(new TpbQuery(query, 0, searchOrder, searchCategory));
                        if (torrents.Count == 0)
                        {
                            RunOnUiThread(() => Toast.MakeText(this, "No results found for " + query, ToastLength.Short).Show());
                        }
                        else
                        {
                            //listViewAnimShow.Duration = 200;
                            rlStatusLayout.StartAnimation(statusAnimShow);
                            listView.StartAnimation(listViewAnimShow);
                            RunOnUiThread(() => rlStatusLayout.Visibility = ViewStates.Visible);
                            RunOnUiThread(() => listView.Visibility       = ViewStates.Visible);
                            RunOnUiThread(() => listView.Adapter          = new TorListAdapter(this, torrents));
                        };

                        UserDialogs.Instance.HideLoading();
                    });;
                    thread.Start();
                    torSearchView.ClearFocus();

                    //torSearchView.SetQuery("", false);
                    //MenuItemCompat.CollapseActionView(item);
                    tvStatusText.Text = "Search results for: " + e.NewText.ToString();
                    //tvStatusText.Text = MaterialIcons.md_dis;
                    layoutWelcome.Visibility = ViewStates.Gone;

                    e.Handled = true;
                }
                else
                {
                    torSearchView.ClearFocus();
                    Toast.MakeText(this, "No internet connection detected!", ToastLength.Long).Show();
                };
            };
            //return true;
            return(base.OnCreateOptionsMenu(menu));
        }