commit 22eed0183eb72fecc77127201eecd5058715370c Author: Cal <42492716+ly3027929699@users.noreply.github.com> Date: Mon Dec 4 15:49:31 2023 +0800 first diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8afdcb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,454 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..28f59c3 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,6 @@ + + + enable + 11.0.5 + + diff --git a/Notes.Android/Icon.png b/Notes.Android/Icon.png new file mode 100644 index 0000000..41a2a61 Binary files /dev/null and b/Notes.Android/Icon.png differ diff --git a/Notes.Android/MainActivity.cs b/Notes.Android/MainActivity.cs new file mode 100644 index 0000000..4476ae6 --- /dev/null +++ b/Notes.Android/MainActivity.cs @@ -0,0 +1,23 @@ +using Android.App; +using Android.Content.PM; +using Avalonia; +using Avalonia.Android; +using Avalonia.ReactiveUI; + +namespace Notes.Android; + +[Activity( + Label = "Notes.Android", + Theme = "@style/MyTheme.NoActionBar", + Icon = "@drawable/icon", + MainLauncher = true, + ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode)] +public class MainActivity : AvaloniaMainActivity +{ + protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) + { + return base.CustomizeAppBuilder(builder) + .WithInterFont() + .UseReactiveUI(); + } +} diff --git a/Notes.Android/Notes.Android.csproj b/Notes.Android/Notes.Android.csproj new file mode 100644 index 0000000..5b886e2 --- /dev/null +++ b/Notes.Android/Notes.Android.csproj @@ -0,0 +1,29 @@ + + + Exe + net8.0-android + 21 + enable + com.CompanyName.Notes + 1 + 1.0 + apk + false + true + + + + + Resources\drawable\Icon.png + + + + + + + + + + + + diff --git a/Notes.Android/Properties/AndroidManifest.xml b/Notes.Android/Properties/AndroidManifest.xml new file mode 100644 index 0000000..d234041 --- /dev/null +++ b/Notes.Android/Properties/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/Notes.Android/Resources/AboutResources.txt b/Notes.Android/Resources/AboutResources.txt new file mode 100644 index 0000000..c2bca97 --- /dev/null +++ b/Notes.Android/Resources/AboutResources.txt @@ -0,0 +1,44 @@ +Images, layout descriptions, binary blobs and string dictionaries can be included +in your application as resource files. Various Android APIs are designed to +operate on the resource IDs instead of dealing with images, strings or binary blobs +directly. + +For example, a sample Android app that contains a user interface layout (main.axml), +an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) +would keep its resources in the "Resources" directory of the application: + +Resources/ + drawable/ + icon.png + + layout/ + main.axml + + values/ + strings.xml + +In order to get the build system to recognize Android resources, set the build action to +"AndroidResource". The native Android APIs do not operate directly with filenames, but +instead operate on resource IDs. When you compile an Android application that uses resources, +the build system will package the resources for distribution and generate a class called "R" +(this is an Android convention) that contains the tokens for each one of the resources +included. For example, for the above Resources layout, this is what the R class would expose: + +public class R { + public class drawable { + public const int icon = 0x123; + } + + public class layout { + public const int main = 0x456; + } + + public class strings { + public const int first_string = 0xabc; + public const int second_string = 0xbcd; + } +} + +You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main +to reference the layout/main.axml file, or R.strings.first_string to reference the first +string in the dictionary file values/strings.xml. \ No newline at end of file diff --git a/Notes.Android/Resources/drawable-night-v31/avalonia_anim.xml b/Notes.Android/Resources/drawable-night-v31/avalonia_anim.xml new file mode 100644 index 0000000..dde4b5a --- /dev/null +++ b/Notes.Android/Resources/drawable-night-v31/avalonia_anim.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Notes.Android/Resources/drawable-v31/avalonia_anim.xml b/Notes.Android/Resources/drawable-v31/avalonia_anim.xml new file mode 100644 index 0000000..94f27d9 --- /dev/null +++ b/Notes.Android/Resources/drawable-v31/avalonia_anim.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Notes.Android/Resources/drawable/splash_screen.xml b/Notes.Android/Resources/drawable/splash_screen.xml new file mode 100644 index 0000000..2e920b4 --- /dev/null +++ b/Notes.Android/Resources/drawable/splash_screen.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/Notes.Android/Resources/values-night/colors.xml b/Notes.Android/Resources/values-night/colors.xml new file mode 100644 index 0000000..3d47b6f --- /dev/null +++ b/Notes.Android/Resources/values-night/colors.xml @@ -0,0 +1,4 @@ + + + #212121 + diff --git a/Notes.Android/Resources/values-v31/styles.xml b/Notes.Android/Resources/values-v31/styles.xml new file mode 100644 index 0000000..d5ecec4 --- /dev/null +++ b/Notes.Android/Resources/values-v31/styles.xml @@ -0,0 +1,21 @@ + + + + + + + + diff --git a/Notes.Android/Resources/values/colors.xml b/Notes.Android/Resources/values/colors.xml new file mode 100644 index 0000000..59279d5 --- /dev/null +++ b/Notes.Android/Resources/values/colors.xml @@ -0,0 +1,4 @@ + + + #FFFFFF + diff --git a/Notes.Android/Resources/values/styles.xml b/Notes.Android/Resources/values/styles.xml new file mode 100644 index 0000000..6e534de --- /dev/null +++ b/Notes.Android/Resources/values/styles.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/Notes.Browser/AppBundle/Logo.svg b/Notes.Browser/AppBundle/Logo.svg new file mode 100644 index 0000000..9685a23 --- /dev/null +++ b/Notes.Browser/AppBundle/Logo.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/Notes.Browser/AppBundle/app.css b/Notes.Browser/AppBundle/app.css new file mode 100644 index 0000000..a424538 --- /dev/null +++ b/Notes.Browser/AppBundle/app.css @@ -0,0 +1,74 @@ +:root { + --sat: env(safe-area-inset-top); + --sar: env(safe-area-inset-right); + --sab: env(safe-area-inset-bottom); + --sal: env(safe-area-inset-left); +} + +/* HTML styles for the splash screen */ + +.highlight { + color: white; + font-size: 2.5rem; + display: block; +} + +.purple { + color: #8b44ac; +} + +.icon { + opacity: 0.05; + height: 35%; + width: 35%; + position: absolute; + background-repeat: no-repeat; + right: 0px; + bottom: 0px; + margin-right: 3%; + margin-bottom: 5%; + z-index: 5000; + background-position: right bottom; + pointer-events: none; +} + +#avalonia-splash a { + color: whitesmoke; + text-decoration: none; +} + +.center { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +#avalonia-splash { + position: relative; + height: 100%; + width: 100%; + color: whitesmoke; + background: #1b2a4e; + font-family: 'Nunito', sans-serif; + background-position: center; + background-size: cover; + background-repeat: no-repeat; + justify-content: center; + align-items: center; +} + +.splash-close { + animation: fadeout 0.25s linear forwards; +} + +@keyframes fadeout { + 0% { + opacity: 100%; + } + + 100% { + opacity: 0; + visibility: collapse; + } +} diff --git a/Notes.Browser/AppBundle/favicon.ico b/Notes.Browser/AppBundle/favicon.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/Notes.Browser/AppBundle/favicon.ico differ diff --git a/Notes.Browser/AppBundle/index.html b/Notes.Browser/AppBundle/index.html new file mode 100644 index 0000000..e3b115b --- /dev/null +++ b/Notes.Browser/AppBundle/index.html @@ -0,0 +1,30 @@ + + + + + Notes.Browser + + + + + + + + + + +
+
+
+

