Example #1
0
        public static List <EmojiGroup> Get(EmojiSkinTone skin, bool flags)
        {
            var results = new List <EmojiGroup>();
            var recent  = new EmojiGroup
            {
                Title    = Strings.Resources.RecentStickers,
                Glyph    = Icons.EmojiRecents,
                SkinTone = skin,
                Stickers = SettingsService.Current.Emoji.RecentEmoji.Select(x =>
                {
                    if (EmojiGroupInternal._skinEmojis.Contains(x))
                    {
                        return(new EmojiSkinData(x, skin));
                    }

                    return(new EmojiData(x));
                }).ToArray()
            };

            //results.Add(recent);

            if (flags)
            {
                results.AddRange(Items.Select(x => x.ToGroup(skin)));
            }
            else
            {
                results.AddRange(Items.Take(Items.Count - 1).Select(x => x.ToGroup(skin)));
            }

            return(results);
        }
        /// <summary>
        /// Returns the Emoji Skin Tone modifier character
        /// </summary>
        /// <param name="skinTone">Skin tone</param>
        /// <returns>Modifier character</returns>
        public static string ToModifierCharacter(this EmojiSkinTone skinTone)
        {
            string hexadecimalCode;

            switch (skinTone)
            {
            case EmojiSkinTone.Type12:
                hexadecimalCode = "1F3FB";
                break;

            case EmojiSkinTone.Type3:
                hexadecimalCode = "1F3FC";
                break;

            case EmojiSkinTone.Type4:
                hexadecimalCode = "1F3FD";
                break;

            case EmojiSkinTone.Type5:
                hexadecimalCode = "1F3FE";
                break;

            case EmojiSkinTone.Type6:
                hexadecimalCode = "1F3FF";
                break;

            default:
                return(string.Empty);    //generic yellow color, no modifier
            }
            var code = int.Parse(hexadecimalCode, NumberStyles.HexNumber);

            return(char.ConvertFromUtf32(code));
        }
Example #3
0
        public void SetValue(EmojiSkinTone tone)
        {
            if (tone == EmojiSkinTone.Default)
            {
                Value = _value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));

                return;
            }

            var emoji  = _value;
            var result = string.Empty;

            if (char.IsSurrogatePair(emoji, 0))
            {
                result = emoji.Substring(0, 2);
                emoji  = emoji.Substring(2);
            }
            else if (emoji.Length <= 2)
            {
                result = emoji;
                emoji  = string.Empty;
            }
            else if (emoji.Length == 5 && (emoji[3] == '\u2642' || emoji[3] == '\u2640'))
            {
                result = emoji.Substring(0, 1);
                emoji  = emoji.Substring(1);
            }

            switch (tone)
            {
            case EmojiSkinTone.Fitz12:
                result += "\uD83C\uDFFB";
                break;

            case EmojiSkinTone.Fitz3:
                result += "\uD83C\uDFFC";
                break;

            case EmojiSkinTone.Fitz4:
                result += "\uD83C\uDFFD";
                break;

            case EmojiSkinTone.Fitz5:
                result += "\uD83C\uDFFE";
                break;

            case EmojiSkinTone.Fitz6:
                result += "\uD83C\uDFFF";
                break;
            }

            Value = result + emoji;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
        }
Example #4
0
        public static IList <EmojiData> GetRecents(EmojiSkinTone skin)
        {
            return(SettingsService.Current.Emoji.RecentEmoji.Select(x =>
            {
                if (EmojiGroupInternal._skinEmojis.Contains(x))
                {
                    return new EmojiSkinData(x, skin);
                }

                return new EmojiData(x);
            }).ToArray());
        }
Example #5
0
        public static List <EmojiGroup> Get(EmojiSkinTone skin, bool flags)
        {
            var results = new List <EmojiGroup>();

            if (flags)
            {
                results.AddRange(Items.Select(x => x.ToGroup(skin)));
            }
            else
            {
                results.AddRange(Items.Take(Items.Count - 1).Select(x => x.ToGroup(skin)));
            }

            return(results);
        }
Example #6
0
            public EmojiGroup ToGroup(EmojiSkinTone tone)
            {
                return(new EmojiGroup
                {
                    Title = Title,
                    Glyph = Glyph,
                    Items = Items.Select(x =>
                    {
                        if (_skinEmojis.Contains(x))
                        {
                            return new EmojiSkinData(x, tone);
                        }

                        return new EmojiData(x);
                    }).ToArray()
                });
            }
 public SkinToneItem(EmojiSkinTone skinTone)
 {
     SkinTone = skinTone;
     Glyph    = skinTone.ToModifierCharacter();
 }
Example #8
0
 public EmojiSkinData(string value, EmojiSkinTone tone)
 {
     _value = value;
     SetValue(tone);
 }
