Skip to content

Commit

Permalink
Preparing Theme Create Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Oct 23, 2023
1 parent 610154e commit 0e30acf
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 3 deletions.
62 changes: 62 additions & 0 deletions src/Portal/Sucrose.Portal/Views/Controls/ThemeCreate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,68 @@
Appearance="Secondary"
BorderBrush="Transparent"
Icon="{ui:SymbolIcon ArrowLeft24}" />

<Grid x:Name="VideoArea" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0 12 0 0" AllowDrop="True" Drop="VideoArea_Drop" DragOver="VideoArea_DragOver" DragLeave="GifArea_DragLeave">
<Grid.Background>
<VisualBrush Stretch="UniformToFill">
<VisualBrush.Visual>
<Grid>
<MediaElement x:Name="VideoImagine" Volume="0" Stretch="UniformToFill" StretchDirection="Both" VerticalAlignment="Center" HorizontalAlignment="Stretch" LoadedBehavior="Play" UnloadedBehavior="Manual" />
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Grid.Background>

<Rectangle x:Name="VideoRectangle" Stroke="{DynamicResource TextFillColorDisabledBrush}" StrokeThickness="2" StrokeDashArray="4 4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

<StackPanel Margin="48" VerticalAlignment="Center" HorizontalAlignment="Center">
<ui:SymbolIcon
FontSize="32"
x:Name="VideoIcon"
Symbol="SaveCopy24"
VerticalAlignment="Center"
HorizontalAlignment="Center" />

<ui:TextBlock
FontSize="20"
Margin="0 10 0 0"
x:Name="VideoText"
TextWrapping="NoWrap"
TextAlignment="Center"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Text="{DynamicResource Portal.ThemeCreate.DragDrop.Video}" />

<ui:Button
Margin="48"
Cursor="Hand"
Appearance="Danger"
x:Name="VideoDelete"
Visibility="Collapsed"
Click="VideoDelete_Click"
Icon="{ui:SymbolIcon Delete24}"
Content="{DynamicResource Portal.ThemeCreate.DragDrop.Delete}" />
</StackPanel>
</Grid>

<TextBlock Text="{DynamicResource Portal.ThemeCreate.ThemeThumbnail}" Margin="0 12 0 0" TextWrapping="WrapWithOverflow" FontSize="16" Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
<ui:Button x:Name="VideoThumbnail" Cursor="Hand" Content="{DynamicResource Portal.ThemeCreate.ThemeThumbnail.Hint}" Margin="0 3 0 0" HorizontalAlignment="Stretch" Click="ThemeThumbnail_Click" />

<TextBlock Text="{DynamicResource Portal.ThemeCreate.ThemePreview}" Margin="0 12 0 0" TextWrapping="WrapWithOverflow" FontSize="16" Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
<ui:Button x:Name="VideoPreview" Cursor="Hand" Content="{DynamicResource Portal.ThemeCreate.ThemePreview.Hint}" Margin="0 3 0 0" HorizontalAlignment="Stretch" Click="ThemePreview_Click" />

<TextBlock Text="{DynamicResource Portal.ThemeCreate.ThemeTitle}" Margin="0 12 0 0" TextWrapping="WrapWithOverflow" FontSize="16" Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
<ui:TextBox x:Name="VideoTitle" PlaceholderText="{DynamicResource Portal.ThemeCreate.ThemeTitle.Hint}" Margin="0 3 0 0" MaxLength="50" AcceptsReturn="False" AcceptsTab="False" />

<TextBlock Text="{DynamicResource Portal.ThemeCreate.ThemeDescription}" Margin="0 12 0 0" TextWrapping="WrapWithOverflow" FontSize="16" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<ui:TextBox x:Name="VideoDescription" PlaceholderText="{DynamicResource Portal.ThemeCreate.ThemeDescription.Hint}" Margin="0 3 0 0" MaxLength="500" MaxLines="10" TextWrapping="WrapWithOverflow" MinLines="5" AcceptsReturn="False" AcceptsTab="False" />

