feature: parellel downloading animation

This commit is contained in:
2020-05-15 16:44:06 +08:00
parent 2da73d5f51
commit 00e8fe0f04
6 changed files with 566 additions and 327 deletions

View File

@@ -19,6 +19,8 @@ namespace Pixiview.Illust
public static readonly BindableProperty IllustsProperty = BindableProperty.Create(
nameof(Illusts), typeof(IllustDetailItem[]), typeof(ViewIllustPage));
public static readonly BindableProperty IsPageVisibleProperty = BindableProperty.Create(
nameof(IsPageVisible), typeof(bool), typeof(ViewIllustPage));
public static readonly BindableProperty PagePositionTextProperty = BindableProperty.Create(
nameof(PagePositionText), typeof(string), typeof(ViewIllustPage));
public static readonly BindableProperty CurrentPageProperty = BindableProperty.Create(
@@ -64,6 +66,11 @@ namespace Pixiview.Illust
get => (IllustDetailItem[])GetValue(IllustsProperty);
set => SetValue(IllustsProperty, value);
}
public bool IsPageVisible
{
get => (bool)GetValue(IsPageVisibleProperty);
set => SetValue(IsPageVisibleProperty, value);
}
public string PagePositionText
{
get => (string)GetValue(PagePositionTextProperty);
@@ -101,7 +108,6 @@ namespace Pixiview.Illust
}
public IllustItem IllustItem { get; private set; }
public bool IsPageVisible { get; private set; }
private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads };
private readonly bool saveFavorites;
@@ -124,9 +130,8 @@ namespace Pixiview.Illust
? fontIconLove
: fontIconNotLove;
var pageVisible = illust != null && illust.PageCount > 1;
IsPageVisible = pageVisible;
Resources.Add("carouselView", GetCarouseTemplate(pageVisible));
IsPageVisible = illust != null && illust.PageCount > 1;
Resources.Add("carouselView", GetCarouseTemplate());
InitializeComponent();
@@ -156,6 +161,7 @@ namespace Pixiview.Illust
if (ugoira != null)
{
IllustItem.IsPlaying = false;
ugoira.FrameChanged -= OnUgoiraFrameChanged;
ugoira.TogglePlay(false);
ugoira.Dispose();
ugoira = null;
@@ -167,11 +173,8 @@ namespace Pixiview.Illust
}
}
private DataTemplate GetCarouseTemplate(bool multiPages)
private DataTemplate GetCarouseTemplate()
{
var tap = new TapGestureRecognizer();
tap.Tapped += Image_Tapped;
return new DataTemplate(() =>
{
// image
@@ -179,8 +182,7 @@ namespace Pixiview.Illust
{
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.Fill,
Aspect = Aspect.AspectFit,
GestureRecognizers = { tap }
Aspect = Aspect.AspectFit
}
.Binding(Image.SourceProperty, nameof(IllustDetailItem.Image));
@@ -214,51 +216,12 @@ namespace Pixiview.Illust
.Binding(IsVisibleProperty, nameof(IllustDetailItem.Downloading))
.DynamicResource(ActivityIndicator.ColorProperty, ThemeBase.TextColor);
if (multiPages)
{
var tapPrevious = new TapGestureRecognizer();
tapPrevious.Tapped += TapPrevious_Tapped;
var tapNext = new TapGestureRecognizer();
tapNext.Tapped += TapNext_Tapped;
return new Grid
{
Children =
{
// image
image,
// tap holder
new Grid
{
RowDefinitions =
{
new RowDefinition(),
new RowDefinition(),
new RowDefinition()
},
Children =
{
new Label
{
GestureRecognizers = { tapPrevious }
},
new Label
{
GestureRecognizers = { tapNext }
}
.GridRow(2)
}
},
// downloading
downloading,
// loading original
original
}
};
}
var tap = new TapGestureRecognizer();
tap.Tapped += Image_Tapped;
var tapPrevious = new TapGestureRecognizer();
tapPrevious.Tapped += TapPrevious_Tapped;
var tapNext = new TapGestureRecognizer();
tapNext.Tapped += TapNext_Tapped;
return new Grid
{
@@ -267,6 +230,23 @@ namespace Pixiview.Illust
// image
image,
// tap holder
new Grid
{
RowDefinitions =
{
new RowDefinition { Height = new GridLength(.3, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(.4, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(.3, GridUnitType.Star) }
},
Children =
{
new Label { GestureRecognizers = { tapPrevious } },
new Label { GestureRecognizers = { tap } }.GridRow(1),
new Label { GestureRecognizers = { tapNext } }.GridRow(2)
}
},
// downloading
downloading,
@@ -346,7 +326,12 @@ namespace Pixiview.Illust
if (preload != null && preload.illust.TryGetValue(illustItem.Id, out var illust))
{
illust.CopyToItem(illustItem);
MainThread.BeginInvokeOnMainThread(() => Title = illustItem.Title);
MainThread.BeginInvokeOnMainThread(() =>
{
Title = illustItem.Title;
IsPageVisible = illustItem.PageCount > 1;
IsAnimateSliderVisible = illustItem.IsAnimeVisible;
});
if (preload.user.TryGetValue(illust.userId, out var user))
{
illustItem.ProfileUrl = user.image;
@@ -463,10 +448,9 @@ namespace Pixiview.Illust
ugoira.TogglePlay(playing);
illustItem.IsPlaying = playing;
}
else if (((Image)sender).BindingContext is IllustDetailItem item)
else if (((VisualElement)sender).BindingContext is IllustDetailItem item)
{
if (illustItem.IsPlaying ||
illustItem.IllustType != IllustType.Anime)
if (illustItem.IsPlaying || !illustItem.IsAnimeVisible)
{
return;
}