mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-01-13 17:22:48 -05:00
Start cleaning up account types
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using FeedCenter.Feeds;
|
||||
using Realms;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Realms;
|
||||
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
public class Account : RealmObject, INotifyDataErrorInfo
|
||||
{
|
||||
@@ -25,6 +26,15 @@ public class Account : RealmObject, INotifyDataErrorInfo
|
||||
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
|
||||
}
|
||||
|
||||
private IAccountReader _accountReader;
|
||||
|
||||
private IAccountReader GetAccountReader()
|
||||
{
|
||||
_accountReader ??= AccountReaderFactory.CreateAccountReader(this);
|
||||
|
||||
return _accountReader;
|
||||
}
|
||||
|
||||
[PrimaryKey]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
@@ -34,23 +44,9 @@ public class Account : RealmObject, INotifyDataErrorInfo
|
||||
set => TypeRaw = value.ToString();
|
||||
}
|
||||
|
||||
public bool SupportsFeedEdit => Type switch
|
||||
{
|
||||
AccountType.Fever => false,
|
||||
AccountType.GoogleReader => false,
|
||||
AccountType.Miniflux => true,
|
||||
AccountType.Local => true,
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
public bool SupportsFeedEdit => GetAccountReader().SupportsFeedEdit;
|
||||
|
||||
public bool SupportsFeedDelete => Type switch
|
||||
{
|
||||
AccountType.Fever => false,
|
||||
AccountType.GoogleReader => false,
|
||||
AccountType.Miniflux => true,
|
||||
AccountType.Local => true,
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
public bool SupportsFeedDelete => GetAccountReader().SupportsFeedDelete;
|
||||
|
||||
private string TypeRaw { get; set; }
|
||||
|
||||
@@ -161,17 +157,9 @@ public class Account : RealmObject, INotifyDataErrorInfo
|
||||
return new Account { Name = DefaultName, Type = AccountType.Local };
|
||||
}
|
||||
|
||||
public async Task<int> GetProgressSteps(Account account, AccountReadInput accountReadInput)
|
||||
public async Task<int> GetProgressSteps(AccountReadInput accountReadInput)
|
||||
{
|
||||
var progressSteps = Type switch
|
||||
{
|
||||
// Delegate to the right reader based on the account type
|
||||
AccountType.Fever => await new FeverReader(account).GetProgressSteps(accountReadInput),
|
||||
AccountType.GoogleReader => await new GoogleReaderReader(account).GetProgressSteps(accountReadInput),
|
||||
AccountType.Miniflux => await new MinifluxReader(account).GetProgressSteps(accountReadInput),
|
||||
AccountType.Local => await new LocalReader(account).GetProgressSteps(accountReadInput),
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
var progressSteps = await GetAccountReader().GetProgressSteps(accountReadInput);
|
||||
|
||||
return progressSteps;
|
||||
}
|
||||
@@ -193,25 +181,7 @@ public class Account : RealmObject, INotifyDataErrorInfo
|
||||
return AccountReadResult.NotDue;
|
||||
}
|
||||
|
||||
AccountReadResult accountReadResult;
|
||||
switch (Type)
|
||||
{
|
||||
// Delegate to the right reader based on the account type
|
||||
case AccountType.Fever:
|
||||
accountReadResult = await new FeverReader(this).Read(accountReadInput);
|
||||
break;
|
||||
case AccountType.GoogleReader:
|
||||
accountReadResult = await new GoogleReaderReader(this).Read(accountReadInput);
|
||||
break;
|
||||
case AccountType.Miniflux:
|
||||
accountReadResult = await new MinifluxReader(this).Read(accountReadInput);
|
||||
break;
|
||||
case AccountType.Local:
|
||||
accountReadResult = await new LocalReader(this).Read(accountReadInput);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
var accountReadResult = await GetAccountReader().Read(accountReadInput);
|
||||
|
||||
return accountReadResult;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
public class AccountReadInput(FeedCenterEntities entities, Guid? feedId, bool forceRead, Action incrementProgress)
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
public enum AccountReadResult
|
||||
{
|
||||
16
Application/Accounts/AccountReaderFactory.cs
Normal file
16
Application/Accounts/AccountReaderFactory.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
internal static class AccountReaderFactory
|
||||
{
|
||||
internal static IAccountReader CreateAccountReader(Account account) =>
|
||||
account.Type switch
|
||||
{
|
||||
AccountType.Miniflux => new MinifluxReader(account),
|
||||
AccountType.Local => new LocalReader(account),
|
||||
AccountType.Fever => new FeverReader(account),
|
||||
AccountType.GoogleReader => new GoogleReaderReader(account),
|
||||
_ => throw new NotSupportedException($"Account type '{account.Type}' is not supported."),
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
public enum AccountType
|
||||
{
|
||||
@@ -4,8 +4,9 @@ using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FeedCenter.Feeds;
|
||||
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
internal class FeverReader(Account account) : IAccountReader
|
||||
{
|
||||
@@ -142,6 +143,10 @@ internal class FeverReader(Account account) : IAccountReader
|
||||
await feverClient.MarkFeedItemAsRead(int.Parse(feedItemId));
|
||||
}
|
||||
|
||||
public bool SupportsFeedDelete => false;
|
||||
|
||||
public bool SupportsFeedEdit => false;
|
||||
|
||||
private static string GetApiKey(Account account)
|
||||
{
|
||||
var input = $"{account.Username}:{account.Password}";
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
internal class GoogleReaderReader(Account account) : IAccountReader
|
||||
{
|
||||
@@ -134,6 +134,10 @@ internal class GoogleReaderReader(Account account) : IAccountReader
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public bool SupportsFeedDelete => false;
|
||||
|
||||
public bool SupportsFeedEdit => false;
|
||||
|
||||
//private static string GetApiKey(Account account)
|
||||
//{
|
||||
// var input = $"{account.Username}:{account.Password}";
|
||||
@@ -1,10 +1,12 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
public interface IAccountReader
|
||||
{
|
||||
public Task<int> GetProgressSteps(AccountReadInput accountReadInput);
|
||||
public Task<AccountReadResult> Read(AccountReadInput accountReadInput);
|
||||
public Task MarkFeedItemRead(string feedItemId);
|
||||
public bool SupportsFeedDelete { get; }
|
||||
public bool SupportsFeedEdit { get; }
|
||||
}
|
||||
@@ -2,8 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FeedCenter.Feeds;
|
||||
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
public class LocalReader(Account account) : IAccountReader
|
||||
{
|
||||
@@ -45,4 +46,8 @@ public class LocalReader(Account account) : IAccountReader
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool SupportsFeedDelete => true;
|
||||
|
||||
public bool SupportsFeedEdit => true;
|
||||
}
|
||||
@@ -2,8 +2,9 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ChrisKaczor.MinifluxClient;
|
||||
using FeedCenter.Feeds;
|
||||
|
||||
namespace FeedCenter.Feeds;
|
||||
namespace FeedCenter.Accounts;
|
||||
|
||||
internal class MinifluxReader(Account account) : IAccountReader
|
||||
{
|
||||
@@ -143,4 +144,8 @@ internal class MinifluxReader(Account account) : IAccountReader
|
||||
|
||||
await minifluxClient.MarkFeedEntries([long.Parse(feedItemId)], FeedEntryStatus.Read);
|
||||
}
|
||||
|
||||
public bool SupportsFeedDelete => true;
|
||||
|
||||
public bool SupportsFeedEdit => true;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using FeedCenter.Options;
|
||||
using Realms;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FeedCenter.Accounts;
|
||||
using FeedCenter.Feeds;
|
||||
|
||||
namespace FeedCenter;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using FeedCenter.Accounts;
|
||||
using JetBrains.Annotations;
|
||||
using Realms;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using ChrisKaczor.ApplicationUpdate;
|
||||
using FeedCenter.Accounts;
|
||||
using FeedCenter.FeedParsers;
|
||||
using FeedCenter.Properties;
|
||||
using FeedCenter.Xml;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using FeedCenter.Accounts;
|
||||
using FeedCenter.Options;
|
||||
using Realms;
|
||||
|
||||
@@ -86,24 +86,7 @@ public partial class FeedItem : RealmObject
|
||||
if (feed == null || feed.Account.Type == AccountType.Local)
|
||||
return;
|
||||
|
||||
switch (feed.Account.Type)
|
||||
{
|
||||
case AccountType.Fever:
|
||||
// Delegate to the right reader based on the account type
|
||||
await new FeverReader(feed.Account).MarkFeedItemRead(RemoteId);
|
||||
|
||||
break;
|
||||
case AccountType.Miniflux:
|
||||
// Delegate to the right reader based on the account type
|
||||
await new MinifluxReader(feed.Account).MarkFeedItemRead(RemoteId);
|
||||
|
||||
break;
|
||||
case AccountType.Local:
|
||||
break;
|
||||
default:
|
||||
Debug.Assert(false);
|
||||
break;
|
||||
}
|
||||
await AccountReaderFactory.CreateAccountReader(feed.Account).MarkFeedItemRead(RemoteId);
|
||||
}
|
||||
|
||||
[GeneratedRegex("\\n")]
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using FeedCenter.Properties;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using FeedCenter.Accounts;
|
||||
|
||||
namespace FeedCenter;
|
||||
|
||||
@@ -47,7 +48,7 @@ public partial class MainWindow
|
||||
var accountReadInput = new AccountReadInput(_database, _currentFeed.Id, forceRead, () => { });
|
||||
|
||||
// Switch to progress mode
|
||||
SetProgressMode(true, await _currentFeed.Account.GetProgressSteps(_currentFeed.Account, accountReadInput));
|
||||
SetProgressMode(true, await _currentFeed.Account.GetProgressSteps(accountReadInput));
|
||||
|
||||
// Start reading
|
||||
await HandleFeedReadWorkerStart(forceRead, _currentFeed.Id);
|
||||
@@ -77,7 +78,7 @@ public partial class MainWindow
|
||||
|
||||
foreach (var account in _database.Accounts)
|
||||
{
|
||||
progressSteps += await account.GetProgressSteps(account, accountReadInput);
|
||||
progressSteps += await account.GetProgressSteps(accountReadInput);
|
||||
}
|
||||
|
||||
// Switch to progress mode
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using FeedCenter.Feeds;
|
||||
using FeedCenter.Accounts;
|
||||
|
||||
namespace FeedCenter.Options;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
using FeedCenter.Feeds;
|
||||
using FeedCenter.Accounts;
|
||||
|
||||
namespace FeedCenter.Options;
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
xmlns:properties="clr-namespace:FeedCenter.Properties"
|
||||
xmlns:feedCenter="clr-namespace:FeedCenter"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
d:DataContext="{d:DesignInstance Type=feeds:Account}"
|
||||
d:DataContext="{d:DesignInstance Type=accounts:Account}"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
|
||||
xmlns:options="clr-namespace:FeedCenter.Options"
|
||||
xmlns:feeds="clr-namespace:FeedCenter.Feeds"
|
||||
xmlns:accounts="clr-namespace:FeedCenter.Accounts"
|
||||
mc:Ignorable="d"
|
||||
Title="AccountWindow"
|
||||
Height="350"
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using ChrisKaczor.Wpf.Validation;
|
||||
using FeedCenter.Feeds;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using FeedCenter.Accounts;
|
||||
|
||||
namespace FeedCenter.Options;
|
||||
|
||||
@@ -58,7 +57,7 @@ public partial class AccountWindow
|
||||
var accountReadInput = new AccountReadInput(_entities, null, true, () => AccountReadProgressBar.Value++);
|
||||
|
||||
AccountReadProgressBar.Value = 0;
|
||||
AccountReadProgressBar.Maximum = await _account.GetProgressSteps(_account, accountReadInput);
|
||||
AccountReadProgressBar.Maximum = await _account.GetProgressSteps(accountReadInput);
|
||||
|
||||
AccountReadProgress.Visibility = Visibility.Visible;
|
||||
ButtonPanel.Visibility = Visibility.Collapsed;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
xmlns:controls="clr-namespace:ChrisKaczor.Wpf.Controls;assembly=ChrisKaczor.Wpf.Controls.Link"
|
||||
xmlns:feedCenter="clr-namespace:FeedCenter"
|
||||
xmlns:feeds="clr-namespace:FeedCenter.Feeds"
|
||||
xmlns:accounts="clr-namespace:FeedCenter.Accounts"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="311"
|
||||
d:DesignWidth="425">
|
||||
@@ -47,7 +48,7 @@
|
||||
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
|
||||
AllowDrop="True"
|
||||
Background="{x:Null}"
|
||||
d:DataContext="{d:DesignInstance feeds:Account }">
|
||||
d:DataContext="{d:DesignInstance accounts:Account }">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding Name}"
|
||||
Header="{x:Static properties:Resources.AccountNameColumnHeader}"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using FeedCenter.Feeds;
|
||||
using FeedCenter.Accounts;
|
||||
|
||||
namespace FeedCenter.Options;
|
||||
|
||||
@@ -53,7 +52,7 @@ public partial class AccountsOptionsPanel
|
||||
|
||||
private void AddAccount()
|
||||
{
|
||||
var account = new Account(AccountType.Fever);
|
||||
var account = new Account(AccountType.Miniflux);
|
||||
|
||||
var accountWindow = new AccountWindow(_entities);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Xml;
|
||||
using FeedCenter.Accounts;
|
||||
using FeedCenter.Feeds;
|
||||
|
||||
namespace FeedCenter.Options;
|
||||
|
||||
Reference in New Issue
Block a user