Start cleaning up account types

This commit is contained in:
2025-11-15 15:30:23 -05:00
parent 6bae35a255
commit 66ea567eaa
23 changed files with 82 additions and 88 deletions

View File

@@ -1,11 +1,12 @@
using System; using FeedCenter.Feeds;
using Realms;
using System;
using System.Collections; using System.Collections;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Realms;
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
public class Account : RealmObject, INotifyDataErrorInfo public class Account : RealmObject, INotifyDataErrorInfo
{ {
@@ -25,6 +26,15 @@ public class Account : RealmObject, INotifyDataErrorInfo
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged; _dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
} }
private IAccountReader _accountReader;
private IAccountReader GetAccountReader()
{
_accountReader ??= AccountReaderFactory.CreateAccountReader(this);
return _accountReader;
}
[PrimaryKey] [PrimaryKey]
public Guid Id { get; set; } = Guid.NewGuid(); public Guid Id { get; set; } = Guid.NewGuid();
@@ -34,23 +44,9 @@ public class Account : RealmObject, INotifyDataErrorInfo
set => TypeRaw = value.ToString(); set => TypeRaw = value.ToString();
} }
public bool SupportsFeedEdit => Type switch public bool SupportsFeedEdit => GetAccountReader().SupportsFeedEdit;
{
AccountType.Fever => false,
AccountType.GoogleReader => false,
AccountType.Miniflux => true,
AccountType.Local => true,
_ => throw new NotSupportedException()
};
public bool SupportsFeedDelete => Type switch public bool SupportsFeedDelete => GetAccountReader().SupportsFeedDelete;
{
AccountType.Fever => false,
AccountType.GoogleReader => false,
AccountType.Miniflux => true,
AccountType.Local => true,
_ => throw new NotSupportedException()
};
private string TypeRaw { get; set; } private string TypeRaw { get; set; }
@@ -161,17 +157,9 @@ public class Account : RealmObject, INotifyDataErrorInfo
return new Account { Name = DefaultName, Type = AccountType.Local }; 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 var progressSteps = await GetAccountReader().GetProgressSteps(accountReadInput);
{
// 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()
};
return progressSteps; return progressSteps;
} }
@@ -193,25 +181,7 @@ public class Account : RealmObject, INotifyDataErrorInfo
return AccountReadResult.NotDue; return AccountReadResult.NotDue;
} }
AccountReadResult accountReadResult; var accountReadResult = await GetAccountReader().Read(accountReadInput);
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();
}
return accountReadResult; return accountReadResult;
} }

View File

