protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); this.SetContentView(Resource.Layout.Main); var playButton = this.FindViewById <Button>(Resource.Id.PlayPauseButton); var stopButton = this.FindViewById <Button>(Resource.Id.StopButton); var searchView = this.FindViewById <SearchView>(Resource.Id.SearchView); this.listView = this.FindViewById <ListView>(Resource.Id.listView1); this.timeDisplay = this.FindViewById <TextView>(Resource.Id.TimeDisplay); this.adapter = new SongResultsAdapter(this, new Song[0]); this.player = new MediaPlayer(); this.switcher = this.FindViewById <ViewSwitcher>(Resource.Id.ViewSwitcher); this.loadingMessage = this.FindViewById <TextView>(Resource.Id.LoadingMessage); playButton.Click += this.PlayButton_Click; stopButton.Click += this.StopButton_Click; searchView.QueryTextSubmit += this.SearchView_QueryTextSubmit; searchView.QueryTextChange += this.SearchView_QueryTextChange; this.listView.ItemClick += this.ListView_ItemClick; this.player.BufferingUpdate += this.Player_BufferingUpdate; this.player.Error += this.Player_Error; this.ShowListViewMessage("Write in the search box to start."); }
private async void SearchView_QueryTextSubmit(object sender, SearchView.QueryTextSubmitEventArgs e) { try { this.searchToken?.Cancel(); this.searchToken = new CancellationTokenSource(); this.ShowListViewMessage("Loading..."); this.adapter.Clear(); var client = new WebClient(); var qstring = e.Query.Replace(".", string.Empty).Replace("/", string.Empty); var uri = new System.Uri("http://hq.skivent.com.co:8080/search/" + qstring + ".json", UriKind.Absolute); var ret = await Run(() => client.DownloadString(uri), this.searchToken.Token); var songs = this.MapSongs(ret); if (songs.Any()) { this.adapter = new SongResultsAdapter(this, songs); this.listView.Adapter = this.adapter; this.ShowListView(); } else { this.ShowListViewMessage("No results"); } } catch (Exception ex) { this.ShowListViewMessage($"Error loading search results: {ex.Message}"); } finally { this.searchToken = null; } }