Skip to content

Commit

Permalink
Created new view model specifically for the "Desktop" application in …
Browse files Browse the repository at this point in the history
…G Hub
  • Loading branch information
AJLeuer committed Jan 17, 2022
1 parent 953993c commit 64f95df
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
49 changes: 22 additions & 27 deletions GHelper/GHelper/ViewModel/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ protected ApplicationViewModel(Application application)
this.Application = application;
SaveBackup();
}

private static ApplicationViewModel CreateApplicationViewModelForApplicationModel(Application application)
{
ApplicationViewModel applicationViewModel;

switch (application)
{
case DesktopApplication desktopApplication:
applicationViewModel = new DesktopApplicationViewModel(desktopApplication);
break;
case CustomApplication customApplication:
applicationViewModel = new CustomApplicationViewModel(customApplication);
break;
default:
applicationViewModel = new ApplicationViewModel(application);
break;
}

return applicationViewModel;
}

public override void DiscardUserChanges(GHubRecordViewModel? origin = null)
{
Expand Down Expand Up @@ -243,16 +263,8 @@ private void HandleProfileSetActiveForApplication(ProfileViewModel profileWithCh
}
}
}

public override void Delete()
{
if (this.Application is not DesktopApplication)
{
base.Delete();
}
}

[NotifyPropertyChangedInvocator]
[NotifyPropertyChangedInvocator]
protected override void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
Expand All @@ -272,24 +284,7 @@ public static IEnumerable<ApplicationViewModel> CreateFromCollection(IEnumerable
}
return applicationViewModels;
}

private static ApplicationViewModel CreateApplicationViewModelForApplicationModel(Application application)
{
ApplicationViewModel applicationViewModel;

switch (application)
{
case CustomApplication customApplication:
applicationViewModel = new CustomApplicationViewModel(customApplication);
break;
default:
applicationViewModel = new ApplicationViewModel(application);
break;
}

return applicationViewModel;
}
}
}

public enum InstallState
{
Expand Down
28 changes: 28 additions & 0 deletions GHelper/GHelper/ViewModel/DesktopApplicationViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using GHelperLogic.Model;
using SixLabors.ImageSharp;

namespace GHelper.ViewModel
{
public class DesktopApplicationViewModel : ApplicationViewModel
{
protected internal DesktopApplicationViewModel(DesktopApplication application) : base(application)
{
}

public override void Delete()
{
//Do nothing, we don't allow deleting the Desktop app
}

public override void SetNewCustomPosterImage(Image customPoster)
{
//Do nothing, we don't allow setting custom posters
}

protected override void RestorePosterIfNeeded()
{
//Do nothing, we don't allow setting custom posters anyway so there's no way our poster could
//have been changed in the first place
}
}
}

0 comments on commit 64f95df

Please sign in to comment.