Ejemplo n.º 1
0
		public async Task AddAsync(StreamItem item)
		{
			if (_items.Value.Any(t => t.Id == item.Id))
				return;

			var folderName = Guid.NewGuid().ToString("N");

			var parser = new HtmlParser();
			var plainText = parser.GetPlainText(item.Content, 200);

			var cacheFolder = await _rootCacheFolder.CreateFolderAsync(CacheFolderName, CreationCollisionOption.OpenIfExists).AsTask().ConfigureAwait(false);
			var folder = await cacheFolder.CreateFolderAsync(folderName).AsTask().ConfigureAwait(false);

			var newHtml = await SaveImagesAsync(folder, item.Content).ConfigureAwait(false);

			var savedItem = new SavedStreamItem
			{
				Id = item.Id,
				Title = item.Title,
				Published = item.Published,
				WebUri = item.WebUri,
				ShortContent = plainText,
				Content = newHtml,
				ImageFolder = folderName
			};

			_items.Value.Add(savedItem);
			_storageManager.Save(savedItem);
		}
Ejemplo n.º 2
0
		private void OnSelectItem(object obj)
		{
			var item = obj as StreamItem;
			if (item != null && !(item is EmptySpaceStreamItem) && !(item is HeaderSpaceStreamItem))
			{
				if (_currentItem != null)
					_currentItem.IsSelected = false;

				_currentItem = item;
				_currentItem.IsSelected = true;

				if (!item.NeedSetReadExplicitly && item.Unread && !_isStarsList)
				{
					item.Unread = false;
					MarkAsRead(item.Id, true);
				}

				SetCurrentItemRead(!_currentItem.Unread);
				SetCurrentItemStarred(_currentItem.Starred);

				CurrentItemReadEnabled = _currentItem != null;
				CurrentItemStarredEnabled = _currentItem != null;
				RaiseOpenWebCommandCanExecuteChanged();
				RaiseShareCommandCanExecuteChanged();
				RaiseSaveCommandCanExecuteChanged();
			}
			else
			{
				CurrentItemReadEnabled = false;
				CurrentItemStarredEnabled = false;
			}
		}
Ejemplo n.º 3
0
		private void OnItemsScroll(object obj)
		{
			var items = (object[])obj;
			var firstItem = (StreamItem)items[0];
			if (firstItem is EmptySpaceStreamItem || firstItem is HeaderSpaceStreamItem)
			{
				CurrentItemReadEnabled = false;
				CurrentItemStarredEnabled = false;
				return;
			}

			if (!firstItem.NeedSetReadExplicitly && firstItem.Unread && _autoMarkAsRead && !_isStarsList)
			{
				firstItem.Unread = false;
				MarkAsRead(firstItem.Id, true);
			}

			if (_currentItem != null)
				_currentItem.IsSelected = false;

			_currentItem = firstItem;
			_currentItem.IsSelected = true;
			SetCurrentItemRead(!_currentItem.Unread);
			SetCurrentItemStarred(_currentItem.Starred);

			//CurrentItemReadEnabled = _currentItem != null;
			CurrentItemStarredEnabled = _currentItem != null;
			RaiseOpenWebCommandCanExecuteChanged();
			RaiseShareCommandCanExecuteChanged();
			RaiseSaveCommandCanExecuteChanged();
		}
Ejemplo n.º 4
0
		private async Task LoadDataInternalAsync()
		{
			await _localStorageManager.ClearTempFilesAsync();

			var streamItems = new StreamItemCollection(_apiClient, _streamId, _showNewestFirst, _telemetryClient, AllArticles, b => IsBusy = b, _preloadItemCount);
			streamItems.LoadMoreItemsError += (sender, args) => IsOffline = true;
			await streamItems.InitAsync();
			
			Items = streamItems;
			_currentItem = Items.FirstOrDefault();

			if (_currentItem != null)
			{
				_currentItem.IsSelected = true;
				SetCurrentItemRead(!_currentItem.Unread);
				SetCurrentItemStarred(_currentItem.Starred);
			}
			else
			{
				SetCurrentItemRead(false);
				SetCurrentItemStarred(false);
			}

			CurrentItemReadEnabled = _currentItem != null && !(_currentItem is EmptySpaceStreamItem) && !(_currentItem is HeaderSpaceStreamItem);
			CurrentItemStarredEnabled = _currentItem != null && !(_currentItem is EmptySpaceStreamItem) && !(_currentItem is HeaderSpaceStreamItem);
			RaiseOpenWebCommandCanExecuteChanged();
			RaiseShareCommandCanExecuteChanged();
			RaiseSaveCommandCanExecuteChanged();

			if (Items != null)
			{
				var streamItemCollectionState = Items.GetSate();
				//await _cacheManager.SaveStreamAsync(streamItemCollectionState);
				await _localStorageManager.SaveStreamCollectionAsync(streamItemCollectionState);
			}
		}
