favorite issue fix.

This commit is contained in:
Tsanie Lily 2021-08-04 21:51:31 +08:00
parent a553b156f7
commit c60e3a6445
4 changed files with 137 additions and 118 deletions

View File

@ -18,7 +18,7 @@
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>Apple Development: Li Chen (5559SN7Z38)</CodesignKey>
<CodesignKey>Apple Distribution: Li Chen (7HSM5CKPJ2)</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchFastDev>true</MtouchFastDev>
@ -28,6 +28,7 @@
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<DeviceSpecificBuild>false</DeviceSpecificBuild>
<MtouchVerbosity></MtouchVerbosity>
<CodesignProvision>Gallery.Extensions.Ad-Hoc</CodesignProvision>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>pdbonly</DebugType>
@ -68,7 +69,7 @@
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>Apple Development: Li Chen (5559SN7Z38)</CodesignKey>
<CodesignKey>Apple Distribution: Li Chen (7HSM5CKPJ2)</CodesignKey>
<DeviceSpecificBuild>true</DeviceSpecificBuild>
<MtouchDebug>true</MtouchDebug>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
@ -80,6 +81,7 @@
<MtouchArch>ARM64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<MtouchVerbosity></MtouchVerbosity>
<CodesignProvision>Gallery.Extensions.Ad-Hoc</CodesignProvision>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

View File

@ -32,6 +32,7 @@ namespace Gallery.Utils
[JsonInclude]
public string illustTitle;
[JsonInclude]
[JsonConverter(typeof(StringConverter))]
public string id;
[JsonInclude]
public string title;
@ -46,6 +47,7 @@ namespace Gallery.Utils
[JsonInclude]
public string[] tags;
[JsonInclude]
[JsonConverter(typeof(StringConverter))]
public string userId;
[JsonInclude]
public string userName;

View File

