Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Oct 3, 2021
0 parents commit dbca2fb
Show file tree
Hide file tree
Showing 18 changed files with 666 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin
obj
.idea
*.user
16 changes: 16 additions & 0 deletions Portramatic.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portramatic", "Portramatic\Portramatic.csproj", "{E1DEBD84-A5DD-43CA-97B6-FF326346D25E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E1DEBD84-A5DD-43CA-97B6-FF326346D25E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1DEBD84-A5DD-43CA-97B6-FF326346D25E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1DEBD84-A5DD-43CA-97B6-FF326346D25E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1DEBD84-A5DD-43CA-97B6-FF326346D25E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions Portramatic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea/
.vscode/
.vs/

bin/
obj/

*.user
12 changes: 12 additions & 0 deletions Portramatic/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Portramatic"
x:Class="Portramatic.App">
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<FluentTheme Mode="Dark"/>
</Application.Styles>
</Application>
29 changes: 29 additions & 0 deletions Portramatic/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Portramatic.ViewModels;
using Portramatic.Views;

namespace Portramatic
{
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}

base.OnFrameworkInitializationCompleted();
}
}
}
Binary file added Portramatic/Assets/avalonia-logo.ico
Binary file not shown.
27 changes: 27 additions & 0 deletions Portramatic/Extensions/IObservableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Reactive.Disposables;
using System.Reactive.Subjects;
using System.Threading.Tasks;

namespace Portramatic.Extensions
{
public static class IObservableExtensions
{

public static IObservable<TOut> SelectAsync<TIn, TOut>(this IObservable<TIn> input,
CompositeDisposable disposable,
Func<TIn, ValueTask<TOut>> func)
{
Subject<TOut> returnObs = new();

input.Subscribe(x => Task.Run(async () =>
{
var result = await func(x);
returnObs.OnNext(result);
})).DisposeWith(disposable);

return returnObs;
}

}
}
17 changes: 17 additions & 0 deletions Portramatic/Extensions/IgnoreIObservable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Portramatic.Extensions;

public class IgnoreIObservable<T> : JsonConverter<IObservable<T>>
{
public override IObservable<T>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
public override void Write(Utf8JsonWriter writer, IObservable<T> value, JsonSerializerOptions options)
{
return;
}
}
3 changes: 3 additions & 0 deletions Portramatic/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ReactiveUI />
</Weavers>
26 changes: 26 additions & 0 deletions Portramatic/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ReactiveUI" minOccurs="0" maxOccurs="1" type="xs:anyType" />
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
21 changes: 21 additions & 0 deletions Portramatic/Portramatic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.7" />
<PackageReference Include="Avalonia.Controls.PanAndZoom" Version="4.0.0" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.7" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.7" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.7" />
<PackageReference Include="ReactiveUI.Fody" Version="16.2.6" />
<PackageReference Include="ReactiveUI.Validation" Version="2.2.1" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions Portramatic/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;

namespace Portramatic
{
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.
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<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
}
}
32 changes: 32 additions & 0 deletions Portramatic/ViewLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Portramatic.ViewModels;

namespace Portramatic
{
public class ViewLocator : IDataTemplate
{
public bool SupportsRecycling => false;

public IControl Build(object data)
{
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);

if (type != null)
{
return (Control)Activator.CreateInstance(type)!;
}
else
{
return new TextBlock { Text = "Not Found: " + name };
}
}

public bool Match(object data)
{
return data is ViewModelBase;
}
}
}
81 changes: 81 additions & 0 deletions Portramatic/ViewModels/CroppedImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace Portramatic.ViewModels;

public enum ImageSize
{
Small,
Medium,
Full
}

public class CroppedImage : ViewModelBase
{
[Reactive]
[JsonPropertyName("scale")]
public double Scale { get; set; }

[Reactive]
[JsonPropertyName("offset_x")]
public double OffsetX { get; set; }

[Reactive]
[JsonPropertyName("offset_y")]
public double OffsetY { get; set; }

[Reactive]
[JsonPropertyName("size")]
public ImageSize Size { get; set; }

[JsonIgnore]
public (int, int) FinalSize =>
Size switch
{
ImageSize.Full => (692, 1024),
ImageSize.Medium => (330, 432),
ImageSize.Small => (185, 242),
_ => throw new ArgumentOutOfRangeException()
};

[JsonIgnore]
public string FileName =>
Size switch
{
ImageSize.Full => "Fulllength.png",
ImageSize.Medium => "Medium.png",
ImageSize.Small => "Small.png",
_ => throw new ArgumentOutOfRangeException()
};
}


public class PortraitDefinition : ViewModelBase
{
[Reactive]
[JsonPropertyName("source")]
public Uri Source { get; set; }

[Reactive]
[JsonPropertyName("md5")]
public string MD5 { get; set; }

[Reactive]
[JsonPropertyName("tags")]
public string[] Tags { get; set; }

[Reactive]
[JsonPropertyName("small")]
public CroppedImage Small { get; set; } = new() {Size = ImageSize.Small};

[Reactive]
[JsonPropertyName("medium")]
public CroppedImage Medium { get; set; } = new() {Size = ImageSize.Medium};

[Reactive]
[JsonPropertyName("full")]
public CroppedImage Full { get; set; } = new() { Size = ImageSize.Full };
}
Loading

0 comments on commit dbca2fb

Please sign in to comment.