feature: favorite illusts
This commit is contained in:
parent
84aecdf39b
commit
8cf9ae288b
@ -85,6 +85,11 @@
|
|||||||
Route="{x:Static util:Routes.Ranking}">
|
Route="{x:Static util:Routes.Ranking}">
|
||||||
<ShellContent ContentTemplate="{DataTemplate i:RankingPage}"/>
|
<ShellContent ContentTemplate="{DataTemplate i:RankingPage}"/>
|
||||||
</Tab>
|
</Tab>
|
||||||
|
<Tab Icon="{DynamicResource FontIconFavorite}"
|
||||||
|
Title="{r:Text Favorites}"
|
||||||
|
Route="{x:Static util:Routes.Favorites}">
|
||||||
|
<ShellContent ContentTemplate="{DataTemplate i:FavoritesPage}"/>
|
||||||
|
</Tab>
|
||||||
</FlyoutItem>
|
</FlyoutItem>
|
||||||
<FlyoutItem Icon="{DynamicResource FontIconOption}"
|
<FlyoutItem Icon="{DynamicResource FontIconOption}"
|
||||||
Title="{r:Text Option}"
|
Title="{r:Text Option}"
|
||||||
|
25
Pixiview/Illust/FavoritesPage.xaml
Normal file
25
Pixiview/Illust/FavoritesPage.xaml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<i:FavoriteIllustCollectionPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
xmlns:i="clr-namespace:Pixiview.Illust"
|
||||||
|
xmlns:u="clr-namespace:Pixiview.UI"
|
||||||
|
xmlns:r="clr-namespace:Pixiview.Resources"
|
||||||
|
x:Class="Pixiview.Illust.FavoritesPage"
|
||||||
|
BackgroundColor="{DynamicResource WindowColor}"
|
||||||
|
Title="{r:Text Favorites}">
|
||||||
|
<Grid>
|
||||||
|
<ScrollView HorizontalOptions="Fill">
|
||||||
|
<u:FlowLayout ItemsSource="{Binding Illusts}"
|
||||||
|
HorizontalOptions="Fill" Column="{Binding Columns}"
|
||||||
|
Margin="16" RowSpacing="16" ColumnSpacing="16"
|
||||||
|
ItemTemplate="{StaticResource cardView}"/>
|
||||||
|
</ScrollView>
|
||||||
|
<Frame HasShadow="False" Margin="0" Padding="20" CornerRadius="8"
|
||||||
|
IsVisible="{Binding Loading}"
|
||||||
|
HorizontalOptions="Center" VerticalOptions="Center"
|
||||||
|
BackgroundColor="{DynamicResource MaskColor}">
|
||||||
|
<ActivityIndicator IsRunning="True" IsVisible="True"
|
||||||
|
Color="{DynamicResource WindowColor}"/>
|
||||||
|
</Frame>
|
||||||
|
</Grid>
|
||||||
|
</i:FavoriteIllustCollectionPage>
|
53
Pixiview/Illust/FavoritesPage.xaml.cs
Normal file
53
Pixiview/Illust/FavoritesPage.xaml.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Pixiview.Utils;
|
||||||
|
|
||||||
|
namespace Pixiview.Illust
|
||||||
|
{
|
||||||
|
public partial class FavoritesPage : FavoriteIllustCollectionPage
|
||||||
|
{
|
||||||
|
public FavoritesPage()
|
||||||
|
{
|
||||||
|
Resources.Add("cardView", GetCardViewTemplate());
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
|
|
||||||
|
StartLoad(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDisappearing()
|
||||||
|
{
|
||||||
|
base.OnDisappearing();
|
||||||
|
|
||||||
|
var illusts = Illusts;
|
||||||
|
if (illusts != null)
|
||||||
|
{
|
||||||
|
illusts.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<IllustItem> DoGetIllustList(IllustItem[] data, ICommand command)
|
||||||
|
{
|
||||||
|
return data.Select(i =>
|
||||||
|
{
|
||||||
|
i.IllustTapped = command;
|
||||||
|
return i;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IllustItem[] DoLoadIllustData(bool force)
|
||||||
|
{
|
||||||
|
var favorites = Stores.LoadFavoritesIllusts();
|
||||||
|
if (favorites == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return favorites.Illusts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Pixiview.Resources;
|
using Pixiview.Resources;
|
||||||
using Pixiview.UI;
|
using Pixiview.UI;
|
||||||
using Pixiview.UI.Theme;
|
using Pixiview.UI.Theme;
|
||||||
@ -12,20 +14,28 @@ using Xamarin.Forms;
|
|||||||
|
|
||||||
namespace Pixiview.Illust
|
namespace Pixiview.Illust
|
||||||
{
|
{
|
||||||
public abstract class IllustCollectionPage : AdaptedPage
|
public interface IIllustCollectionPage
|
||||||
|
{
|
||||||
|
List<IllustItem> Favorites { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class IllustDataCollectionPage : IllustCollectionPage<IllustData> { }
|
||||||
|
public abstract class FavoriteIllustCollectionPage : IllustCollectionPage<IllustItem[]> { }
|
||||||
|
|
||||||
|
public abstract class IllustCollectionPage<T> : AdaptedPage, IIllustCollectionPage
|
||||||
{
|
{
|
||||||
#region - Properties -
|
#region - Properties -
|
||||||
|
|
||||||
public static readonly BindableProperty IllustsProperty = BindableProperty.Create(
|
public static readonly BindableProperty IllustsProperty = BindableProperty.Create(
|
||||||
nameof(Illusts), typeof(IllustCollection), typeof(IllustCollectionPage));
|
nameof(Illusts), typeof(IllustCollection), typeof(IllustCollectionPage<T>));
|
||||||
public static readonly BindableProperty ColumnsProperty = BindableProperty.Create(
|
public static readonly BindableProperty ColumnsProperty = BindableProperty.Create(
|
||||||
nameof(Columns), typeof(int), typeof(IllustCollectionPage), 2);
|
nameof(Columns), typeof(int), typeof(IllustCollectionPage<T>), 2);
|
||||||
public static readonly BindableProperty LoadingProperty = BindableProperty.Create(
|
public static readonly BindableProperty LoadingProperty = BindableProperty.Create(
|
||||||
nameof(Loading), typeof(bool), typeof(IllustCollectionPage), propertyChanged: OnLoadingPropertyChanged);
|
nameof(Loading), typeof(bool), typeof(IllustCollectionPage<T>), propertyChanged: OnLoadingPropertyChanged);
|
||||||
|
|
||||||
private static void OnLoadingPropertyChanged(BindableObject obj, object oldValue, object newValue)
|
private static void OnLoadingPropertyChanged(BindableObject obj, object oldValue, object newValue)
|
||||||
{
|
{
|
||||||
var page = (IllustCollectionPage)obj;
|
var page = (IllustCollectionPage<T>)obj;
|
||||||
var now = (bool)newValue;
|
var now = (bool)newValue;
|
||||||
if (!page.loaded && now && Stores.NetworkAvailable)
|
if (!page.loaded && now && Stores.NetworkAvailable)
|
||||||
{
|
{
|
||||||
@ -50,11 +60,13 @@ namespace Pixiview.Illust
|
|||||||
set => SetValue(LoadingProperty, value);
|
set => SetValue(LoadingProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<IllustItem> Favorites { get; } = new List<IllustItem>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
protected bool loaded;
|
protected bool loaded;
|
||||||
|
|
||||||
private IllustData illustData;
|
private T illustData;
|
||||||
private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads };
|
private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads };
|
||||||
private readonly Command<IllustItem> commandIllustImageTapped;
|
private readonly Command<IllustItem> commandIllustImageTapped;
|
||||||
|
|
||||||
@ -62,6 +74,12 @@ namespace Pixiview.Illust
|
|||||||
{
|
{
|
||||||
BindingContext = this;
|
BindingContext = this;
|
||||||
commandIllustImageTapped = new Command<IllustItem>(IllustImageTapped);
|
commandIllustImageTapped = new Command<IllustItem>(IllustImageTapped);
|
||||||
|
|
||||||
|
var favorites = Stores.LoadFavoritesIllusts();
|
||||||
|
if (favorites != null)
|
||||||
|
{
|
||||||
|
Favorites.AddRange(favorites.Illusts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void IllustImageTapped(IllustItem illust)
|
private void IllustImageTapped(IllustItem illust)
|
||||||
@ -128,11 +146,11 @@ namespace Pixiview.Illust
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
protected abstract IllustData DoLoadIllustData(bool force);
|
protected abstract T DoLoadIllustData(bool force);
|
||||||
protected abstract IEnumerable<string> DoGetIllustList(IllustData data);
|
protected abstract IEnumerable<IllustItem> DoGetIllustList(T data, ICommand command);
|
||||||
protected virtual void OnIllustImageTapped(IllustItem illust)
|
protected virtual void OnIllustImageTapped(IllustItem illust)
|
||||||
{
|
{
|
||||||
var page = new ViewIllustPage(illust);
|
var page = new ViewIllustPage(illust, this);
|
||||||
Navigation.PushAsync(page);
|
Navigation.PushAsync(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,33 +288,12 @@ namespace Pixiview.Illust
|
|||||||
illustData = DoLoadIllustData(force);
|
illustData = DoLoadIllustData(force);
|
||||||
if (illustData == null)
|
if (illustData == null)
|
||||||
{
|
{
|
||||||
App.DebugError("illusts.load", "failed to load illusts data.");
|
//App.DebugError("illusts.load", "failed to load illusts data.");
|
||||||
|
Loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = DoGetIllustList(illustData).Select(id =>
|
var data = DoGetIllustList(illustData, commandIllustImageTapped).Where(i => i != null);
|
||||||
{
|
|
||||||
var illust = illustData.body.thumbnails.illust.FirstOrDefault(l => l.illustId == id);
|
|
||||||
if (illust == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new IllustItem
|
|
||||||
{
|
|
||||||
Id = illust.illustId,
|
|
||||||
ImageUrl = illust.urls.x360 ?? illust.url,
|
|
||||||
Title = illust.illustTitle,
|
|
||||||
IsRestrict = illust.xRestrict == 1,
|
|
||||||
ProfileUrl = illust.profileImageUrl,
|
|
||||||
UserId = illust.userId,
|
|
||||||
UserName = illust.userName,
|
|
||||||
Width = illust.width,
|
|
||||||
Height = illust.height,
|
|
||||||
PageCount = illust.pageCount,
|
|
||||||
|
|
||||||
IllustTapped = commandIllustImageTapped
|
|
||||||
};
|
|
||||||
}).Where(i => i != null);
|
|
||||||
|
|
||||||
var collection = new IllustCollection(data);
|
var collection = new IllustCollection(data);
|
||||||
Illusts = collection;
|
Illusts = collection;
|
||||||
@ -340,7 +337,24 @@ namespace Pixiview.Illust
|
|||||||
public class IllustCollection : ObservableCollection<IllustItem>
|
public class IllustCollection : ObservableCollection<IllustItem>
|
||||||
{
|
{
|
||||||
private static readonly object sync = new object();
|
private static readonly object sync = new object();
|
||||||
|
private static IllustCollection empty;
|
||||||
|
|
||||||
|
public static IllustCollection Empty
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (empty == null)
|
||||||
|
{
|
||||||
|
empty = new IllustCollection();
|
||||||
|
}
|
||||||
|
return empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IllustCollection() : base()
|
||||||
|
{
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
public IllustCollection(IEnumerable<IllustItem> illusts) : base(illusts)
|
public IllustCollection(IEnumerable<IllustItem> illusts) : base(illusts)
|
||||||
{
|
{
|
||||||
running = true;
|
running = true;
|
||||||
@ -360,6 +374,13 @@ namespace Pixiview.Illust
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class IllustFavorite
|
||||||
|
{
|
||||||
|
public DateTime LastFavoriteUtc { get; set; }
|
||||||
|
public IllustItem[] Illusts { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonObject(MemberSerialization.OptIn)]
|
||||||
public class IllustItem : BindableObject
|
public class IllustItem : BindableObject
|
||||||
{
|
{
|
||||||
public static readonly BindableProperty ImageProperty = BindableProperty.Create(
|
public static readonly BindableProperty ImageProperty = BindableProperty.Create(
|
||||||
@ -379,6 +400,7 @@ namespace Pixiview.Illust
|
|||||||
get => (ImageSource)GetValue(ProfileImageProperty);
|
get => (ImageSource)GetValue(ProfileImageProperty);
|
||||||
set => SetValue(ProfileImageProperty, value);
|
set => SetValue(ProfileImageProperty, value);
|
||||||
}
|
}
|
||||||
|
[JsonProperty]
|
||||||
public GridLength ImageHeight
|
public GridLength ImageHeight
|
||||||
{
|
{
|
||||||
get => (GridLength)GetValue(ImageHeightProperty);
|
get => (GridLength)GetValue(ImageHeightProperty);
|
||||||
@ -386,16 +408,27 @@ namespace Pixiview.Illust
|
|||||||
}
|
}
|
||||||
public ICommand IllustTapped { get; set; }
|
public ICommand IllustTapped { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty]
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public string ImageUrl { get; set; }
|
public string ImageUrl { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public bool IsRestrict { get; set; }
|
public bool IsRestrict { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public string ProfileUrl { get; set; }
|
public string ProfileUrl { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public string UserId { get; set; }
|
public string UserId { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public int Width { get; set; }
|
public int Width { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public int Height { get; set; }
|
public int Height { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
public int PageCount { get; set; }
|
public int PageCount { get; set; }
|
||||||
|
|
||||||
public string PageCountText => $"{StyleDefinition.IconLayer} {PageCount}";
|
public string PageCountText => $"{StyleDefinition.IconLayer} {PageCount}";
|
||||||
public bool IsPageVisible => PageCount > 1;
|
public bool IsPageVisible => PageCount > 1;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<i:IllustCollectionPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<i:IllustDataCollectionPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:i="clr-namespace:Pixiview.Illust"
|
xmlns:i="clr-namespace:Pixiview.Illust"
|
||||||
xmlns:u="clr-namespace:Pixiview.UI"
|
xmlns:u="clr-namespace:Pixiview.UI"
|
||||||
xmlns:util="clr-namespace:Pixiview.Utils"
|
xmlns:r="clr-namespace:Pixiview.Resources"
|
||||||
xmlns:r="clr-namespace:Pixiview.Resources"
|
x:Class="Pixiview.Illust.MainPage"
|
||||||
x:Class="Pixiview.Illust.MainPage"
|
BackgroundColor="{DynamicResource WindowColor}"
|
||||||
util:Screen.StatusBarStyle="{DynamicResource StatusBarStyle}"
|
Title="{r:Text Follow}">
|
||||||
BackgroundColor="{DynamicResource WindowColor}"
|
|
||||||
Title="{r:Text Follow}">
|
|
||||||
<ContentPage.ToolbarItems>
|
<ContentPage.ToolbarItems>
|
||||||
<ToolbarItem Order="Primary" Clicked="Refresh_Clicked"
|
<ToolbarItem Order="Primary" Clicked="Refresh_Clicked"
|
||||||
IconImageSource="{DynamicResource FontIconRefresh}"/>
|
IconImageSource="{DynamicResource FontIconRefresh}"/>
|
||||||
@ -28,4 +26,4 @@
|
|||||||
Color="{DynamicResource WindowColor}"/>
|
Color="{DynamicResource WindowColor}"/>
|
||||||
</Frame>
|
</Frame>
|
||||||
</Grid>
|
</Grid>
|
||||||
</i:IllustCollectionPage>
|
</i:IllustDataCollectionPage>
|
||||||
|
@ -1,26 +1,41 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Windows.Input;
|
||||||
using Pixiview.Utils;
|
using Pixiview.Utils;
|
||||||
|
|
||||||
namespace Pixiview.Illust
|
namespace Pixiview.Illust
|
||||||
{
|
{
|
||||||
// Learn more about making custom code visible in the Xamarin.Forms previewer
|
public partial class MainPage : IllustDataCollectionPage
|
||||||
// by visiting https://aka.ms/xamarinforms-previewer
|
|
||||||
//[DesignTimeVisible(false)]
|
|
||||||
public partial class MainPage : IllustCollectionPage
|
|
||||||
{
|
{
|
||||||
public MainPage()
|
public MainPage()
|
||||||
{
|
{
|
||||||
Resources.Add("cardView", GetCardViewTemplate());
|
Resources.Add("cardView", GetCardViewTemplate());
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnLoad()
|
||||||
|
{
|
||||||
StartLoad();
|
StartLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<string> DoGetIllustList(IllustData data)
|
public override void OnUnload()
|
||||||
{
|
{
|
||||||
return data.body.page.follow.Select(i => i.ToString());
|
Illusts = IllustCollection.Empty;
|
||||||
|
loaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<IllustItem> DoGetIllustList(IllustData data, ICommand command)
|
||||||
|
{
|
||||||
|
return data.body.page.follow.Select(i =>
|
||||||
|
{
|
||||||
|
var item = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == i.ToString())?.ConvertToItem();
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
item.IllustTapped = command;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IllustData DoLoadIllustData(bool force)
|
protected override IllustData DoLoadIllustData(bool force)
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<i:IllustCollectionPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<i:IllustDataCollectionPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:i="clr-namespace:Pixiview.Illust"
|
xmlns:i="clr-namespace:Pixiview.Illust"
|
||||||
xmlns:u="clr-namespace:Pixiview.UI"
|
xmlns:u="clr-namespace:Pixiview.UI"
|
||||||
xmlns:util="clr-namespace:Pixiview.Utils"
|
x:Class="Pixiview.Illust.RankingPage"
|
||||||
x:Class="Pixiview.Illust.RankingPage"
|
BackgroundColor="{DynamicResource WindowColor}">
|
||||||
util:Screen.StatusBarStyle="{DynamicResource StatusBarStyle}"
|
<ContentPage.ToolbarItems>
|
||||||
BackgroundColor="{DynamicResource WindowColor}">
|
<ToolbarItem Order="Primary" Clicked="Refresh_Clicked"
|
||||||
|
IconImageSource="{DynamicResource FontIconRefresh}"/>
|
||||||
|
</ContentPage.ToolbarItems>
|
||||||
<Grid>
|
<Grid>
|
||||||
<ScrollView HorizontalOptions="Fill">
|
<ScrollView HorizontalOptions="Fill">
|
||||||
<u:FlowLayout ItemsSource="{Binding Illusts}"
|
<u:FlowLayout ItemsSource="{Binding Illusts}"
|
||||||
@ -22,4 +24,4 @@
|
|||||||
Color="{DynamicResource WindowColor}"/>
|
Color="{DynamicResource WindowColor}"/>
|
||||||
</Frame>
|
</Frame>
|
||||||
</Grid>
|
</Grid>
|
||||||
</i:IllustCollectionPage>
|
</i:IllustDataCollectionPage>
|
||||||
|
@ -1,23 +1,42 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Windows.Input;
|
||||||
using Pixiview.Utils;
|
using Pixiview.Utils;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Pixiview.Illust
|
namespace Pixiview.Illust
|
||||||
{
|
{
|
||||||
public partial class RankingPage : IllustCollectionPage
|
public partial class RankingPage : IllustDataCollectionPage
|
||||||
{
|
{
|
||||||
public RankingPage()
|
public RankingPage()
|
||||||
{
|
{
|
||||||
Resources.Add("cardView", GetCardViewTemplate());
|
Resources.Add("cardView", GetCardViewTemplate());
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnLoad()
|
||||||
|
{
|
||||||
StartLoad();
|
StartLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<string> DoGetIllustList(IllustData data)
|
public override void OnUnload()
|
||||||
{
|
{
|
||||||
return data.body.page.ranking.items.Select(i => i.id);
|
Illusts = IllustCollection.Empty;
|
||||||
|
loaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<IllustItem> DoGetIllustList(IllustData data, ICommand command)
|
||||||
|
{
|
||||||
|
return data.body.page.ranking.items.Select(i =>
|
||||||
|
{
|
||||||
|
var item = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == i.id)?.ConvertToItem();
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
item.IllustTapped = command;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IllustData DoLoadIllustData(bool force)
|
protected override IllustData DoLoadIllustData(bool force)
|
||||||
@ -34,5 +53,14 @@ namespace Pixiview.Illust
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Refresh_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (Loading)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StartLoad(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<i:IllustCollectionPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<i:IllustDataCollectionPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:i="clr-namespace:Pixiview.Illust"
|
xmlns:i="clr-namespace:Pixiview.Illust"
|
||||||
xmlns:u="clr-namespace:Pixiview.UI"
|
xmlns:u="clr-namespace:Pixiview.UI"
|
||||||
xmlns:util="clr-namespace:Pixiview.Utils"
|
xmlns:r="clr-namespace:Pixiview.Resources"
|
||||||
xmlns:r="clr-namespace:Pixiview.Resources"
|
x:Class="Pixiview.Illust.RecommendsPage"
|
||||||
x:Class="Pixiview.Illust.RecommendsPage"
|
BackgroundColor="{DynamicResource WindowColor}"
|
||||||
util:Screen.StatusBarStyle="{DynamicResource StatusBarStyle}"
|
Title="{r:Text Recommends}">
|
||||||
BackgroundColor="{DynamicResource WindowColor}"
|
<ContentPage.ToolbarItems>
|
||||||
Title="{r:Text Recommends}">
|
<ToolbarItem Order="Primary" Clicked="Refresh_Clicked"
|
||||||
|
IconImageSource="{DynamicResource FontIconRefresh}"/>
|
||||||
|
</ContentPage.ToolbarItems>
|
||||||
<Grid>
|
<Grid>
|
||||||
<ScrollView HorizontalOptions="Fill">
|
<ScrollView HorizontalOptions="Fill">
|
||||||
<u:FlowLayout ItemsSource="{Binding Illusts}"
|
<u:FlowLayout ItemsSource="{Binding Illusts}"
|
||||||
@ -24,4 +26,4 @@
|
|||||||
Color="{DynamicResource WindowColor}"/>
|
Color="{DynamicResource WindowColor}"/>
|
||||||
</Frame>
|
</Frame>
|
||||||
</Grid>
|
</Grid>
|
||||||
</i:IllustCollectionPage>
|
</i:IllustDataCollectionPage>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Windows.Input;
|
||||||
using Pixiview.Utils;
|
using Pixiview.Utils;
|
||||||
|
|
||||||
namespace Pixiview.Illust
|
namespace Pixiview.Illust
|
||||||
{
|
{
|
||||||
public partial class RecommendsPage : IllustCollectionPage
|
public partial class RecommendsPage : IllustDataCollectionPage
|
||||||
{
|
{
|
||||||
public bool ByUser { get; set; }
|
public bool ByUser { get; set; }
|
||||||
|
|
||||||
@ -12,19 +14,45 @@ namespace Pixiview.Illust
|
|||||||
{
|
{
|
||||||
Resources.Add("cardView", GetCardViewTemplate());
|
Resources.Add("cardView", GetCardViewTemplate());
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnLoad()
|
||||||
|
{
|
||||||
StartLoad();
|
StartLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<string> DoGetIllustList(IllustData data)
|
public override void OnUnload()
|
||||||
|
{
|
||||||
|
Illusts = IllustCollection.Empty;
|
||||||
|
loaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<IllustItem> DoGetIllustList(IllustData data, ICommand command)
|
||||||
{
|
{
|
||||||
if (ByUser)
|
if (ByUser)
|
||||||
{
|
{
|
||||||
return data.body.page.recommendUser.SelectMany(i => i.illustIds);
|
return data.body.page.recommendUser.SelectMany(i => i.illustIds)
|
||||||
|
.Select(id =>
|
||||||
|
{
|
||||||
|
var item = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == id)?.ConvertToItem();
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
item.IllustTapped = command;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return data.body.page.recommend;
|
return data.body.page.recommend.Select(id =>
|
||||||
|
{
|
||||||
|
var item = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == id)?.ConvertToItem();
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
item.IllustTapped = command;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,5 +60,14 @@ namespace Pixiview.Illust
|
|||||||
{
|
{
|
||||||
return Stores.LoadIllustData(force);
|
return Stores.LoadIllustData(force);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Refresh_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (Loading)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StartLoad(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,15 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:mdl="clr-namespace:Pixiview.Illust"
|
xmlns:mdl="clr-namespace:Pixiview.Illust"
|
||||||
xmlns:u="clr-namespace:Pixiview.UI"
|
xmlns:u="clr-namespace:Pixiview.UI"
|
||||||
xmlns:util="clr-namespace:Pixiview.Utils"
|
|
||||||
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
|
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
|
||||||
x:Class="Pixiview.Illust.ViewIllustPage"
|
x:Class="Pixiview.Illust.ViewIllustPage"
|
||||||
util:Screen.StatusBarStyle="{DynamicResource StatusBarStyle}"
|
|
||||||
ios:Page.UseSafeArea="False"
|
ios:Page.UseSafeArea="False"
|
||||||
Shell.TabBarIsVisible="False"
|
Shell.TabBarIsVisible="False"
|
||||||
BackgroundColor="{DynamicResource WindowColor}"
|
BackgroundColor="{DynamicResource WindowColor}"
|
||||||
Title="{Binding IllustItem.Title}">
|
Title="{Binding IllustItem.Title}">
|
||||||
<ContentPage.ToolbarItems>
|
<ContentPage.ToolbarItems>
|
||||||
<ToolbarItem Order="Primary" Clicked="Download_Clicked"
|
<ToolbarItem Order="Primary" Clicked="Favorite_Clicked"
|
||||||
IconImageSource="{DynamicResource FontIconDownload}"/>
|
IconImageSource="{Binding IsFavorite}"/>
|
||||||
</ContentPage.ToolbarItems>
|
</ContentPage.ToolbarItems>
|
||||||
<Grid Padding="{Binding PageTopMargin}">
|
<Grid Padding="{Binding PageTopMargin}">
|
||||||
<CarouselView ItemsSource="{Binding Illusts}" HorizontalScrollBarVisibility="Never"
|
<CarouselView ItemsSource="{Binding Illusts}" HorizontalScrollBarVisibility="Never"
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Pixiview.Resources;
|
using Pixiview.Resources;
|
||||||
using Pixiview.UI;
|
using Pixiview.UI;
|
||||||
|
using Pixiview.UI.Theme;
|
||||||
using Pixiview.Utils;
|
using Pixiview.Utils;
|
||||||
using Xamarin.Essentials;
|
using Xamarin.Essentials;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
@ -11,6 +13,8 @@ namespace Pixiview.Illust
|
|||||||
[QueryProperty("IllustId", "id")]
|
[QueryProperty("IllustId", "id")]
|
||||||
public partial class ViewIllustPage : AdaptedPage
|
public partial class ViewIllustPage : AdaptedPage
|
||||||
{
|
{
|
||||||
|
public static readonly BindableProperty IsFavoriteProperty = BindableProperty.Create(
|
||||||
|
nameof(IsFavorite), typeof(ImageSource), typeof(ViewIllustPage));
|
||||||
public static readonly BindableProperty IllustsProperty = BindableProperty.Create(
|
public static readonly BindableProperty IllustsProperty = BindableProperty.Create(
|
||||||
nameof(Illusts), typeof(IllustDetailItem[]), typeof(ViewIllustPage));
|
nameof(Illusts), typeof(IllustDetailItem[]), typeof(ViewIllustPage));
|
||||||
public static readonly BindableProperty PagePositionTextProperty = BindableProperty.Create(
|
public static readonly BindableProperty PagePositionTextProperty = BindableProperty.Create(
|
||||||
@ -22,6 +26,8 @@ namespace Pixiview.Illust
|
|||||||
public static readonly BindableProperty PageTopMarginProperty = BindableProperty.Create(
|
public static readonly BindableProperty PageTopMarginProperty = BindableProperty.Create(
|
||||||
nameof(PageTopMargin), typeof(Thickness), typeof(ViewIllustPage));
|
nameof(PageTopMargin), typeof(Thickness), typeof(ViewIllustPage));
|
||||||
|
|
||||||
|
public ImageSource IsFavorite => (ImageSource)GetValue(IsFavoriteProperty);
|
||||||
|
|
||||||
public IllustDetailItem[] Illusts
|
public IllustDetailItem[] Illusts
|
||||||
{
|
{
|
||||||
get => (IllustDetailItem[])GetValue(IllustsProperty);
|
get => (IllustDetailItem[])GetValue(IllustsProperty);
|
||||||
@ -50,23 +56,38 @@ namespace Pixiview.Illust
|
|||||||
|
|
||||||
public int CurrentPage { get; private set; }
|
public int CurrentPage { get; private set; }
|
||||||
|
|
||||||
public ViewIllustPage(IllustItem illust)
|
private readonly IIllustCollectionPage collectionPage;
|
||||||
|
private readonly object fontIconLove;
|
||||||
|
private readonly object fontIconNotLove;
|
||||||
|
|
||||||
|
public ViewIllustPage(IllustItem illust, IIllustCollectionPage page)
|
||||||
{
|
{
|
||||||
IllustItem = illust;
|
IllustItem = illust;
|
||||||
|
collectionPage = page;
|
||||||
BindingContext = this;
|
BindingContext = this;
|
||||||
|
|
||||||
InitializeComponent();
|
fontIconLove = Application.Current.Resources[ThemeBase.FontIconLove];
|
||||||
}
|
fontIconNotLove = Application.Current.Resources[ThemeBase.FontIconNotLove];
|
||||||
|
if (page.Favorites != null)
|
||||||
|
{
|
||||||
|
SetValue(IsFavoriteProperty, page.Favorites.Any(i => i.Id == illust.Id)
|
||||||
|
? fontIconLove
|
||||||
|
: fontIconNotLove);
|
||||||
|
}
|
||||||
|
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
public override void OnLoad()
|
|
||||||
{
|
|
||||||
var illust = IllustItem;
|
|
||||||
if (illust != null)
|
if (illust != null)
|
||||||
{
|
{
|
||||||
LoadIllust(illust);
|
LoadIllust(illust);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnLoad()
|
||||||
|
{
|
||||||
|
OnOrientationChanged(CurrentOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadIllust(IllustItem illust)
|
private void LoadIllust(IllustItem illust)
|
||||||
{
|
{
|
||||||
if (illust == null)
|
if (illust == null)
|
||||||
@ -95,7 +116,6 @@ namespace Pixiview.Illust
|
|||||||
}
|
}
|
||||||
|
|
||||||
Illusts = items;
|
Illusts = items;
|
||||||
OnOrientationChanged(CurrentOrientation);
|
|
||||||
Task.Run(DoLoadImages);
|
Task.Run(DoLoadImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +154,13 @@ namespace Pixiview.Illust
|
|||||||
protected override void OnDisappearing()
|
protected override void OnDisappearing()
|
||||||
{
|
{
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
|
|
||||||
|
var favorite = new IllustFavorite
|
||||||
|
{
|
||||||
|
LastFavoriteUtc = DateTime.UtcNow,
|
||||||
|
Illusts = collectionPage.Favorites.ToArray()
|
||||||
|
};
|
||||||
|
Stores.SaveFavoritesIllusts(favorite);
|
||||||
Screen.SetHomeIndicatorAutoHidden(Shell.Current, false);
|
Screen.SetHomeIndicatorAutoHidden(Shell.Current, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,6 +247,25 @@ namespace Pixiview.Illust
|
|||||||
item.Loading = false;
|
item.Loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Favorite_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (collectionPage.Favorites == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var index = collectionPage.Favorites.FindIndex(i => i.Id == IllustItem.Id);
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
collectionPage.Favorites.Insert(0, IllustItem);
|
||||||
|
SetValue(IsFavoriteProperty, fontIconLove);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
collectionPage.Favorites.RemoveAt(index);
|
||||||
|
SetValue(IsFavoriteProperty, fontIconNotLove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async void Download_Clicked(object sender, EventArgs e)
|
private async void Download_Clicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var status = await Permissions.CheckStatusAsync<Permissions.Photos>();
|
var status = await Permissions.CheckStatusAsync<Permissions.Photos>();
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
<u:AdaptedPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<u:AdaptedPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:u="clr-namespace:Pixiview.UI"
|
xmlns:u="clr-namespace:Pixiview.UI"
|
||||||
xmlns:util="clr-namespace:Pixiview.Utils"
|
xmlns:r="clr-namespace:Pixiview.Resources"
|
||||||
x:Class="Pixiview.OptionPage"
|
x:Class="Pixiview.OptionPage"
|
||||||
util:Screen.StatusBarStyle="{DynamicResource StatusBarStyle}"
|
BackgroundColor="{DynamicResource WindowColor}"
|
||||||
BackgroundColor="{DynamicResource WindowColor}">
|
Title="{r:Text Option}">
|
||||||
<ContentPage.Content>
|
<ContentPage.Content>
|
||||||
<Label Text="Option" Margin="20"/>
|
<Label Text="Option" Margin="20"/>
|
||||||
</ContentPage.Content>
|
</ContentPage.Content>
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
<Recommends>推荐</Recommends>
|
<Recommends>推荐</Recommends>
|
||||||
<ByUser>按用户</ByUser>
|
<ByUser>按用户</ByUser>
|
||||||
<Ranking>排行榜</Ranking>
|
<Ranking>排行榜</Ranking>
|
||||||
|
<Favorites>收藏夹</Favorites>
|
||||||
<Option>选项</Option>
|
<Option>选项</Option>
|
||||||
<Preview>预览</Preview>
|
<Preview>预览</Preview>
|
||||||
<SaveSuccess>成功保存图片到照片库。</SaveSuccess>
|
<SaveSuccess>成功保存图片到照片库。</SaveSuccess>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Pixiview.UI.Theme;
|
||||||
|
using Pixiview.Utils;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Pixiview.UI
|
namespace Pixiview.UI
|
||||||
@ -13,6 +15,7 @@ namespace Pixiview.UI
|
|||||||
|
|
||||||
public AdaptedPage()
|
public AdaptedPage()
|
||||||
{
|
{
|
||||||
|
SetDynamicResource(Screen.StatusBarStyleProperty, ThemeBase.StatusBarStyle);
|
||||||
Shell.SetNavBarHasShadow(this, true);
|
Shell.SetNavBarHasShadow(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,10 @@ namespace Pixiview.UI
|
|||||||
public const string IconOrder = "\uf88f";
|
public const string IconOrder = "\uf88f";
|
||||||
public const string IconLayer = "\uf302";
|
public const string IconLayer = "\uf302";
|
||||||
public const string IconRefresh = "\uf2f1";
|
public const string IconRefresh = "\uf2f1";
|
||||||
|
public const string IconLove = "\uf004";
|
||||||
public const string IconOption = "\uf013";
|
public const string IconOption = "\uf013";
|
||||||
public const string IconDownload = "\uf019";
|
public const string IconDownload = "\uf019";
|
||||||
|
public const string IconFavorite = "\uf02e";
|
||||||
|
|
||||||
static StyleDefinition()
|
static StyleDefinition()
|
||||||
{
|
{
|
||||||
|
@ -10,8 +10,11 @@ namespace Pixiview.UI.Theme
|
|||||||
public const string FontIconSparkles = nameof(FontIconSparkles);
|
public const string FontIconSparkles = nameof(FontIconSparkles);
|
||||||
public const string FontIconOrder = nameof(FontIconOrder);
|
public const string FontIconOrder = nameof(FontIconOrder);
|
||||||
public const string FontIconRefresh = nameof(FontIconRefresh);
|
public const string FontIconRefresh = nameof(FontIconRefresh);
|
||||||
|
public const string FontIconLove = nameof(FontIconLove);
|
||||||
|
public const string FontIconNotLove = nameof(FontIconNotLove);
|
||||||
public const string FontIconOption = nameof(FontIconOption);
|
public const string FontIconOption = nameof(FontIconOption);
|
||||||
public const string FontIconDownload = nameof(FontIconDownload);
|
public const string FontIconDownload = nameof(FontIconDownload);
|
||||||
|
public const string FontIconFavorite = nameof(FontIconFavorite);
|
||||||
|
|
||||||
public const string StatusBarStyle = nameof(StatusBarStyle);
|
public const string StatusBarStyle = nameof(StatusBarStyle);
|
||||||
public const string WindowColor = nameof(WindowColor);
|
public const string WindowColor = nameof(WindowColor);
|
||||||
@ -87,8 +90,11 @@ namespace Pixiview.UI.Theme
|
|||||||
Add(FontIconSparkles, GetSolidIcon(StyleDefinition.IconSparkles, solidFontFamily, mainColor));
|
Add(FontIconSparkles, GetSolidIcon(StyleDefinition.IconSparkles, solidFontFamily, mainColor));
|
||||||
Add(FontIconOrder, GetSolidIcon(StyleDefinition.IconOrder, solidFontFamily, mainColor));
|
Add(FontIconOrder, GetSolidIcon(StyleDefinition.IconOrder, solidFontFamily, mainColor));
|
||||||
Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily, mainColor));
|
Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily, mainColor));
|
||||||
|
Add(FontIconLove, GetSolidIcon(StyleDefinition.IconLove, solidFontFamily, mainColor));
|
||||||
|
Add(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, (string)this[IconRegularFontFamily], mainColor));
|
||||||
Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily, mainColor));
|
Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily, mainColor));
|
||||||
Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily, mainColor));
|
Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily, mainColor));
|
||||||
|
Add(FontIconFavorite, GetSolidIcon(StyleDefinition.IconFavorite, solidFontFamily, mainColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
private FontImageSource GetSolidIcon(string icon, string family, Color color)
|
private FontImageSource GetSolidIcon(string icon, string family, Color color)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Pixiview.Illust;
|
||||||
|
|
||||||
namespace Pixiview.Utils
|
namespace Pixiview.Utils
|
||||||
{
|
{
|
||||||
@ -89,6 +90,23 @@ namespace Pixiview.Utils
|
|||||||
[JsonProperty("540x540")]
|
[JsonProperty("540x540")]
|
||||||
public string x540;
|
public string x540;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IllustItem ConvertToItem()
|
||||||
|
{
|
||||||
|
return new IllustItem
|
||||||
|
{
|
||||||
|
Id = illustId,
|
||||||
|
ImageUrl = urls.x360 ?? url,
|
||||||
|
Title = illustTitle,
|
||||||
|
IsRestrict = xRestrict == 1,
|
||||||
|
ProfileUrl = profileImageUrl,
|
||||||
|
UserId = userId,
|
||||||
|
UserName = userName,
|
||||||
|
Width = width,
|
||||||
|
Height = height,
|
||||||
|
PageCount = pageCount
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ using System.Net;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Pixiview.Illust;
|
||||||
using Xamarin.Essentials;
|
using Xamarin.Essentials;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
@ -14,12 +15,17 @@ namespace Pixiview.Utils
|
|||||||
{
|
{
|
||||||
public static readonly string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
public static readonly string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||||
public static readonly string CacheFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
|
public static readonly string CacheFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
|
||||||
|
|
||||||
private const string pagesFolder = "pages";
|
private const string pagesFolder = "pages";
|
||||||
private const string imageFolder = "img-original";
|
private const string imageFolder = "img-original";
|
||||||
private const string previewFolder = "img-master";
|
private const string previewFolder = "img-master";
|
||||||
private const string thumbFolder = "img-thumb";
|
private const string thumbFolder = "img-thumb";
|
||||||
private const string userFolder = "user-profile";
|
private const string userFolder = "user-profile";
|
||||||
|
|
||||||
private const string illustFile = "illust.json";
|
private const string illustFile = "illust.json";
|
||||||
|
private const string favoriteFile = "favorites.json";
|
||||||
|
|
||||||
|
private static readonly object sync = new object();
|
||||||
|
|
||||||
public static bool NetworkAvailable
|
public static bool NetworkAvailable
|
||||||
{
|
{
|
||||||
@ -87,6 +93,64 @@ namespace Pixiview.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static T ReadObject<T>(string file)
|
||||||
|
{
|
||||||
|
string content = null;
|
||||||
|
if (File.Exists(file))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
content = File.ReadAllText(file);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
App.DebugError("read", $"failed to read file: {file}, error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
App.DebugError("read", $"file not found: {file}");
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(content);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
App.DebugError("read", $"failed to parse illust JSON object, error: {ex.Message}");
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteObject(string file, object obj)
|
||||||
|
{
|
||||||
|
var dir = Path.GetDirectoryName(file);
|
||||||
|
if (!Directory.Exists(dir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
}
|
||||||
|
string content;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
content = JsonConvert.SerializeObject(obj, Formatting.None);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
App.DebugError("write", $"failed to serialize object, error: {ex.Message}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllText(file, content, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
App.DebugError("write", $"failed to write file: {file}, error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static IllustData LoadIllustData(bool force = false)
|
public static IllustData LoadIllustData(bool force = false)
|
||||||
{
|
{
|
||||||
var file = Path.Combine(PersonalFolder, illustFile);
|
var file = Path.Combine(PersonalFolder, illustFile);
|
||||||
@ -118,6 +182,21 @@ namespace Pixiview.Utils
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IllustFavorite LoadFavoritesIllusts()
|
||||||
|
{
|
||||||
|
var file = Path.Combine(PersonalFolder, favoriteFile);
|
||||||
|
return ReadObject<IllustFavorite>(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SaveFavoritesIllusts(IllustFavorite data)
|
||||||
|
{
|
||||||
|
var file = Path.Combine(PersonalFolder, favoriteFile);
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
WriteObject(file, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ImageSource LoadIllustImage(string url)
|
public static ImageSource LoadIllustImage(string url)
|
||||||
{
|
{
|
||||||
return LoadImage(url, PersonalFolder, imageFolder);
|
return LoadImage(url, PersonalFolder, imageFolder);
|
||||||
@ -306,6 +385,7 @@ namespace Pixiview.Utils
|
|||||||
public const string Recommends = "recommends";
|
public const string Recommends = "recommends";
|
||||||
public const string ByUser = "byuser";
|
public const string ByUser = "byuser";
|
||||||
public const string Ranking = "ranking";
|
public const string Ranking = "ranking";
|
||||||
|
public const string Favorites = "favorites";
|
||||||
public const string Option = "option";
|
public const string Option = "option";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user