UI adjustment

This commit is contained in:
2020-05-09 08:38:31 +08:00
parent 33cac052f6
commit 8c9f79f06d
19 changed files with 492 additions and 314 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
@@ -58,6 +59,13 @@ namespace Pixiview.Utils
{
favoriteObject = favorites;
}
else
{
favoriteObject = new IllustFavorite
{
Illusts = new List<IllustItem>()
};
}
}
return favoriteObject;
}
@@ -89,7 +97,7 @@ namespace Pixiview.Utils
private static T LoadObject<T>(string file, string url, string referer = null, bool force = false)
{
string content = null;
if (!force && File.Exists(file))
if (!force && file != null && File.Exists(file))
{
try
{
@@ -117,18 +125,21 @@ namespace Pixiview.Utils
using (response)
{
content = response.Content.ReadAsStringAsync().Result;
try
if (file != null)
{
var folder = Path.GetDirectoryName(file);
if (!Directory.Exists(folder))
try
{
Directory.CreateDirectory(folder);
var folder = Path.GetDirectoryName(file);
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
File.WriteAllText(file, content, Encoding.UTF8);
}
catch (Exception ex)
{
App.DebugError("save", $"failed to save illust JSON object, error: {ex.Message}");
}
File.WriteAllText(file, content, Encoding.UTF8);
}
catch (Exception ex)
{
App.DebugError("save", $"failed to save illust JSON object, error: {ex.Message}");
}
}
}
@@ -222,14 +233,32 @@ namespace Pixiview.Utils
return result;
}
public static IllustUserData LoadIllustUserData(string userId, bool force = false)
{
var list = LoadObject<IllustUserListData>(
null,
string.Format(Configs.UrlIllustUserAll, userId),
string.Format(Configs.UrlIllustUser, userId),
force: force);
var ids = string.Join("&ids%5B%5D=", list.body.illusts.Keys.Take(20));
var result = LoadObject<IllustUserData>(
null,
string.Format(Configs.UrlIllustUserArtworks, userId, ids, 1),
string.Format(Configs.UrlIllustUser, userId),
force: force);
return result;
}
public static ImageSource LoadIllustImage(string url)
{
return LoadImage(url, PersonalFolder, imageFolder);
}
public static ImageSource LoadPreviewImage(string url)
public static ImageSource LoadPreviewImage(string url, bool downloading = true)
{
return LoadImage(url, PersonalFolder, previewFolder);
return LoadImage(url, PersonalFolder, previewFolder, downloading);
}
public static ImageSource LoadThumbnailImage(string url)
@@ -258,7 +287,7 @@ namespace Pixiview.Utils
return null;
}
private static ImageSource LoadImage(string url, string working, string folder)
private static ImageSource LoadImage(string url, string working, string folder, bool downloading = true)
{
var file = Path.Combine(working, folder, Path.GetFileName(url));
ImageSource image;
@@ -278,7 +307,7 @@ namespace Pixiview.Utils
{
image = null;
}
if (image == null)
if (downloading && image == null)
{
file = DownloadImage(url, working, folder);
if (file != null)
@@ -386,6 +415,9 @@ namespace Pixiview.Utils
public const int MaxThreads = 3;
public const string UrlIllustList = "https://www.pixiv.net/ajax/top/illust?mode=all&lang=zh";
public const string UrlIllust = "https://www.pixiv.net/artworks/{0}";
public const string UrlIllustUserAll = "https://www.pixiv.net/ajax/user/{0}/profile/all?lang=zh";
public const string UrlIllustUserArtworks = "https://www.pixiv.net/ajax/user/{0}/profile/illusts?ids%5B%5D={1}&work_category=illustManga&is_first_page={2}&lang=zh";
public const string UrlIllustUser = "https://www.pixiv.net/users/{0}/artworks";
public const string UrlIllustPage = "https://www.pixiv.net/ajax/illust/{0}/pages?lang=zh";
public const string UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36";
public const string AcceptImage = "image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5";