Skip to content

Commit

Permalink
Added stories page for TgDownloaderDesktop
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianMorozov committed Jan 1, 2025
1 parent 7c7949a commit 770d619
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 37 deletions.
2 changes: 2 additions & 0 deletions Clients/TgDownloaderDesktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public App()
services.AddTransient<TgSourcesPage>();
services.AddTransient<TgFiltersViewModel>();
services.AddTransient<TgFiltersPage>();
services.AddTransient<TgStoriesViewModel>();
services.AddTransient<TgStoriesPage>();
// Configuration
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
})
Expand Down
1 change: 1 addition & 0 deletions Clients/TgDownloaderDesktop/Services/PageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public PageService()
Configure<TgContactsViewModel, TgContactsPage>();
Configure<TgFiltersViewModel, TgFiltersPage>();
Configure<TgSourcesViewModel, TgSourcesPage>();
Configure<TgStoriesViewModel, TgStoriesPage>();
Configure<WebViewViewModel, WebViewPage>();
Configure<ListDetailsViewModel, ListDetailsPage>();
Configure<ContentGridViewModel, ContentGridPage>();
Expand Down
12 changes: 12 additions & 0 deletions Clients/TgDownloaderDesktop/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
<data name="Shell_Sources.Content" xml:space="preserve">
<value>Sources</value>
</data>
<data name="Shell_Stories.Content" xml:space="preserve">
<value>Stories</value>
</data>
<data name="WebView_Loading.Text" xml:space="preserve">
<value>Loading...</value>
</data>
Expand Down Expand Up @@ -567,6 +570,12 @@
<data name="TemplateColumnUpdated.Header" xml:space="preserve">
<value>Updated</value>
</data>
<data name="TemplateColumnDate.Header" xml:space="preserve">
<value>Date</value>
</data>
<data name="TemplateColumnExpireDate.Header" xml:space="preserve">
<value>Expires</value>
</data>
<data name="TemplateColumnUserName.Header" xml:space="preserve">
<value>User name</value>
</data>
Expand Down Expand Up @@ -615,6 +624,9 @@
<data name="TemplateColumnSize.Header" xml:space="preserve">
<value>Size</value>
</data>
<data name="TemplateColumnCaption.Header" xml:space="preserve">
<value>Caption</value>
</data>
<data name="DataLoadWait.Text" xml:space="preserve">
<value>Wait until the data download is complete</value>
</data>
Expand Down
12 changes: 12 additions & 0 deletions Clients/TgDownloaderDesktop/Strings/ru-RU/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<data name="Shell_Sources.Content" xml:space="preserve">
<value>Источники</value>
</data>
<data name="Shell_Stories.Content" xml:space="preserve">
<value>Сторис</value>
</data>
<data name="WebView_Loading.Text" xml:space="preserve">
<value>Загрузка...</value>
</data>
Expand Down Expand Up @@ -629,6 +632,12 @@
<data name="TemplateColumnUpdated.Header" xml:space="preserve">
<value>Обновлено</value>
</data>
<data name="TemplateColumnDate.Header" xml:space="preserve">
<value>Дата</value>
</data>
<data name="TemplateColumnExpireDate.Header" xml:space="preserve">
<value>Истекает</value>
</data>
<data name="TemplateColumnUserName.Header" xml:space="preserve">
<value>Имя пользователя</value>
</data>
Expand Down Expand Up @@ -677,6 +686,9 @@
<data name="TemplateColumnSize.Header" xml:space="preserve">
<value>Размер</value>
</data>
<data name="TemplateColumnCaption.Header" xml:space="preserve">
<value>Заголовок</value>
</data>
<data name="DataLoadWait.Text" xml:space="preserve">
<value>Дождитесь окончания загрузки данных</value>
</data>
Expand Down
5 changes: 4 additions & 1 deletion Clients/TgDownloaderDesktop/TgDownloaderDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
</ItemGroup>

