-
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.
- Loading branch information
Showing
17 changed files
with
268 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Monbsoft.Feeader.Avalonia.Models | ||
{ | ||
public class FeedContext | ||
{ | ||
public FeedContext(IEnumerable<Feed> feeds) | ||
{ | ||
Feeds = feeds.ToList(); | ||
} | ||
|
||
public List<Feed> Feeds { get; } | ||
} | ||
} |
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
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
110 changes: 110 additions & 0 deletions
110
src/Monbsoft.Feeader.Avalonia/ViewModels/ChangeFeedViewModel.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,110 @@ | ||
using Monbsoft.Feeader.Avalonia.Models; | ||
using Monbsoft.Feeader.Avalonia.Services; | ||
using NLog.Fluent; | ||
using ReactiveUI; | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Reactive; | ||
using System.Reactive.Linq; | ||
|
||
namespace Monbsoft.Feeader.Avalonia.ViewModels | ||
{ | ||
public class ChangeFeedViewModel : ViewModelBase | ||
{ | ||
private FeedContext _context; | ||
private string _name; | ||
private string _url; | ||
private Feed? _selectedFeed; | ||
private FeedState _state; | ||
|
||
public ChangeFeedViewModel(FeedContext context) | ||
{ | ||
this.WhenAnyValue(x => x.Url) | ||
.Where(x => !string.IsNullOrWhiteSpace(x)) | ||
.Throttle(TimeSpan.FromMilliseconds(400)) | ||
.ObserveOn(RxApp.MainThreadScheduler) | ||
.Subscribe(DoSearch); | ||
|
||
this.WhenAnyValue(x => x.SelectedFeed) | ||
.ObserveOn(RxApp.MainThreadScheduler) | ||
.Subscribe(f => | ||
{ | ||
Name = f?.Name; | ||
Url = f?.Link; | ||
_state = f != null ? FeedState.Change : FeedState.Add; | ||
}); | ||
|
||
Feeds = new ObservableCollection<Feed>(context.Feeds); | ||
_state = FeedState.Add; | ||
_context = context; | ||
|
||
AddCommand = ReactiveCommand.Create(() => | ||
{ | ||
if(_state == FeedState.Change && _selectedFeed != null) | ||
{ | ||
_context.Feeds.Remove(_selectedFeed); | ||
} | ||
_context.Feeds.Add(new Feed(Name!, Url!)); | ||
return _context; | ||
}); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// A | ||
/// </summary> | ||
public ReactiveCommand<Unit, FeedContext> AddCommand { get; } | ||
/// <summary> | ||
/// Gets the feeds | ||
/// </summary> | ||
public ObservableCollection<Feed> Feeds { get; } | ||
/// <summary> | ||
/// Gets the name of the feed | ||
/// </summary> | ||
public string? Name | ||
{ | ||
get => _name; | ||
set => this.RaiseAndSetIfChanged(ref _name, value); | ||
} | ||
/// <summary> | ||
/// Gets or sets the selected feed | ||
/// </summary> | ||
public Feed? SelectedFeed | ||
{ | ||
get => _selectedFeed; | ||
set => this.RaiseAndSetIfChanged(ref _selectedFeed, 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); | ||
} | ||
} | ||
|
||
enum FeedState | ||
{ | ||
Add = 0, | ||
Change = 1 | ||
} | ||
|
||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
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 | ||
{ | ||
private readonly FeedContext _feedContext; | ||
|
||
public SettingsWindowViewModel(FeedContext context) | ||
{ | ||
ChangeFeedViewModel = new ChangeFeedViewModel(context); | ||
} | ||
|
||
public ChangeFeedViewModel ChangeFeedViewModel { get; } | ||
} | ||
} |
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
Oops, something went wrong.