feature: login support for Android
feature: display profile information
This commit is contained in:
@ -80,6 +80,7 @@
|
||||
<Compile Include="SplashActivity.cs" />
|
||||
<Compile Include="Renderers\RoundImageRenderer.cs" />
|
||||
<Compile Include="Renderers\AdaptedPageRenderer.cs" />
|
||||
<Compile Include="Renderers\HybridWebViewRenderer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\AboutResources.txt" />
|
||||
@ -95,10 +96,6 @@
|
||||
<SubType></SubType>
|
||||
<Generator></Generator>
|
||||
</AndroidResource>
|
||||
<AndroidResource Include="Resources\drawable\userprofile.jpg">
|
||||
<SubType></SubType>
|
||||
<Generator></Generator>
|
||||
</AndroidResource>
|
||||
<AndroidResource Include="Resources\mipmap-xxxhdpi\icon_foreground.png">
|
||||
<SubType></SubType>
|
||||
<Generator></Generator>
|
||||
@ -207,6 +204,10 @@
|
||||
<SubType></SubType>
|
||||
<Generator></Generator>
|
||||
</AndroidResource>
|
||||
<AndroidResource Include="Resources\drawable\no_profile.png">
|
||||
<SubType></SubType>
|
||||
<Generator></Generator>
|
||||
</AndroidResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\drawable\" />
|
||||
|
117
Pixiview.Android/Renderers/HybridWebViewRenderer.cs
Normal file
117
Pixiview.Android/Renderers/HybridWebViewRenderer.cs
Normal file
@ -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<Xamarin.Forms.WebView> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
Pixiview.Android/Resources/Resource.designer.cs
generated
44
Pixiview.Android/Resources/Resource.designer.cs
generated
@ -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()
|
||||
{
|
||||
|
BIN
Pixiview.Android/Resources/drawable/no_profile.png
Normal file
BIN
Pixiview.Android/Resources/drawable/no_profile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 20 KiB |
Reference in New Issue
Block a user