<ItemGroup>
<Page Update="Views\TgClientPage.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Views\TgFiltersPage.xaml">
<SubType>Designer</SubType>
</Page>
Expand All @@ -73,7 +76,7 @@
<Page Update="Views\TgSourcesPage.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Views\TgClientPage.xaml">
<Page Update="Views\TgStoriesPage.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Clients/TgDownloaderDesktop/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
global using TgStorage.Domain.Filters;
global using TgStorage.Domain.Proxies;
global using TgStorage.Domain.Sources;
global using TgStorage.Domain.Stories;
global using TgStorage.Models;
global using TgStorage.Utils;
global using Windows.ApplicationModel;
Expand Down
14 changes: 7 additions & 7 deletions Clients/TgDownloaderDesktop/ViewModels/TgContactsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public sealed partial class TgContactsViewModel : TgPageViewModelBase
{
#region Public and private fields, properties, constructor

private TgEfContactRepository ContactRepository { get; } = new(TgEfUtils.EfContext);
private TgEfContactRepository Repository { get; } = new(TgEfUtils.EfContext);
[ObservableProperty]
private ObservableCollection<TgEfContactDto> _contactsVms = [];
private ObservableCollection<TgEfContactDto> _dtos = [];
[ObservableProperty]
private bool _isReady;
public IRelayCommand LoadDataStorageCommand { get; }
Expand Down Expand Up @@ -51,18 +51,18 @@ private void SetOrderData(IEnumerable<TgEfContactDto> dtos)
List<TgEfContactDto> list = dtos.ToList();
if (!list.Any())
return;
ContactsVms = [];
Dtos = [];
dtos = [.. list.OrderBy(x => x.UserName).ThenBy(x => x.FirstName).ThenBy(x => x.LastName)];
if (dtos.Any())
foreach (var dto in dtos)
ContactsVms.Add(dto);
Dtos.Add(dto);
}

private async Task ClearDataStorageAsync() => await ContentDialogAsync(ClearDataStorageCoreAsync, TgResourceExtensions.AskDataClear());

private async Task ClearDataStorageCoreAsync()
{
ContactsVms.Clear();
Dtos.Clear();
await Task.CompletedTask;
}

Expand All @@ -72,13 +72,13 @@ private async Task LoadDataStorageCoreAsync()
{
if (!SettingsService.IsExistsAppStorage)
return;
var dtos = await ContactRepository.GetListDtosAsync(take: 0, skip: 0);
var dtos = await Repository.GetListDtosAsync(take: 0, skip: 0);
SetOrderData(dtos);
}

private async Task DefaultSortAsync()
{
SetOrderData(ContactsVms);
SetOrderData(Dtos);
await Task.CompletedTask;
}

