public static void LoadRecents() { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists("EmojiRecents")) { return; } using (var stream = new IsolatedStorageFileStream("EmojiRecents", FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite, store)) { if (stream.Length <= 0) { return; } using (var br = new BinaryReader(stream)) { var count = br.ReadInt32(); Recents = new List <EmojiDataItem>(); for (var i = 0; i < count; i++) { var emoji = new EmojiDataItem(br.ReadString(), br.ReadUInt64()); Recents.Add(emoji); } } } } }
public static void AddToRecents(EmojiDataItem emojiDataItem) { if (Recents == null) { LoadRecents(); if (Recents == null) { return; } } var prevItem = Recents.FirstOrDefault(x => x.Code == emojiDataItem.Code); if (prevItem != null) { Recents.Remove(prevItem); Recents.Insert(0, prevItem); } else { Recents.Insert(0, emojiDataItem); Recents = Recents.Take(30).ToList(); } SaveRecents(); }
private void OnEmojiSelected(object sender, EmojiDataItem emojiDataItem) { TextBoxTarget.Dispatcher.BeginInvoke(() => { var selectionStart = TextBoxTarget.SelectionStart; TextBoxTarget.Text = TextBoxTarget.Text.Insert(selectionStart, emojiDataItem.String); TextBoxTarget.Select(selectionStart + emojiDataItem.String.Length, 0); }); if (_currentCategory == RecentsCategoryIndex) { return; } var that = emojiDataItem; ThreadPool.QueueUserWorkItem(state => EmojiData.AddToRecents(that)); }
public static EmojiDataItem GetByIndex(int categoryIndex, int spriteIndex, int itemIndex) { var category = EmojiData.CodesByCategory[categoryIndex]; var emojiIndex = spriteIndex * EmojiData.ItemsInSprite + itemIndex; if (category.Length <= emojiIndex) { return(null); // out of bounds } ulong code = category[emojiIndex]; var result = new EmojiDataItem { Code = code, String = BuildString(code) }; result.Uri = BuildUri(result.String); return(result); }
private void ViewOnTap(object sender, GestureEventArgs args) { var point = args.GetPosition(View); var column = (int)Math.Ceiling(point.X / 79); var row = (int)Math.Ceiling(point.Y / 70); if (column <= 0 || row <= 0) { return; } //Debug.WriteLine("{0}-{1}", column, row); var itemIndex = (row - 1) * EmojiData.ItemsInRow + (column - 1); var emoji = EmojiDataItem.GetByIndex(CategoryIndex, SpriteOffset, itemIndex); if (emoji != null) { EmojiSelected(null, emoji); } }