diff --git a/.gitignore b/.gitignore
index 9491a2f..79c68eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -360,4 +360,6 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
-FodyWeavers.xsd
\ No newline at end of file
+FodyWeavers.xsd
+
+SimepleList/SimpleList - Backup.csproj
\ No newline at end of file
diff --git a/README.md b/README.md
index 3ee4c0e..a044cce 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Unzip and then double click
- [x] Index
- [x] Download
- [x] Share
-- [ ] Preview
+- [x] Preview
- [x] Download progress
- [x] Upload
- [ ] Automatic synchronization
diff --git a/README_zh_CN.md b/README_zh_CN.md
index 7991431..5a6af36 100644
--- a/README_zh_CN.md
+++ b/README_zh_CN.md
@@ -15,7 +15,7 @@ OneDrive
- [x] 列表
- [x] 下载
- [x] 共享
-- [ ] 预览
+- [x] 预览
- [x] 下载进度
- [x] 上传
- [ ] 自动同步
diff --git a/SimpleList/Models/FileType.cs b/SimpleList/Models/FileType.cs
new file mode 100644
index 0000000..2688e6d
--- /dev/null
+++ b/SimpleList/Models/FileType.cs
@@ -0,0 +1,13 @@
+锘縩amespace SimpleList.Models
+{
+ public enum FileType
+ {
+ Text,
+ Markdown,
+ Code,
+ Image,
+ Media,
+ Office,
+ Unknown
+ }
+}
diff --git a/SimpleList/Services/Utils.cs b/SimpleList/Services/Utils.cs
index b41696c..c9944b0 100644
--- a/SimpleList/Services/Utils.cs
+++ b/SimpleList/Services/Utils.cs
@@ -1,4 +1,6 @@
-锘縰sing System;
+锘縰sing SimpleList.Models;
+using System;
+using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
@@ -60,5 +62,20 @@ public static string ReadableFileSize(long? bytes)
}
return "0";
}
+
+ public static FileType GetFileType(string ext)
+ {
+ return ext switch
+ {
+ ".txt" => FileType.Text,
+ ".md" => FileType.Markdown,
+ string _ when ImageType.Contains(ext) => FileType.Image,// https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.image?view=windows-app-sdk-1.4#image-file-formats
+ string _ when MediaType.Contains(ext) => FileType.Media,
+ _ => FileType.Unknown,
+ };
+ }
+
+ public static readonly string[] ImageType = { ".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff", ".ico", ".svg" };
+ public static readonly string[] MediaType = { "mp3", ".mp4", ".wma", ".3gp", ".aac", ".flac", ".wax", ".wav", ".wmx", ".wpl", ".avi" };
}
}
diff --git a/SimpleList/SimpleList.csproj b/SimpleList/SimpleList.csproj
index 418a71d..07e7b92 100644
--- a/SimpleList/SimpleList.csproj
+++ b/SimpleList/SimpleList.csproj
@@ -7,7 +7,7 @@
app.manifest
x86;x64;ARM64
win10-x86;win10-x64;win10-arm64
- Properties\PublishProfiles\win10-$(Platform).pubxml
+ win10-$(Platform).pubxml
true
true
@@ -58,6 +58,9 @@
+
+
+
@@ -77,6 +80,7 @@
+
@@ -111,6 +115,15 @@
True
\
+
+ MSBuild:Compile
+
+
+ MSBuild:Compile
+
+
+ MSBuild:Compile
+
MSBuild:Compile
diff --git a/SimpleList/Strings/en-US/Resources.resw b/SimpleList/Strings/en-US/Resources.resw
index cfd2eb4..1650211 100644
--- a/SimpleList/Strings/en-US/Resources.resw
+++ b/SimpleList/Strings/en-US/Resources.resw
@@ -141,6 +141,27 @@
Your drive
+
+ Convert
+
+
+ Delete
+
+
+ Download
+
+
+ Open
+
+
+ Property
+
+
+ Rename
+
+
+ Share
+
Capacity锛
diff --git a/SimpleList/Strings/zh-CN/Resources.resw b/SimpleList/Strings/zh-CN/Resources.resw
index e5a6e2d..735fbde 100644
--- a/SimpleList/Strings/zh-CN/Resources.resw
+++ b/SimpleList/Strings/zh-CN/Resources.resw
@@ -141,6 +141,27 @@
浣犵殑缃戠洏
+
+ 杞崲
+
+
+ 鍒犻櫎
+
+
+ 涓嬭浇
+
+
+ 鎵撳紑
+
+
+ 灞炴
+
+
+ 閲嶅懡鍚
+
+
+ 鍒嗕韩
+
瀹归噺:
diff --git a/SimpleList/ViewModels/CloudViewModel.cs b/SimpleList/ViewModels/CloudViewModel.cs
index 9ca012f..d450327 100644
--- a/SimpleList/ViewModels/CloudViewModel.cs
+++ b/SimpleList/ViewModels/CloudViewModel.cs
@@ -1,10 +1,6 @@
锘縰sing CommunityToolkit.Mvvm.ComponentModel;
-using CommunityToolkit.Mvvm.Input;
-using Microsoft.Graph.Models;
-using SimpleList.Services;
using System.Collections.ObjectModel;
using System.Linq;
-using System.Threading.Tasks;
namespace SimpleList.ViewModels
{
diff --git a/SimpleList/ViewModels/DriveViewModel.cs b/SimpleList/ViewModels/DriveViewModel.cs
index 4c920fa..e3dd396 100644
--- a/SimpleList/ViewModels/DriveViewModel.cs
+++ b/SimpleList/ViewModels/DriveViewModel.cs
@@ -19,6 +19,7 @@ public DriveViewModel(OneDrive provider, string displayName = null)
BreadcrumbItems.Add(new BreadcrumbItem { Name = "RootFileName".GetLocalized(), ItemId = "Root" });
}
+ [RelayCommand]
public async Task GetFiles(string itemId = "Root")
{
IsLoading = Visibility.Visible;
diff --git a/SimpleList/ViewModels/FileViewModel.cs b/SimpleList/ViewModels/FileViewModel.cs
index e36bdee..cf42880 100644
--- a/SimpleList/ViewModels/FileViewModel.cs
+++ b/SimpleList/ViewModels/FileViewModel.cs
@@ -4,6 +4,8 @@
using Microsoft.Graph.Models;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media.Imaging;
+using SimpleList.Models;
+using SimpleList.Services;
using System;
using System.Collections.Generic;
using System.IO;
@@ -58,7 +60,17 @@ public async Task LoadImage()
}
}
+ [RelayCommand]
+ public async Task LoadContent()
+ {
+ if (IsFile)
+ {
+ Content = (await Drive.Provider.GetItemContent(Id)).ToString();
+ }
+ }
+
[ObservableProperty] private BitmapImage _image;
+ [ObservableProperty] private string _content;
private readonly DriveItem _file;
public string Id { get => _file.Id; }
@@ -70,5 +82,7 @@ public async Task LoadImage()
public int? ChildrenCount { get => _file.Folder?.ChildCount; }
public DriveViewModel Drive { get; }
public string ItemType { get; }
+ public string DownloadUrl { get => _file.AdditionalData["@microsoft.graph.downloadUrl"].ToString(); }
+ public bool CanPreview { get => IsFile && Utils.GetFileType(Path.GetExtension(Name)) != FileType.Unknown; }
}
}
diff --git a/SimpleList/ViewModels/PreviewViewModel.cs b/SimpleList/ViewModels/PreviewViewModel.cs
new file mode 100644
index 0000000..a68d772
--- /dev/null
+++ b/SimpleList/ViewModels/PreviewViewModel.cs
@@ -0,0 +1,59 @@
+锘縰sing CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using Microsoft.Graph.Models;
+using Microsoft.UI.Xaml.Media.Imaging;
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using Windows.Media.Core;
+using Windows.Storage.Streams;
+
+namespace SimpleList.ViewModels
+{
+ public partial class PreviewViewModel : ObservableObject
+ {
+ public PreviewViewModel(FileViewModel file)
+ {
+ _file = file;
+ }
+
+ [RelayCommand]
+ public async Task LoadTextContent()
+ {
+ IsLoading = true;
+ Stream stram = await _file.Drive.Provider.GetItemContent(_file.Id);
+ using StreamReader reader = new(stram);
+ Text = await reader.ReadToEndAsync();
+ IsLoading = false;
+ }
+
+ [RelayCommand]
+ public async Task LoadImageContent()
+ {
+ IsLoading = true;
+ Stream stream = await _file.Drive.Provider.GetItemContent(_file.Id);
+ InMemoryRandomAccessStream randomAccessStream = new();
+ await RandomAccessStream.CopyAsync(stream.AsInputStream(), randomAccessStream);
+ randomAccessStream.Seek(0);
+ BitmapImage img = new();
+ await img.SetSourceAsync(randomAccessStream);
+ Image = img;
+ IsLoading = false;
+ }
+
+ public void LoadMediaSource()
+ {
+ IsLoading = true;
+ string downloadUri = _file.DownloadUrl;
+ MediaSource mediaSource = MediaSource.CreateFromUri(new Uri(downloadUri));
+ Media = mediaSource;
+ IsLoading = false;
+ }
+
+ private readonly FileViewModel _file;
+ [ObservableProperty] private bool _isLoading = false;
+ [ObservableProperty] private string _text;
+ [ObservableProperty] private BitmapImage _image;
+ [ObservableProperty] private MediaSource _media;
+ }
+}
diff --git a/SimpleList/ViewModels/ShareFileViewModel.cs b/SimpleList/ViewModels/ShareFileViewModel.cs
index 49d122a..5e7a815 100644
--- a/SimpleList/ViewModels/ShareFileViewModel.cs
+++ b/SimpleList/ViewModels/ShareFileViewModel.cs
@@ -23,7 +23,7 @@ private async Task ShareFile()
}
[RelayCommand]
- private async Task CopyToClipboard()
+ private void CopyToClipboard()
{
DataPackage package = new();
package.SetText(ShareLink);
diff --git a/SimpleList/Views/Layout/ColumnFileView.xaml b/SimpleList/Views/Layout/ColumnFileView.xaml
index b1f8078..1977afa 100644
--- a/SimpleList/Views/Layout/ColumnFileView.xaml
+++ b/SimpleList/Views/Layout/ColumnFileView.xaml
@@ -21,13 +21,23 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/SimpleList/Views/Layout/ColumnFileView.xaml.cs b/SimpleList/Views/Layout/ColumnFileView.xaml.cs
index cc5f781..e4fec9e 100644
--- a/SimpleList/Views/Layout/ColumnFileView.xaml.cs
+++ b/SimpleList/Views/Layout/ColumnFileView.xaml.cs
@@ -1,7 +1,11 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
+using SimpleList.Models;
+using SimpleList.Services;
using SimpleList.ViewModels;
+using SimpleList.Views.Preview;
using System;
+using System.IO;
namespace SimpleList.Views.Layout
{
@@ -78,6 +82,45 @@ private async void ShowDeleteFileDialogAsync(object sender, RoutedEventArgs e)
};
await dialog.ShowAsync();
}
+
+ private async void ShowPreviewDialogAsync(object sender, RoutedEventArgs e)
+ {
+ FileViewModel viewModel = DataContext as FileViewModel;
+ switch (Utils.GetFileType(Path.GetExtension(viewModel.Name).ToLower()))
+ {
+ case FileType.Markdown:
+ {
+ MarkdownPreviewView dialog = new()
+ {
+ XamlRoot = XamlRoot,
+ DataContext = new PreviewViewModel(viewModel)
+ };
+ await dialog.ShowAsync();
+ break;
+ }
+ case FileType.Image:
+ {
+ ImagePreviewView dialog = new()
+ {
+ XamlRoot = XamlRoot,
+ DataContext = new PreviewViewModel(viewModel)
+ };
+ await dialog.ShowAsync();
+ break;
+ }
+ case FileType.Media:
+ {
+ MediaPreviewView dialog = new()
+ {
+ XamlRoot = XamlRoot,
+ DataContext = new PreviewViewModel(viewModel)
+ };
+ await dialog.ShowAsync();
+ break;
+ }
+ }
+
+ }
}
}
diff --git a/SimpleList/Views/Preview/ImagePreviewView.xaml b/SimpleList/Views/Preview/ImagePreviewView.xaml
new file mode 100644
index 0000000..c5e03e1
--- /dev/null
+++ b/SimpleList/Views/Preview/ImagePreviewView.xaml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
diff --git a/SimpleList/Views/Preview/ImagePreviewView.xaml.cs b/SimpleList/Views/Preview/ImagePreviewView.xaml.cs
new file mode 100644
index 0000000..481980d
--- /dev/null
+++ b/SimpleList/Views/Preview/ImagePreviewView.xaml.cs
@@ -0,0 +1,20 @@
+using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using SimpleList.ViewModels;
+
+namespace SimpleList.Views.Preview
+{
+ public sealed partial class ImagePreviewView : ContentDialog
+ {
+ public ImagePreviewView()
+ {
+ InitializeComponent();
+ }
+
+ private void LoadImageContentAsync(object sender, RoutedEventArgs e)
+ {
+ PreviewViewModel vm = DataContext as PreviewViewModel;
+ _ = vm.LoadImageContent();
+ }
+ }
+}
diff --git a/SimpleList/Views/Preview/MarkdownPreviewView.xaml b/SimpleList/Views/Preview/MarkdownPreviewView.xaml
new file mode 100644
index 0000000..dc0b3e9
--- /dev/null
+++ b/SimpleList/Views/Preview/MarkdownPreviewView.xaml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/SimpleList/Views/Preview/MarkdownPreviewView.xaml.cs b/SimpleList/Views/Preview/MarkdownPreviewView.xaml.cs
new file mode 100644
index 0000000..515d4df
--- /dev/null
+++ b/SimpleList/Views/Preview/MarkdownPreviewView.xaml.cs
@@ -0,0 +1,20 @@
+using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using SimpleList.ViewModels;
+
+namespace SimpleList.Views.Preview
+{
+ public sealed partial class MarkdownPreviewView : ContentDialog
+ {
+ public MarkdownPreviewView()
+ {
+ InitializeComponent();
+ }
+
+ private void LoadTextContentAsync(object sender, RoutedEventArgs e)
+ {
+ PreviewViewModel vm = DataContext as PreviewViewModel;
+ _ = vm.LoadTextContent();
+ }
+ }
+}
diff --git a/SimpleList/Views/Preview/MediaPreviewView.xaml b/SimpleList/Views/Preview/MediaPreviewView.xaml
new file mode 100644
index 0000000..5039c66
--- /dev/null
+++ b/SimpleList/Views/Preview/MediaPreviewView.xaml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
diff --git a/SimpleList/Views/Preview/MediaPreviewView.xaml.cs b/SimpleList/Views/Preview/MediaPreviewView.xaml.cs
new file mode 100644
index 0000000..261a276
--- /dev/null
+++ b/SimpleList/Views/Preview/MediaPreviewView.xaml.cs
@@ -0,0 +1,22 @@
+using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using SimpleList.ViewModels;
+using Windows.Media.Core;
+using Windows.Media.Playback;
+
+namespace SimpleList.Views.Preview
+{
+ public sealed partial class MediaPreviewView : ContentDialog
+ {
+ public MediaPreviewView()
+ {
+ InitializeComponent();
+ }
+
+ private void LoadDonwloadUrlAsync(object sender, RoutedEventArgs e)
+ {
+ PreviewViewModel vm = DataContext as PreviewViewModel;
+ vm.LoadMediaSource();
+ }
+ }
+}