Development 1.1
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Documents;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
||||
namespace FoxTube
|
||||
{
|
||||
class Methods
|
||||
{
|
||||
public static MainPage MainPage
|
||||
{
|
||||
get { return (Window.Current.Content as Frame).Content as MainPage; }
|
||||
}
|
||||
|
||||
public static string GetAgo(DateTime dateTime)
|
||||
{
|
||||
TimeSpan span = DateTime.Now - dateTime;
|
||||
if (span.TotalMinutes < 1)
|
||||
return "Just now";
|
||||
else if (span.Minutes == 1)
|
||||
return "1 minute ago";
|
||||
else if (span.TotalMinutes > 60)
|
||||
return span.Minutes + " minutes ago";
|
||||
else if (span.Hours == 1)
|
||||
return "1 hour ago";
|
||||
else if (span.TotalHours > 24)
|
||||
return span.Hours + " hours ago";
|
||||
else if (span.Days == 1)
|
||||
return "1 day ago";
|
||||
else if (span.TotalDays > 7)
|
||||
return span.Days + " days ago";
|
||||
else if (span.Days == 7)
|
||||
return "1 week ago";
|
||||
else if (span.Days > 30)
|
||||
return (int)(span.Days / 7) + " weeks ago";
|
||||
else if (span.Days == 30)
|
||||
return "1 month ago";
|
||||
else if (span.Days > 365)
|
||||
return (int)(span.Days / 30) + " months ago";
|
||||
else if (span.Days == 365)
|
||||
return "1 year ago";
|
||||
else
|
||||
return (int)(span.Days / 365) + " years ago";
|
||||
}
|
||||
|
||||
public static void FormatText(ref TextBlock block, string text)
|
||||
{
|
||||
block.Inlines.Clear();
|
||||
|
||||
Regex regx = new Regex(@"(http(s)?://[\S]+|www.[\S]+|[\S]+@[\S]+)", RegexOptions.IgnoreCase);
|
||||
Regex isWWW = new Regex(@"(http[s]?://[\S]+|www.[\S]+)");
|
||||
Regex isEmail = new Regex(@"[\S]+@[\S]+");
|
||||
foreach (var item in regx.Split(text))
|
||||
{
|
||||
if (isWWW.IsMatch(item))
|
||||
{
|
||||
Hyperlink link = new Hyperlink { NavigateUri = new Uri(item.ToLower().StartsWith("http") ? item : $"http://{item}"), Foreground = new SolidColorBrush(Colors.Red) };
|
||||
link.Inlines.Add(new Run { Text = item });
|
||||
block.Inlines.Add(link);
|
||||
}
|
||||
else if (isEmail.IsMatch(item))
|
||||
{
|
||||
Hyperlink link = new Hyperlink { NavigateUri = new Uri($"mailto:{item}"), Foreground = new SolidColorBrush(Colors.Red) };
|
||||
link.Inlines.Add(new Run { Text = item });
|
||||
block.Inlines.Add(link);
|
||||
}
|
||||
else block.Inlines.Add(new Run { Text = item });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user