@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using Gallery.Illust;
@ -239,6 +240,10 @@ namespace Gallery.Utils
{
return reader.GetString();
}
else if (reader.TokenType == JsonTokenType.Number)
{
return reader.GetInt64().ToString();
}
return null;
}
@ -247,4 +252,118 @@ namespace Gallery.Utils
throw new System.NotImplementedException();
}
}
public class FavoriteListConverter : JsonConverter<FavoriteList>
{
public override FavoriteList Read(ref Utf8JsonReader reader, System.Type typeToConvert, JsonSerializerOptions options)
{
var list = new FavoriteList();
if (reader.TokenType != JsonTokenType.StartArray)
{
return list;
}
var item = new IllustItem();
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray)
{
return list;
}
if (reader.TokenType == JsonTokenType.EndObject)
{
list.Add(item);
item = new IllustItem();
}
else if (reader.TokenType == JsonTokenType.PropertyName)
{
var name = reader.GetString();
reader.Read();
switch (name)
{
case nameof(IllustItem.Title): item.Title = reader.GetString(); break;
case nameof(IllustItem.Id): item.Id = reader.GetString(); break;
case nameof(IllustItem.BookmarkId): item.BookmarkId = reader.GetString(); break;
case nameof(IllustItem.FavoriteDateUtc): item.FavoriteDateUtc = reader.GetDateTime(); break;
case nameof(IllustItem.ImageUrl): item.ImageUrl = reader.GetString(); break;
case nameof(IllustItem.IsRestrict): item.IsRestrict = reader.GetBoolean(); break;
case nameof(IllustItem.Tags):
if (reader.TokenType == JsonTokenType.StartArray)
{
var tags = new List<string>();
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray)
{
break;
}
if (reader.TokenType == JsonTokenType.String)
{
tags.Add(reader.GetString());
}
}
item.Tags = tags.ToArray();
}
break;
case nameof(IllustItem.ProfileUrl): item.ProfileUrl = reader.GetString(); break;
case nameof(IllustItem.UserId): item.UserId = reader.GetString(); break;
case nameof(IllustItem.UserName): item.UserName = reader.GetString(); break;
case nameof(IllustItem.Width): item.Width = reader.GetInt32(); break;
case nameof(IllustItem.Height): item.Height = reader.GetInt32(); break;
case nameof(IllustItem.PageCount): item.PageCount = reader.GetInt32(); break;
case nameof(IllustItem.ImageHeightValue): item.ImageHeightValue = reader.GetDouble(); break;
case nameof(IllustItem.YesRank): item.YesRank = reader.GetInt32(); break;
case nameof(IllustItem.RatingCount): item.RatingCount = reader.GetInt32(); break;
case nameof(IllustItem.ViewCount): item.ViewCount = reader.GetInt32(); break;
case nameof(IllustItem.UploadTimestamp): item.UploadTimestamp = reader.GetInt64(); break;
case nameof(IllustItem.IllustType): item.IllustType = (IllustType)reader.GetInt32(); break;
}
}
}
throw new JsonException("unexpected favorite list ending");
}
public override void Write(Utf8JsonWriter writer, FavoriteList value, JsonSerializerOptions options)
{
writer.WriteStartArray();
if (value != null)
{
for (var i = 0; i < value.Count; i++)
{
var item = value[i];
writer.WriteStartObject();
writer.WriteString(nameof(IllustItem.Title), item.Title);
writer.WriteString(nameof(IllustItem.Id), item.Id);
writer.WriteString(nameof(IllustItem.BookmarkId), item.BookmarkId);
writer.WriteString(nameof(IllustItem.FavoriteDateUtc), item.FavoriteDateUtc);
writer.WriteString(nameof(IllustItem.ImageUrl), item.ImageUrl);
writer.WriteBoolean(nameof(IllustItem.IsRestrict), item.IsRestrict);
if (item.Tags != null)
{
writer.WritePropertyName(nameof(IllustItem.Tags));
writer.WriteStartArray();
for (var n = 0; n < item.Tags.Length; n++)
{
writer.WriteStringValue(item.Tags[n]);
}
writer.WriteEndArray();
}
writer.WriteString(nameof(IllustItem.ProfileUrl), item.ProfileUrl);
writer.WriteString(nameof(IllustItem.UserId), item.UserId);
writer.WriteString(nameof(IllustItem.UserName), item.UserName);
writer.WriteNumber(nameof(IllustItem.Width), item.Width);
writer.WriteNumber(nameof(IllustItem.Height), item.Height);
writer.WriteNumber(nameof(IllustItem.PageCount), item.PageCount);
writer.WriteNumber(nameof(IllustItem.ImageHeightValue), item.ImageHeightValue);
writer.WriteNumber(nameof(IllustItem.YesRank), item.YesRank);
writer.WriteNumber(nameof(IllustItem.RatingCount), item.RatingCount);
writer.WriteNumber(nameof(IllustItem.ViewCount), item.ViewCount);
writer.WriteNumber(nameof(IllustItem.UploadTimestamp), item.UploadTimestamp);
writer.WriteNumber(nameof(IllustItem.IllustType), (int)item.IllustType);
writer.WriteEndObject();
}
}
writer.WriteEndArray();
}
}
}

View File