Ejemplo n.º 5
0
		private async void LoadData()
		{
			IsBusy = true;

			Exception error = null;
			try
			{
				IsOffline = false;
				await LoadDataInternalAsync();
			}
			catch (AuthenticationApiException)
			{
				_apiClient.ClearSession();
				_navigationService.Navigate(PageTokens.SignIn, null);
				return;
			}
			catch (Exception ex)
			{
				error = ex;
				_telemetryClient.TrackExceptionFull(ex);
			}
			finally
			{
				IsBusy = false;
			}

			if (error == null) return;

			IsOffline = true;

			IsBusy = true;
			var cacheData = await _localStorageManager.LoadStreamCollectionAsync(_streamId);
			IsBusy = false;

			if (cacheData != null)
			{
				var items = new StreamItemCollection(cacheData, _apiClient, _telemetryClient, b => IsBusy = b, _preloadItemCount);
				_currentItem = items.FirstOrDefault(i => i.IsSelected);
				_currentItemRead = _currentItem != null && !_currentItem.Unread;
				CurrentItemReadEnabled = _currentItem != null;
				_currentItemStarred = _currentItem != null && _currentItem.Starred;
				CurrentItemStarredEnabled = _currentItem != null;

				Items = items;
			}

			MessageDialog msgbox = new MessageDialog(error.Message, Strings.Resources.ErrorDialogTitle);
			await msgbox.ShowAsync();
		}
Ejemplo n.º 6
0
		private bool RestoreState(Dictionary<string, object> viewModelState)
		{
			if (viewModelState == null)
				return false;
			
			object stateValue;
			if (viewModelState.TryGetValue("Title", out stateValue))
				Title = (string)stateValue;

			_currentItemRead = viewModelState.GetValue<bool>("CurrentItemRead");
			OnPropertyChanged("CurrentItemRead");

			CurrentItemReadEnabled = viewModelState.GetValue<bool>("CurrentItemReadEnabled");

			_currentItemStarred = viewModelState.GetValue<bool>("CurrentItemStarred");
			OnPropertyChanged("CurrentItemStarred");

			CurrentItemStarredEnabled = viewModelState.GetValue<bool>("CurrentItemStarredEnabled");

			var itemsState = viewModelState.GetValue<StreamItemCollectionState>("Items");
			if (itemsState == null)
				return false;

			_currentItem = itemsState.Items.FirstOrDefault(i => i.IsSelected);
			Items = new StreamItemCollection(itemsState, _apiClient, _telemetryClient, b => IsBusy = b, _preloadItemCount);
			Items.LoadMoreItemsError += (sender, args) => IsOffline = true;

			return true;
		}
Ejemplo n.º 7
0
		private StreamItem[] LoadStreamCollectionItems(SQLiteConnection connection, string streamId)
		{
			List<StreamItem> items = new List<StreamItem>();
			items.Add(new HeaderSpaceStreamItem());

			using (var statement = connection.Prepare(@"SELECT ID, PUBLISHED, TITLE, WEB_URI, CONTENT, UNREAD, NEED_SET_READ_EXPLICITLY, IS_SELECTED, STARRED, SAVED FROM STREAM_ITEM WHERE STREAM_ID = @STREAM_ID;"))
			{
				statement.Bind("@STREAM_ID", streamId);

				while (statement.Step() == SQLiteResult.ROW)
				{
					var item = new StreamItem
					{
						Id = (string)statement[0],
						Published = DateTimeOffset.Parse((string)statement[1]),
						Title = (string)statement[2],
						WebUri = (string)statement[3],
						Content = (string)statement[4],
						Unread = statement.GetInteger(5) == 1,
						NeedSetReadExplicitly = statement.GetInteger(6) == 1,
						IsSelected = statement.GetInteger(7) == 1,
						Starred = statement.GetInteger(8) == 1,
						Saved = statement.GetInteger(9) == 1,
					};
					items.Add(item);
				}
			}

			items.Add(new EmptySpaceStreamItem());

			return items.ToArray();
		}