+ Powered by + Avalonia UI +

+
+ Avalonia Logo +
+
+ + + + \ No newline at end of file diff --git a/Notes.Browser/AppBundle/main.js b/Notes.Browser/AppBundle/main.js new file mode 100644 index 0000000..0dbe2e4 --- /dev/null +++ b/Notes.Browser/AppBundle/main.js @@ -0,0 +1,13 @@ +import { dotnet } from './dotnet.js' + +const is_browser = typeof window != "undefined"; +if (!is_browser) throw new Error(`Expected to be running in a browser`); + +const dotnetRuntime = await dotnet + .withDiagnosticTracing(false) + .withApplicationArgumentsFromQuery() + .create(); + +const config = dotnetRuntime.getConfig(); + +await dotnetRuntime.runMainAndExit(config.mainAssemblyName, [window.location.search]); \ No newline at end of file diff --git a/Notes.Browser/Notes.Browser.csproj b/Notes.Browser/Notes.Browser.csproj new file mode 100644 index 0000000..bb0cfec --- /dev/null +++ b/Notes.Browser/Notes.Browser.csproj @@ -0,0 +1,20 @@ + + + net8.0 + browser-wasm + AppBundle\main.js + Exe + + + + + + + + + + + + + + diff --git a/Notes.Browser/Program.cs b/Notes.Browser/Program.cs new file mode 100644 index 0000000..4c77333 --- /dev/null +++ b/Notes.Browser/Program.cs @@ -0,0 +1,19 @@ +using System.Runtime.Versioning; +using System.Threading.Tasks; +using Avalonia; +using Avalonia.Browser; +using Avalonia.ReactiveUI; +using Notes; + +[assembly: SupportedOSPlatform("browser")] + +internal sealed partial class Program +{ + private static Task Main(string[] args) => BuildAvaloniaApp() + .WithInterFont() + .UseReactiveUI() + .StartBrowserAppAsync("out"); + + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure(); +} \ No newline at end of file diff --git a/Notes.Browser/Properties/launchSettings.json b/Notes.Browser/Properties/launchSettings.json new file mode 100644 index 0000000..ec7c46d --- /dev/null +++ b/Notes.Browser/Properties/launchSettings.json @@ -0,0 +1,13 @@ +{ + "profiles": { + "Notes.Browser": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/debug?browser={browserInspectUri}" + } + } +} \ No newline at end of file diff --git a/Notes.Browser/runtimeconfig.template.json b/Notes.Browser/runtimeconfig.template.json new file mode 100644 index 0000000..c6990ba --- /dev/null +++ b/Notes.Browser/runtimeconfig.template.json @@ -0,0 +1,11 @@ +{ + "wasmHostProperties": { + "perHostConfig": [ + { + "name": "browser", + "html-path": "index.html", + "Host": "browser" + } + ] + } +} \ No newline at end of file diff --git a/Notes.Desktop/Notes.Desktop.csproj b/Notes.Desktop/Notes.Desktop.csproj new file mode 100644 index 0000000..5e86c4e --- /dev/null +++ b/Notes.Desktop/Notes.Desktop.csproj @@ -0,0 +1,24 @@ + + + WinExe + + net8.0 + enable + true + + + + app.manifest + + + + + + + + + + + + diff --git a/Notes.Desktop/Program.cs b/Notes.Desktop/Program.cs new file mode 100644 index 0000000..80a11ba --- /dev/null +++ b/Notes.Desktop/Program.cs @@ -0,0 +1,23 @@ +using System; +using Avalonia; +using Avalonia.ReactiveUI; + +namespace Notes.Desktop; + +sealed class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace() + .UseReactiveUI(); +} diff --git a/Notes.Desktop/app.manifest b/Notes.Desktop/app.manifest new file mode 100644 index 0000000..3fd114f --- /dev/null +++ b/Notes.Desktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/Notes.iOS/AppDelegate.cs b/Notes.iOS/AppDelegate.cs new file mode 100644 index 0000000..0af1c4d --- /dev/null +++ b/Notes.iOS/AppDelegate.cs @@ -0,0 +1,25 @@ +using Foundation; +using UIKit; +using Avalonia; +using Avalonia.Controls; +using Avalonia.iOS; +using Avalonia.Media; +using Avalonia.ReactiveUI; + +namespace Notes.iOS; + +// The UIApplicationDelegate for the application. This class is responsible for launching the +// User Interface of the application, as well as listening (and optionally responding) to +// application events from iOS. +[Register("AppDelegate")] +#pragma warning disable CA1711 // Identifiers should not have incorrect suffix +public partial class AppDelegate : AvaloniaAppDelegate +#pragma warning restore CA1711 // Identifiers should not have incorrect suffix +{ + protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) + { + return base.CustomizeAppBuilder(builder) + .WithInterFont() + .UseReactiveUI(); + } +} diff --git a/Notes.iOS/Entitlements.plist b/Notes.iOS/Entitlements.plist new file mode 100644 index 0000000..0c67376 --- /dev/null +++ b/Notes.iOS/Entitlements.plist @@ -0,0 +1,5 @@ + + + + + diff --git a/Notes.iOS/Info.plist b/Notes.iOS/Info.plist new file mode 100644 index 0000000..d426281 --- /dev/null +++ b/Notes.iOS/Info.plist @@ -0,0 +1,43 @@ + + + + + CFBundleDisplayName + Notes + CFBundleIdentifier + companyName.Notes + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + MinimumOSVersion + 13.0 + UIDeviceFamily + + 1 + 2 + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Notes.iOS/Main.cs b/Notes.iOS/Main.cs new file mode 100644 index 0000000..70a60da --- /dev/null +++ b/Notes.iOS/Main.cs @@ -0,0 +1,14 @@ +using UIKit; + +namespace Notes.iOS; + +public class Application +{ + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } +} diff --git a/Notes.iOS/Notes.iOS.csproj b/Notes.iOS/Notes.iOS.csproj new file mode 100644 index 0000000..4e1b922 --- /dev/null +++ b/Notes.iOS/Notes.iOS.csproj @@ -0,0 +1,16 @@ + + + Exe + net8.0-ios + 13.0 + enable + + + + + + + + + + diff --git a/Notes.iOS/Resources/LaunchScreen.xib b/Notes.iOS/Resources/LaunchScreen.xib new file mode 100644 index 0000000..7fd3b21 --- /dev/null +++ b/Notes.iOS/Resources/LaunchScreen.xib @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Notes.sln b/Notes.sln new file mode 100644 index 0000000..d5df493 --- /dev/null +++ b/Notes.sln @@ -0,0 +1,54 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32811.315 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notes", "Notes\Notes.csproj", "{EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notes.Desktop", "Notes.Desktop\Notes.Desktop.csproj", "{ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notes.Browser", "Notes.Browser\Notes.Browser.csproj", "{1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notes.iOS", "Notes.iOS\Notes.iOS.csproj", "{EBD9022F-BC83-4846-9A11-6F7F3772DC64}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notes.Android", "Notes.Android\Notes.Android.csproj", "{7AD1DAC8-7FBE-49D5-8614-7321233DB82E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3DA99C4E-89E3-4049-9C22-0A7EC60D83D8}" + ProjectSection(SolutionItems) = preProject + Directory.Build.props = Directory.Build.props + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}.Release|Any CPU.Build.0 = Release|Any CPU + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}.Release|Any CPU.Build.0 = Release|Any CPU + {1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}.Release|Any CPU.Build.0 = Release|Any CPU + {EBD9022F-BC83-4846-9A11-6F7F3772DC64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBD9022F-BC83-4846-9A11-6F7F3772DC64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBD9022F-BC83-4846-9A11-6F7F3772DC64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBD9022F-BC83-4846-9A11-6F7F3772DC64}.Release|Any CPU.Build.0 = Release|Any CPU + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {83CB65B8-011F-4ED7-BCD3-A6CFA935EF7E} + EndGlobalSection +EndGlobal diff --git a/Notes/App.axaml b/Notes/App.axaml new file mode 100644 index 0000000..faa0aa2 --- /dev/null +++ b/Notes/App.axaml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/Notes/App.axaml.cs b/Notes/App.axaml.cs new file mode 100644 index 0000000..247e5a1 --- /dev/null +++ b/Notes/App.axaml.cs @@ -0,0 +1,34 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using Notes.ViewModels; +using Notes.Views; + +namespace Notes; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + }; + } + else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) + { + singleViewPlatform.MainView = new MainView + { + + }; + } + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/Notes/Assets/avalonia-logo.ico b/Notes/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/Notes/Assets/avalonia-logo.ico differ diff --git a/Notes/ConsoleApp1.csproj b/Notes/ConsoleApp1.csproj new file mode 100644 index 0000000..cd204a9 --- /dev/null +++ b/Notes/ConsoleApp1.csproj @@ -0,0 +1,29 @@ + + + + Exe + net8.0 + enable + enable + Notes + + + + + + + + + + + + App.axaml + Code + + + + + + + + diff --git a/Notes/IOUtils.cs b/Notes/IOUtils.cs new file mode 100644 index 0000000..17c15d4 --- /dev/null +++ b/Notes/IOUtils.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.IO; + +namespace Utils; + +public static class IOUtils +{ + public static void DeleteFile(string path) + { + if (File.Exists(path)) + File.Delete(path); + } + public static void EnsureDirectory(string path,bool isFile = true) + { + var directoryInfo = new DirectoryInfo(path); + Stack paths = new Stack(); + if (!isFile) + { + paths.Push(directoryInfo.Name); + } + var directoryInfoParent = directoryInfo.Parent; + while (directoryInfoParent != null && !Directory.Exists(directoryInfoParent.FullName)) + { + paths.Push(directoryInfoParent.Name); + directoryInfoParent = directoryInfoParent.Parent; + } + + if (directoryInfoParent != null) + while (paths.Count > 0) + { + var pop = paths.Pop(); + Directory.CreateDirectory(Path.Combine(directoryInfoParent.FullName, pop)); + } + } +} \ No newline at end of file diff --git a/Notes/Models/Note.cs b/Notes/Models/Note.cs new file mode 100644 index 0000000..0136a52 --- /dev/null +++ b/Notes/Models/Note.cs @@ -0,0 +1,74 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Utils; + +namespace Notes.Models; + +public class Note +{ + public const string Extension = ".notes.txt"; + public string Filename { get; set; } + public string Text { get; set; } + public DateTime Date { get; set; } + + public string ShortName => Filename.Replace(Extension, string.Empty); + + public static string AppDataDirectory + { + get + { + var appDataDirectory = Path.Combine(AppContext.BaseDirectory, "Data"); + IOUtils.EnsureDirectory(appDataDirectory,false); + return appDataDirectory; + } + } + public Note() + { + Filename = $"{Path.GetRandomFileName()}{Extension}"; + Date = DateTime.Now; + Text = ""; + } + + public void Save() => + File.WriteAllText(Path.Combine(AppDataDirectory, Filename), Text); + + public void Delete() => + File.Delete(Path.Combine(AppDataDirectory, Filename)); + + public static Note Load(string filename) + { + filename = Path.Combine(AppDataDirectory, filename); + + if (!File.Exists(filename)) + throw new FileNotFoundException("Unable to find file on local storage.", filename); + + return + new() + { + Filename = Path.GetFileName(filename), + Text = File.ReadAllText(filename), + Date = File.GetLastWriteTime(filename) + }; + } + + public static IEnumerable LoadAll() + { + // Get the folder where the notes are stored. + string appDataPath = AppDataDirectory; + + // Use Linq extensions to load the *.notes.txt files. + return Directory + + // Select the file names from the directory + .EnumerateFiles(appDataPath, "*.notes.txt") + + // Each file name is used to load a note + .Select(filename => Load(Path.GetFileName(filename))) + + // With the final collection of notes, order them by date + .OrderByDescending(note => note.Date); + } +} \ No newline at end of file diff --git a/Notes/Models/Notes.cs b/Notes/Models/Notes.cs new file mode 100644 index 0000000..6180bde --- /dev/null +++ b/Notes/Models/Notes.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace Notes.Models; + +public class Notes +{ + public List notes { get; } + + public Notes() + { + var loadAll = Note.LoadAll(); + this.notes = new List(loadAll); + } + + public void Delete(Note note) + { + notes.Remove(note); + note.Delete(); + } +} \ No newline at end of file diff --git a/Notes/Notes.csproj b/Notes/Notes.csproj new file mode 100644 index 0000000..3b0e75e --- /dev/null +++ b/Notes/Notes.csproj @@ -0,0 +1,22 @@ + + + net8.0 + enable + latest + true + + + + + + + + + + + + + + + + diff --git a/Notes/ViewLocator.cs b/Notes/ViewLocator.cs new file mode 100644 index 0000000..90c6c2d --- /dev/null +++ b/Notes/ViewLocator.cs @@ -0,0 +1,70 @@ +using System; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using Notes.ViewModels; + +namespace Notes; +// public class ViewLocator : IDataTemplate +// { +// Control? ITemplate.Build(object? param) +// { +// if (param == null) throw new NullReferenceException(nameof(param)); +// var name = param.GetType().FullName!.Replace("ViewModel", "View"); +// var type = Type.GetType(name); +// +// if (type != null) +// { +// return (Control?)Activator.CreateInstance(type); +// } +// else +// { +// return new TextBlock { Text = "1Not Found: " + name }; +// } +// } +// +// public bool Match(object? data) +// { +// return data is ViewModelBase; +// } +// } + + +public sealed class ViewSelector : AvaloniaObject, IDataTemplate +{ + private IServices? _services; + + public static readonly DirectProperty ServicesProperty = + AvaloniaProperty.RegisterDirect(nameof(Services), o => o.Services, (o, v) => o.Services = v); + + public ViewSelector() + { + + } + public IServices? Services + { + get => this._services; + set => SetAndRaise(ServicesProperty, ref this._services, value); + } + + public Control? Build(object? param) + { + if (param == null) throw new NullReferenceException(nameof(param)); + var name = param.GetType().FullName!.Replace("ViewModel", "View"); + var type = Type.GetType(name); + + if (type != null) + { + return (Control?)Activator.CreateInstance(type); + } + else + { + return new TextBlock { Text = "2Not Found: " + name }; + } + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} diff --git a/Notes/ViewModels/AboutViewModel.cs b/Notes/ViewModels/AboutViewModel.cs new file mode 100644 index 0000000..ea5b152 --- /dev/null +++ b/Notes/ViewModels/AboutViewModel.cs @@ -0,0 +1,37 @@ +using System; +using CommunityToolkit.Mvvm.Input; +using System.Windows.Input; + +namespace Notes.ViewModels; + +public partial class AboutViewModel:ViewModelBase +{ + private readonly IServices _services; + public string Title => AppInfo.Name; + public string Version => AppInfo.VersionString; + private string Message => "This app is written in XAML and C# with Avalonia UI"; + + [RelayCommand] + public void ShowAllNotes() + { + _services.GetAs().Navitation(this._services); + } + + [Obsolete("Used by designer",true)] +#pragma warning disable CS8618 + public AboutViewModel() +#pragma warning restore CS8618 + { + + } + public AboutViewModel(IServices services) + { + this._services = services; + } +} + +internal class AppInfo +{ + public static string Name = "Cal Note"; + public static string VersionString = "1.0.0"; +} \ No newline at end of file diff --git a/Notes/ViewModels/AllNotesViewModel.cs b/Notes/ViewModels/AllNotesViewModel.cs new file mode 100644 index 0000000..140ba8a --- /dev/null +++ b/Notes/ViewModels/AllNotesViewModel.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.ObjectModel; +using System.Linq; +using Avalonia.Controls.Selection; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Notes.Models; + +namespace Notes.ViewModels; + + +public partial class AllNotesViewModel: ViewModelBase +{ + private readonly IServices _services; + + [ObservableProperty] + private ObservableCollection _notes; + [ObservableProperty] + private ObservableCollection _noteViewModels; + + private Models.Notes _originNotes; + + + [RelayCommand] + public void NewNote() + { + var note = new Note(); + note.Filename = string.Empty; + this._services.GetAs().Navitation(this._services,this,note); + } + [RelayCommand] + public void DeleteNote(ISelectionModel selectionModel) + { + for (var index = selectionModel.SelectedIndexes.Count - 1; index >= 0; index--) + { + var selectionModelSelectedIndex = selectionModel.SelectedIndexes[index]; + NoteViewModels.RemoveAt(selectionModelSelectedIndex); + var note = this.Notes[selectionModelSelectedIndex]; + Notes.RemoveAt(selectionModelSelectedIndex); + _originNotes.Delete(note); + } + } + [RelayCommand] + public void OpenAbout() + { + this._services.GetAs().Navitation(this._services); + } + + [Obsolete("Used by designer",true)] +#pragma warning disable CS8618 + public AllNotesViewModel():base() +#pragma warning restore CS8618 + { + + } + public AllNotesViewModel(IServices services) + { + this._services = services; + this._originNotes = new Models.Notes(); + _notes = new ObservableCollection(this._originNotes.notes); + _noteViewModels = new ObservableCollection(); + foreach (var note in this._notes) + { + this._noteViewModels.Add(new NoteViewModel(services,this,note)); + } + } + + + public void AddNote(NoteViewModel viewModel) + { + var viewModelNote = viewModel.Note; + if (NoteViewModels.Contains(viewModel)) + { + return; + } + if (this.Notes.Any(x=>x.Filename == viewModel.Note.Filename)) + { + return; + } + Notes.Add(viewModelNote); + this._originNotes.notes.Add(viewModelNote); + this.NoteViewModels.Add(viewModel); + } +} \ No newline at end of file diff --git a/Notes/ViewModels/MainViewModel.cs b/Notes/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..ddfa105 --- /dev/null +++ b/Notes/ViewModels/MainViewModel.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using CommunityToolkit.Mvvm.ComponentModel; +using Utils; + +namespace Notes.ViewModels; + +public interface IServices +{ + void Register(T t); + T? Get(); + T GetAs(); +} + +public sealed class Sevices:IServices +{ + private readonly Dictionary map = new Dictionary(); + public void Register(T t) + { + map.Add(typeof(T), t); + } + + public T? Get() + { + map.TryGetValue(typeof(T), out var t); + return (T?)t; + } + + public T GetAs() + { + T? foo = this.Get(); + if (foo is { } t) + return t; + throw new InvalidOperationException($"Not find type '{typeof(T)}'"); + } +} +public partial class MainViewModel:ViewModelBase +{ + /// + /// current viewModel + /// + [ObservableProperty] private ViewModelBase _contentViewModel; + + [ObservableProperty] + private IServices _service; + + public MainViewModel() + { + _service = new Sevices(); + _service.Register(this); + _contentViewModel = new AboutViewModel(_service); + } + + public void Navitation(params object[] param) + { + var type = typeof(T); + if (type.IsAssignableTo(typeof(ViewModelBase))) + { + ViewModelBase? instance = (ViewModelBase?)Activator.CreateInstance(type, param); + if (instance == null) throw new NullReferenceException(nameof(instance)); + this.ContentViewModel = instance; + return; + } + + throw new InvalidOperationException($"{typeof(T)} is not a {nameof(ViewModelBase)}"); + } +} \ No newline at end of file diff --git a/Notes/ViewModels/NoteViewModel.cs b/Notes/ViewModels/NoteViewModel.cs new file mode 100644 index 0000000..421b139 --- /dev/null +++ b/Notes/ViewModels/NoteViewModel.cs @@ -0,0 +1,68 @@ +using System; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Notes.Models; + +namespace Notes.ViewModels; + +public partial class NoteViewModel:ViewModelBase +{ + private readonly IServices _services; + + [ObservableProperty] + private AllNotesViewModel _allNotesViewModel; + + [ObservableProperty] + private Note _note; + + [Obsolete("Used by designer",true)] +#pragma warning disable CS8618 + public NoteViewModel():base() +#pragma warning restore CS8618 + { + + } + public NoteViewModel(IServices services,AllNotesViewModel allNotesViewModel, Note note) + { + this._note = note; + this._allNotesViewModel = allNotesViewModel; + this._services = services; + } + + public void SaveNote(string? iptTitleText, string? iptContentText) + { + if (string.IsNullOrWhiteSpace(iptTitleText)) + { + return; + } + var newName = $"{iptTitleText}{Models.Note.Extension}"; + Models.Note note = _note; + note.Filename = newName; + note.Text = iptContentText; + note.Date = TimeProvider.System.GetLocalNow().DateTime; + note.Save(); + Note = note; + AllNotesViewModel.AddNote(this); +// this.OnPropertyChanged(nameof(AllNotesViewModel.NoteViewModels)); + } + public void Back() + { + _services.GetAs().Navitation(this._services); + } + + [RelayCommand] + public void OpenNote() + { + this._services.GetAs().Navitation(this._services,this.AllNotesViewModel, this.Note); + } + + public void NewNote() + { + AllNotesViewModel.NewNote(); + } + + public void ReplaceNote(Note note) + { + Note = note; + } +} \ No newline at end of file diff --git a/Notes/ViewModels/ViewModelBase.cs b/Notes/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..a128f78 --- /dev/null +++ b/Notes/ViewModels/ViewModelBase.cs @@ -0,0 +1,9 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace Notes.ViewModels; + +public class ViewModelBase : ObservableObject +{ + + +} \ No newline at end of file diff --git a/Notes/Views/AboutView.axaml b/Notes/Views/AboutView.axaml new file mode 100644 index 0000000..becd2c6 --- /dev/null +++ b/Notes/Views/AboutView.axaml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Notes/Views/NoteView.axaml.cs b/Notes/Views/NoteView.axaml.cs new file mode 100644 index 0000000..a3db798 --- /dev/null +++ b/Notes/Views/NoteView.axaml.cs @@ -0,0 +1,54 @@ +using System; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using Notes.ViewModels; + +namespace Notes.Views; + +public partial class NoteView : UserControl +{ + private NoteViewModel _viewModel; + public NoteView() + { + InitializeComponent(); + + this.btnSave.Click += BtnSaveOnClick; + this.btnBack.Click += BtnBackOnClick; + this.btnNew.Click += BtnNewOnClick; + } + + + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + var noteViewModel = this.DataContext as NoteViewModel; + if (noteViewModel == null) throw new NullReferenceException(nameof(noteViewModel)); + _viewModel = noteViewModel; + } + + private void BtnSaveOnClick(object? sender, RoutedEventArgs e) + { + var iptTitleText = this.iptTitle.Text; + var iptContentText = this.iptContent.Text; + _viewModel.SaveNote(iptTitleText,iptContentText); + } + private void BtnBackOnClick(object? sender, RoutedEventArgs e) + { + _viewModel.Back(); + } + private void BtnNewOnClick(object? sender, RoutedEventArgs e) + { + this._viewModel.NewNote(); + } + + private void SelectingItemsControl_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) + { + if(e.AddedItems.Count==0) + return; + var noteViewModel = (NoteViewModel?)e.AddedItems[0]; + if (noteViewModel == null) throw new NullReferenceException(nameof(noteViewModel)); + this._viewModel.ReplaceNote(noteViewModel.Note); + } +} \ No newline at end of file