Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
394 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace Maui.Apps.Framework.Extensions; | ||
|
||
public static class DateExtensions | ||
{ | ||
public static string ToTimeAgo(this DateTime baseTime) | ||
{ | ||
var _timeSpan = DateTime.Now - baseTime; | ||
|
||
if (_timeSpan.TotalMinutes == 0) | ||
return "Just now"; | ||
|
||
if (_timeSpan.TotalMinutes < 60) | ||
return Convert.ToInt32(_timeSpan.TotalMinutes).ToString() + " mins ago"; | ||
|
||
if (_timeSpan.TotalHours < 2) | ||
return Convert.ToInt32(_timeSpan.TotalHours).ToString() + " hour ago"; | ||
|
||
if (_timeSpan.TotalHours < 24) | ||
return Convert.ToInt32(_timeSpan.TotalHours).ToString() + " hours ago"; | ||
|
||
if (_timeSpan.TotalDays < 2) | ||
return Convert.ToInt32(_timeSpan.TotalDays).ToString() + " day ago"; | ||
|
||
if (_timeSpan.TotalDays < 365) | ||
return Convert.ToInt32(_timeSpan.TotalDays).ToString() + " days ago"; | ||
|
||
if (Convert.ToDouble(_timeSpan.TotalDays / 365) < 2) | ||
return "1 year ago"; | ||
|
||
return Convert.ToDouble(_timeSpan.TotalDays / 365).ToString("#") + " years ago"; | ||
} | ||
|
||
public static string ToReadableString(this TimeSpan span) => | ||
string.Format("{0}{1}{2}{3}", | ||
span.Duration().Days > 0 ? string.Format("{0:0} day{1}, ", span.Days, span.Days == 1 ? string.Empty : "s") : string.Empty, | ||
span.Duration().Hours > 0 ? string.Format("{0:0} hr{1}, ", span.Hours, span.Hours == 1 ? string.Empty : "s") : string.Empty, | ||
span.Duration().Minutes > 0 ? string.Format("{0:0} min{1}, ", span.Minutes, span.Minutes == 1 ? string.Empty : "s") : string.Empty, | ||
span.Duration().Seconds > 0 ? string.Format("{0:0} sec{1}", span.Seconds, span.Seconds == 1 ? string.Empty : "s") : string.Empty); | ||
|
||
public static TimeSpan ToTimeSpan(this string isoDuration) => | ||
System.Xml.XmlConvert.ToTimeSpan(isoDuration); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Maui.Apps.Framework.Extensions; | ||
|
||
public static class NumberExtensions | ||
{ | ||
public static string FormattedNumber(this double number) => | ||
number switch | ||
{ | ||
>= 1000000 => (number / 1000000D).ToString("0.#M"), | ||
>= 10000 => (number / 1000D).ToString("0.#K"), | ||
_ => number.ToString("#,0") | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/MauiTubePlayer/ViewModels/VideoDetailsPageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
namespace MauiTubePlayer.ViewModels; | ||
|
||
public partial class VideoDetailsPageViewModel : AppViewModelBase | ||
{ | ||
[ObservableProperty] | ||
private YoutubeVideoDetail theVideo; | ||
|
||
[ObservableProperty] | ||
private List<YoutubeVideo> similarVideos; | ||
|
||
[ObservableProperty] | ||
private Channel theChannel; | ||
|
||
[ObservableProperty] | ||
private bool similarVideosAvailable; | ||
|
||
[ObservableProperty] | ||
private List<Comment> comments; | ||
|
||
public event EventHandler DownloadCompleted; | ||
|
||
|
||
public VideoDetailsPageViewModel(IApiService appApiService) : base(appApiService) | ||
{ | ||
this.Title = "TUBE PLAYER"; | ||
} | ||
|
||
public override async void OnNavigatedTo(object parameters) | ||
{ | ||
var videoID = (string)parameters; | ||
|
||
SetDataLodingIndicators(true); | ||
|
||
this.LoadingText = "Hold on while we load the video details..."; | ||
|
||
try | ||
{ | ||
SimilarVideos = new(); | ||
Comments = new(); | ||
|
||
//Get Video Details | ||
TheVideo = await _appApiService.GetVideoDetails(videoID); | ||
|
||
//Get Channel URL and set in the video | ||
var channelSearchResult = await _appApiService.GetChannels(TheVideo.Snippet.ChannelId); | ||
TheChannel = channelSearchResult.Items.First(); | ||
|
||
//Find Similar Videos | ||
if (TheVideo.Snippet.Tags is not null) | ||
{ | ||
var similarVideosSearchResult = await _appApiService.SearchVideos(TheVideo.Snippet.Tags.First(), ""); | ||
|
||
SimilarVideos = similarVideosSearchResult.Items; | ||
SimilarVideosAvailable = (SimilarVideos?.Count > 0); | ||
} | ||
|
||
//Get Comments | ||
var commentsSearchResult = await _appApiService.GetComments(videoID); | ||
Comments = commentsSearchResult.Items; | ||
|
||
|
||
//Raise Data Load completed event to the UI | ||
this.DataLoaded = true; | ||
|
||
//Raise the Event to notify the UI of download completion | ||
DownloadCompleted?.Invoke(this, new EventArgs()); | ||
} | ||
catch (InternetConnectionException iex) | ||
{ | ||
this.IsErrorState = true; | ||
this.ErrorMessage = "Slow or no internet connection." + Environment.NewLine + "Please check you internet connection and try again."; | ||
ErrorImage = "nointernet.png"; | ||
} | ||
catch (Exception ex) | ||
{ | ||
this.IsErrorState = true; | ||
this.ErrorMessage = $"Something went wrong. If the problem persists, plz contact support at {Constants.EmailAddress} with the error message:" + Environment.NewLine + Environment.NewLine + ex.Message; | ||
ErrorImage = "error.png"; | ||
} | ||
finally | ||
{ | ||
SetDataLodingIndicators(false); | ||
} | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.