Add custom theme deletion flow
This commit is contained in:
@@ -15,6 +15,7 @@ public interface INewThemeService : IInitializeAsync
|
||||
Task<List<AppThemeBase>> GetAvailableThemesAsync();
|
||||
Task<CustomThemeMetadata> CreateNewCustomThemeAsync(string themeName, string accentColor, byte[] wallpaperData);
|
||||
Task<List<CustomThemeMetadata>> GetCurrentCustomThemesAsync();
|
||||
Task<bool> DeleteCustomThemeAsync(Guid themeId);
|
||||
List<string> GetAvailableAccountColors();
|
||||
Task ApplyCustomThemeAsync(bool isInitializing);
|
||||
|
||||
|
||||
@@ -807,6 +807,10 @@
|
||||
"SettingsConfigureSpecialFolders_Description": "Set folders with special functions. Folders such as Archive, Inbox, and Drafts are essential for Wino to function properly.",
|
||||
"SettingsConfigureSpecialFolders_Title": "Configure System Folders",
|
||||
"SettingsCustomTheme_Description": "Create your own custom theme with custom wallpaper and accent color.",
|
||||
"SettingsCustomTheme_DeleteConfirm_Message": "Delete custom theme \"{0}\"? Its saved wallpaper will also be removed from disk.",
|
||||
"SettingsCustomTheme_DeleteConfirm_Title": "Delete Theme",
|
||||
"SettingsCustomTheme_DeleteMissing": "This custom theme no longer exists.",
|
||||
"SettingsCustomTheme_DeleteSuccess": "Custom theme \"{0}\" was deleted.",
|
||||
"SettingsCustomTheme_Title": "Custom Theme",
|
||||
"SettingsDeleteAccount_Description": "Delete all e-mails and credentials associated with this account.",
|
||||
"SettingsDeleteAccount_Title": "Delete this account",
|
||||
|
||||
@@ -174,8 +174,46 @@ public partial class PersonalizationPageViewModel : CoreBaseViewModel
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task DeleteCustomThemeAsync(AppThemeBase theme)
|
||||
{
|
||||
if (theme == null || theme.AppThemeType != AppThemeType.Custom)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var shouldDelete = await _dialogService.ShowConfirmationDialogAsync(
|
||||
string.Format(Translator.SettingsCustomTheme_DeleteConfirm_Message, theme.ThemeName),
|
||||
Translator.SettingsCustomTheme_DeleteConfirm_Title,
|
||||
Translator.Buttons_Delete);
|
||||
|
||||
if (!shouldDelete)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var isDeleted = await _newThemeService.DeleteCustomThemeAsync(theme.Id);
|
||||
|
||||
if (!isDeleted)
|
||||
{
|
||||
_dialogService.InfoBarMessage(
|
||||
Translator.GeneralTitle_Warning,
|
||||
Translator.SettingsCustomTheme_DeleteMissing,
|
||||
InfoBarMessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
await InitializeSettingsAsync();
|
||||
|
||||
_dialogService.InfoBarMessage(
|
||||
Translator.GeneralTitle_Info,
|
||||
string.Format(Translator.SettingsCustomTheme_DeleteSuccess, theme.ThemeName),
|
||||
InfoBarMessageType.Success);
|
||||
}
|
||||
|
||||
private void InitializeColors()
|
||||
{
|
||||
Colors.Clear();
|
||||
Colors.Add(new AppColorViewModel("#0078d7"));
|
||||
Colors.Add(new AppColorViewModel("#00838c"));
|
||||
Colors.Add(new AppColorViewModel("#e3008c"));
|
||||
|
||||
@@ -587,6 +587,31 @@ public class NewThemeService : INewThemeService
|
||||
return results;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteCustomThemeAsync(Guid themeId)
|
||||
{
|
||||
var themeFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(CustomThemeFolderName, CreationCollisionOption.OpenIfExists);
|
||||
var metadataFileName = $"{themeId}.json";
|
||||
var themeItem = await themeFolder.TryGetItemAsync(metadataFileName);
|
||||
|
||||
if (themeItem == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentApplicationThemeId == themeId)
|
||||
{
|
||||
currentApplicationThemeId = preDefinedThemes[0].Id;
|
||||
_configurationService.Set(CurrentApplicationThemeKey, currentApplicationThemeId);
|
||||
await ApplyCustomThemeAsync(false);
|
||||
}
|
||||
|
||||
await DeleteThemeAssetIfExistsAsync(themeFolder, metadataFileName);
|
||||
await DeleteThemeAssetIfExistsAsync(themeFolder, $"{themeId}.jpg");
|
||||
await DeleteThemeAssetIfExistsAsync(themeFolder, $"{themeId}_preview.jpg");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<CustomThemeMetadata?> GetCustomMetadataAsync(IStorageFile file)
|
||||
{
|
||||
var fileContent = await FileIO.ReadTextAsync(file);
|
||||
@@ -594,6 +619,16 @@ public class NewThemeService : INewThemeService
|
||||
return JsonSerializer.Deserialize(fileContent, DomainModelsJsonContext.Default.CustomThemeMetadata);
|
||||
}
|
||||
|
||||
private static async Task DeleteThemeAssetIfExistsAsync(StorageFolder themeFolder, string fileName)
|
||||
{
|
||||
var item = await themeFolder.TryGetItemAsync(fileName);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
await item.DeleteAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSystemAccentColorHex()
|
||||
=> uiSettings.GetColorValue(UIColorType.Accent).ToHex();
|
||||
|
||||
|
||||
@@ -49,6 +49,68 @@
|
||||
CompactTemplate="{StaticResource CompactDisplayModePreviewTemplate}"
|
||||
MediumTemplate="{StaticResource MediumDisplayModePreviewTemplate}"
|
||||
SpaciousTemplate="{StaticResource SpaciousDisplayModePreviewTemplate}" />
|
||||
|
||||
<DataTemplate x:Key="PersonalizationCustomAppThemeTemplate" x:DataType="personalization:CustomAppTheme">
|
||||
<Grid
|
||||
Width="175"
|
||||
CornerRadius="6"
|
||||
RowSpacing="0">
|
||||
<Grid.ContextFlyout>
|
||||
<MenuFlyout Placement="BottomEdgeAlignedRight">
|
||||
<MenuFlyoutItem
|
||||
Command="{Binding ElementName=root, Path=ViewModel.DeleteCustomThemeCommand}"
|
||||
CommandParameter="{x:Bind}"
|
||||
Text="{x:Bind domain:Translator.Buttons_Delete}">
|
||||
<MenuFlyoutItem.Icon>
|
||||
<SymbolIcon Symbol="Delete" />
|
||||
</MenuFlyoutItem.Icon>
|
||||
</MenuFlyoutItem>
|
||||
</MenuFlyout>
|
||||
</Grid.ContextFlyout>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="125" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid CornerRadius="6,6,0,0">
|
||||
<Grid.Background>
|
||||
<ImageBrush ImageSource="{x:Bind BackgroundPreviewImage}" />
|
||||
</Grid.Background>
|
||||
<Grid x:Name="AccentAssignedGrid" x:Load="{x:Bind IsAccentColorAssigned}">
|
||||
<Grid
|
||||
Width="20"
|
||||
Height="20"
|
||||
Margin="0,12,12,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Background="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(AccentColor)}" />
|
||||
</Grid>
|
||||
|
||||
<Grid x:Name="AccentNotAssignedGrid" x:Load="{x:Bind IsAccentColorAssigned, Converter={StaticResource ReverseBooleanConverter}}">
|
||||
<Grid
|
||||
Width="20"
|
||||
Height="20"
|
||||
Margin="0,12,12,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Background="{ThemeResource SystemAccentColor}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<TextBlock
|
||||
Padding="0,8"
|
||||
HorizontalAlignment="Center"
|
||||
Text="{x:Bind ThemeName}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<coreSelectors:AppThemePreviewTemplateSelector
|
||||
x:Key="PersonalizationAppThemePreviewTemplateSelector"
|
||||
CustomAppTemplate="{StaticResource PersonalizationCustomAppThemeTemplate}"
|
||||
PreDefinedThemeTemplate="{StaticResource PreDefinedAppThemeTemplate}"
|
||||
SystemThemeTemplate="{StaticResource SystemAppThemeTemplate}" />
|
||||
</Page.Resources>
|
||||
|
||||
<ScrollViewer>
|
||||
@@ -147,7 +209,7 @@
|
||||
<!-- TODO: Group by custom/wino -->
|
||||
<GridView
|
||||
toolkitExt:ListViewExtensions.ItemContainerStretchDirection="Horizontal"
|
||||
ItemTemplateSelector="{StaticResource AppThemePreviewTemplateSelector}"
|
||||
ItemTemplateSelector="{StaticResource PersonalizationAppThemePreviewTemplateSelector}"
|
||||
ItemsSource="{x:Bind ViewModel.AppThemes, Mode=OneWay}"
|
||||
SelectedItem="{x:Bind ViewModel.SelectedAppTheme, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
|
||||
Reference in New Issue
Block a user