Example #9
0
        public static async Task <List <EmojiGroup> > SearchAsync(IProtoService protoService, string query, EmojiSkinTone skin)
        {
            var result = new List <EmojiData>();

            var response = await protoService.SendAsync(new SearchEmojis(query, false));

            if (response is Emojis suggestions)
            {
                foreach (var item in suggestions.EmojisValue)
                {
                    var emoji = item;
                    if (EmojiGroupInternal._skinEmojis.Contains(emoji) || EmojiGroupInternal._skinEmojis.Contains(emoji.TrimEnd('\uFE0F')))
                    {
                        result.Add(new EmojiSkinData(emoji, skin));
                    }
                    else
                    {
                        result.Add(new EmojiData(item));
                    }
                }
            }

            return(new List <EmojiGroup>
            {
                new EmojiGroup
                {
                    Title = result.Count > 0 ? Strings.Resources.SearchEmojiHint : Strings.Resources.NoEmojiFound,
                    Items = result.ToArray()
                }
            });
        }
Example #10
0
        private void UpdateSkinTone(EmojiSkinTone selected, bool expand, bool animated)
        {
            Canvas.SetZIndex(SkinDefault, (int)selected == 0 ? 6 : 5);
            Canvas.SetZIndex(SkinFitz12, (int)selected == 1 ? 6 : 4);
            Canvas.SetZIndex(SkinFitz3, (int)selected == 2 ? 6 : 3);
            Canvas.SetZIndex(SkinFitz4, (int)selected == 3 ? 6 : 2);
            Canvas.SetZIndex(SkinFitz5, (int)selected == 4 ? 6 : 1);
            Canvas.SetZIndex(SkinFitz6, (int)selected == 5 ? 6 : 0);

            Grid.SetColumn(SkinDefault, expand ? (int)selected < 0 ? 0 : (int)selected > 0 ? 1 : 0 : 0);
            Grid.SetColumn(SkinFitz12, expand ? (int)selected < 1 ? 1 : (int)selected > 1 ? 2 : 0 : 0);
            Grid.SetColumn(SkinFitz3, expand ? (int)selected < 2 ? 2 : (int)selected > 2 ? 3 : 0 : 0);
            Grid.SetColumn(SkinFitz4, expand ? (int)selected < 3 ? 3 : (int)selected > 3 ? 4 : 0 : 0);
            Grid.SetColumn(SkinFitz5, expand ? (int)selected < 4 ? 4 : (int)selected > 4 ? 5 : 0 : 0);
            Grid.SetColumn(SkinFitz6, expand ? (int)selected < 5 ? 5 : (int)selected > 5 ? 5 : 0 : 0);
            Grid.SetColumn(Toolbar, expand ? 6 : 1);

            SkinDefault.IsEnabled = expand || selected == EmojiSkinTone.Default;
            SkinFitz12.IsEnabled  = expand || selected == EmojiSkinTone.Fitz12;
            SkinFitz3.IsEnabled   = expand || selected == EmojiSkinTone.Fitz3;
            SkinFitz4.IsEnabled   = expand || selected == EmojiSkinTone.Fitz4;
            SkinFitz5.IsEnabled   = expand || selected == EmojiSkinTone.Fitz5;
            SkinFitz6.IsEnabled   = expand || selected == EmojiSkinTone.Fitz6;

            SkinDefault.IsChecked = selected == EmojiSkinTone.Default;
            SkinFitz12.IsChecked  = selected == EmojiSkinTone.Fitz12;
            SkinFitz3.IsChecked   = selected == EmojiSkinTone.Fitz3;
            SkinFitz4.IsChecked   = selected == EmojiSkinTone.Fitz4;
            SkinFitz5.IsChecked   = selected == EmojiSkinTone.Fitz5;
            SkinFitz6.IsChecked   = selected == EmojiSkinTone.Fitz6;

            if (_expanded == expand || !animated)
            {
                _selected = selected;
                _expanded = expand;
                return;
            }

            var elements = new UIElement[] { SkinDefault, SkinFitz12, SkinFitz3, SkinFitz4, SkinFitz5, SkinFitz6, Toolbar };

            for (int i = 0; i < elements.Length; i++)
            {
                var visual = ElementCompositionPreview.GetElementVisual(VisualTreeHelper.GetChild(elements[i], 0) as UIElement);

                var from = i;
                if (elements[i] == Toolbar)
                {
                    from--;
                }
                else
                {
                    from = (int)_selected <i?i : (int)_selected> i ? i + 1 : 0;
                }

                var anim = visual.Compositor.CreateScalarKeyFrameAnimation();
                anim.InsertKeyFrame(0, expand ? from * -40 : from * 40);
                anim.InsertKeyFrame(1, 0);

                visual.StartAnimation("Offset.X", anim);
            }

            _selected = selected;
            _expanded = expand;
        }
 /// <summary>
 /// Changes the Emoji skin tone. In case the provided emoji is not an Emoji Modifier Base, it does nothing.
 /// </summary>
 /// <param name="emoji">Emoji</param>
 /// <param name="skinTone">Requested skin tone</param>
 /// <returns>Emoji with requested skin tone</returns>
 public static string ChangeSkinTone(this string emoji, EmojiSkinTone skinTone)
 => _modifierBases.Value.Contains(emoji) ? emoji + skinTone.ToModifierCharacter() : emoji;