-
-
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 contact edit page for TgDownloaderDesktop
- Loading branch information
1 parent
ca2c874
commit baffe44
Showing
11 changed files
with
784 additions
and
195 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
80 changes: 80 additions & 0 deletions
80
Clients/TgDownloaderDesktop/ViewModels/TgContactDetailsViewModel.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,80 @@ | ||
// 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 TgContactDetailsViewModel : TgPageViewModelBase | ||
{ | ||
#region Public and private fields, properties, constructor | ||
|
||
private TgEfContactRepository Repository { get; } = new(TgEfUtils.EfContext); | ||
[ObservableProperty] | ||
public partial Guid Uid { get; set; } = default!; | ||
[ObservableProperty] | ||
public partial TgEfContactDto Dto { get; set; } = default!; | ||
public IRelayCommand LoadDataStorageCommand { get; } | ||
public IRelayCommand ClearDataStorageCommand { get; } | ||
public IRelayCommand UpdateOnlineCommand { get; } | ||
|
||
public TgContactDetailsViewModel(ITgSettingsService settingsService) : base(settingsService) | ||
{ | ||
// Commands | ||
ClearDataStorageCommand = new AsyncRelayCommand(ClearDataStorageAsync); | ||
LoadDataStorageCommand = new AsyncRelayCommand(LoadDataStorageAsync); | ||
UpdateOnlineCommand = new AsyncRelayCommand(UpdateOnlineAsync); | ||
} | ||
|
||
#endregion | ||
|
||
#region Public and private methods | ||
|
||
public override async Task OnNavigatedToAsync(NavigationEventArgs e) => await LoadDataAsync(async () => | ||
{ | ||
TgEfUtils.AppStorage = SettingsService.AppStorage; | ||
TgEfUtils.RecreateEfContext(); | ||
Uid = e.Parameter is Guid uid ? uid : Guid.Empty; | ||
await LoadDataStorageCoreAsync(); | ||
await ReloadUiAsync(); | ||
}); | ||
|
||
private async Task ReloadUiAsync() | ||
{ | ||
ConnectionDt = string.Empty; | ||
ConnectionMsg = string.Empty; | ||
Exception.Default(); | ||
await TgDesktopUtils.TgClient.CheckClientIsReadyAsync(); | ||
IsOnlineReady = TgDesktopUtils.TgClient.IsReady; | ||
await Task.CompletedTask; | ||
} | ||
|
||
private async Task ClearDataStorageAsync() => await ContentDialogAsync(ClearDataStorageCoreAsync, TgResourceExtensions.AskDataClear()); | ||
|
||
private async Task ClearDataStorageCoreAsync() | ||
{ | ||
Dto = new(); | ||
await Task.CompletedTask; | ||
} | ||
|
||
private async Task LoadDataStorageAsync() => await ContentDialogAsync(LoadDataStorageCoreAsync, TgResourceExtensions.AskDataLoad(), useLoadData: true); | ||
|
||
private async Task LoadDataStorageCoreAsync() | ||
{ | ||
if (!SettingsService.IsExistsAppStorage) return; | ||
Dto = await Repository.GetDtoAsync(x => x.Uid == Uid); | ||
} | ||
|
||
private async Task UpdateOnlineAsync() => await ContentDialogAsync(UpdateOnlineCoreAsync, TgResourceExtensions.AskUpdateOnline()); | ||
|
||
private async Task UpdateOnlineCoreAsync() | ||
{ | ||
await LoadDataAsync(async () => { | ||
if (!await TgDesktopUtils.TgClient.CheckClientIsReadyAsync()) return; | ||
var tgDownloadSettings = new TgDownloadSettingsViewModel(); | ||
await TgDesktopUtils.TgClient.SearchSourcesTgAsync(tgDownloadSettings, TgEnumSourceType.Contact); | ||
await LoadDataStorageCoreAsync(); | ||
}); | ||
} | ||
|
||
#endregion | ||
} |
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.