<TextBlock Text="{DynamicResource Portal.ThemeCreate.ThemeAuthor}" Margin="0 12 0 0" TextWrapping="WrapWithOverflow" FontSize="16" Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
<ui:TextBox x:Name="VideoAuthor" PlaceholderText="{DynamicResource Portal.ThemeCreate.ThemeAuthor.Hint}" Margin="0 3 0 0" MaxLength="50" AcceptsReturn="False" AcceptsTab="False" />

<TextBlock Text="{DynamicResource Portal.ThemeCreate.ThemeContact}" Margin="0 12 0 0" TextWrapping="WrapWithOverflow" FontSize="16" Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
<ui:TextBox x:Name="VideoContact" PlaceholderText="{DynamicResource Portal.ThemeCreate.ThemeContact.Hint}" Margin="0 3 0 0" MaxLength="250" AcceptsReturn="False" AcceptsTab="False" />
</StackPanel>

<StackPanel x:Name="YouTubeCard" HorizontalAlignment="Stretch" VerticalAlignment="Center" Orientation="Vertical" Visibility="Collapsed">
Expand Down
161 changes: 161 additions & 0 deletions src/Portal/Sucrose.Portal/Views/Controls/ThemeCreate.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ private void Back_Click(object sender, RoutedEventArgs e)
VideoCard.Visibility = Visibility.Collapsed;
YouTubeCard.Visibility = Visibility.Collapsed;
ApplicationCard.Visibility = Visibility.Collapsed;

GifDelete_Click(null, null);
VideoDelete_Click(null, null);

Dispose();
}

private void GifArea_Drop(object sender, DragEventArgs e)
Expand Down Expand Up @@ -70,6 +75,34 @@ private void GifArea_Drop(object sender, DragEventArgs e)
}
}

private void VideoArea_Drop(object sender, DragEventArgs e)
{
VideoRectangle.Stroke = SSRER.GetResource<Brush>("TextFillColorDisabledBrush");

if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] Files = (string[])e.Data.GetData(DataFormats.FileDrop);

if (Files.Any())
{
foreach (string Record in Files)
{
string Extension = Path.GetExtension(Record).ToLowerInvariant();

if (Extension is ".mp4" or ".avi" or ".mov" or ".mkv" or ".ogv" or ".flv" or ".wmv" or ".hevc" or ".webm" or ".mpeg" or ".mpeg1" or ".mpeg2" or ".mpeg4")
{
VideoDelete.Visibility = Visibility.Visible;
VideoIcon.Visibility = Visibility.Collapsed;
VideoText.Visibility = Visibility.Collapsed;
VideoRectangle.Stroke = Brushes.SeaGreen;
VideoImagine.Source = new(Record);
break;
}
}
}
}
}

private void GifArea_DragOver(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop) || e.AllowedEffects.HasFlag(DragDropEffects.Copy) == false)
Expand Down Expand Up @@ -125,13 +158,47 @@ private void GifDelete_Click(object sender, RoutedEventArgs e)
GifRectangle.Stroke = SSRER.GetResource<Brush>("TextFillColorDisabledBrush");
}

private void VideoArea_DragOver(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop) || e.AllowedEffects.HasFlag(DragDropEffects.Copy) == false)
{
e.Effects = DragDropEffects.None;
}
else
{
e.Effects = DragDropEffects.Copy;
VideoRectangle.Stroke = Brushes.DodgerBlue;
}
}

private void VideoDelete_Click(object sender, RoutedEventArgs e)
{
VideoImagine.Source = null;
VideoIcon.Visibility = Visibility.Visible;
VideoText.Visibility = Visibility.Visible;
VideoDelete.Visibility = Visibility.Collapsed;
VideoRectangle.Stroke = SSRER.GetResource<Brush>("TextFillColorDisabledBrush");
}

private void VideoCreate_Click(object sender, RoutedEventArgs e)
{
IsPrimaryButtonEnabled = true;
VideoCard.Visibility = Visibility.Visible;
CreateCard.Visibility = Visibility.Collapsed;
}

