-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #8 : Change article view * #8 : Add settings window * #5 : Add settings for feeds * #5 : Change edit feed
- Loading branch information
Showing
17 changed files
with
336 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Monbsoft.Feeader.Avalonia.Models | ||
{ | ||
public class SettingsContext | ||
{ | ||
public SettingsContext() | ||
{ | ||
Feeds = new ObservableCollection<Feed>(); | ||
} | ||
public SettingsContext(IEnumerable<Feed> feeds) | ||
{ | ||
Feeds = new ObservableCollection<Feed>(feeds); | ||
} | ||
|
||
public ObservableCollection<Feed> Feeds { get; } | ||
} | ||
} |
61 changes: 0 additions & 61 deletions
61
src/Monbsoft.Feeader.Avalonia/ViewModels/AddFeedViewModel.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/Monbsoft.Feeader.Avalonia/ViewModels/EditFeedViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Monbsoft.Feeader.Avalonia.Models; | ||
using Monbsoft.Feeader.Avalonia.Services; | ||
using NLog.Fluent; | ||
using ReactiveUI; | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reactive; | ||
using System.Reactive.Linq; | ||
|
||
namespace Monbsoft.Feeader.Avalonia.ViewModels | ||
{ | ||
public class EditFeedViewModel : ViewModelBase | ||
{ | ||
private string _name; | ||
private Feed? _selected; | ||
private string _url; | ||
public EditFeedViewModel(SettingsContext context) | ||
{ | ||
this.WhenAnyValue(x => x.Url) | ||
.Where(x => !string.IsNullOrWhiteSpace(x)) | ||
.Throttle(TimeSpan.FromMilliseconds(400)) | ||
.ObserveOn(RxApp.MainThreadScheduler) | ||
.Subscribe(DoSearch); | ||
|
||
Feeds = new ObservableCollection<Feed>(context.Feeds); | ||
|
||
AddCommand = ReactiveCommand.Create(() => | ||
{ | ||
Feeds.Add(new Feed("name", "https://feed.com")); | ||
Debug.WriteLine($"Feed added"); | ||
}); | ||
RemoveCommand = ReactiveCommand.Create(() => | ||
{ | ||
if(_selected != null) | ||
{ | ||
Feeds.Remove(_selected); | ||
Debug.WriteLine($"Feed {_selected?.Name} removed"); | ||
} | ||
}); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Gets the add command | ||
/// </summary> | ||
public ReactiveCommand<Unit, Unit> AddCommand { get; } | ||
public ObservableCollection<Feed> Feeds { get; } | ||
/// <summary> | ||
/// Gets the name of the feed | ||
/// </summary> | ||
public string? Name | ||
{ | ||
get => _name; | ||
set => this.RaiseAndSetIfChanged(ref _name, value); | ||
} | ||
public ReactiveCommand<Unit, Unit> RemoveCommand { get; } | ||
/// <summary> | ||
/// Gets or sets the selected feed | ||
/// </summary> | ||
public Feed SelectedFeed | ||
{ | ||
get => _selected; | ||
set => this.RaiseAndSetIfChanged(ref _selected, value); | ||
} | ||
/// <summary> | ||
/// Gets the url of the feed | ||
/// </summary> | ||
public string? Url | ||
{ | ||
get => _url; | ||
set => this.RaiseAndSetIfChanged(ref _url, value); | ||
} | ||
|
||
private async void DoSearch(string? url) | ||
{ | ||
try | ||
{ | ||
if (!string.IsNullOrEmpty(url)) | ||
{ | ||
var feed = await FeedService.GetFeedDataAsync(url); | ||
Name = feed.Name; | ||
} | ||
} | ||
catch(Exception ex) | ||
{ | ||
Log.Error(ex.Message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Monbsoft.Feeader.Avalonia/ViewModels/SettingsWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Monbsoft.Feeader.Avalonia.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Monbsoft.Feeader.Avalonia.ViewModels | ||
{ | ||
public class SettingsWindowViewModel : ViewModelBase | ||
{ | ||
|
||
public SettingsWindowViewModel(SettingsContext context) | ||
{ | ||
EditFeedViewModel = new EditFeedViewModel(context); | ||
} | ||
|
||
public EditFeedViewModel EditFeedViewModel { get; } | ||
|
||
public SettingsContext CreateContext() | ||
{ | ||
return new SettingsContext(EditFeedViewModel.Feeds); | ||
} | ||
} | ||
} |
Oops, something went wrong.