Esempio n. 1
0
        async void OnAlbumItemClicked(object sender, AdapterView.ItemClickEventArgs e)
        {
            var selectedEpisode = _album.Episodes [e.Position];

            if (AndroidAudioDownloader.ViewsDownloadInProgressByAudioId.ContainsKey(selectedEpisode.RemoteUrl))
            {
                return;
            }

            if (AudioDownloader.HasLocalFile(selectedEpisode.RemoteUrl, selectedEpisode.FileSize))
            {
                var resultIntent = new Intent();
                ExtraUtils.PutEpisode(resultIntent, selectedEpisode.Id);
                ExtraUtils.PutAlbum(resultIntent, _album.Id);
                ExtraUtils.PutSelectedTab(resultIntent, (int)MainActivity.TabTitle.Player);
                SetResult(Result.Ok, resultIntent);

                StartService(PlayerService.CreateIntent(
                                 this,
                                 PlayerService.ACTION_PLAY,
                                 _album.Id,
                                 selectedEpisode.Id
                                 ));

                Finish();
            }
            else
            {
                await AndroidAudioDownloader.StartDownloadAsync(e.Position, selectedEpisode.RemoteUrl, ListView);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        void StartForeground()
        {
            var intent = new Intent(ApplicationContext, typeof(MainActivity));

            intent.SetAction(Intent.ActionMain);
            intent.AddCategory(Intent.CategoryLauncher);
            ExtraUtils.PutSelectedTab(intent, (int)MainActivity.TabTitle.Player);

            var pendingIntent = PendingIntent.GetActivity(
                ApplicationContext,
                0,
                intent,
                PendingIntentFlags.UpdateCurrent
                );

            var notificationBuilder = new Notification.Builder(ApplicationContext);

            notificationBuilder.SetContentTitle(CurrentEpisode.Title);
            notificationBuilder.SetContentText(
                String.Format(
                    ApplicationContext.GetString(Resource.String.NotificationContentText),
                    ApplicationContext.GetString(Resource.String.ApplicationName)
                    )
                );
            notificationBuilder.SetSmallIcon(Resource.Drawable.ic_stat_av_play_over_video);
            notificationBuilder.SetTicker(
                String.Format(
                    Application.GetString(Resource.String.NoticifationTicker),
                    CurrentEpisode.Title
                    )
                );
            notificationBuilder.SetOngoing(true);
            notificationBuilder.SetContentIntent(pendingIntent);

            StartForeground(NotificationId, notificationBuilder.Build());
        }