mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-20 07:48:39 +08:00
update emojis
This commit is contained in:
@@ -23,7 +23,7 @@ public interface IEmojisFileService
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<EmoticonAction>> GetEmojisFileListAsync(int pageIndex, int pageSize);
|
||||
Task<List<EmoticonActionModel>> GetEmojisFileListAsync(int pageIndex, int pageSize);
|
||||
|
||||
/// <summary>
|
||||
/// 保存表情文件
|
||||
@@ -50,5 +50,5 @@ public interface IEmojisFileService
|
||||
/// </summary>
|
||||
/// <param name="emoticonAction"></param>
|
||||
/// <returns></returns>
|
||||
Task<EmoticonAction> SaveEmojisAsync(EmoticonAction emoticonAction);
|
||||
Task<EmoticonActionModel> SaveEmojisAsync(EmoticonAction emoticonAction);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Verdure.Braincase.Core.Models.Emojis.Enums;
|
||||
|
||||
namespace ElectronBot.Braincase.Models;
|
||||
public class EmoticonAction : ObservableRecipient
|
||||
@@ -28,10 +29,10 @@ public class EmoticonAction : ObservableRecipient
|
||||
{
|
||||
get; set;
|
||||
} = "";
|
||||
public EmojisType EmojisType
|
||||
public string Type
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
} = EmojisFileType.Default;
|
||||
public string EmojisActionPath
|
||||
{
|
||||
get; set;
|
||||
@@ -47,10 +48,4 @@ public class EmoticonAction : ObservableRecipient
|
||||
get => _hasAction;
|
||||
set => SetProperty(ref _hasAction, value);
|
||||
}
|
||||
}
|
||||
|
||||
public enum EmojisType
|
||||
{
|
||||
Default = 1,
|
||||
Custom = 2
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Verdure.Braincase.Core.Models.Emojis.Enums;
|
||||
|
||||
namespace ElectronBot.Braincase.Models;
|
||||
public class EmoticonActionModel : IDisposable
|
||||
{
|
||||
public string NameId
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public string Desc
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public Stream? Avatar
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string EmojisVideoPath
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
public string Type
|
||||
{
|
||||
get; set;
|
||||
} = EmojisFileType.Default;
|
||||
|
||||
public string EmojisActionPath
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public string EmojisAuthor
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = string.Empty;
|
||||
|
||||
public bool HasAction
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Avatar?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Verdure.Braincase.Core.Models.Emojis.Enums;
|
||||
public class EmojisFileType
|
||||
{
|
||||
public const string Default = "Default";
|
||||
|
||||
public const string Custom = "Custom";
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class Constants
|
||||
NameId="left",
|
||||
Avatar = "ms-appx:///Assets/Emoji/left.png",
|
||||
Desc ="LeftName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "left.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -96,7 +96,7 @@ public class Constants
|
||||
NameId="right",
|
||||
Avatar = "ms-appx:///Assets/Emoji/right.png",
|
||||
Desc ="RightName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "right.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -106,7 +106,7 @@ public class Constants
|
||||
NameId="normal",
|
||||
Avatar = "ms-appx:///Assets/Emoji/normal.png",
|
||||
Desc ="NormalName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "normal.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -116,7 +116,7 @@ public class Constants
|
||||
NameId="normal",
|
||||
Avatar = "ms-appx:///Assets/Emoji/normal.png",
|
||||
Desc ="NormalName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "normal.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -126,7 +126,7 @@ public class Constants
|
||||
NameId="anger",
|
||||
Avatar = "ms-appx:///Assets/Emoji/anger.png",
|
||||
Desc ="AngerName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "anger.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -136,7 +136,7 @@ public class Constants
|
||||
NameId="disdain",
|
||||
Avatar = "ms-appx:///Assets/Emoji/disdain.png",
|
||||
Desc ="DisdainName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "disdain.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -146,7 +146,7 @@ public class Constants
|
||||
NameId="excited",
|
||||
Avatar = "ms-appx:///Assets/Emoji/excited.png",
|
||||
Desc ="ExcitedName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "defaultaction.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -156,7 +156,7 @@ public class Constants
|
||||
NameId="fear",
|
||||
Avatar = "ms-appx:///Assets/Emoji/fear.png",
|
||||
Desc ="FearName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "defaultaction.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -166,7 +166,7 @@ public class Constants
|
||||
NameId="sad",
|
||||
Avatar = "ms-appx:///Assets/Emoji/sad.png",
|
||||
Desc ="SadName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "defaultaction.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -176,7 +176,7 @@ public class Constants
|
||||
NameId="hello",
|
||||
Avatar = "ms-appx:///Assets/Emoji/hello.jpg",
|
||||
Desc ="HelloName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "hello.json",
|
||||
HasAction = true
|
||||
},
|
||||
@@ -186,7 +186,7 @@ public class Constants
|
||||
NameId="goodbye",
|
||||
Avatar = "ms-appx:///Assets/Emoji/Goodbye.jpg",
|
||||
Desc ="GoodbyeName".GetLocalized(),
|
||||
EmojisType = EmojisType.Default,
|
||||
Type = EmojisFileType.Default,
|
||||
EmojisActionPath = "goodbye.json",
|
||||
HasAction = true
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ public class ElectronBotHelper
|
||||
{
|
||||
var path = string.Empty;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
path = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.EmojisActionPath}";
|
||||
}
|
||||
@@ -388,7 +388,7 @@ public class ElectronBotHelper
|
||||
|
||||
string? videoPath;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
videoPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.NameId}.mp4";
|
||||
}
|
||||
@@ -431,7 +431,7 @@ public class ElectronBotHelper
|
||||
{
|
||||
var path = string.Empty;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
path = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.EmojisActionPath}";
|
||||
}
|
||||
@@ -460,7 +460,7 @@ public class ElectronBotHelper
|
||||
|
||||
string? videoPath;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
videoPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.NameId}.mp4";
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using ElectronBot.Braincase.Models;
|
||||
using Verdure.Braincase.Core.Models.Emojis.Enums;
|
||||
|
||||
namespace Models;
|
||||
public class EmojisFileManifest
|
||||
@@ -23,9 +23,15 @@ public class EmojisFileManifest
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public EmojisType EmojisType
|
||||
public int EmojisType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Type
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = EmojisFileType.Custom;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using ElectronBot.Braincase;
|
||||
using ElectronBot.Braincase.Helpers;
|
||||
using ElectronBot.Braincase.Models;
|
||||
using Models;
|
||||
using Verdure.Braincase.Core.Models.Emojis.Enums;
|
||||
using Verdure.WinUI.Common.Helpers;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Storage;
|
||||
@@ -40,7 +41,7 @@ public class EmojisFileService : IEmojisFileService
|
||||
NameId = emoticonAction.NameId,
|
||||
Description = emoticonAction.Desc,
|
||||
HasAction = emoticonAction.HasAction,
|
||||
EmojisType = emoticonAction.EmojisType
|
||||
Type = emoticonAction.Type
|
||||
};
|
||||
|
||||
|
||||
@@ -61,7 +62,7 @@ public class EmojisFileService : IEmojisFileService
|
||||
var destinationFile = await destinationFolder
|
||||
.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
|
||||
|
||||
if (emoticonAction != null && emoticonAction.EmojisType == EmojisType.Default)
|
||||
if (emoticonAction != null && emoticonAction.Type == EmojisFileType.Default)
|
||||
{
|
||||
var videoPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emoticonAction.NameId}.mp4";
|
||||
filePaths.Add(videoPath);
|
||||
@@ -70,7 +71,7 @@ public class EmojisFileService : IEmojisFileService
|
||||
var actionPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\defaultaction.json";
|
||||
filePaths.Add(actionPath);
|
||||
}
|
||||
else if (emoticonAction != null && emoticonAction.EmojisType == EmojisType.Custom)
|
||||
else if (emoticonAction != null && emoticonAction.Type == EmojisFileType.Custom)
|
||||
{
|
||||
filePaths.Add(emoticonAction.Avatar);
|
||||
filePaths.Add(emoticonAction.EmojisVideoPath);
|
||||
@@ -113,7 +114,7 @@ public class EmojisFileService : IEmojisFileService
|
||||
NameId = emoticonAction.NameId,
|
||||
Description = emoticonAction.Desc,
|
||||
HasAction = emoticonAction.HasAction,
|
||||
EmojisType = emoticonAction.EmojisType
|
||||
Type = emoticonAction.Type
|
||||
};
|
||||
|
||||
|
||||
@@ -130,7 +131,7 @@ public class EmojisFileService : IEmojisFileService
|
||||
var destinationFile = await destinationFolder
|
||||
.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
|
||||
|
||||
if (emoticonAction != null && emoticonAction.EmojisType == EmojisType.Default)
|
||||
if (emoticonAction != null && emoticonAction.Type == EmojisFileType.Default)
|
||||
{
|
||||
var videoPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emoticonAction.NameId}.mp4";
|
||||
filePaths.Add(videoPath);
|
||||
@@ -139,7 +140,7 @@ public class EmojisFileService : IEmojisFileService
|
||||
var actionPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\defaultaction.json";
|
||||
filePaths.Add(actionPath);
|
||||
}
|
||||
else if (emoticonAction != null && emoticonAction.EmojisType == EmojisType.Custom)
|
||||
else if (emoticonAction != null && emoticonAction.Type == EmojisFileType.Custom)
|
||||
{
|
||||
filePaths.Add(emoticonAction.Avatar);
|
||||
filePaths.Add(emoticonAction.EmojisVideoPath);
|
||||
@@ -168,7 +169,8 @@ public class EmojisFileService : IEmojisFileService
|
||||
}
|
||||
|
||||
public Task<List<EmoticonAction>> GetEmojisFileListAsync(int pageIndex, int pageSize) => throw new NotImplementedException();
|
||||
public Task<EmoticonAction> SaveEmojisAsync(EmoticonAction emoticonAction) => throw new NotImplementedException();
|
||||
public Task<EmoticonActionModel> SaveEmojisAsync(EmoticonAction emoticonAction) => throw new NotImplementedException();
|
||||
public Task<string> SaveEmojisFileAsync(Stream stream, string fileName, string fileType = ".mp4") => throw new NotImplementedException();
|
||||
public Task<string> SaveEmojisFileAsync(string path, string fileName, string fileType = ".mp4") => throw new NotImplementedException();
|
||||
Task<List<EmoticonActionModel>> IEmojisFileService.GetEmojisFileListAsync(int pageIndex, int pageSize) => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class EmojiseShopService : IEmojiseShopService
|
||||
action.Name = emojisFileInfo.Name;
|
||||
action.NameId = emojisFileInfo.NameId;
|
||||
action.Desc = emojisFileInfo.Description;
|
||||
action.EmojisType = emojisFileInfo.EmojisType;
|
||||
action.Type = emojisFileInfo.Type;
|
||||
action.HasAction = emojisFileInfo.HasAction;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -5,3 +5,4 @@ global using Verdure.Braincase.Core.Contracts;
|
||||
global using Verdure.Braincase.Core.Helpers;
|
||||
global using Verdure.Braincase.Core.Services;
|
||||
global using Verdure.Braincase.Core.Models;
|
||||
global using Verdure.Braincase.Core.Models.Emojis.Enums;
|
||||
|
||||
@@ -207,7 +207,7 @@ public class GamepadViewModel : ObservableRecipient, INavigationAware
|
||||
|
||||
string? videoPath;
|
||||
|
||||
if (action.EmojisType == EmojisType.Default)
|
||||
if (action.Type == EmojisFileType.Default)
|
||||
{
|
||||
videoPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{action.NameId}.mp4";
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Services;
|
||||
using Verdure.Braincase.Core.Models;
|
||||
using Verdure.Braincase.Core.Models.Emojis.Enums;
|
||||
using Verdure.WinUI.Common.Helpers;
|
||||
using Verdure.WinUI.Common.Models;
|
||||
using Verdure.WinUI.Common.Services;
|
||||
@@ -310,7 +311,7 @@ public partial class MainViewModel : ObservableRecipient, INavigationAware
|
||||
var list = (await _localSettingsService
|
||||
.ReadSettingAsync<List<EmoticonAction>>(Constants.EmojisActionListKey)) ?? new List<EmoticonAction>();
|
||||
|
||||
if (!list.Any(a => a.EmojisType == EmojisType.Default))
|
||||
if (!list.Any(a => a.Type == EmojisFileType.Default))
|
||||
{
|
||||
var emoticonActions = Constants.EMOJI_ACTION_LIST;
|
||||
await _localSettingsService.SaveSettingAsync(Constants.EmojisActionListKey, emoticonActions.ToList());
|
||||
@@ -333,7 +334,7 @@ public partial class MainViewModel : ObservableRecipient, INavigationAware
|
||||
{
|
||||
var path = string.Empty;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
path = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.EmojisActionPath}";
|
||||
}
|
||||
@@ -362,7 +363,7 @@ public partial class MainViewModel : ObservableRecipient, INavigationAware
|
||||
|
||||
string? videoPath;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
videoPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.NameId}.mp4";
|
||||
}
|
||||
@@ -399,7 +400,7 @@ public partial class MainViewModel : ObservableRecipient, INavigationAware
|
||||
var list = (await _localSettingsService
|
||||
.ReadSettingAsync<List<EmoticonAction>>(Constants.EmojisActionListKey)) ?? new List<EmoticonAction>();
|
||||
|
||||
if (!list.Any(a => a.EmojisType == EmojisType.Default))
|
||||
if (!list.Any(a => a.Type == EmojisFileType.Default))
|
||||
{
|
||||
var emoticonActions = Constants.EMOJI_ACTION_LIST;
|
||||
await _localSettingsService.SaveSettingAsync(Constants.EmojisActionListKey, emoticonActions.ToList());
|
||||
@@ -422,7 +423,7 @@ public partial class MainViewModel : ObservableRecipient, INavigationAware
|
||||
{
|
||||
var path = string.Empty;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
path = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.EmojisActionPath}";
|
||||
}
|
||||
@@ -451,7 +452,7 @@ public partial class MainViewModel : ObservableRecipient, INavigationAware
|
||||
|
||||
string? videoPath;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
videoPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.NameId}.mp4";
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public partial class AddEmojisDialogViewModel : ObservableRecipient
|
||||
Name = EmojisName,
|
||||
NameId = EmojisNameId,
|
||||
EmojisVideoPath = EmojisVideoUrl,
|
||||
EmojisType = EmojisType.Custom,
|
||||
Type = EmojisFileType.Custom,
|
||||
EmojisActionPath = EmojisActionPath,
|
||||
EmojisAuthor = EmojisAuthor
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ using Controls;
|
||||
using ElectronBot.Braincase.Helpers;
|
||||
using ElectronBot.Braincase.Models;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Models;
|
||||
using Verdure.WinUI.Common.Helpers;
|
||||
using Verdure.WinUI.Common.Models;
|
||||
@@ -31,7 +32,7 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
{
|
||||
try
|
||||
{
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
ToastHelper.SendToast("默认表情禁止导出", TimeSpan.FromSeconds(3));
|
||||
return;
|
||||
@@ -113,7 +114,7 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
action.Name = emojisFileInfo.Name;
|
||||
action.NameId = emojisFileInfo.NameId;
|
||||
action.Desc = emojisFileInfo.Description;
|
||||
action.EmojisType = emojisFileInfo.EmojisType;
|
||||
action.Type = emojisFileInfo.Type;
|
||||
action.HasAction = emojisFileInfo.HasAction;
|
||||
}
|
||||
else
|
||||
@@ -143,10 +144,33 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
}
|
||||
}
|
||||
|
||||
await _emojisFileService.SaveEmojisAsync(action);
|
||||
var emojiModel = await _emojisFileService.SaveEmojisAsync(action);
|
||||
|
||||
if (emojiModel != null)
|
||||
{
|
||||
var data = new EmoticonActionUIModel
|
||||
{
|
||||
Name = emojiModel.Name,
|
||||
NameId = emojiModel.NameId,
|
||||
Desc = emojiModel.Desc,
|
||||
EmojisActionPath = emojiModel.EmojisActionPath,
|
||||
EmojisAuthor = emojiModel.EmojisAuthor,
|
||||
EmojisVideoPath = emojiModel.EmojisVideoPath,
|
||||
HasAction = emojiModel.HasAction,
|
||||
Type = emojiModel.Type
|
||||
};
|
||||
|
||||
Actions.Add(action);
|
||||
if (emojiModel.Avatar != null)
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
|
||||
await bitmapImage.SetSourceAsync(emojiModel.Avatar.AsRandomAccessStream());
|
||||
|
||||
data.Avatar = bitmapImage;
|
||||
}
|
||||
|
||||
Emojis.Add(data);
|
||||
}
|
||||
|
||||
await storageFolder.DeleteAsync();
|
||||
}
|
||||
@@ -212,7 +236,7 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
{
|
||||
try
|
||||
{
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
ToastHelper.SendToast("默认表情禁止删除", TimeSpan.FromSeconds(3));
|
||||
return;
|
||||
@@ -275,7 +299,7 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
{
|
||||
var path = string.Empty;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
path = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.EmojisActionPath}";
|
||||
}
|
||||
@@ -304,7 +328,7 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
|
||||
string? videoPath;
|
||||
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
videoPath = Package.Current.InstalledLocation.Path + $"\\Assets\\Emoji\\{emojis.NameId}.mp4";
|
||||
}
|
||||
@@ -360,7 +384,7 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
{
|
||||
if (obj is EmoticonAction emojis)
|
||||
{
|
||||
if (emojis.EmojisType == EmojisType.Default)
|
||||
if (emojis.Type == EmojisFileType.Default)
|
||||
{
|
||||
ToastHelper.SendToast("默认表情不能分享", TimeSpan.FromSeconds(3));
|
||||
return;
|
||||
@@ -415,7 +439,7 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
Desc = EmojisDesc,
|
||||
Name = EmojisName,
|
||||
NameId = EmojisNameId,
|
||||
EmojisType = EmojisType.Custom
|
||||
Type = EmojisFileType.Custom
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,17 @@ using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using ElectronBot.Braincase.Models;
|
||||
using Verdure.WinUI.Common.Models;
|
||||
|
||||
namespace ElectronBot.Braincase.ViewModels;
|
||||
public partial class EmojisEditViewModel : ObservableRecipient
|
||||
{
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<EmoticonAction> _actions = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<EmoticonActionUIModel> _emojis = new();
|
||||
|
||||
/// <summary>
|
||||
/// 表情名称
|
||||
/// </summary>
|
||||
|
||||
@@ -147,9 +147,9 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
[RelayCommand]
|
||||
public Task OnLoadedAsync()
|
||||
{
|
||||
Actions.Clear();
|
||||
Emojis.Clear();
|
||||
// IncrementalLoadingCollection can be bound to a GridView or a ListView. In this case it is a ListView called PeopleListView.
|
||||
Actions = new IncrementalLoadingCollection<EmojisSource, EmoticonAction>(Ioc.Default.GetRequiredService<EmojisSource>());
|
||||
Emojis = new IncrementalLoadingCollection<EmojisSource, EmoticonActionUIModel>(Ioc.Default.GetRequiredService<EmojisSource>());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:models="using:ElectronBot.Braincase.Models"
|
||||
xmlns:uiModels="using:Verdure.WinUI.Common.Models"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<i:Interaction.Behaviors>
|
||||
@@ -19,7 +20,7 @@
|
||||
<Page.Resources>
|
||||
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
|
||||
<DataTemplate x:Key="PhotosTemplate" x:DataType="models:EmoticonAction">
|
||||
<DataTemplate x:Key="PhotosTemplate" x:DataType="uiModels:EmoticonActionUIModel">
|
||||
<Grid
|
||||
Margin="8"
|
||||
BorderBrush="{ThemeResource SystemAccentColor}"
|
||||
@@ -27,12 +28,12 @@
|
||||
CornerRadius="8">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Grid Width="120">
|
||||
<!--<Image
|
||||
<Image
|
||||
Width="120"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Source="{x:Bind Avatar}"
|
||||
Stretch="UniformToFill" />-->
|
||||
Stretch="UniformToFill" />
|
||||
<Border
|
||||
Width="24"
|
||||
Height="24"
|
||||
@@ -109,7 +110,7 @@
|
||||
IsEnabled="True"
|
||||
IsItemClickEnabled="True"
|
||||
ItemTemplate="{StaticResource PhotosTemplate}"
|
||||
ItemsSource="{x:Bind ViewModel.Actions, Mode=OneWay}"
|
||||
ItemsSource="{x:Bind ViewModel.Emojis, Mode=OneWay}"
|
||||
SelectionMode="Single">
|
||||
<GridView.ContextFlyout>
|
||||
<MenuFlyout>
|
||||
|
||||
@@ -14,7 +14,7 @@ public static class EmojisMappers
|
||||
Desc = model.Desc,
|
||||
Avatar = model.Avatar,
|
||||
EmojisVideoPath = model.EmojisVideoPath,
|
||||
Type = model.EmojisType.ToString(),
|
||||
Type = model.Type,
|
||||
EmojisActionJson = model.EmojisActionPath,
|
||||
EmojisAuthor = model.EmojisAuthor,
|
||||
HasAction = model.HasAction
|
||||
@@ -22,7 +22,7 @@ public static class EmojisMappers
|
||||
};
|
||||
}
|
||||
|
||||
public static EmoticonAction ToModel(this EmojisDocument doc)
|
||||
public static EmoticonAction ToModel1(this EmojisDocument doc)
|
||||
{
|
||||
return new EmoticonAction
|
||||
{
|
||||
@@ -31,7 +31,22 @@ public static class EmojisMappers
|
||||
Desc = doc.Desc,
|
||||
Avatar = doc.Avatar,
|
||||
EmojisVideoPath = doc.EmojisVideoPath,
|
||||
EmojisType = Enum.Parse<EmojisType>(doc.Type),
|
||||
Type = doc.Type,
|
||||
EmojisActionPath = doc.EmojisActionJson,
|
||||
EmojisAuthor = doc.EmojisAuthor,
|
||||
HasAction = doc.HasAction
|
||||
};
|
||||
}
|
||||
|
||||
public static EmoticonActionModel ToModel(this EmojisDocument doc)
|
||||
{
|
||||
return new EmoticonActionModel
|
||||
{
|
||||
Name = doc.Name,
|
||||
NameId = doc.NameId,
|
||||
Desc = doc.Desc,
|
||||
EmojisVideoPath = doc.EmojisVideoPath,
|
||||
Type = doc.Type,
|
||||
EmojisActionPath = doc.EmojisActionJson,
|
||||
EmojisAuthor = doc.EmojisAuthor,
|
||||
HasAction = doc.HasAction
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Contracts.Services;
|
||||
using ElectronBot.Braincase.Models;
|
||||
using LiteDB;
|
||||
using Verdure.Braincase.DataStorage.Mappers;
|
||||
|
||||
namespace Verdure.Braincase.DataStorage.Services;
|
||||
@@ -15,23 +16,57 @@ public class LiteDBEmojisFileService : IEmojisFileService
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public Task<(string path, string name)> ExportEmojisFileToTempAsync(EmoticonAction emoticonAction) => throw new NotImplementedException();
|
||||
public Task<List<EmoticonAction>> GetEmojisFileListAsync(int pageIndex, int pageSize)
|
||||
public Task<List<EmoticonActionModel>> GetEmojisFileListAsync(int pageIndex, int pageSize)
|
||||
{
|
||||
var emojis = _db.Emojis.FindAll().Skip(pageIndex * pageSize).Take(pageSize).Select(x => x.ToModel()).ToList();
|
||||
return Task.FromResult(emojis);
|
||||
var list = new List<EmoticonActionModel>();
|
||||
|
||||
var emojisDocs = _db.Emojis.FindAll().Skip(pageIndex * pageSize).Take(pageSize).ToList();
|
||||
|
||||
foreach (var item in emojisDocs)
|
||||
{
|
||||
var model = item.ToModel();
|
||||
|
||||
var avatarFile = _db.FileStorage.FindById(item.Avatar);
|
||||
|
||||
var stream = new MemoryStream();
|
||||
|
||||
_db.FileStorage.Download(avatarFile.Id, stream);
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
model.Avatar = stream;
|
||||
|
||||
list.Add(model);
|
||||
}
|
||||
return Task.FromResult(list);
|
||||
}
|
||||
public Task<EmoticonAction> SaveEmojisAsync(EmoticonAction emoticonAction)
|
||||
public Task<EmoticonActionModel> SaveEmojisAsync(EmoticonAction emoticonAction)
|
||||
{
|
||||
var doc = emoticonAction.ToDoc();
|
||||
var emoticon = _db.Emojis.FindOne(x => x.NameId == emoticonAction.NameId);
|
||||
if (emoticon != null)
|
||||
{
|
||||
var doc = emoticonAction.ToDoc();
|
||||
doc.Id = emoticon.Id;
|
||||
_db.Emojis.Update(doc);
|
||||
return Task.FromResult(emoticonAction);
|
||||
}
|
||||
_db.Emojis.Insert(emoticonAction.ToDoc());
|
||||
return Task.FromResult(emoticonAction);
|
||||
else
|
||||
{
|
||||
_db.Emojis.Insert(doc);
|
||||
}
|
||||
|
||||
var model = doc.ToModel();
|
||||
|
||||
var avatarFile = _db.FileStorage.FindById(doc.Avatar);
|
||||
|
||||
var stream = new MemoryStream();
|
||||
|
||||
_db.FileStorage.Download(avatarFile.Id, stream);
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
model.Avatar = stream;
|
||||
|
||||
return Task.FromResult(model);
|
||||
}
|
||||
public Task<string> SaveEmojisFileAsync(Stream stream, string fileName, string fileType = ".mp4")
|
||||
{
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Verdure.Braincase.Core.Models.Emojis.Enums;
|
||||
|
||||
namespace Verdure.WinUI.Common.Models;
|
||||
|
||||
public class EmoticonActionUIModel
|
||||
{
|
||||
public string NameId
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public string Desc
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public BitmapImage? Avatar
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string EmojisVideoPath
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
public string Type
|
||||
{
|
||||
get; set;
|
||||
} = EmojisFileType.Default;
|
||||
|
||||
public string EmojisActionPath
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public string EmojisAuthor
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = string.Empty;
|
||||
|
||||
public bool HasAction
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
using System.Threading;
|
||||
using CommunityToolkit.WinUI.Collections;
|
||||
using Contracts.Services;
|
||||
using ElectronBot.Braincase.Models;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Verdure.WinUI.Common.Models;
|
||||
|
||||
namespace Verdure.WinUI.Common.ViewDataSource;
|
||||
public class EmojisSource : IIncrementalSource<EmoticonAction>
|
||||
public class EmojisSource : IIncrementalSource<EmoticonActionUIModel>
|
||||
{
|
||||
private readonly IEmojisFileService _emojisFileService;
|
||||
public EmojisSource(IEmojisFileService emojisFileService)
|
||||
@@ -12,8 +13,37 @@ public class EmojisSource : IIncrementalSource<EmoticonAction>
|
||||
_emojisFileService = emojisFileService;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<EmoticonAction>> GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default)
|
||||
public async Task<IEnumerable<EmoticonActionUIModel>> GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _emojisFileService.GetEmojisFileListAsync(pageIndex, pageSize);
|
||||
var emojis = await _emojisFileService.GetEmojisFileListAsync(pageIndex, pageSize);
|
||||
var retData = new List<EmoticonActionUIModel>();
|
||||
|
||||
foreach (var item in emojis)
|
||||
{
|
||||
var data = new EmoticonActionUIModel
|
||||
{
|
||||
Name = item.Name,
|
||||
NameId = item.NameId,
|
||||
Desc = item.Desc,
|
||||
EmojisActionPath = item.EmojisActionPath,
|
||||
EmojisAuthor = item.EmojisAuthor,
|
||||
EmojisVideoPath = item.EmojisVideoPath,
|
||||
HasAction = item.HasAction,
|
||||
Type = item.Type
|
||||
};
|
||||
|
||||
if (item.Avatar != null)
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
|
||||
await bitmapImage.SetSourceAsync(item.Avatar.AsRandomAccessStream());
|
||||
|
||||
data.Avatar = bitmapImage;
|
||||
}
|
||||
|
||||
retData.Add(data);
|
||||
}
|
||||
|
||||
return retData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user