diff --git a/Pixiview.Android/Pixiview.Android.csproj b/Pixiview.Android/Pixiview.Android.csproj index fff1223..47aaf0d 100644 --- a/Pixiview.Android/Pixiview.Android.csproj +++ b/Pixiview.Android/Pixiview.Android.csproj @@ -80,6 +80,7 @@ + @@ -95,10 +96,6 @@ - - - - @@ -207,6 +204,10 @@ + + + + diff --git a/Pixiview.Android/Renderers/HybridWebViewRenderer.cs b/Pixiview.Android/Renderers/HybridWebViewRenderer.cs new file mode 100644 index 0000000..5f41826 --- /dev/null +++ b/Pixiview.Android/Renderers/HybridWebViewRenderer.cs @@ -0,0 +1,117 @@ +using Android.Content; +using Android.Webkit; +using Pixiview.Droid.Renderers; +using Pixiview.Login; +using Pixiview.Utils; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Android; + +[assembly: ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))] +namespace Pixiview.Droid.Renderers +{ + public class HybridWebViewRenderer : WebViewRenderer + { + public HybridWebViewRenderer(Context context) : base(context) + { + } + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + if (e.NewElement is HybridWebView webView) + { + Control.SetWebViewClient(new PixivWebViewClient(this)); + Control.LoadUrl(webView.Uri); + } + } + + private class PixivWebViewClient : FormsWebViewClient + { + private readonly HybridWebView webView; + + public PixivWebViewClient(HybridWebViewRenderer renderer) : base(renderer) + { + if (renderer.Element is HybridWebView view) + { + webView = view; + } + } + + //public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request) + //{ + // var uri = request.Url; + // if (uri.Host == "www.pixiv.net" && uri.Path == "/") + // { + // var client = new HttpClient(new HttpClientHandler { UseCookies = false }) + // { + // BaseAddress = new Uri($"{uri.Scheme}://{uri.Host}"), + // Timeout = TimeSpan.FromSeconds(30) + // }; + // var pathAndQuery = uri.Path; + // if (!string.IsNullOrEmpty(uri.Query)) + // { + // pathAndQuery += "?" + uri.EncodedQuery; + // } + // using (var req = new HttpRequestMessage( + // request.Method == "POST" ? HttpMethod.Post : HttpMethod.Get, + // pathAndQuery)) + // { + // var headers = req.Headers; + // if (request.RequestHeaders != null) + // { + // foreach (var h in request.RequestHeaders) + // { + // headers.Add(h.Key, h.Value); + // } + // } + + // using (var response = client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead).Result) + // { + // if (response.Headers.TryGetValues("x-userid", out var vals)) + // { + // Configs.SetUserId(string.Join(';', vals), true); + // } + // } + // } + // return true; + // } + // return base.ShouldOverrideUrlLoading(view, request); + //} + + public override void OnPageFinished(Android.Webkit.WebView view, string url) + { + base.OnPageFinished(view, url); + + if (url == "https://www.pixiv.net/" || + url == "https://www.pixiv.net/en/") + { + var cookieManager = CookieManager.Instance; + var cookie = cookieManager.GetCookie(url); + Configs.SetCookie(cookie, true); + + // user-id + if (cookie != null) + { + var index = cookie.IndexOf("PHPSESSID="); + if (index >= 0) + { + var session = cookie.Substring(index + 10); + index = session.IndexOf('_'); + if (index > 0) + { + session = session.Substring(0, index); + Configs.SetUserId(session, true); + } + } + } + + if (webView != null) + { + webView.OnLoginHandle(); + } + } + } + } + } +} diff --git a/Pixiview.Android/Resources/Resource.designer.cs b/Pixiview.Android/Resources/Resource.designer.cs index e9756e4..f0122b8 100644 --- a/Pixiview.Android/Resources/Resource.designer.cs +++ b/Pixiview.Android/Resources/Resource.designer.cs @@ -8337,65 +8337,65 @@ namespace Pixiview.Droid // aapt resource value: 0x7F070069 public const int navigation_empty_icon = 2131165289; - // aapt resource value: 0x7F07006A - public const int notification_action_background = 2131165290; - // aapt resource value: 0x7F07006B - public const int notification_bg = 2131165291; + public const int notification_action_background = 2131165291; // aapt resource value: 0x7F07006C - public const int notification_bg_low = 2131165292; + public const int notification_bg = 2131165292; // aapt resource value: 0x7F07006D - public const int notification_bg_low_normal = 2131165293; + public const int notification_bg_low = 2131165293; // aapt resource value: 0x7F07006E - public const int notification_bg_low_pressed = 2131165294; + public const int notification_bg_low_normal = 2131165294; // aapt resource value: 0x7F07006F - public const int notification_bg_normal = 2131165295; + public const int notification_bg_low_pressed = 2131165295; // aapt resource value: 0x7F070070 - public const int notification_bg_normal_pressed = 2131165296; + public const int notification_bg_normal = 2131165296; // aapt resource value: 0x7F070071 - public const int notification_icon_background = 2131165297; + public const int notification_bg_normal_pressed = 2131165297; // aapt resource value: 0x7F070072 - public const int notification_template_icon_bg = 2131165298; + public const int notification_icon_background = 2131165298; // aapt resource value: 0x7F070073 - public const int notification_template_icon_low_bg = 2131165299; + public const int notification_template_icon_bg = 2131165299; // aapt resource value: 0x7F070074 - public const int notification_tile_bg = 2131165300; + public const int notification_template_icon_low_bg = 2131165300; // aapt resource value: 0x7F070075 - public const int notify_panel_notification_icon_bg = 2131165301; + public const int notification_tile_bg = 2131165301; // aapt resource value: 0x7F070076 - public const int segmented_control_background = 2131165302; + public const int notify_panel_notification_icon_bg = 2131165302; + + // aapt resource value: 0x7F07006A + public const int no_profile = 2131165290; // aapt resource value: 0x7F070077 - public const int segmented_control_first_background = 2131165303; + public const int segmented_control_background = 2131165303; // aapt resource value: 0x7F070078 - public const int segmented_control_last_background = 2131165304; + public const int segmented_control_first_background = 2131165304; // aapt resource value: 0x7F070079 - public const int splash_logo = 2131165305; + public const int segmented_control_last_background = 2131165305; // aapt resource value: 0x7F07007A - public const int splash_screen = 2131165306; + public const int splash_logo = 2131165306; // aapt resource value: 0x7F07007B - public const int tooltip_frame_dark = 2131165307; + public const int splash_screen = 2131165307; // aapt resource value: 0x7F07007C - public const int tooltip_frame_light = 2131165308; + public const int tooltip_frame_dark = 2131165308; // aapt resource value: 0x7F07007D - public const int userprofile = 2131165309; + public const int tooltip_frame_light = 2131165309; static Drawable() { diff --git a/Pixiview.Android/Resources/drawable/no_profile.png b/Pixiview.Android/Resources/drawable/no_profile.png new file mode 100644 index 0000000..9c4e4fb Binary files /dev/null and b/Pixiview.Android/Resources/drawable/no_profile.png differ diff --git a/Pixiview.Android/Resources/drawable/userprofile.jpg b/Pixiview.Android/Resources/drawable/userprofile.jpg deleted file mode 100644 index 91428d8..0000000 Binary files a/Pixiview.Android/Resources/drawable/userprofile.jpg and /dev/null differ diff --git a/Pixiview.iOS/Pixiview.iOS.csproj b/Pixiview.iOS/Pixiview.iOS.csproj index 35d2c29..894b5e9 100644 --- a/Pixiview.iOS/Pixiview.iOS.csproj +++ b/Pixiview.iOS/Pixiview.iOS.csproj @@ -167,7 +167,7 @@ - + \ No newline at end of file diff --git a/Pixiview.iOS/Renderers/HybridWebViewRenderer.cs b/Pixiview.iOS/Renderers/HybridWebViewRenderer.cs index a3cdf90..933bde7 100644 --- a/Pixiview.iOS/Renderers/HybridWebViewRenderer.cs +++ b/Pixiview.iOS/Renderers/HybridWebViewRenderer.cs @@ -64,7 +64,7 @@ namespace Pixiview.iOS.Renderers public override async void DidFinishNavigation(WKWebView webView, WKNavigation navigation) { var url = webView.Url; - if (url.Host == "www.pixiv.net" && url.Path == "/") + if (url.Host == "www.pixiv.net" && (url.Path == "/" || url.Path == "/en/")) { var store = webView.Configuration.WebsiteDataStore.HttpCookieStore; var result = await Configs.RequestCookieContainer(store); diff --git a/Pixiview.iOS/Resources/no_profile.png b/Pixiview.iOS/Resources/no_profile.png new file mode 100644 index 0000000..9c4e4fb Binary files /dev/null and b/Pixiview.iOS/Resources/no_profile.png differ diff --git a/Pixiview.iOS/Resources/userprofile.jpg b/Pixiview.iOS/Resources/userprofile.jpg deleted file mode 100644 index 91428d8..0000000 Binary files a/Pixiview.iOS/Resources/userprofile.jpg and /dev/null differ diff --git a/Pixiview/App.cs b/Pixiview/App.cs index 3f522f0..037dd68 100644 --- a/Pixiview/App.cs +++ b/Pixiview/App.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Pixiview.Illust; using Pixiview.Resources; using Pixiview.UI.Theme; @@ -34,6 +35,9 @@ namespace Pixiview Configs.SetCookie(Preferences.Get(Configs.CookieKey, null)); Configs.SetUserId(Preferences.Get(Configs.UserIdKey, null)); + // login info + Task.Run(() => AppShell.Current.DoLoginInformation()); + Configs.IsOnR18 = Preferences.Get(Configs.IsOnR18Key, false); var isProxied = Preferences.Get(Configs.IsProxiedKey, false); if (isProxied) diff --git a/Pixiview/AppShell.xaml b/Pixiview/AppShell.xaml index 16eb2b4..5d7d4df 100644 --- a/Pixiview/AppShell.xaml +++ b/Pixiview/AppShell.xaml @@ -20,16 +20,16 @@ - + -