improvements

This commit is contained in:
Royce551 2021-08-07 23:11:42 -05:00
parent ef509caad1
commit cbe73bcea0
10 changed files with 55 additions and 24 deletions

View file

@ -126,6 +126,7 @@ namespace FRESHMusicPlayer.Handlers.Integrations
OnPropertiesChanged += MediaPlayer2_OnPropertiesChanged;
viewModel.PropertyChanged += ViewModel_PropertyChanged;
UpdateMetadata();
InitializeState();
}
private void Player_SongStopped(object sender, EventArgs e)
@ -188,6 +189,13 @@ namespace FRESHMusicPlayer.Handlers.Integrations
viewModel.CurrentTime.Add(TimeSpan.FromMilliseconds(offset * 1000));
}
private void InitializeState()
{
ViewModel_PropertyChanged(null, new("Paused")); // jank alert!
ViewModel_PropertyChanged(null, new("Volume"));
ViewModel_PropertyChanged(null, new("Shuffle"));
}
private void UpdateMetadata()
{

View file

@ -104,8 +104,7 @@ namespace FRESHMusicPlayer.ViewModels
this.RaisePropertyChanged(nameof(CurrentTimeSeconds));
if (Config.ShowTimeInWindow) WindowTitle = $"{CurrentTime:mm\\:ss}/{TotalTime:mm\\:ss} | {ProjectName}";
if (Config.ShowRemainingProgress) this.RaisePropertyChanged(nameof(TotalTime)); // little hacky but this triggers it
// to show the new time
if (Config.ShowRemainingProgress) this.RaisePropertyChanged(nameof(TotalTime));
Player.AvoidNextQueue = false;
}
@ -114,8 +113,8 @@ namespace FRESHMusicPlayer.ViewModels
{
LoggingHandler.Log("Player: SongChanged");
CurrentTrack = new Track(Player.FilePath);
Artist = CurrentTrack.Artist;
Title = CurrentTrack.Title;
Artist = string.IsNullOrEmpty(CurrentTrack.Artist) ? "Unknown Artist" : CurrentTrack.Artist;
Title = string.IsNullOrEmpty(CurrentTrack.Title) ? "Unknown Title" : CurrentTrack.Title;
if (CurrentTrack.EmbeddedPictures.Count != 0)
CoverArt = new Bitmap(new MemoryStream(CurrentTrack.EmbeddedPictures[0].PictureData));
this.RaisePropertyChanged(nameof(TotalTime));
@ -123,6 +122,7 @@ namespace FRESHMusicPlayer.ViewModels
WindowTitle = $"{CurrentTrack.Artist} - {CurrentTrack.Title} | {ProjectName}";
ProgressTimer.Start();
Integrations.Update(CurrentTrack, PlaybackStatus.Playing);
UpdatePausedState();
if (PauseAfterCurrentTrack && !Player.Paused)
{
@ -156,10 +156,10 @@ namespace FRESHMusicPlayer.ViewModels
public void SkipPreviousCommand()
{
if (!Player.FileLoaded) return;
if (Player.CurrentTime.TotalSeconds <= 5) Player.PreviousSong();
else
{
if (!Player.FileLoaded) return;
Player.CurrentTime = TimeSpan.FromSeconds(0);
ProgressTimer.Start(); // to resync the progress timer
}
@ -187,15 +187,14 @@ namespace FRESHMusicPlayer.ViewModels
if (Player.Paused)
{
Player.ResumeMusic();
Paused = false;
Integrations.Update(CurrentTrack, PlaybackStatus.Playing);
}
else
{
Player.PauseMusic();
Paused = true;
Integrations.Update(CurrentTrack, PlaybackStatus.Paused);
}
UpdatePausedState();
}
public void ShuffleCommand()
{
@ -219,6 +218,8 @@ namespace FRESHMusicPlayer.ViewModels
public void ShowRemainingProgressCommand() => Config.ShowRemainingProgress = !Config.ShowRemainingProgress;
private void UpdatePausedState() => Paused = Player.Paused;
private TimeSpan currentTime;
public TimeSpan CurrentTime
{
@ -775,7 +776,10 @@ namespace FRESHMusicPlayer.ViewModels
public void OpenTagEditorCommand()
{
new FRESHMusicPlayer.Views.TagEditor.TagEditor().SetStuff(Player, Library).Show();
var tracks = new List<string>();
if (Player.FileLoaded) tracks.Add(Player.FilePath);
else tracks = Player.Queue.Queue;
new Views.TagEditor.TagEditor().SetStuff(Player, Library).SetInitialFiles(tracks).Show();
}
#endregion
}

View file

@ -9,12 +9,7 @@ namespace FRESHMusicPlayer.ViewModels
{
public class MessageBoxViewModel : ViewModelBase
{
private string title;
public string Title
{
get => title;
set => this.RaiseAndSetIfChanged(ref title, value);
}
public string Title => MainWindowViewModel.ProjectName;
private string content;
public string Content

View file

@ -132,7 +132,7 @@ namespace FRESHMusicPlayer.ViewModels
if (dialog.OK)
{
if (string.IsNullOrWhiteSpace((dialog.DataContext as TextEntryBoxViewModel).Text))
new MessageBox().SetStuff(MainWindowViewModel.ProjectName, Properties.Resources.PlaylistManagement_InvalidName).Show(GetMainWindow());
new MessageBox().SetStuff(Properties.Resources.PlaylistManagement_InvalidName).Show(GetMainWindow());
else
{
MainWindow.Library.CreatePlaylist((dialog.DataContext as TextEntryBoxViewModel).Text, Track);

View file

@ -201,7 +201,7 @@ namespace FRESHMusicPlayer.ViewModels
}
public async void NukeLibraryCommand()
{
var messageBox = new MessageBox().SetStuff(MainWindowViewModel.ProjectName, "You are about to irreversibly clear your library.", true, false, false, true);
var messageBox = new MessageBox().SetStuff("You are about to irreversibly clear your library.", true, false, false, true);
await messageBox.ShowDialog(Window);
if (messageBox.OK) Library.Nuke();
}

View file

@ -108,10 +108,9 @@ namespace FRESHMusicPlayer.ViewModels.TagEditor
}
}
public List<string> FilePaths { get; private set; } = new();
public List<string> FilePaths { get; set; } = new();
private const string windowName = "FRESHMusicPlayer Tag Editor";
private string windowTitle = "FRESHMusicPlayer Tag Editor";
public string WindowTitle
{
get
@ -150,6 +149,7 @@ namespace FRESHMusicPlayer.ViewModels.TagEditor
public void Initialize(List<string> filePaths)
{
FilePaths = filePaths;
this.RaisePropertyChanged(nameof(WindowTitle));
foreach (var path in filePaths)
{
var track = new Track(path);

View file

@ -192,7 +192,7 @@ namespace FRESHMusicPlayer.Views
DisplayAsToast = true,
OnButtonClicked = () =>
{
new MessageBox().SetStuff("lols", "wtf, that actually worked?").ShowDialog(this);
new MessageBox().SetStuff("wtf, that actually worked?").ShowDialog(this);
return true;
}
});

View file

@ -25,14 +25,13 @@ namespace FRESHMusicPlayer.Views
}
public MessageBox SetStuff(string title,
public MessageBox SetStuff(
string content,
bool hasOK = true,
bool hasYes = false,
bool hasNo = false,
bool hasCancel = false)
{
ViewModel.Title = title;
ViewModel.Content = content;
ViewModel.HasOK = hasOK;
ViewModel.HasYes = hasYes;

View file

@ -5,7 +5,7 @@
xmlns:resx ="clr-namespace:FRESHMusicPlayer.Properties"
xmlns:vm="using:FRESHMusicPlayer.ViewModels.TagEditor"
mc:Ignorable="d" Height="451" Width="600"
x:Class="FRESHMusicPlayer.Views.TagEditor.TagEditor"
x:Class="FRESHMusicPlayer.Views.TagEditor.TagEditor" Closing="OnClosing"
Title="{Binding WindowTitle}">
<Window.DataContext>

View file

@ -4,6 +4,7 @@ using Avalonia.Markup.Xaml;
using FRESHMusicPlayer.ViewModels.TagEditor;
using FRESHMusicPlayer.Handlers;
using System.ComponentModel;
using System.Collections.Generic;
namespace FRESHMusicPlayer.Views.TagEditor
{
@ -27,11 +28,35 @@ namespace FRESHMusicPlayer.Views.TagEditor
return this;
}
private void OnClosing(object sender, CancelEventArgs e)
public TagEditor SetInitialFiles(List<string> initialFiles)
{
ViewModel.Initialize(initialFiles);
return this;
}
private async void OnClosing(object sender, CancelEventArgs e)
{
if (ViewModel.UnsavedChanges)
{
e.Cancel = true;
var messageBox = new MessageBox().SetStuff($"Save changes to {string.Join(", ", ViewModel.FilePaths)}?", false, true, true, true);
await messageBox.ShowDialog(this);
if (messageBox.Yes)
{
ViewModel.SaveCommand();
e.Cancel = false;
Close();
}
else if (messageBox.No)
{
e.Cancel = false;
ViewModel.UnsavedChanges = false; // this is a lie, but it's ok because it's gonna close anyway :)
Close();
}
else
{
e.Cancel = true;
}
}
}