private async void OnEnterClick(object sender, RoutedEventArgs e)
        {
            if (_navParams.SpeechMode)
            {
                var text   = TextControl.Text.ToString();
                var stream = await _speechSynthesizer.SynthesizeTextToStreamAsync(text);

                _mediaElement.SetSource(stream, stream.ContentType);
                _mediaElement.AutoPlay = true;
                _mediaElement.Play();
            }
            else
            {
                var childNode = _navParams.ChildNode;
                if (childNode == null)
                {
                    childNode = new PhraseNode();
                    if (_navParams.IsCategory)
                    {
                        childNode.IsCategory = true;
                    }
                    _navParams.CurrentNode.Children.Add(childNode);
                }
                childNode.Caption      = TextControl.Text;
                childNode.Parent       = _navParams.CurrentNode;
                _navParams.NeedsSaving = true;
                Frame.Navigate(typeof(MainPage), _navParams);
            }
        }
Пример #2
0
        private PhraseNode LoadPhraseNode(IJsonValue jsonValue, PhraseNode parent)
        {
            var jsonObj    = jsonValue.GetObject();
            var caption    = jsonObj.GetNamedString("caption");
            var items      = jsonObj.ContainsKey("items") ? jsonObj.GetNamedArray("items") : null;
            var isCategory = jsonObj.ContainsKey("isCategory") ? jsonObj.GetNamedBoolean("isCategory") : (items != null) && (items.Count > 0);

            var phraseNode = new PhraseNode
            {
                Caption    = caption,
                Parent     = parent,
                IsCategory = isCategory,
            };

            if (items == null)
            {
                return(phraseNode);
            }

            foreach (var item in items)
            {
                var childNode = LoadPhraseNode(item, phraseNode);
                phraseNode.Children.Add(childNode);
            }
            return(phraseNode);
        }
Пример #3
0
        public ViewModel()
        {
            Tiles = new ObservableCollection <PhraseNode>();

            RootNode = new PhraseNode();

            TileWidth  = 200;
            TileHeight = 200;

            Settings = new AppSettings();
            Settings.Load();
        }
Пример #4
0
        public void GoToNode(PhraseNode node)
        {
            Tiles.Clear();

            var sortedChildren =
                from t in node.Children
                orderby t.Caption
                orderby t.IsCategory descending
                select t;

            foreach (PhraseNode chlldNode in sortedChildren)
            {
                Tiles.Add(chlldNode);
            }
            CurrentNode = node;

            AtRootNode = false;
            if (node == RootNode)
            {
                AtRootNode = true;
            }
        }
Пример #5
0
        private JsonObject SavePhraseNode(PhraseNode node)
        {
            var jsonObj = new JsonObject();

            jsonObj.Add("caption", JsonValue.CreateStringValue(node.Caption));
            jsonObj.Add("isCategory", JsonValue.CreateBooleanValue(node.IsCategory));

            var items = new JsonArray();

            jsonObj.Add("items", items);

            if (node.Children == null)
            {
                return(jsonObj);
            }

            foreach (var childNode in node.Children)
            {
                items.Add(SavePhraseNode(childNode));
            }
            return(jsonObj);
        }