@ -516,10 +516,20 @@ namespace Gallery.Utils
null,
string.Format(Configs.UrlFavoriteList, userId, offset, 48),
string.Format(Configs.RefererFavorites, userId),
#if DEBUG
out string error);
if (error != null)
{
App.DebugPrint($"error to deserialize json: {error}");
}
#else
out _);
#endif
if (result == null || result.error)
{
App.DebugPrint($"error when load favorites data: {result?.message}");
break;
}
else
{
@ -534,7 +544,7 @@ namespace Gallery.Utils
list.AddRange(result.body.works.Select(i => i.ConvertToItem()));
}
}
return list.Where(l => l != null).ToArray();
return list.Where(l => l != null && l.ProfileUrl != null).ToArray();
}
public static ImageSource LoadIllustImage(string url)
@ -684,120 +694,6 @@ namespace Gallery.Utils
}
}
public class FavoriteListConverter : JsonConverter<FavoriteList>
{
public override FavoriteList Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var list = new FavoriteList();
if (reader.TokenType != JsonTokenType.StartArray)
{
return list;
}
var item = new IllustItem();
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray)
{
return list;
}
if (reader.TokenType == JsonTokenType.EndObject)
{
list.Add(item);
item = new IllustItem();
}
else if (reader.TokenType == JsonTokenType.PropertyName)
{
var name = reader.GetString();
reader.Read();
switch (name)
{
case nameof(IllustItem.Title): item.Title = reader.GetString(); break;
case nameof(IllustItem.Id): item.Id = reader.GetString(); break;
case nameof(IllustItem.BookmarkId): item.BookmarkId = reader.GetString(); break;
case nameof(IllustItem.FavoriteDateUtc): item.FavoriteDateUtc = reader.GetDateTime(); break;
case nameof(IllustItem.ImageUrl): item.ImageUrl = reader.GetString(); break;
case nameof(IllustItem.IsRestrict): item.IsRestrict = reader.GetBoolean(); break;
case nameof(IllustItem.Tags):
if (reader.TokenType == JsonTokenType.StartArray)
{
var tags = new List<string>();
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray)
{
break;
}
if (reader.TokenType == JsonTokenType.String)
{
tags.Add(reader.GetString());
}
}
item.Tags = tags.ToArray();
}
break;
case nameof(IllustItem.ProfileUrl): item.ProfileUrl = reader.GetString(); break;
case nameof(IllustItem.UserId): item.UserId = reader.GetString(); break;
case nameof(IllustItem.UserName): item.UserName = reader.GetString(); break;
case nameof(IllustItem.Width): item.Width = reader.GetInt32(); break;
case nameof(IllustItem.Height): item.Height = reader.GetInt32(); break;
case nameof(IllustItem.PageCount): item.PageCount = reader.GetInt32(); break;
case nameof(IllustItem.ImageHeightValue): item.ImageHeightValue = reader.GetDouble(); break;
case nameof(IllustItem.YesRank): item.YesRank = reader.GetInt32(); break;
case nameof(IllustItem.RatingCount): item.RatingCount = reader.GetInt32(); break;
case nameof(IllustItem.ViewCount): item.ViewCount = reader.GetInt32(); break;
case nameof(IllustItem.UploadTimestamp): item.UploadTimestamp = reader.GetInt64(); break;
case nameof(IllustItem.IllustType): item.IllustType = (IllustType)reader.GetInt32(); break;
}
}
}
throw new JsonException("unexpected favorite list ending");
}
public override void Write(Utf8JsonWriter writer, FavoriteList value, JsonSerializerOptions options)
{
writer.WriteStartArray();
if (value != null)
{
for (var i = 0; i < value.Count; i++)
{
var item = value[i];
writer.WriteStartObject();
writer.WriteString(nameof(IllustItem.Title), item.Title);
writer.WriteString(nameof(IllustItem.Id), item.Id);
writer.WriteString(nameof(IllustItem.BookmarkId), item.BookmarkId);
writer.WriteString(nameof(IllustItem.FavoriteDateUtc), item.FavoriteDateUtc);
writer.WriteString(nameof(IllustItem.ImageUrl), item.ImageUrl);
writer.WriteBoolean(nameof(IllustItem.IsRestrict), item.IsRestrict);
if (item.Tags != null)
{
writer.WritePropertyName(nameof(IllustItem.Tags));
writer.WriteStartArray();
for (var n = 0; n < item.Tags.Length; n++)
{
writer.WriteStringValue(item.Tags[n]);
}
writer.WriteEndArray();
}
writer.WriteString(nameof(IllustItem.ProfileUrl), item.ProfileUrl);
writer.WriteString(nameof(IllustItem.UserId), item.UserId);
writer.WriteString(nameof(IllustItem.UserName), item.UserName);
writer.WriteNumber(nameof(IllustItem.Width), item.Width);
writer.WriteNumber(nameof(IllustItem.Height), item.Height);
writer.WriteNumber(nameof(IllustItem.PageCount), item.PageCount);
writer.WriteNumber(nameof(IllustItem.ImageHeightValue), item.ImageHeightValue);
writer.WriteNumber(nameof(IllustItem.YesRank), item.YesRank);
writer.WriteNumber(nameof(IllustItem.RatingCount), item.RatingCount);
writer.WriteNumber(nameof(IllustItem.ViewCount), item.ViewCount);
writer.WriteNumber(nameof(IllustItem.UploadTimestamp), item.UploadTimestamp);
writer.WriteNumber(nameof(IllustItem.IllustType), (int)item.IllustType);
writer.WriteEndObject();
}
}
writer.WriteEndArray();
}
}
public enum SyncType
{
None = 0,