@@ -1,6 +1,6 @@
using System; using System;
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
public class AccountReadInput(FeedCenterEntities entities, Guid? feedId, bool forceRead, Action incrementProgress) public class AccountReadInput(FeedCenterEntities entities, Guid? feedId, bool forceRead, Action incrementProgress)
{ {

View File

@@ -1,4 +1,4 @@
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
public enum AccountReadResult public enum AccountReadResult
{ {

View 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."),
};
}

View File

@@ -1,4 +1,4 @@
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
public enum AccountType public enum AccountType
{ {

View File

@@ -4,8 +4,9 @@ using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using FeedCenter.Feeds;
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
internal class FeverReader(Account account) : IAccountReader internal class FeverReader(Account account) : IAccountReader
{ {
@@ -142,6 +143,10 @@ internal class FeverReader(Account account) : IAccountReader
await feverClient.MarkFeedItemAsRead(int.Parse(feedItemId)); await feverClient.MarkFeedItemAsRead(int.Parse(feedItemId));
} }
public bool SupportsFeedDelete => false;
public bool SupportsFeedEdit => false;
private static string GetApiKey(Account account) private static string GetApiKey(Account account)
{ {
var input = $"{account.Username}:{account.Password}"; var input = $"{account.Username}:{account.Password}";

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
internal class GoogleReaderReader(Account account) : IAccountReader internal class GoogleReaderReader(Account account) : IAccountReader
{ {
@@ -134,6 +134,10 @@ internal class GoogleReaderReader(Account account) : IAccountReader
return Task.CompletedTask; return Task.CompletedTask;
} }
public bool SupportsFeedDelete => false;
public bool SupportsFeedEdit => false;
//private static string GetApiKey(Account account) //private static string GetApiKey(Account account)
//{ //{
// var input = $"{account.Username}:{account.Password}"; // var input = $"{account.Username}:{account.Password}";

View File

@@ -1,10 +1,12 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
public interface IAccountReader public interface IAccountReader
{ {
public Task<int> GetProgressSteps(AccountReadInput accountReadInput); public Task<int> GetProgressSteps(AccountReadInput accountReadInput);
public Task<AccountReadResult> Read(AccountReadInput accountReadInput); public Task<AccountReadResult> Read(AccountReadInput accountReadInput);
public Task MarkFeedItemRead(string feedItemId); public Task MarkFeedItemRead(string feedItemId);
public bool SupportsFeedDelete { get; }
public bool SupportsFeedEdit { get; }
} }

View File

@@ -2,8 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using FeedCenter.Feeds;
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
public class LocalReader(Account account) : IAccountReader public class LocalReader(Account account) : IAccountReader
{ {
@@ -45,4 +46,8 @@ public class LocalReader(Account account) : IAccountReader
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public bool SupportsFeedDelete => true;
public bool SupportsFeedEdit => true;
} }

View File

@@ -2,8 +2,9 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using ChrisKaczor.MinifluxClient; using ChrisKaczor.MinifluxClient;
using FeedCenter.Feeds;
namespace FeedCenter.Feeds; namespace FeedCenter.Accounts;
internal class MinifluxReader(Account account) : IAccountReader internal class MinifluxReader(Account account) : IAccountReader
{ {
@@ -143,4 +144,8 @@ internal class MinifluxReader(Account account) : IAccountReader
await minifluxClient.MarkFeedEntries([long.Parse(feedItemId)], FeedEntryStatus.Read); await minifluxClient.MarkFeedEntries([long.Parse(feedItemId)], FeedEntryStatus.Read);
} }
public bool SupportsFeedDelete => true;
public bool SupportsFeedEdit => true;
} }

View File

@@ -3,6 +3,7 @@ using FeedCenter.Options;
using Realms; using Realms;
using System; using System;
using System.Linq; using System.Linq;
using FeedCenter.Accounts;
using FeedCenter.Feeds; using FeedCenter.Feeds;
namespace FeedCenter; namespace FeedCenter;

View File

@@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using FeedCenter.Accounts;
using JetBrains.Annotations; using JetBrains.Annotations;
using Realms; using Realms;

View File

@@ -12,6 +12,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using ChrisKaczor.ApplicationUpdate; using ChrisKaczor.ApplicationUpdate;
using FeedCenter.Accounts;
using FeedCenter.FeedParsers; using FeedCenter.FeedParsers;
using FeedCenter.Properties; using FeedCenter.Properties;
using FeedCenter.Xml; using FeedCenter.Xml;

View File

@@ -1,8 +1,8 @@
using System; using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using FeedCenter.Accounts;
using FeedCenter.Options; using FeedCenter.Options;
using Realms; using Realms;
@@ -86,24 +86,7 @@ public partial class FeedItem : RealmObject
if (feed == null || feed.Account.Type == AccountType.Local) if (feed == null || feed.Account.Type == AccountType.Local)
return; return;
switch (feed.Account.Type) await AccountReaderFactory.CreateAccountReader(feed.Account).MarkFeedItemRead(RemoteId);
{
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;
}
} }
[GeneratedRegex("\\n")] [GeneratedRegex("\\n")]

View File

@@ -2,7 +2,6 @@
using FeedCenter.Properties; using FeedCenter.Properties;
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;

View File

@@ -8,6 +8,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using FeedCenter.Accounts;
namespace FeedCenter; namespace FeedCenter;
@@ -47,7 +48,7 @@ public partial class MainWindow
var accountReadInput = new AccountReadInput(_database, _currentFeed.Id, forceRead, () => { }); var accountReadInput = new AccountReadInput(_database, _currentFeed.Id, forceRead, () => { });
// Switch to progress mode // Switch to progress mode
SetProgressMode(true, await _currentFeed.Account.GetProgressSteps(_currentFeed.Account, accountReadInput)); SetProgressMode(true, await _currentFeed.Account.GetProgressSteps(accountReadInput));
// Start reading // Start reading
await HandleFeedReadWorkerStart(forceRead, _currentFeed.Id); await HandleFeedReadWorkerStart(forceRead, _currentFeed.Id);
@@ -77,7 +78,7 @@ public partial class MainWindow
foreach (var account in _database.Accounts) foreach (var account in _database.Accounts)
{ {
progressSteps += await account.GetProgressSteps(account, accountReadInput); progressSteps += await account.GetProgressSteps(accountReadInput);
} }
// Switch to progress mode // Switch to progress mode

View File

@@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using FeedCenter.Feeds; using FeedCenter.Accounts;
namespace FeedCenter.Options; namespace FeedCenter.Options;

View File

@@ -2,7 +2,7 @@ using System;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Windows.Data; using System.Windows.Data;
using FeedCenter.Feeds; using FeedCenter.Accounts;
namespace FeedCenter.Options; namespace FeedCenter.Options;

View File

@@ -4,11 +4,12 @@
xmlns:properties="clr-namespace:FeedCenter.Properties" xmlns:properties="clr-namespace:FeedCenter.Properties"
xmlns:feedCenter="clr-namespace:FeedCenter" xmlns:feedCenter="clr-namespace:FeedCenter"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:options="clr-namespace:FeedCenter.Options" xmlns:options="clr-namespace:FeedCenter.Options"
xmlns:feeds="clr-namespace:FeedCenter.Feeds" xmlns:feeds="clr-namespace:FeedCenter.Feeds"
xmlns:accounts="clr-namespace:FeedCenter.Accounts"
mc:Ignorable="d" mc:Ignorable="d"
Title="AccountWindow" Title="AccountWindow"
Height="350" Height="350"

View File

@@ -1,9 +1,8 @@
using ChrisKaczor.Wpf.Validation; using ChrisKaczor.Wpf.Validation;
using FeedCenter.Feeds;
using System; using System;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Threading; using FeedCenter.Accounts;
namespace FeedCenter.Options; namespace FeedCenter.Options;
@@ -58,7 +57,7 @@ public partial class AccountWindow
var accountReadInput = new AccountReadInput(_entities, null, true, () => AccountReadProgressBar.Value++); var accountReadInput = new AccountReadInput(_entities, null, true, () => AccountReadProgressBar.Value++);
AccountReadProgressBar.Value = 0; AccountReadProgressBar.Value = 0;
AccountReadProgressBar.Maximum = await _account.GetProgressSteps(_account, accountReadInput); AccountReadProgressBar.Maximum = await _account.GetProgressSteps(accountReadInput);
AccountReadProgress.Visibility = Visibility.Visible; AccountReadProgress.Visibility = Visibility.Visible;
ButtonPanel.Visibility = Visibility.Collapsed; ButtonPanel.Visibility = Visibility.Collapsed;

View File

@@ -8,6 +8,7 @@
xmlns:controls="clr-namespace:ChrisKaczor.Wpf.Controls;assembly=ChrisKaczor.Wpf.Controls.Link" xmlns:controls="clr-namespace:ChrisKaczor.Wpf.Controls;assembly=ChrisKaczor.Wpf.Controls.Link"
xmlns:feedCenter="clr-namespace:FeedCenter" xmlns:feedCenter="clr-namespace:FeedCenter"
xmlns:feeds="clr-namespace:FeedCenter.Feeds" xmlns:feeds="clr-namespace:FeedCenter.Feeds"
xmlns:accounts="clr-namespace:FeedCenter.Accounts"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="311" d:DesignHeight="311"
d:DesignWidth="425"> d:DesignWidth="425">
@@ -47,7 +48,7 @@
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
AllowDrop="True" AllowDrop="True"
Background="{x:Null}" Background="{x:Null}"
d:DataContext="{d:DesignInstance feeds:Account }"> d:DataContext="{d:DesignInstance accounts:Account }">
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" <DataGridTextColumn Binding="{Binding Name}"
Header="{x:Static properties:Resources.AccountNameColumnHeader}" Header="{x:Static properties:Resources.AccountNameColumnHeader}"

View File

@@ -1,10 +1,9 @@
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using FeedCenter.Feeds; using FeedCenter.Accounts;
namespace FeedCenter.Options; namespace FeedCenter.Options;
@@ -53,7 +52,7 @@ public partial class AccountsOptionsPanel
private void AddAccount() private void AddAccount()
{ {
var account = new Account(AccountType.Fever); var account = new Account(AccountType.Miniflux);
var accountWindow = new AccountWindow(_entities); var accountWindow = new AccountWindow(_entities);

View File

@@ -7,6 +7,7 @@ using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using System.Xml; using System.Xml;
using FeedCenter.Accounts;
using FeedCenter.Feeds; using FeedCenter.Feeds;
namespace FeedCenter.Options; namespace FeedCenter.Options;