-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added stories page for TgDownloaderDesktop
- Loading branch information
1 parent
7c7949a
commit 770d619
Showing
16 changed files
with
413 additions
and
37 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
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
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
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
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
86 changes: 86 additions & 0 deletions
86
Clients/TgDownloaderDesktop/ViewModels/TgStoriesViewModel.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,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 | ||
} |
Oops, something went wrong.