Able to return to the Player view by taping on the player indicator now. Added progress bar on the player indicator as well as the artist of the song

This commit is contained in:
amazing-username
2019-06-18 17:29:49 -07:00
parent 17f07b5040
commit a59bfa67c0
5 changed files with 249 additions and 32 deletions
+73 -6
View File
@@ -19,7 +19,9 @@ namespace Mear.Views
{
#region Fields
private StackLayout _playerIndicatorLayout;
private ProgressBar _songProgress;
private Button _controlButton;
private Label _songArtistLabel;
private Label _songTitleLabel;
private ArtistViewModel _viewModel;
#endregion
@@ -33,8 +35,7 @@ namespace Mear.Views
public ArtistView()
{
InitializeComponent();
AddPlayerIndicator();
BackgroundControl();
Initialize();
BindingContext = _viewModel = new ArtistViewModel();
}
@@ -42,6 +43,12 @@ namespace Mear.Views
#region Methods
private async Task Initialize()
{
AddPlayerIndicator();
BackgroundControl();
BackgroundSongProgress();
}
private async Task AddPlayerIndicator()
{
var mainLayout = ArtistViewMainLayout;
@@ -55,28 +62,54 @@ namespace Mear.Views
private async Task<StackLayout> ConfigureSongIndicatorLayout()
{
var indicatorLayout = new StackLayout();
var songDetailLayout = new StackLayout();
songDetailLayout.Orientation = StackOrientation.Vertical;
indicatorLayout.Orientation = StackOrientation.Horizontal;
indicatorLayout.HorizontalOptions = LayoutOptions.Fill;
indicatorLayout.MinimumWidthRequest = 400;
indicatorLayout.Padding = 5;
_songProgress = new ProgressBar();
_songProgress.HorizontalOptions = LayoutOptions.Fill;
_songProgress.MinimumWidthRequest = 400;
_songProgress.Progress = 0;
_controlButton = new Button();
_controlButton.Clicked += ControlButton_Clicked;
_songTitleLabel = new Label();
_songTitleLabel.HorizontalOptions = LayoutOptions.Center;
_songTitleLabel.FontSize = 13;
_songTitleLabel.HorizontalOptions = LayoutOptions.Start;
_songTitleLabel.VerticalOptions = LayoutOptions.Start;
_songArtistLabel = new Label();
_songArtistLabel.FontSize = 10;
var isSongPlayer = MearPlayer.IsPlaying();
if (isSongPlayer)
{
_controlButton.Text = "P";
_songTitleLabel.Text = await MearPlayer.SongTitle();
_songTitleLabel.Text = MearPlayer.OnSong.Title;
_songArtistLabel.Text = MearPlayer.OnSong.Artist;
}
else
{
_controlButton.Text = "S";
_songTitleLabel.Text = string.Empty;
_songArtistLabel.Text = string.Empty;
}
_songTitleLabel.HorizontalOptions = LayoutOptions.Fill;
var tapped = new TapGestureRecognizer();
tapped.Tapped += OpenPlayer;
songDetailLayout.GestureRecognizers.Add(tapped);
songDetailLayout.Children.Add(_songTitleLabel);
songDetailLayout.Children.Add(_songArtistLabel);
songDetailLayout.Children.Add(_songProgress);
indicatorLayout.Children.Add(_controlButton);
indicatorLayout.Children.Add(_songTitleLabel);
indicatorLayout.Children.Add(songDetailLayout);
return indicatorLayout;
}
@@ -94,7 +127,8 @@ namespace Mear.Views
{
if (MearPlayer.SongHasBeenChanged(MearPlayer.MusicViews.Artist))
{
_songTitleLabel.Text = MearPlayer.SongTitle().Result;
_songTitleLabel.Text = MearPlayer.OnSong.Title;
_songArtistLabel.Text = MearPlayer.OnSong.Artist;
MearPlayer.ResetSongChange(MearPlayer.MusicViews.Artist);
}
});
@@ -107,9 +141,42 @@ namespace Mear.Views
var msg = ex.Message;
}
}
private async Task BackgroundSongProgress()
{
try
{
new Thread(async () =>
{
while (true)
{
Device.BeginInvokeOnMainThread(async () =>
{
var progress = MearPlayer.ProgressValue().Result;
if (progress != null)
{
_songProgress.Progress = progress.Value / 100.0;
}
});
await Task.Delay(250);
}
}).Start();
}
catch (Exception ex)
{
var msg = ex.Message;
}
}
#endregion
#region Events
private async void OpenPlayer(object sender, EventArgs e)
{
if (MearPlayer.IsPlaying())
{
Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(MearPlayer.OnSong)));
}
}
private async void ControlButton_Clicked(object sender, EventArgs e)
{
if (MearPlayer.IsPlaying())