diff --git a/MusicApp/Resources/Portable Class/MusicPlayer.cs b/MusicApp/Resources/Portable Class/MusicPlayer.cs index 9f07b04..d81f75d 100644 --- a/MusicApp/Resources/Portable Class/MusicPlayer.cs +++ b/MusicApp/Resources/Portable Class/MusicPlayer.cs @@ -328,7 +328,7 @@ namespace MusicApp.Resources.Portable_Class if (progress != -1) { player.SeekTo(progress); - Player.instance.FindViewById(Resource.Id.playButton).SetImageResource(Resource.Drawable.ic_pause_black_24dp); + Player.instance?.FindViewById(Resource.Id.playButton).SetImageResource(Resource.Drawable.ic_pause_black_24dp); } SaveQueueSlot(); @@ -774,7 +774,7 @@ namespace MusicApp.Resources.Portable_Class db.DropTable(); db.CreateTable(); } - + foreach (Song item in queue) { db.InsertOrReplace(item); @@ -1096,7 +1096,7 @@ namespace MusicApp.Resources.Portable_Class currentID = -1; progress = 0; MainActivity.instance.HideSmallPlayer(); - Player.instance?.Stoped(); + //Player.instance?.Stoped(); if (player != null) { if (isRunning) diff --git a/MusicApp/Resources/Portable Class/Player.cs b/MusicApp/Resources/Portable Class/Player.cs index c81c8f7..ad03dd6 100644 --- a/MusicApp/Resources/Portable Class/Player.cs +++ b/MusicApp/Resources/Portable Class/Player.cs @@ -8,7 +8,6 @@ using Android.OS; using Android.Support.Design.Widget; using Android.Support.V7.App; using Android.Support.V7.Graphics; -using Android.Util; using Android.Views; using Android.Widget; using MusicApp.Resources.values; @@ -45,6 +44,11 @@ namespace MusicApp.Resources.Portable_Class instance = this; CreatePlayer(); + + if(Intent.Action == "Sleep") + { + SleepButton_Click("", null); + } } protected override void OnDestroy() @@ -159,10 +163,9 @@ namespace MusicApp.Resources.Portable_Class smallQueue.ImageTintList = ColorStateList.ValueOf(Color.Argb(255, 0, 0, 0)); } - DisplayMetrics displayMetrics = new DisplayMetrics(); - WindowManager.DefaultDisplay.GetMetrics(displayMetrics); - if(displayMetrics.HeightPixels < displayMetrics.WidthPixels + FindViewById(Resource.Id.infoPanel).Height + FindViewById(Resource.Id.nextSong).Height + ShowQueue.Height) + if(ShowQueue.Height < 100) { + Console.WriteLine("&Small Queue"); smallQueue.Visibility = ViewStates.Visible; ShowQueue.Visibility = ViewStates.Gone; } @@ -481,7 +484,6 @@ namespace MusicApp.Resources.Portable_Class void Sleep(int time) { - Console.WriteLine("&Going to sleep in " + time + ", slected item is the " + checkedItem + " one."); Intent intent = new Intent(this, typeof(Sleeper)); intent.PutExtra("time", time); StartService(intent); diff --git a/MusicApp/Resources/Portable Class/Sleeper.cs b/MusicApp/Resources/Portable Class/Sleeper.cs index f7ecc50..7a5fadd 100644 --- a/MusicApp/Resources/Portable Class/Sleeper.cs +++ b/MusicApp/Resources/Portable Class/Sleeper.cs @@ -2,7 +2,6 @@ using Android.Content; using Android.OS; using Android.Support.V4.App; -using System.Threading; using System.Threading.Tasks; namespace MusicApp.Resources.Portable_Class @@ -13,8 +12,6 @@ namespace MusicApp.Resources.Portable_Class public static Sleeper instance; public int timer; - private bool stoped = false; - public override IBinder OnBind(Intent intent) { return null; @@ -31,23 +28,23 @@ namespace MusicApp.Resources.Portable_Class StartTimer(intent); else { + NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService); int time = intent.GetIntExtra("time", timer); - if (time == 0) + if (time < 1) { - stoped = true; - StopForeground(true); + notificationManager.Cancel(1001); + StopSelf(); } else { timer = time; NotificationCompat.Builder notification = new NotificationCompat.Builder(Application.Context, "MusicApp.Channel") - .SetVisibility(NotificationCompat.VisibilityPublic) - .SetSmallIcon(Resource.Drawable.MusicIcon) - .SetContentTitle("Music will stop in:") - .SetContentText(timer + " minutes") - .SetOngoing(true); + .SetVisibility(NotificationCompat.VisibilityPublic) + .SetSmallIcon(Resource.Drawable.MusicIcon) + .SetContentTitle("Music will stop in:") + .SetContentText(timer + " minutes") + .SetOngoing(true); - NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService); notificationManager.Notify(1001, notification.Build()); } } @@ -59,11 +56,18 @@ namespace MusicApp.Resources.Portable_Class instance = this; timer = intent.GetIntExtra("time", 0); // In minutes + Intent mainActivity = new Intent(Application.Context, typeof(MainActivity)); + Intent sleepIntent = new Intent(Application.Context, typeof(Player)); + sleepIntent.SetAction("Sleep"); + PendingIntent defaultIntent = PendingIntent.GetActivities(Application.Context, 0, new Intent[] { mainActivity, sleepIntent }, PendingIntentFlags.UpdateCurrent); + + NotificationCompat.Builder notification = new NotificationCompat.Builder(Application.Context, "MusicApp.Channel") .SetVisibility(NotificationCompat.VisibilityPublic) .SetSmallIcon(Resource.Drawable.MusicIcon) .SetContentTitle("Music will stop in:") .SetContentText(timer + " minutes") + .SetContentIntent(defaultIntent) .SetOngoing(true); NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService); @@ -75,16 +79,14 @@ namespace MusicApp.Resources.Portable_Class await Task.Delay(60000); // One minute in ms timer -= 1; - - if (stoped) - return; } Intent musicIntent = new Intent(Application.Context, typeof(MusicPlayer)); musicIntent.SetAction("SleepPause"); - MainActivity.instance.StartService(musicIntent); + Application.Context.StartService(musicIntent); notificationManager.Cancel(1001); instance = null; + StopSelf(); } } } \ No newline at end of file