Skip to content

Commit

Permalink
Fallback icons on unsupported platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
FrayxRulez committed Jul 29, 2022
1 parent d27d90e commit 683e1c6
Show file tree
Hide file tree
Showing 16 changed files with 657 additions and 5,824 deletions.
867 changes: 514 additions & 353 deletions Unigram/Unigram/Assets/Fonts/Telegram.json

Large diffs are not rendered by default.

Binary file modified Unigram/Unigram/Assets/Fonts/Telegram.ttf
Binary file not shown.
552 changes: 0 additions & 552 deletions Unigram/Unigram/Assets/Icons/EmojiToGif.cs

Large diffs are not rendered by default.

567 changes: 0 additions & 567 deletions Unigram/Unigram/Assets/Icons/EmojiToSticker.cs

Large diffs are not rendered by default.

527 changes: 0 additions & 527 deletions Unigram/Unigram/Assets/Icons/GifToEmoji.cs

Large diffs are not rendered by default.

765 changes: 0 additions & 765 deletions Unigram/Unigram/Assets/Icons/GifToSticker.cs

Large diffs are not rendered by default.

1,028 changes: 0 additions & 1,028 deletions Unigram/Unigram/Assets/Icons/MuteUnmute.cs

Large diffs are not rendered by default.

555 changes: 0 additions & 555 deletions Unigram/Unigram/Assets/Icons/StickerToEmoji.cs

Large diffs are not rendered by default.

746 changes: 0 additions & 746 deletions Unigram/Unigram/Assets/Icons/StickerToGif.cs

Large diffs are not rendered by default.

655 changes: 3 additions & 652 deletions Unigram/Unigram/Assets/Icons/VoiceVideo.cs

Large diffs are not rendered by default.

83 changes: 58 additions & 25 deletions Unigram/Unigram/Controls/AnimatedGlyphToggleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class AnimatedGlyphToggleButton : ToggleButton
private FrameworkElement _label;
private Visual _visual;

protected bool _animateOnToggle = true;

public AnimatedGlyphToggleButton()
{
DefaultStyleKey = typeof(AnimatedGlyphToggleButton);
Expand All @@ -29,62 +31,93 @@ public AnimatedGlyphToggleButton()
Unchecked += OnToggle;
}

protected virtual bool IsRuntimeCompatible()
{
return false;
}

protected override void OnApplyTemplate()
{
if (IsRuntimeCompatible())
{
return;
}

_label1 = _label = GetTemplateChild("ContentPresenter1") as FrameworkElement;
_label2 = GetTemplateChild("ContentPresenter2") as FrameworkElement;

_visual1 = _visual = ElementCompositionPreview.GetElementVisual(_label1);
_visual2 = ElementCompositionPreview.GetElementVisual(_label2);

if (_label2 is TextBlock text2)
if (_label1 != null && _label2 != null)
{
text2.Text = string.Empty;
_visual1 = _visual = ElementCompositionPreview.GetElementVisual(_label1);
_visual2 = ElementCompositionPreview.GetElementVisual(_label2);

if (_label2 is TextBlock text2)
{
text2.Text = string.Empty;
}
else if (_label2 is ContentPresenter presenter2)
{
presenter2.Content = new object();
}

_visual2.Opacity = 0;
_visual2.Scale = new Vector3();
_visual2.CenterPoint = new Vector3(10);

if (_label1 is TextBlock text1)
{
text1.Text = (IsChecked == true ? CheckedGlyph : Glyph) ?? string.Empty;
}
else if (_label1 is ContentPresenter presenter1)
{
presenter1.Content = (IsChecked == true ? CheckedContent : Content) ?? new object();
}

_visual1.Opacity = 1;
_visual1.Scale = new Vector3(1);
_visual1.CenterPoint = new Vector3(10);
}
else if (_label2 is ContentPresenter presenter2)

base.OnApplyTemplate();
}

private void OnToggle(object sender, RoutedEventArgs e)
{
if (_animateOnToggle is false)
{
presenter2.Content = new object();
return;
}

_visual2.Opacity = 0;
_visual2.Scale = new Vector3();
_visual2.CenterPoint = new Vector3(10);

if (_label1 is TextBlock text1)
if (_label is TextBlock)
{
text1.Text = IsChecked == true ? CheckedGlyph : Glyph ?? string.Empty;
OnGlyphChanged(IsChecked == true ? CheckedGlyph : Glyph);
}
else if (_label1 is ContentPresenter presenter1)
else
{
presenter1.Content = IsChecked == true ? CheckedContent : Content ?? new object();
OnGlyphChanged(IsChecked == true ? CheckedContent : Content);
}

_visual1.Opacity = 1;
_visual1.Scale = new Vector3(1);
_visual1.CenterPoint = new Vector3(10);

base.OnApplyTemplate();
}

