change: favorite merge rule

fix: page progress renderer
This commit is contained in:
Tsanie Lily 2020-05-16 00:02:14 +08:00
parent 8433b44d4f
commit ffb789b8b7
2 changed files with 70 additions and 49 deletions

View File

@ -18,6 +18,11 @@ namespace Pixiview
public static AppTheme CurrentTheme { get; private set; } public static AppTheme CurrentTheme { get; private set; }
public static PlatformCulture CurrentCulture { get; private set; } public static PlatformCulture CurrentCulture { get; private set; }
public App()
{
Device.SetFlags(new string[0]);
}
private void InitResources() private void InitResources()
{ {
var theme = AppInfo.RequestedTheme; var theme = AppInfo.RequestedTheme;
@ -137,47 +142,70 @@ namespace Pixiview
ResourceHelper.Ok)); ResourceHelper.Ok));
} }
} }
else if (File.Exists(url)) else
{ {
IllustFavorite favObj; url = System.Net.WebUtility.UrlDecode(url);
try if (File.Exists(url))
{ {
favObj = Stores.LoadFavoritesIllusts(url); IllustFavorite favObj;
} try
catch (Exception ex)
{
DebugError("open.file", $"failed to parse file, name: {url}, error: {ex.Message}");
return true;
}
var path = Stores.FavoritesPath;
if (File.Exists(path))
{
MainThread.BeginInvokeOnMainThread(async () =>
{ {
var opReplace = ResourceHelper.FavoritesReplace; favObj = Stores.LoadFavoritesIllusts(url);
var opCombine = ResourceHelper.FavoritesCombine; }
var result = await current.DisplayActionSheet( catch (Exception ex)
ResourceHelper.FavoritesOperation, {
ResourceHelper.Cancel, DebugError("open.file", $"failed to parse file, name: {url}, error: {ex.Message}");
opCombine, return true;
opReplace); }
if (result == opReplace) var path = Stores.FavoritesPath;
if (url == path)
{
return false;
}
if (File.Exists(path))
{
MainThread.BeginInvokeOnMainThread(async () =>
{ {
// replace favorite file var opReplace = ResourceHelper.FavoritesReplace;
File.Copy(url, path, true); var opCombine = ResourceHelper.FavoritesCombine;
} var result = await current.DisplayActionSheet(
else if (result == opCombine) ResourceHelper.FavoritesOperation,
{ ResourceHelper.Cancel,
// combine favorite file opCombine,
var favNow = Stores.GetFavoriteObject(); opReplace);
var list = favObj.Illusts; if (result == opReplace)
var distinct = favNow.Illusts.Where(f => !list.Any(i => i.Id == f.Id)).ToList(); {
list.AddRange(distinct); // replace favorite file
File.Delete(path);
File.Move(url, path);
}
else if (result == opCombine)
{
// combine favorite file
var favNow = Stores.GetFavoriteObject();
var list = favNow.Illusts;
var distinct = favObj.Illusts.Where(f => !list.Any(i => i.Id == f.Id)).ToList();
list.InsertRange(0, distinct);
favNow.Illusts = list; favNow.Illusts = list;
Stores.SaveFavoritesIllusts(); Stores.SaveFavoritesIllusts();
} }
File.Delete(url);
if (Shell.Current.CurrentState.Location.OriginalString.EndsWith(Routes.Favorites))
{
var sc = (IShellSectionController)Shell.Current.CurrentItem.CurrentItem;
if (sc.PresentedPage is FavoritesPage fav)
{
fav.Reload(true);
}
}
});
}
else
{
File.Move(url, path);
if (Shell.Current.CurrentState.Location.OriginalString.EndsWith(Routes.Favorites)) if (Shell.Current.CurrentState.Location.OriginalString.EndsWith(Routes.Favorites))
{ {
var sc = (IShellSectionController)Shell.Current.CurrentItem.CurrentItem; var sc = (IShellSectionController)Shell.Current.CurrentItem.CurrentItem;
@ -186,18 +214,6 @@ namespace Pixiview
fav.Reload(true); fav.Reload(true);
} }
} }
});
}
else
{
File.Copy(url, path);
if (Shell.Current.CurrentState.Location.OriginalString.EndsWith(Routes.Favorites))
{
var sc = (IShellSectionController)Shell.Current.CurrentItem.CurrentItem;
if (sc.PresentedPage is FavoritesPage fav)
{
fav.Reload(true);
}
} }
} }
} }

View File

@ -122,7 +122,8 @@ namespace Pixiview.Illust
private IllustUgoiraData ugoiraData; private IllustUgoiraData ugoiraData;
private Ugoira ugoira; private Ugoira ugoira;
private volatile int downloaded = 0; private readonly object sync = new object();
private int downloaded = 0;
private int pageCount; private int pageCount;
public ViewIllustPage(IllustItem illust, bool save) public ViewIllustPage(IllustItem illust, bool save)
@ -413,11 +414,15 @@ namespace Pixiview.Illust
return; return;
} }
downloaded++; lock (sync)
{
downloaded++;
}
if (downloaded >= pageCount) if (downloaded >= pageCount)
{ {
MainThread.BeginInvokeOnMainThread(async () => MainThread.BeginInvokeOnMainThread(async () =>
{ {
ViewExtensions.CancelAnimations(progress);
await progress.ProgressTo(1, 250, Easing.CubicIn); await progress.ProgressTo(1, 250, Easing.CubicIn);
await progress.FadeTo(0, easing: Easing.CubicIn); await progress.FadeTo(0, easing: Easing.CubicIn);
ProgressVisible = false; ProgressVisible = false;