mirror of
https://github.com/zoriya/Opus.git
synced 2026-06-04 14:56:23 +00:00
Adding edit sleep timer intent on notification click.
This commit is contained in:
@@ -328,7 +328,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
if (progress != -1)
|
||||
{
|
||||
player.SeekTo(progress);
|
||||
Player.instance.FindViewById<ImageButton>(Resource.Id.playButton).SetImageResource(Resource.Drawable.ic_pause_black_24dp);
|
||||
Player.instance?.FindViewById<ImageButton>(Resource.Id.playButton).SetImageResource(Resource.Drawable.ic_pause_black_24dp);
|
||||
}
|
||||
|
||||
SaveQueueSlot();
|
||||
@@ -774,7 +774,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
db.DropTable<Song>();
|
||||
db.CreateTable<Song>();
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
|
||||
@@ -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<LinearLayout>(Resource.Id.infoPanel).Height + FindViewById<RelativeLayout>(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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user