feature: r-18 filter

This commit is contained in:
Tsanie Lily 2020-05-15 00:45:47 +08:00
parent 90816bc57e
commit f83f533f5f
9 changed files with 44 additions and 8 deletions

View File

@ -26,6 +26,7 @@ namespace Pixiview
private void InitPreferences() private void InitPreferences()
{ {
Configs.IsOnR18 = Preferences.Get(Configs.IsOnR18Key, false);
var isProxied = Preferences.Get(Configs.IsProxiedKey, false); var isProxied = Preferences.Get(Configs.IsProxiedKey, false);
if (isProxied) if (isProxied)
{ {

View File

@ -17,10 +17,6 @@ namespace Pixiview.Illust
protected override bool IsFavoriteVisible => false; protected override bool IsFavoriteVisible => false;
public override void OnUnload()
{
}
protected override void OnAppearing() protected override void OnAppearing()
{ {
//base.OnAppearing(); //base.OnAppearing();

View File

@ -443,7 +443,8 @@ namespace Pixiview.Illust
lastUpdated = now; lastUpdated = now;
} }
var data = DoGetIllustList(illustData).Where(i => i != null); var r18 = Configs.IsOnR18;
var data = DoGetIllustList(illustData).Where(i => i != null && (r18 || !i.IsRestrict));
var collection = new IllustCollection(data); var collection = new IllustCollection(data);
if (IsFavoriteVisible) if (IsFavoriteVisible)

View File

@ -14,7 +14,7 @@
<Grid> <Grid>
<ScrollView HorizontalOptions="Fill" HorizontalScrollBarVisibility="Never"> <ScrollView HorizontalOptions="Fill" HorizontalScrollBarVisibility="Never">
<StackLayout> <StackLayout>
<u:FlowLayout ItemsSource="{Binding Users}" <u:FlowLayout ItemsSource="{Binding Users}" IsVisible="{Binding UserRecommendsVisible}"
HorizontalOptions="Fill" Column="{Binding UserColumns}" HorizontalOptions="Fill" Column="{Binding UserColumns}"
Margin="16" RowSpacing="16" Margin="16" RowSpacing="16"
ItemTemplate="{StaticResource userCardView}"/> ItemTemplate="{StaticResource userCardView}"/>

View File

@ -15,6 +15,8 @@ namespace Pixiview.Illust
nameof(Users), typeof(List<IllustUserItem>), typeof(RecommendsPage)); nameof(Users), typeof(List<IllustUserItem>), typeof(RecommendsPage));
public static readonly BindableProperty UserColumnsProperty = BindableProperty.Create( public static readonly BindableProperty UserColumnsProperty = BindableProperty.Create(
nameof(UserColumns), typeof(int), typeof(RecommendsPage), 1); nameof(UserColumns), typeof(int), typeof(RecommendsPage), 1);
public static readonly BindableProperty UserRecommendsVisibleProperty = BindableProperty.Create(
nameof(UserRecommendsVisible), typeof(bool), typeof(RecommendsPage));
public List<IllustUserItem> Users public List<IllustUserItem> Users
{ {
@ -26,6 +28,11 @@ namespace Pixiview.Illust
get => (int)GetValue(UserColumnsProperty); get => (int)GetValue(UserColumnsProperty);
set => SetValue(UserColumnsProperty, value); set => SetValue(UserColumnsProperty, value);
} }
public bool UserRecommendsVisible
{
get => (bool)GetValue(UserRecommendsVisibleProperty);
set => SetValue(UserRecommendsVisibleProperty, value);
}
private readonly Command<IllustUserItem> commandUserTapped; private readonly Command<IllustUserItem> commandUserTapped;
@ -200,6 +207,7 @@ namespace Pixiview.Illust
private void DoLoadUserRecommendsData(IllustData data) private void DoLoadUserRecommendsData(IllustData data)
{ {
var r18 = Configs.IsOnR18;
var defaultImage = StyleDefinition.DownloadBackground; var defaultImage = StyleDefinition.DownloadBackground;
var users = data.body.page.recommendUser.Select(u => var users = data.body.page.recommendUser.Select(u =>
{ {
@ -229,6 +237,15 @@ namespace Pixiview.Illust
item3 = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == id)?.ConvertToItem(defaultImage); item3 = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == id)?.ConvertToItem(defaultImage);
} }
} }
if (!r18)
{
if (item1?.IsRestrict == true ||
item2?.IsRestrict == true ||
item3?.IsRestrict == true)
{
return null;
}
}
return new IllustUserItem return new IllustUserItem
{ {
UserId = usrId, UserId = usrId,
@ -238,9 +255,10 @@ namespace Pixiview.Illust
Image2Item = item2, Image2Item = item2,
Image3Item = item3 Image3Item = item3
}; };
}); }).Where(u => u != null);
var list = new List<IllustUserItem>(users); var list = new List<IllustUserItem>(users);
UserRecommendsVisible = list.Count > 0;
Users = list; Users = list;
Illusts = IllustCollection; Illusts = IllustCollection;

View File