private async void OnToggle(object sender, RoutedEventArgs e)
protected async void OnGlyphChanged(object newValue)
{
if (_visual == null || _label == null)
{
return;
}

var visualShow = _visual == _visual1 ? _visual2 : _visual1;
var visualHide = _visual == _visual1 ? _visual1 : _visual2;

var labelShow = _visual == _visual1 ? _label2 : _label1;
var labelHide = _visual == _visual1 ? _label1 : _label2;

if (labelShow is TextBlock textShow)
if (labelShow is TextBlock textShow && newValue is string glyph)
{
textShow.Text = IsChecked == true ? CheckedGlyph : Glyph;
textShow.Text = glyph;
}
else if (labelShow is ContentPresenter presenterShow)
{
presenterShow.Content = IsChecked == true ? CheckedContent : Content;
presenterShow.Content = newValue;
}

await this.UpdateLayoutAsync();
Expand Down
38 changes: 5 additions & 33 deletions Unigram/Unigram/Controls/AnimatedIconToggleButton.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using Microsoft.UI.Xaml.Controls;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;

namespace Unigram.Controls
{
public class AnimatedIconToggleButton : ToggleButton
public class AnimatedIconToggleButton : AnimatedGlyphToggleButton
{
public AnimatedIconToggleButton()
{
DefaultStyleKey = typeof(AnimatedIconToggleButton);
RegisterPropertyChangedCallback(ForegroundProperty, OnForegroundChanged);
}
protected override bool IsRuntimeCompatible()
{
return Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 11);
}

private void OnForegroundChanged(DependencyObject sender, DependencyProperty dp)
{
Expand Down Expand Up @@ -46,34 +47,5 @@ private static void OnSourceChanged(DependencyObject d, DependencyPropertyChange
}

#endregion

#region IsOneWay

public bool IsOneWay
{
get => (bool)GetValue(IsOneWayProperty);
set => SetValue(IsOneWayProperty, value);
}

public static readonly DependencyProperty IsOneWayProperty =
DependencyProperty.Register("IsOneWay", typeof(bool), typeof(AnimatedIconToggleButton), new PropertyMetadata(true));

#endregion

protected override void OnToggle()
{
if (IsOneWay)
{
var binding = GetBindingExpression(IsCheckedProperty);
if (binding != null && binding.ParentBinding.Mode == BindingMode.TwoWay)
{
base.OnToggle();
}
}
else
{
base.OnToggle();
}
}
}
}
67 changes: 47 additions & 20 deletions Unigram/Unigram/Controls/Chats/ChatStickerButton.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.UI.Xaml.Controls;
using System.Numerics;
using Unigram.Assets.Icons;
using Unigram.Converters;
using Unigram.Services.Settings;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Media;

namespace Unigram.Controls.Chats
{
public class ChatStickerButton : ToggleButton
public class ChatStickerButton : AnimatedGlyphToggleButton
{
private Border Icon;

Expand All @@ -25,6 +25,8 @@ public ChatStickerButton()
{
DefaultStyleKey = typeof(ChatStickerButton);
RegisterPropertyChangedCallback(ForegroundProperty, OnForegroundChanged);

_animateOnToggle = false;
}

private void OnForegroundChanged(DependencyObject sender, DependencyProperty dp)
Expand All @@ -37,10 +39,22 @@ private void OnForegroundChanged(DependencyObject sender, DependencyProperty dp)

protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

Icon = GetTemplateChild(nameof(Icon)) as Border;

OnSourceChanged(Source, StickersTab.None);
base.OnApplyTemplate();
OnGlyphChanged(Source switch
{
StickersTab.Emoji => Icons.Emoji24,
StickersTab.Stickers => Icons.Sticker24,
StickersTab.Animations => Icons.Gif24,
});
}

protected override bool IsRuntimeCompatible()
{
return Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 11);
}

#region Source
Expand Down Expand Up @@ -68,30 +82,43 @@ private void OnSourceChanged(StickersTab newValue, StickersTab oldValue)
return;
}