private void VideoArea_DragLeave(object sender, DragEventArgs e)
{
if (string.IsNullOrEmpty($"{VideoImagine.Source}"))
{
VideoRectangle.Stroke = SSRER.GetResource<Brush>("TextFillColorDisabledBrush");
}
else
{
VideoRectangle.Stroke = Brushes.SeaGreen;
}
}

private void ThemePreview_Click(object sender, RoutedEventArgs e)
{
Button Button = sender as Button;
Expand Down Expand Up @@ -426,6 +493,100 @@ protected override async void OnButtonClick(ContentDialogButton Button)
SSTHI.WriteJson(Path.Combine(Theme, SMR.SucroseInfo), Info);
}
}
else if (VideoCard.Visibility == Visibility.Visible)
{
Uri Video = VideoImagine.Source;

if (Video == null || string.IsNullOrEmpty(Video.LocalPath))
{
VideoRectangle.Stroke = Brushes.Crimson;
return;
}
else if (string.IsNullOrEmpty(VideoTitle.Text))
{
VideoTitle.Focus();
return;
}
else if (string.IsNullOrEmpty(VideoDescription.Text))
{
VideoDescription.Focus();
return;
}
else if (string.IsNullOrEmpty(VideoAuthor.Text))
{
VideoAuthor.Focus();
return;
}
else if (!SSTHV.IsUrl(VideoContact.Text) && !SSTHV.IsMail(VideoContact.Text))
{
VideoContact.Focus();
return;
}
else
{
string Name;
string Theme;
string Preview = "Preview.gif";
string Thumbnail = "Thumbnail.jpg";

do
{
SPMI.LibraryService.Theme = SHG.GenerateString(SMMM.Chars, 25, SMR.Randomise);
Theme = Path.Combine(SMMM.LibraryLocation, SPMI.LibraryService.Theme);
} while (File.Exists(Theme));

Directory.CreateDirectory(Theme);

if (File.Exists(Video.LocalPath))
{
Name = "s_" + Path.GetFileName(Video.LocalPath);
await Task.Run(() => File.Copy(Video.LocalPath, Path.Combine(Theme, Name), true));
}
else
{
VideoRectangle.Stroke = Brushes.Crimson;
return;
}

if (File.Exists($"{VideoThumbnail.Content}"))
{
string Source = $"{VideoThumbnail.Content}";
Thumbnail = "t_" + Path.GetFileName(Source);
await Task.Run(() => File.Copy(Source, Path.Combine(Theme, Thumbnail), true));
}
else
{
await Task.Run(async () => await ExtractResources(Thumbnail, Theme));
}

if (File.Exists($"{VideoPreview.Content}"))
{
string Source = $"{VideoPreview.Content}";
Preview = "p_" + Path.GetFileName(Source);
await Task.Run(() => File.Copy(Source, Path.Combine(Theme, Preview), true));
}
else
{
await Task.Run(async () => await ExtractResources(Preview, Theme));
}

SSTHI Info = new()
{
Source = Name,
Preview = Preview,
Type = SSDEWT.Video,
Thumbnail = Thumbnail,
Title = VideoTitle.Text,
AppVersion = SSCHV.Get(),
Version = new(1, 0, 0, 0),
Author = VideoAuthor.Text,
Contact = VideoContact.Text,
Description = VideoDescription.Text
};

SSTHI.WriteJson(Path.Combine(Theme, SMR.SucroseInfo), Info);
}
}
else if (YouTubeCard.Visibility == Visibility.Visible)
{
if (!SSTHV.IsYouTubeAll(YouTubeUrl.Text))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
<system:String x:Key="Portal.ThemeCreate.DragDrop.Delete">Rückgängig</system:String>

<system:String x:Key="Portal.ThemeCreate.DragDrop.Gif">Ziehen und Ablegen Sie Ihre Gif-Datei hier</system:String>

<system:String x:Key="Portal.ThemeCreate.DragDrop.Video">Ziehen und Ablegen Sie Ihre Videodatei hier</system:String>

<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Title">Deckbild Auswählen</system:String>
<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Filter">Bilddateien (*.png;*.jpg;*.jpeg;*.tiff;*.webp)|*.png;*.jpg;*.jpeg;*.tiff;*.webp</system:String>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<system:String x:Key="Portal.ThemeCreate.DragDrop.Delete">Undo</system:String>

<system:String x:Key="Portal.ThemeCreate.DragDrop.Gif">Drag and drop your gif file here</system:String>
<system:String x:Key="Portal.ThemeCreate.DragDrop.Video">Drag and drop your video file here</system:String>

<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Title">Select Cover Image</system:String>
<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Filter">Image Files (*.png;*.jpg;*.jpeg;*.tiff;*.webp)|*.png;*.jpg;*.jpeg;*.tiff;*.webp</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<system:String x:Key="Portal.ThemeCreate.DragDrop.Delete">Deshacer</system:String>

<system:String x:Key="Portal.ThemeCreate.DragDrop.Gif">Arrastra y suelta tu archivo gif aquí</system:String>
<system:String x:Key="Portal.ThemeCreate.DragDrop.Video">Arrastre y suelte su archivo de video aquí</system:String>

<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Title">Selecciona Imagen de Portada</system:String>
<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Filter">Archivos de Imagen (*.png;*.jpg;*.jpeg;*.tiff;*.webp)|*.png;*.jpg;*.jpeg;*.tiff;*.webp</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@

<system:String x:Key="Portal.ThemeCreate.DragDrop.Delete">Annuler</system:String>

<system:String x:Key="Portal.ThemeCreate.DragDrop.Gif">Glissez-déposez votre fichier gif ici</system:String>
<system:String x:Key="Portal.ThemeCreate.DragDrop.Gif">Faites glisser et déposez votre fichier gif ici</system:String>
<system:String x:Key="Portal.ThemeCreate.DragDrop.Video">Faites glisser et déposez votre fichier vidéo ici</system:String>

<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Title">Sélectionner une Image de Couverture</system:String>
<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Filter">Fichiers Image (*.png;*.jpg;*.jpeg;*.tiff;*.webp)|*.png;*.jpg;*.jpeg;*.tiff;*.webp</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
<system:String x:Key="Portal.ThemeCreate.ThemeArguments.Hint">Proszę podać poprawne argumenty aplikacji</system:String>

<system:String x:Key="Portal.ThemeCreate.DragDrop.Delete">Cofnij</system:String>

<system:String x:Key="Portal.ThemeCreate.DragDrop.Gif">Przeciągnij i upuść swój plik gif tutaj</system:String>
<system:String x:Key="Portal.ThemeCreate.DragDrop.Video">Przeciągnij i upuść swój plik wideo tutaj</system:String>

<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Title">Wybierz Obraz Okładki</system:String>
<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Filter">Pliki Obrazów (*.png;*.jpg;*.jpeg;*.tiff;*.webp)|*.png;*.jpg;*.jpeg;*.tiff;*.webp</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<system:String x:Key="Portal.ThemeCreate.DragDrop.Delete">Geri Al</system:String>

<system:String x:Key="Portal.ThemeCreate.DragDrop.Gif">Gif dosyanızı buraya sürükleyin ve bırakın</system:String>
<system:String x:Key="Portal.ThemeCreate.DragDrop.Video">Video dosyanızı buraya sürükleyin ve bırakın</system:String>

<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Title">Kapak Resmi Seç</system:String>
<system:String x:Key="Portal.ThemeCreate.ThemeThumbnail.Filter">Resim Dosyaları (*.png;*.jpg;*.jpeg;*.tiff;*.webp)|*.png;*.jpg;*.jpeg;*.tiff;*.webp</system:String>
Expand Down

0 comments on commit 0e30acf

Please sign in to comment.