@ -8,6 +8,10 @@
<TableView Intent="Settings" VerticalOptions="Start" <TableView Intent="Settings" VerticalOptions="Start"
BackgroundColor="{DynamicResource OptionBackColor}"> BackgroundColor="{DynamicResource OptionBackColor}">
<TableRoot> <TableRoot>
<TableSection Title="{r:Text Illusts}">
<u:OptionSwitchCell Title="{r:Text R18}"
IsToggled="{Binding IsOnR18, Mode=TwoWay}"/>
</TableSection>
<TableSection Title="{r:Text Proxy}"> <TableSection Title="{r:Text Proxy}">
<u:OptionSwitchCell Title="{r:Text Enabled}" <u:OptionSwitchCell Title="{r:Text Enabled}"
IsToggled="{Binding IsProxied, Mode=TwoWay}"/> IsToggled="{Binding IsProxied, Mode=TwoWay}"/>

View File

@ -7,6 +7,8 @@ namespace Pixiview
{ {
public partial class OptionPage : AdaptedPage public partial class OptionPage : AdaptedPage
{ {
public static readonly BindableProperty IsOnR18Property = BindableProperty.Create(
nameof(IsOnR18), typeof(bool), typeof(OptionPage));
public static readonly BindableProperty IsProxiedProperty = BindableProperty.Create( public static readonly BindableProperty IsProxiedProperty = BindableProperty.Create(
nameof(IsProxied), typeof(bool), typeof(OptionPage)); nameof(IsProxied), typeof(bool), typeof(OptionPage));
public static readonly BindableProperty HostProperty = BindableProperty.Create( public static readonly BindableProperty HostProperty = BindableProperty.Create(
@ -14,6 +16,11 @@ namespace Pixiview
public static readonly BindableProperty PortProperty = BindableProperty.Create( public static readonly BindableProperty PortProperty = BindableProperty.Create(
nameof(Port), typeof(string), typeof(OptionPage)); nameof(Port), typeof(string), typeof(OptionPage));
public bool IsOnR18
{
get => (bool)GetValue(IsOnR18Property);
set => SetValue(IsOnR18Property, value);
}
public bool IsProxied public bool IsProxied
{ {
get => (bool)GetValue(IsProxiedProperty); get => (bool)GetValue(IsProxiedProperty);
@ -40,6 +47,7 @@ namespace Pixiview
{ {
base.OnAppearing(); base.OnAppearing();
IsOnR18 = Preferences.Get(Configs.IsOnR18Key, false);
IsProxied = Preferences.Get(Configs.IsProxiedKey, false); IsProxied = Preferences.Get(Configs.IsProxiedKey, false);
Host = Preferences.Get(Configs.HostKey, string.Empty); Host = Preferences.Get(Configs.HostKey, string.Empty);
int pt = Preferences.Get(Configs.PortKey, 0); int pt = Preferences.Get(Configs.PortKey, 0);
@ -53,9 +61,14 @@ namespace Pixiview
{ {
base.OnDisappearing(); base.OnDisappearing();
var r18 = IsOnR18;
var proxied = IsProxied; var proxied = IsProxied;
var h = Host?.Trim(); var h = Host?.Trim();
Preferences.Set(Configs.IsOnR18Key, r18);
Configs.IsOnR18 = r18;
App.DebugPrint($"r-18 filter: {r18}");
Preferences.Set(Configs.IsProxiedKey, proxied); Preferences.Set(Configs.IsProxiedKey, proxied);
Preferences.Set(Configs.HostKey, h); Preferences.Set(Configs.HostKey, h);
var p = Port; var p = Port;

View File

@ -5,6 +5,7 @@
<Cancel>取消</Cancel> <Cancel>取消</Cancel>
<Yes></Yes> <Yes></Yes>
<No></No> <No></No>
<Illusts>插画</Illusts>
<Proxy>代理</Proxy> <Proxy>代理</Proxy>
<Detail>详细</Detail> <Detail>详细</Detail>
<Enabled>启用</Enabled> <Enabled>启用</Enabled>

View File

@ -442,7 +442,8 @@ namespace Pixiview.Utils
public static class Configs public static class Configs
{ {
public const string IsProxiedKey = "isProxied"; public const string IsOnR18Key = "is_on_r18";
public const string IsProxiedKey = "is_proxied";
public const string HostKey = "host"; public const string HostKey = "host";
public const string PortKey = "port"; public const string PortKey = "port";
public const string QueryModeKey = "query_mode"; public const string QueryModeKey = "query_mode";
@ -455,6 +456,7 @@ namespace Pixiview.Utils
public const string RefererIllustRanking = "https://www.pixiv.net/ranking.php?{0}"; public const string RefererIllustRanking = "https://www.pixiv.net/ranking.php?{0}";
public const string RefererIllustUser = "https://www.pixiv.net/users/{0}/illustrations"; public const string RefererIllustUser = "https://www.pixiv.net/users/{0}/illustrations";
public static bool IsOnR18;
public static WebProxy Proxy; public static WebProxy Proxy;
private static string Prefix => Proxy == null ? private static string Prefix => Proxy == null ?
"https://hk.tsanie.us/reverse/" : "https://hk.tsanie.us/reverse/" :