diff --git a/Pixiview.iOS/Pixiview.iOS.csproj b/Pixiview.iOS/Pixiview.iOS.csproj index a15cffe..ba7184c 100644 --- a/Pixiview.iOS/Pixiview.iOS.csproj +++ b/Pixiview.iOS/Pixiview.iOS.csproj @@ -80,6 +80,8 @@ + + diff --git a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs index 9c79508..351c5a7 100644 --- a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs +++ b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs @@ -85,6 +85,7 @@ namespace Pixiview.iOS.Renderers } if (Element is AdaptedPage page) { + AppShell.Current?.SetStatusBarHeight(UIApplication.SharedApplication.StatusBarFrame.Height); page.OnOrientationChanged((Orientation)lastOrientation); } } diff --git a/Pixiview.iOS/Renderers/AppShellRenderer.cs b/Pixiview.iOS/Renderers/AppShellRenderer.cs index 786c4d7..4c39d54 100644 --- a/Pixiview.iOS/Renderers/AppShellRenderer.cs +++ b/Pixiview.iOS/Renderers/AppShellRenderer.cs @@ -16,28 +16,10 @@ namespace Pixiview.iOS.Renderers protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection) { - var renderer = new AppShellSectionRenderer(this); + var renderer = base.CreateShellSectionRenderer(shellSection); // new AppShellSectionRenderer(this); if (renderer is ShellSectionRenderer sr && Element is AppShell shell) { - shell.SetNavigationBarHeight( - sr.NavigationBar.Frame.Height, - UIApplication.SharedApplication.StatusBarFrame.Height); - } - return renderer; - } - - [SuppressMessage("Code Notifications", "XI0002:Notifies you from using newer Apple APIs when targeting an older OS version", Justification = "")] - protected override IShellItemRenderer CreateShellItemRenderer(ShellItem item) - { - var renderer = base.CreateShellItemRenderer(item); - if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) - { - if (renderer.ViewController is UITabBarController controller) - { - var tabBar = controller.TabBar; - tabBar.TintColor = UIColor.LabelColor; - tabBar.UnselectedItemTintColor = UIColor.SecondaryLabelColor; - } + shell.SetNavigationBarHeight(sr.NavigationBar.Frame.Height); } return renderer; } @@ -52,6 +34,11 @@ namespace Pixiview.iOS.Renderers return new AppShellTabBarAppearanceTracker(); } + protected override IShellNavBarAppearanceTracker CreateNavBarAppearanceTracker() + { + return new AppShellNavBarAppearanceTracker(); + } + protected override void UpdateBackgroundColor() { NativeView.BackgroundColor = Color.Transparent.ToUIColor(); @@ -76,73 +63,6 @@ namespace Pixiview.iOS.Renderers } } - public class AppShellTabBarAppearanceTracker : IShellTabBarAppearanceTracker - { - UIColor _defaultBarTint; - UIColor _defaultTint; - UIColor _defaultUnselectedTint; - - public void Dispose() - { - } - - public void ResetAppearance(UITabBarController controller) - { - if (_defaultTint == null) - return; - - var tabBar = controller.TabBar; - tabBar.BarTintColor = _defaultBarTint; - tabBar.TintColor = _defaultTint; - tabBar.UnselectedItemTintColor = _defaultUnselectedTint; - } - - [SuppressMessage("Code Notifications", "XI0002:Notifies you from using newer Apple APIs when targeting an older OS version", Justification = "")] - public void SetAppearance(UITabBarController controller, ShellAppearance appearance) - { - IShellAppearanceElement appearanceElement = appearance; - //var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor; - var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor; - var tintColor = appearanceElement.EffectiveTabBarForegroundColor; // appearanceElement.EffectiveTabBarTitleColor; - - var tabBar = controller.TabBar; - //bool operatingSystemSupportsUnselectedTint = Forms.IsiOS10OrNewer; - - if (_defaultTint == null) - { - _defaultBarTint = tabBar.BarTintColor; - _defaultTint = tabBar.TintColor; - - //if (operatingSystemSupportsUnselectedTint) - { - _defaultUnselectedTint = tabBar.UnselectedItemTintColor; - } - } - - //if (!backgroundColor.IsDefault) - // tabBar.BarTintColor = backgroundColor.ToUIColor(); - - if (!tintColor.IsDefault) - tabBar.TintColor = tintColor.ToUIColor(); - //if (operatingSystemSupportsUnselectedTint) - { - if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) - { - //tabBar.UnselectedItemTintColor = UIColor.TertiaryLabelColor; - } - else - { - if (!unselectedColor.IsDefault) - tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor(); - } - } - } - - public void UpdateLayout(UITabBarController controller) - { - } - } - public class AppShellSectionRenderer : ShellSectionRenderer { public AppShellSectionRenderer(IShellContext context) : base(context) diff --git a/Pixiview.iOS/Renderers/BlurryPanelRenderer.cs b/Pixiview.iOS/Renderers/BlurryPanelRenderer.cs new file mode 100644 index 0000000..053de1f --- /dev/null +++ b/Pixiview.iOS/Renderers/BlurryPanelRenderer.cs @@ -0,0 +1,86 @@ +using CoreAnimation; +using Pixiview.iOS.Renderers; +using Pixiview.UI; +using UIKit; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(BlurryPanel), typeof(BlurryPanelRenderer))] +namespace Pixiview.iOS.Renderers +{ + public class BlurryPanelRenderer : ViewRenderer + { + private UIVisualEffectView nativeControl; + private CALayer bottom; + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + if (e.OldElement != null) + { + if (bottom != null) + { + if (bottom.SuperLayer != null) + { + bottom.RemoveFromSuperLayer(); + } + bottom.Dispose(); + bottom = null; + } + } + + if (e.NewElement != null) + { + if (Control == null) + { + var blur = UIBlurEffect.FromStyle(UIBlurEffectStyle.SystemMaterial); + nativeControl = new UIVisualEffectView(blur) + { + Frame = Frame + }; + SetNativeControl(nativeControl); + } + } + } + + public override void LayoutSubviews() + { + base.LayoutSubviews(); + + if (nativeControl != null) + { + if (bottom == null) + { + bottom = new CALayer + { + BackgroundColor = UIColor.White.CGColor, + ShadowColor = UIColor.Black.CGColor, + ShadowOpacity = 1.0f + }; + } + if (bottom.SuperLayer == null) + { + nativeControl.Layer.InsertSublayer(bottom, 0); + } + bottom.Frame = new CoreGraphics.CGRect(0, Frame.Height - 5, Frame.Width, 5); + nativeControl.Frame = Frame; + } + } + + protected override void Dispose(bool disposing) + { + if (bottom != null) + { + if (bottom.SuperLayer != null) + { + bottom.RemoveFromSuperLayer(); + } + bottom.Dispose(); + bottom = null; + } + + base.Dispose(disposing); + } + } +} diff --git a/Pixiview.iOS/Renderers/OptionEntryRenderer.cs b/Pixiview.iOS/Renderers/OptionEntryRenderer.cs index 7a5a601..d148418 100644 --- a/Pixiview.iOS/Renderers/OptionEntryRenderer.cs +++ b/Pixiview.iOS/Renderers/OptionEntryRenderer.cs @@ -1,5 +1,4 @@ -using System; -using Pixiview.iOS.Renderers; +using Pixiview.iOS.Renderers; using Pixiview.UI; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS; diff --git a/Pixiview/App.cs b/Pixiview/App.cs index 47fb48f..b44c6f3 100644 --- a/Pixiview/App.cs +++ b/Pixiview/App.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; diff --git a/Pixiview/AppShell.xaml.cs b/Pixiview/AppShell.xaml.cs index 1b7fe89..9fa8a8e 100644 --- a/Pixiview/AppShell.xaml.cs +++ b/Pixiview/AppShell.xaml.cs @@ -9,9 +9,11 @@ namespace Pixiview public static new AppShell Current => Shell.Current as AppShell; public static Thickness NavigationBarOffset { get; private set; } + public static Thickness HalfNavigationBarOffset { get; private set; } public static Thickness TotalBarOffset { get; private set; } public event EventHandler NavigationBarHeightChanged; + public event EventHandler StatusBarHeightChanged; public AppShell() { @@ -20,15 +22,24 @@ namespace Pixiview App.DebugPrint($"folder: {Stores.PersonalFolder}"); } - public void SetNavigationBarHeight(double height, double statusHeight) + public void SetNavigationBarHeight(double height) { NavigationBarOffset = new Thickness(0, height, 0, 0); - TotalBarOffset = new Thickness(0, height + statusHeight, 0, 0); + HalfNavigationBarOffset = new Thickness(0, height / 2, 0, 0); NavigationBarHeightChanged?.Invoke(this, new BarHeightEventArgs { - NavigationBarHeight = height, - StatusBarHeight = statusHeight + NavigationBarHeight = height + }); + } + + public void SetStatusBarHeight(double height) + { + TotalBarOffset = new Thickness(0, NavigationBarOffset.Top + height, 0, 0); + + StatusBarHeightChanged?.Invoke(this, new BarHeightEventArgs + { + StatusBarHeight = height }); } } diff --git a/Pixiview/Illust/IllustCollectionPage.cs b/Pixiview/Illust/IllustCollectionPage.cs index c97c974..23569fb 100644 --- a/Pixiview/Illust/IllustCollectionPage.cs +++ b/Pixiview/Illust/IllustCollectionPage.cs @@ -55,6 +55,7 @@ namespace Pixiview.Illust public IllustCollection IllustCollection { get; set; } protected virtual bool IsFavoriteVisible => true; + protected virtual bool IsLazyload => false; protected DateTime lastUpdated; private T illustData; @@ -87,9 +88,20 @@ namespace Pixiview.Illust if (lastUpdated != LastUpdated) { - StartLoad(); + if (IsLazyload) + { + Device.StartTimer(TimeSpan.FromMilliseconds(200), () => + { + StartLoad(); + return false; + }); + } + else + { + StartLoad(); + } } - else if (IsFavoriteVisible) + else if (IsFavoriteVisible && IllustCollection != null) { var favorites = Stores.Favorites; foreach (var item in IllustCollection) @@ -120,13 +132,19 @@ namespace Pixiview.Illust { base.OnSizeAllocated(width, height); int columns; - if (isPhone) + if (width > height) { - columns = width > height ? 4 : 2; + PanelTopMargin = StyleDefinition.IsFullscreenDevice ? + AppShell.HalfNavigationBarOffset : + StyleDefinition.TopOffset16; + columns = isPhone ? 4 : 6; } else { - columns = width > height ? 6 : 4; + PanelTopMargin = StyleDefinition.IsFullscreenDevice ? + AppShell.NavigationBarOffset : + StyleDefinition.TopOffset32; + columns = isPhone ? 2 : 4; } if (Columns != columns) { diff --git a/Pixiview/Illust/RankingPage.xaml b/Pixiview/Illust/RankingPage.xaml index 767cc9f..1b300ac 100644 --- a/Pixiview/Illust/RankingPage.xaml +++ b/Pixiview/Illust/RankingPage.xaml @@ -5,21 +5,24 @@ xmlns:u="clr-namespace:Pixiview.UI" xmlns:r="clr-namespace:Pixiview.Resources" x:Class="Pixiview.Illust.RankingPage" - BackgroundColor="{DynamicResource WindowColor}"> + BackgroundColor="{DynamicResource WindowColor}" + Shell.NavBarHasShadow="False"> - + - + true; protected override IEnumerable DoGetIllustList(IllustData data, ICommand command) { diff --git a/Pixiview/Illust/RecommendsPage.xaml b/Pixiview/Illust/RecommendsPage.xaml index ae79774..f11fa82 100644 --- a/Pixiview/Illust/RecommendsPage.xaml +++ b/Pixiview/Illust/RecommendsPage.xaml @@ -11,14 +11,15 @@ - + + - + DoGetIllustList(IllustData data, ICommand command) { if (SegmentIndex == 1) diff --git a/Pixiview/Pixiview.projitems b/Pixiview/Pixiview.projitems index 29c7c9b..737e50f 100644 --- a/Pixiview/Pixiview.projitems +++ b/Pixiview/Pixiview.projitems @@ -90,6 +90,7 @@ + diff --git a/Pixiview/UI/AdaptedPage.cs b/Pixiview/UI/AdaptedPage.cs index c99ae0d..d40b411 100644 --- a/Pixiview/UI/AdaptedPage.cs +++ b/Pixiview/UI/AdaptedPage.cs @@ -10,12 +10,19 @@ namespace Pixiview.UI { public static readonly BindableProperty PageTopMarginProperty = BindableProperty.Create( nameof(PageTopMargin), typeof(Thickness), typeof(AdaptedPage)); + public static readonly BindableProperty PanelTopMarginProperty = BindableProperty.Create( + nameof(PanelTopMargin), typeof(Thickness), typeof(AdaptedPage)); public Thickness PageTopMargin { get => (Thickness)GetValue(PageTopMarginProperty); protected set => SetValue(PageTopMarginProperty, value); } + public Thickness PanelTopMargin + { + get => (Thickness)GetValue(PanelTopMarginProperty); + protected set => SetValue(PanelTopMarginProperty, value); + } public Orientation CurrentOrientation { get; private set; } public event EventHandler Load; @@ -48,13 +55,18 @@ namespace Pixiview.UI PageTopMargin = AppShell.TotalBarOffset; break; case Orientation.PortraitUpsideDown: - //PageTopMargin = isPhone ? AppShell.NavigationBarOffset : AppShell.TotalBarOffset; - //break; case Orientation.Unknown: case Orientation.LandscapeLeft: case Orientation.LandscapeRight: default: - PageTopMargin = isPhone ? AppShell.NavigationBarOffset : AppShell.TotalBarOffset; + if (StyleDefinition.IsFullscreenDevice) + { + PageTopMargin = AppShell.NavigationBarOffset; + } + else + { + PageTopMargin = isPhone ? StyleDefinition.TopOffset32 : AppShell.TotalBarOffset; + } break; } OrientationChanged?.Invoke(this, new OrientationEventArgs { CurrentOrientation = orientation }); diff --git a/Pixiview/UI/BlurryPanel.cs b/Pixiview/UI/BlurryPanel.cs new file mode 100644 index 0000000..41c03f1 --- /dev/null +++ b/Pixiview/UI/BlurryPanel.cs @@ -0,0 +1,8 @@ +using Xamarin.Forms; + +namespace Pixiview.UI +{ + public class BlurryPanel : ContentView + { + } +} diff --git a/Pixiview/UI/StyleDefinition.cs b/Pixiview/UI/StyleDefinition.cs index 989c9dd..9413ee5 100644 --- a/Pixiview/UI/StyleDefinition.cs +++ b/Pixiview/UI/StyleDefinition.cs @@ -9,6 +9,8 @@ namespace Pixiview.UI public const double FontSizeTitle = 18.0; public static readonly Thickness ScreenBottomPadding; + public static readonly Thickness TopOffset16 = new Thickness(0, 16, 0, 0); + public static readonly Thickness TopOffset32 = new Thickness(0, 32, 0, 0); public static readonly Color ColorLightShadow = Color.FromRgba(0, 0, 0, 0x20); public static readonly Color ColorDeepShadow = Color.FromRgba(0, 0, 0, 0x50); public static readonly Color ColorRedBackground = Color.FromRgb(0xfd, 0x43, 0x63); diff --git a/Pixiview/UI/Theme/DarkTheme.cs b/Pixiview/UI/Theme/DarkTheme.cs index 8443564..521b91b 100644 --- a/Pixiview/UI/Theme/DarkTheme.cs +++ b/Pixiview/UI/Theme/DarkTheme.cs @@ -29,7 +29,7 @@ namespace Pixiview.UI.Theme { Add(StatusBarStyle, StatusBarStyles.WhiteText); Add(WindowColor, Color.Black); - Add(TintColor, Color.FromRgb(0x00, 0x96, 0xfa)); + Add(TintColor, Color.FromRgb(0x94, 0x95, 0x9a)); Add(TextColor, Color.White); Add(SubTextColor, Color.LightGray); Add(CardBackgroundColor, Color.FromRgb(0x33, 0x33, 0x33)); diff --git a/Pixiview/UI/Theme/LightTheme.cs b/Pixiview/UI/Theme/LightTheme.cs index ca1b227..8239252 100644 --- a/Pixiview/UI/Theme/LightTheme.cs +++ b/Pixiview/UI/Theme/LightTheme.cs @@ -29,7 +29,7 @@ namespace Pixiview.UI.Theme { Add(StatusBarStyle, StatusBarStyles.DarkText); Add(WindowColor, Color.White); - Add(TintColor, Color.FromRgb(0x00, 0x96, 0xfa)); // 0x7f, 0x99, 0xc6 + Add(TintColor, Color.FromRgb(0x87, 0x87, 0x8b)); // 0x7f, 0x99, 0xc6 Add(TextColor, Color.Black); Add(SubTextColor, Color.DimGray); Add(CardBackgroundColor, Color.FromRgb(0xf0, 0xf3, 0xf3)); diff --git a/Pixiview/Utils/Stores.cs b/Pixiview/Utils/Stores.cs index c22b8e0..b6b9a0c 100644 --- a/Pixiview/Utils/Stores.cs +++ b/Pixiview/Utils/Stores.cs @@ -118,10 +118,10 @@ namespace Pixiview.Utils { headers.Referrer = new Uri(referer); } - headers.Add("user-agent", Configs.UserAgent); - headers.Add("accept", Configs.AcceptJson); - headers.Add("cookie", Configs.Cookie); - headers.Add("x-user-id", Configs.UserId); + headers.Add("User-Agent", Configs.UserAgent); + headers.Add("Accept", Configs.AcceptJson); + headers.Add("Cookie", Configs.Cookie); + headers.Add("X-User-Id", Configs.UserId); }); if (response == null) { @@ -393,8 +393,8 @@ namespace Pixiview.Utils var response = Download(url, headers => { headers.Referrer = new Uri(Configs.Referer); - headers.Add("user-agent", Configs.UserAgent); - headers.Add("accept", Configs.AcceptImage); + headers.Add("User-Agent", Configs.UserAgent); + headers.Add("Accept", Configs.AcceptImage); }); if (response == null) { @@ -444,7 +444,8 @@ namespace Pixiview.Utils var proxy = Configs.Proxy; var handler = new HttpClientHandler { - AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate + AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, + UseCookies = false }; if (proxy != null) { @@ -460,13 +461,14 @@ namespace Pixiview.Utils { using (var request = new HttpRequestMessage(HttpMethod.Get, uri.PathAndQuery) { - Version = new Version(2, 0), + Version = new Version(2, 0) }) { var headers = request.Headers; headerAction(headers); - headers.Add("accept-language", Configs.AcceptLanguage); - headers.Add("accept-encoding", Configs.AcceptEncoding); + headers.Add("x-reverse", "yes"); + headers.Add("Accept-Language", Configs.AcceptLanguage); + //headers.Add("Accept-Encoding", Configs.AcceptEncoding); return client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result; } }); @@ -479,34 +481,48 @@ namespace Pixiview.Utils public const string HostKey = "host"; public const string PortKey = "port"; - public static WebProxy Proxy; - public const int MaxThreads = 3; public const string Referer = "https://www.pixiv.net/"; - public const string UrlIllustList = "https://www.pixiv.net/ajax/top/illust?mode=all&lang=zh"; - public const string UrlIllust = "https://www.pixiv.net/artworks/{0}"; + + public static WebProxy Proxy; + private static string Prefix => Proxy == null ? + "https://hk.tsanie.us/reverse/" : + "https://www.pixiv.net/"; + public const string SuffixPreload = " id=\"meta-preload-data\" content='"; public const int SuffixPreloadLength = 33; // SuffixPreload.Length - public const string UrlIllustUserAll = "https://www.pixiv.net/ajax/user/{0}/profile/all?lang=zh"; - public const string UrlIllustUserArtworks = "https://www.pixiv.net/ajax/user/{0}/profile/illusts?{1}work_category=illustManga&is_first_page={2}&lang=zh"; - public const string UrlIllustUser = "https://www.pixiv.net/users/{0}/artworks"; - public const string UrlIllustPage = "https://www.pixiv.net/ajax/illust/{0}/pages?lang=zh"; + public static string UrlIllustList => Prefix + "ajax/top/illust?mode=all&lang=zh"; + public static string UrlIllust = Prefix + "artworks/{0}"; + public static string UrlIllustUserAll = Prefix + "ajax/user/{0}/profile/all?lang=zh"; + public static string UrlIllustUserArtworks = Prefix + "ajax/user/{0}/profile/illusts?{1}work_category=illustManga&is_first_page={2}&lang=zh"; + public static string UrlIllustUser = Prefix + "users/{0}/artworks"; + public static string UrlIllustPage = Prefix + "ajax/illust/{0}/pages?lang=zh"; public const string UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"; public const string AcceptImage = "image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5"; public const string AcceptJson = "application/json"; - public const string AcceptEncoding = "gzip, deflate"; + //public const string AcceptEncoding = "gzip, deflate"; public const string AcceptLanguage = "zh-cn"; - public const string UserId = "2603358"; + //public const string UserId = "2603358"; + //public const string Cookie = + // "PHPSESSID=2603358_VHyGPeRaz7LpeoFkRsHvjXIpApCMb56a; " + + // "a_type=0; b_type=1; c_type=31; d_type=2; " + + // "p_ab_id=2; p_ab_id_2=6; p_ab_d_id=1155161977; " + + // "privacy_policy_agreement=2; " + + // "login_ever=yes; " + + // "__cfduid=d9fa2d4d1ddd30db85ebb519f9855d2561587806747; " + + // "first_visit_datetime_pc=2019-10-29+22%3A05%3A30; " + + // "yuid_b=NgcXQWQ"; + public const string UserId = "53887721"; public const string Cookie = - "PHPSESSID=2603358_VHyGPeRaz7LpeoFkRsHvjXIpApCMb56a; " + - "a_type=0; b_type=1; c_type=31; d_type=2; " + - "p_ab_id=2; p_ab_id_2=6; p_ab_d_id=1155161977; " + + "PHPSESSID=5sn8n049j5c18l0tlj91qrjhesgddhjv; " + + "a_type=0; b_type=1; c_type=29; d_type=2; " + + "p_ab_d_id=1021624041; p_ab_id=2; p_ab_id_2=0; " + "privacy_policy_agreement=2; " + "login_ever=yes; " + - "__cfduid=d9fa2d4d1ddd30db85ebb519f9855d2561587806747; " + - "first_visit_datetime_pc=2019-10-29+22%3A05%3A30; " + - "yuid_b=NgcXQWQ"; + "__cfduid=d84153bf70ae67315a8bc297299d39eb61588856027; " + + "first_visit_datetime_pc=2020-05-07+21%3A53%3A47; " + + "yuid_b=MYkIJXc"; public static string GetThumbnailUrl(string url) {