Переглянути джерело

fixed image resize and crash on end of posts

Veloe 1 рік тому
батько
коміт
21a763a477

+ 3 - 3
VeloeAvaloniaKemonoPartyApp/VeloeAvaloniaKemonoPartyApp.Android/VeloeAvaloniaKemonoPartyApp.Android.csproj

@@ -6,11 +6,11 @@
     <Nullable>enable</Nullable>
     <ApplicationId>com.Veloe.AvaloniaKemonoParty</ApplicationId>
     <ApplicationVersion>1</ApplicationVersion>
-    <ApplicationDisplayVersion>1.0.0.102</ApplicationDisplayVersion>
+    <ApplicationDisplayVersion>1.0.0.117</ApplicationDisplayVersion>
     <AndroidPackageFormat>apk</AndroidPackageFormat>
     <AndroidEnableProfiledAot>False</AndroidEnableProfiledAot>
-    <AssemblyVersion>1.0.0.102</AssemblyVersion>
-    <FileVersion>1.0.0.102</FileVersion>
+    <AssemblyVersion>1.0.0.117</AssemblyVersion>
+    <FileVersion>1.0.0.117</FileVersion>
   </PropertyGroup>
 
   <ItemGroup>

+ 2 - 2
VeloeAvaloniaKemonoPartyApp/VeloeAvaloniaKemonoPartyApp.Desktop/VeloeAvaloniaKemonoPartyApp.Desktop.csproj

@@ -10,8 +10,8 @@
 
   <PropertyGroup>
     <ApplicationManifest>app.manifest</ApplicationManifest>
-    <AssemblyVersion>1.0.0.95</AssemblyVersion>
-    <FileVersion>1.0.0.95</FileVersion>
+    <AssemblyVersion>1.0.0.97</AssemblyVersion>
+    <FileVersion>1.0.0.97</FileVersion>
   </PropertyGroup>
 
   <ItemGroup>

+ 7 - 3
VeloeAvaloniaKemonoPartyApp/VeloeAvaloniaKemonoPartyApp/Services/HttpClient.cs

@@ -57,9 +57,13 @@ namespace VeloeKemonoPartyApp.Services
             using (HttpResponseMessage response = await httpClient.GetAsync($"https://kemono.su/api/v1/{service}/user/{id}?o={start}" + (!string.IsNullOrEmpty(search) ? $"&q={search}" : string.Empty)))
             using (HttpContent content = response.Content)
             {
-                string jsonString = await response.Content.ReadAsStringAsync();
-                // ... Read the string.
-                return JsonSerializer.Deserialize<List<Post>>(jsonString);
+                if (response.IsSuccessStatusCode)
+                {
+                    string jsonString = await response.Content.ReadAsStringAsync();
+                    // ... Read the string.
+                    return JsonSerializer.Deserialize<List<Post>>(jsonString);
+                }
+                return new List<Post>();
             }
         }
 

+ 2 - 2
VeloeAvaloniaKemonoPartyApp/VeloeAvaloniaKemonoPartyApp/VeloeAvaloniaKemonoPartyApp.csproj

@@ -4,8 +4,8 @@
     <Nullable>enable</Nullable>
     <LangVersion>latest</LangVersion>
     <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
-    <AssemblyVersion>1.0.0.258</AssemblyVersion>
-    <FileVersion>1.0.0.258</FileVersion>
+    <AssemblyVersion>1.0.0.268</AssemblyVersion>
+    <FileVersion>1.0.0.268</FileVersion>
   </PropertyGroup>
 
   

+ 10 - 3
VeloeAvaloniaKemonoPartyApp/VeloeAvaloniaKemonoPartyApp/ViewModels/PostImageViewModel.cs

@@ -1,6 +1,7 @@
-using Avalonia.Interactivity;
+using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Interactivity;
 using Avalonia.Media.Imaging;
-using Avalonia.Threading;
 using HanumanInstitute.MvvmDialogs;
 using ReactiveUI;
 using System;
@@ -42,7 +43,13 @@ namespace VeloeAvaloniaKemonoPartyApp.ViewModels
                     try
                     {
                         bitmap = new Bitmap(imageStream);
-                        bitmap = bitmap.CreateScaledBitmap(new Avalonia.PixelSize(bitmap.PixelSize.Width / 2, bitmap.PixelSize.Height / 2));
+                        if (App.Current.ApplicationLifetime is ISingleViewApplicationLifetime lifetime)
+                        {
+                            var topLevel = TopLevel.GetTopLevel(lifetime.MainView);
+
+                            if (bitmap.Size.Width > Math.Ceiling(topLevel.ClientSize.Width * topLevel.RenderScaling))
+                                bitmap = bitmap.CreateScaledBitmap(new Avalonia.PixelSize((int)Math.Ceiling(topLevel.ClientSize.Width*topLevel.RenderScaling), (int)Math.Ceiling(topLevel.ClientSize.Width*topLevel.RenderScaling / bitmap.Size.AspectRatio)));
+                        }
                     }
                     catch (Exception ex)
                     {