if (_previous != null)
if (IsRuntimeCompatible())
{
_previous.Dispose();
_previous = null;
}
if (_previous != null)
{
_previous.Dispose();
_previous = null;
}

if (_props != null)
{
_props.Dispose();
_props = null;
}
if (_props != null)
{
_props.Dispose();
_props = null;
}

var animate = oldValue != StickersTab.None;
var visual = GetVisual(newValue, oldValue, animate, Window.Current.Compositor, out var source, out _props);
var animate = oldValue != StickersTab.None;
var visual = GetVisual(newValue, oldValue, animate, Window.Current.Compositor, out var source, out _props);

_source = source;
_previous = visual;
_source = source;
_previous = visual;

if (Foreground is SolidColorBrush brush)
if (Foreground is SolidColorBrush brush)
{
source.SetColorProperty("Color_000000", brush.Color);
}

ElementCompositionPreview.SetElementChildVisual(Icon, visual?.RootVisual);
}
else
{
source.SetColorProperty("Color_000000", brush.Color);
OnGlyphChanged(newValue switch
{
StickersTab.Emoji => Icons.Emoji24,
StickersTab.Stickers => Icons.Sticker24,
StickersTab.Animations => Icons.Gif24,
_ => null
});
}

ElementCompositionPreview.SetElementChildVisual(Icon, visual?.RootVisual);
}

private IAnimatedVisual GetVisual(StickersTab newValue, StickersTab oldValue, bool animate, Compositor compositor, out IAnimatedVisualSource2 source, out CompositionPropertySet properties)
Expand Down
3 changes: 3 additions & 0 deletions Unigram/Unigram/Converters/ReplyInfoToGlyphConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public class Icons
public const string Image = "\uEB9F";

public const string Sticker = "\uF4AA";
public const string Sticker24 = "\uE9E2";
public const string Gif = "\uF4A9";
public const string Gif24 = "\uE9E1";

public const string Reactions = "\uE980";
public const string Mention16 = "\uE986";
Expand Down Expand Up @@ -187,6 +189,7 @@ public class Icons
public const string FolderMove = "\uE92B";
public const string FolderAdd = "\uE929";
public const string Emoji = "\uE76E";
public const string Emoji24 = "\uE9E3";
public const string ChevronUp = "\uE0E4";
public const string ChevronDown = "\uE0E5";
public const string ChevronRight = "\uE0E3";
Expand Down
24 changes: 23 additions & 1 deletion Unigram/Unigram/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3905,7 +3905,7 @@
<Setter Property="FontFamily"
Value="{StaticResource SymbolThemeFontFamily}" />
<Setter Property="FontSize"
Value="{StaticResource GlyphMediumFontSize}" />
Value="{StaticResource GlyphLargeFontSize}" />
<Setter Property="FontWeight"
Value="Normal" />
<Setter Property="Height"
Expand Down Expand Up @@ -4007,6 +4007,17 @@
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="RootGrid">
<TextBlock x:Name="ContentPresenter1"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw" />
<TextBlock x:Name="ContentPresenter2"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw" />

<muxc:AnimatedIcon x:Name="Icon"
Source="{TemplateBinding Source}"
muxc:AnimatedIcon.State="Normal"
Expand Down Expand Up @@ -4507,6 +4518,17 @@
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="RootGrid">
<TextBlock x:Name="ContentPresenter1"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw" />
<TextBlock x:Name="ContentPresenter2"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw" />

<Border x:Name="Icon"
Width="24"
Height="24"
Expand Down
4 changes: 4 additions & 0 deletions Unigram/Unigram/Views/ChatView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@
Command="{x:Bind ViewModel.ToggleSilentCommand}"
FontSize="{StaticResource GlyphLargeFontSize}"
VerticalAlignment="Bottom"
Glyph="&#xE9DF;"
CheckedGlyph="&#xE9DE;"
Grid.Column="1">
<controls:AnimatedIconToggleButton.Source>
<icons:MuteUnmute />
Expand Down Expand Up @@ -1311,6 +1313,8 @@
Canvas.ZIndex="1000">
<chats:ChatRecordButton x:Name="btnVoiceMessage"
AllowFocusOnInteraction="False"
Glyph="&#xE9E4;"
CheckedGlyph="&#xE9E0;"
RecordingStarted="VoiceButton_RecordingStarted"
RecordingStopped="VoiceButton_RecordingStopped"
RecordingLocked="VoiceButton_RecordingLocked"
Expand Down

0 comments on commit 683e1c6

Please sign in to comment.