Expand Down
14 changes: 7 additions & 7 deletions Clients/TgDownloaderDesktop/ViewModels/TgFiltersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public sealed partial class TgFiltersViewModel : TgPageViewModelBase
{
#region Public and private fields, properties, constructor

private TgEfFilterRepository FilterRepository { get; } = new(TgEfUtils.EfContext);
private TgEfFilterRepository Repository { get; } = new(TgEfUtils.EfContext);
[ObservableProperty]
private ObservableCollection<TgEfFilterDto> _filtersVms = [];
private ObservableCollection<TgEfFilterDto> _dtos = [];
[ObservableProperty]
private bool _isReady;
public IRelayCommand LoadDataStorageCommand { get; }
Expand Down Expand Up @@ -50,18 +50,18 @@ private void SetOrderData(IList<TgEfFilterDto> dtos)
{
if (!dtos.Any())
return;
FiltersVms = [];
Dtos = [];
dtos = [.. dtos.OrderBy(x => x.Name)];
if (dtos.Any())
foreach (var dto in dtos)
FiltersVms.Add(dto);
Dtos.Add(dto);
}

private async Task ClearDataStorageAsync() => await ContentDialogAsync(ClearDataStorageCoreAsync, TgResourceExtensions.AskDataClear());

private async Task ClearDataStorageCoreAsync()
{
FiltersVms.Clear();
Dtos.Clear();
await Task.CompletedTask;
}

Expand All @@ -71,13 +71,13 @@ private async Task LoadDataStorageCoreAsync()
{
if (!SettingsService.IsExistsAppStorage)
return;
var dtos = await FilterRepository.GetListDtosAsync(take: 0, skip: 0);
var dtos = await Repository.GetListDtosAsync(take: 0, skip: 0);
SetOrderData(dtos);
}

private async Task DefaultSortAsync()
{
SetOrderData(FiltersVms);
SetOrderData(Dtos);
await Task.CompletedTask;
}

Expand Down
26 changes: 13 additions & 13 deletions Clients/TgDownloaderDesktop/ViewModels/TgSourcesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public sealed partial class TgSourcesViewModel : TgPageViewModelBase
{
#region Public and private fields, properties, constructor

private TgEfSourceRepository SourceRepository { get; } = new(TgEfUtils.EfContext);
private TgEfSourceRepository Repository { get; } = new(TgEfUtils.EfContext);
[ObservableProperty]
private ObservableCollection<TgEfSourceDto> _sourcesVms = [];
private ObservableCollection<TgEfSourceDto> _dtos = [];
[ObservableProperty]
private bool _isReady;
//public IRelayCommand UpdateSourcesFromTelegramCommand { get; }
Expand Down Expand Up @@ -74,17 +74,17 @@ private void SetOrderData(IList<TgEfSourceDto> dtos)
{
if (!dtos.Any())
return;
SourcesVms = [];
Dtos = [];
dtos = [.. dtos.OrderBy(x => x.UserName).ThenBy(x => x.Title)];
if (dtos.Any())
foreach (var dto in dtos)
SourcesVms.Add(dto);
Dtos.Add(dto);
}

//private async Task UpdateSourcesFromTelegramAsync()
//{
// if (!TgDesktopUtils.TgClient.CheckClientIsReady()) return;
// foreach (TgEfSourceViewModel sourceVm in SourcesVms)
// foreach (TgEfSourceViewModel sourceVm in Dtos)
// await UpdateSourceFromTelegramAsync(sourceVm);
//}

Expand All @@ -101,8 +101,8 @@ private void SetOrderData(IList<TgEfSourceDto> dtos)
// var storageResult = await SourceRepository.GetAsync(new TgEfSourceEntity { Id = sourceVm.Item.Id }, isReadOnly: false);
// if (storageResult.IsExists)
// sourceVm = new(storageResult.Item);
// if (!SourcesVms.Select(x => x.SourceId).Contains(sourceVm.SourceId))
// SourcesVms.Add(sourceVm);
// if (!Dtos.Select(x => x.SourceId).Contains(sourceVm.SourceId))
// Dtos.Add(sourceVm);
// await SaveSourceAsync(sourceVm);
//}

Expand All @@ -118,21 +118,21 @@ private async Task LoadDataStorageCoreAsync()
{
if (!SettingsService.IsExistsAppStorage)
return;
var dtos = await SourceRepository.GetListDtosAsync(take: 0, skip: 0);
var dtos = await Repository.GetListDtosAsync(take: 0, skip: 0);
SetOrderData(dtos);
}

private async Task ClearDataStorageAsync() => await ContentDialogAsync(ClearDataStorageCoreAsync, TgResourceExtensions.AskDataClear());

private async Task ClearDataStorageCoreAsync()
{
SourcesVms.Clear();
Dtos.Clear();
await Task.CompletedTask;
}

private async Task DefaultSortAsync()
{
SetOrderData(SourcesVms);
SetOrderData(Dtos);
await Task.CompletedTask;
}

Expand All @@ -153,11 +153,11 @@ private async Task DefaultSortAsync()
// //TgDesktopUtils.TgItemSourceVm.SetItemSourceVm(sourceVm);
// //await TgDesktopUtils.TgItemSourceVm.OnGetSourceFromStorageAsync();

// //for (int i = 0; i < SourcesVms.Count; i++)
// //for (int i = 0; i < Dtos.Count; i++)
// //{
// // if (SourcesVms[i].SourceId.Equals(sourceVm.SourceId))
// // if (Dtos[i].SourceId.Equals(sourceVm.SourceId))
// // {
// // SourcesVms[i].Item.Fill(TgDesktopUtils.TgItemSourceVm.ItemSourceVm.Item, isUidCopy: false);
// // Dtos[i].Item.Fill(TgDesktopUtils.TgItemSourceVm.ItemSourceVm.Item, isUidCopy: false);
// // break;
// // }
// //}
Expand Down
86 changes: 86 additions & 0 deletions Clients/TgDownloaderDesktop/ViewModels/TgStoriesViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com

namespace TgDownloaderDesktop.ViewModels;

[DebuggerDisplay("{ToDebugString()}")]
public sealed partial class TgStoriesViewModel : TgPageViewModelBase
{
#region Public and private fields, properties, constructor

private TgEfStoryRepository Repository { get; } = new(TgEfUtils.EfContext);
[ObservableProperty]
private ObservableCollection<TgEfStoryDto> _dtos = [];
[ObservableProperty]
private bool _isReady;
public IRelayCommand LoadDataStorageCommand { get; }
public IRelayCommand ClearDataStorageCommand { get; }
public IRelayCommand DefaultSortCommand { get; }

public TgStoriesViewModel(ITgSettingsService settingsService) : base(settingsService)
{
// Commands
ClearDataStorageCommand = new AsyncRelayCommand(ClearDataStorageAsync);
DefaultSortCommand = new AsyncRelayCommand(DefaultSortAsync);
LoadDataStorageCommand = new AsyncRelayCommand(LoadDataStorageAsync);
}

#endregion

#region Public and private methods

public override async Task OnNavigatedToAsync(NavigationEventArgs e) => await LoadDataAsync(async () =>
{
TgEfUtils.AppStorage = SettingsService.AppStorage;
TgEfUtils.RecreateEfContext();
await LoadDataStorageCoreAsync();
await ReloadUiAsync();
});

private async Task ReloadUiAsync()
{
ConnectionDt = string.Empty;
ConnectionMsg = string.Empty;
Exception.Default();
await Task.CompletedTask;
}

/// <summary> Sort data </summary>
private void SetOrderData(IEnumerable<TgEfStoryDto> dtos)
{
List<TgEfStoryDto> list = dtos.ToList();
if (!list.Any())
return;
Dtos = [];
dtos = [.. list.OrderBy(x => x.DtChanged).ThenBy(x => x.FromName)];
if (dtos.Any())
foreach (var dto in dtos)
Dtos.Add(dto);
}

private async Task ClearDataStorageAsync() => await ContentDialogAsync(ClearDataStorageCoreAsync, TgResourceExtensions.AskDataClear());

private async Task ClearDataStorageCoreAsync()
{
Dtos.Clear();
await Task.CompletedTask;
}

private async Task LoadDataStorageAsync() => await ContentDialogAsync(LoadDataStorageCoreAsync, TgResourceExtensions.AskDataLoad(), useLoadData: true);

private async Task LoadDataStorageCoreAsync()
{
if (!SettingsService.IsExistsAppStorage)
return;
var dtos = await Repository.GetListDtosAsync(take: 0, skip: 0);
SetOrderData(dtos);
}

private async Task DefaultSortAsync()
{
SetOrderData(Dtos);
await Task.CompletedTask;
}

#endregion
}
Loading

0 comments on commit 770d619

Please sign in to comment.