protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_download_song); GoogleAnalyticsService.Instance.Initialize(this); GoogleAnalyticsService.Instance.TrackAppPage("Download Song"); video = SearchSongs.getSelectedVideo(); videoName = FindViewById <TextView>(Resource.Id.videoName); channelName = FindViewById <TextView>(Resource.Id.channelName); videoImg = FindViewById <ImageView>(Resource.Id.videoImg); progressBar = FindViewById <ProgressBar>(Resource.Id.downloadingProgressBar); downloadBtn = FindViewById <Button>(Resource.Id.downloadBtn); downloadBtn.SetBackgroundColor(new Color(ContextCompat.GetColor(this, Resource.Color.darkassets))); DownloadWatcher.onDownloaded += (sender, e) => TogglePlay(); DownloadWatcher.onDownloadFailed += (sender, e) => ToggelDownload(); if (AdsService.DownloadSongAd == null) { AdsService.DownloadSongAd = FindViewById <AdView>(Resource.Id.adView); AdsService.LoadBanner(AdsService.DownloadSongAd); } UpdateView(); }
private async void OnDownloadClick(object sender, EventArgs e, int videoPosition) { SearchResultDownloadItem video = searchResults[videoPosition]; video.DownloadState = SearchResultDownloadItem.State.Downloading; string fileName = video.YoutubeResult.Snippet.Title + ".mp3"; UpdateVideoButtonByState(video.DownloadState, (ImageButton)sender); try { if (await Downloader.DownloadSong(video.YoutubeResult.Id.VideoId, fileName)) { video.DownloadState = SearchResultDownloadItem.State.Downloaded; DownloadWatcher.DownloadFinished(sender, e); UpdateVideoButtonByState(video.DownloadState, (ImageButton)sender); Toast.MakeText(context, "Download succeed", ToastLength.Short).Show(); } else { video.DownloadState = SearchResultDownloadItem.State.Downloadable; FailDownload(sender, e); } } catch { video.DownloadState = SearchResultDownloadItem.State.Downloadable; FailDownload(sender, e); } finally { NotifyDataSetInvalidated(); } }
protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_search_songs); GoogleAnalyticsService.Instance.Initialize(this); GoogleAnalyticsService.Instance.TrackAppPage("Search Song"); myVideosListView = FindViewById <ListView>(Resource.Id.songsListView); ImageButton searchButton = FindViewById <ImageButton>(Resource.Id.searchBtn); searchString = FindViewById <AutoCompleteTextView>(Resource.Id.searchEditText); clearBtn = FindViewById <ImageButton>(Resource.Id.clearBtn); searchString.Text = string.Empty; searchString.Background.SetTint(ContextCompat.GetColor(this, Resource.Color.darkassets)); DownloadWatcher.onDownloaded += async(sender, e) => await LoadListView(); DownloadWatcher.onDownloadFailed += async(sender, e) => await LoadListView(); searchButton.Click += async delegate { HideKeyboard(searchButton.Context); await UpdateVideos(searchString.Text); }; searchString.KeyPress += async(object sender, View.KeyEventArgs e) => { e.Handled = false; if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter) { HideKeyboard(searchString.Context); await UpdateVideos(searchString.Text); e.Handled = true; } }; searchString.TextChanged += async(sender, e) => { if (searchString.Text.Length > 0) { clearBtn.Visibility = ViewStates.Visible; if (checkInternetConnection()) { IEnumerable <string> songs = await YoutubeApiClient.SearchTitles(searchString.Text); ArrayAdapter autoCompleteAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleDropDownItem1Line, songs.ToList()); searchString.Adapter = autoCompleteAdapter; } } else { clearBtn.Visibility = ViewStates.Gone; } }; clearBtn.Click += (s, e) => { searchString.Text = string.Empty; }; myVideosListView.ItemClick += (sender, e) => { selectedVideo = videos[e.Position]; Intent intent = new Intent(this, typeof(DownloadSong)); StartActivity(intent); }; await UpdateVideos(string.Empty); }