Exemplo n.º 1
0
        private async Task SaveItemFromExternal(UriSchemeMessage message, Action errorAction = null)
        {
            HomeButtonIsVisible = true;
            var allOk = true;
            ReaderItem item = null;
            try
            {
                IsSavingVisible = true;

                item = await _readerHelper.HandleProtocolMessage(message);
            }
            catch (Exception ex)
            {
                Log.ErrorException("ShareMessage", ex);
                allOk = false;
            }

            if (item != null)
            {
                await SetReaderItem(item, autostart: false);
            }

            IsSavingVisible = false;


            if (allOk && _canStart)
            {
                StartStopTimer();
            }
            else
            {
                errorAction?.Invoke();
            }
        }
Exemplo n.º 2
0
        public async Task<ReaderItem> HandleProtocolMessage(UriSchemeMessage m)
        {
            if (m.IsUri)
            {
                var item = await SaveArticle(new Uri(m.Content));
                if (item != null)
                {
                    var fullItem = await _cacheService.GetArticle(item);
                    return fullItem;
                }
            }
            else
            {
                var item = ReaderItem.NewLocalItem(m.Content);
                await SaveEditedArticle(item);
                return item;
            }

            return null;
        }
Exemplo n.º 3
0
        protected override void WireMessages()
        {
            Messenger.Default.Register<NotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.ReaderViewLeftMsg))
                {
                    ShowFinishedScreen = false;
                    if (_readerTimer != null && _readerTimer.IsEnabled)
                    {
                        _readerTimer.Stop();
                    }

                    var wordsRead = SelectedIndex * _settingsService.WordsAtATime;
                    var articleNotFinished = wordsRead < SelectedItem.WordCount;
                    if (articleNotFinished)
                    {
                        _roamingSettings.Set(SelectedItem.InternalId, wordsRead);
                    }
                    else
                    {
                        _roamingSettings.Remove(SelectedItem.InternalId);
                    }

                    SaveInProgressItems(wordsRead, !articleNotFinished);
                }
            });

            Messenger.Default.Register<ShareMessage>(this, async m =>
            {
                _shareOperation = (ShareOperation)m.Sender;
                if (_shareOperation.Data.Contains(StandardDataFormats.WebLink))
                {
                    var url = await _shareOperation.Data.GetWebLinkAsync();
                    var message = new UriSchemeMessage(url.ToString(), true, SchemeType.Read);

                    await SaveItemFromExternal(message, async () =>
                    {
                        var title = _loader.GetString("ShareErrorTitle");
                        await _messageBox.ShowAsync(_loader.GetString("ShareErrorText"), title, new List<string> { _loader.GetString("MessageBoxOk") });
                        _shareOperation.ReportError(title);
                    });
                }
                else
                {
                    _shareOperation.ReportCompleted();
                }
            });

            Messenger.Default.Register<UriSchemeMessage>(this, async m =>
            {
                if (m.SchemeType != SchemeType.Read)
                {
                    return;
                }

                await SaveItemFromExternal(m);
            });
        }
Exemplo n.º 4
0
 public Task<ReaderItem> HandleProtocolMessage(UriSchemeMessage m)
 {
     return null;
 }