This commit is contained in:
2020-05-03 23:46:08 +08:00
commit 67d4955664
34 changed files with 1295 additions and 0 deletions

28
Pixiview/App.xaml Normal file
View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Pixiview.App">
<Application.Resources>
<Color x:Key="WindowColor">Black</Color>
<Color x:Key="TextColor">White</Color>
<Color x:Key="MainColor">#333333</Color>
<Color x:Key="MainTextColor">White</Color>
<Style x:Key="TitleLabel" TargetType="Label">
<Setter Property="VerticalOptions" Value="Center"/>
<Setter Property="HorizontalOptions" Value="Fill"/>
<Setter Property="HorizontalTextAlignment" Value="Center"/>
<Setter Property="FontSize" Value="{DynamicResource FontSizeTitle}"/>
<Setter Property="TextColor" Value="{DynamicResource MainTextColor}"/>
</Style>
<Style x:Key="TitleButton" TargetType="Button">
<Setter Property="BorderWidth" Value="0"/>
<Setter Property="BackgroundColor" Value="Transparent"/>
<Setter Property="FontFamily" Value="{DynamicResource IconSolidFontFamily}"/>
<Setter Property="FontSize" Value="{DynamicResource FontSizeTitleIcon}"/>
<Setter Property="TextColor" Value="{DynamicResource MainTextColor}"/>
</Style>
</Application.Resources>
</Application>

58
Pixiview/App.xaml.cs Normal file
View File

@@ -0,0 +1,58 @@
using Pixiview.UI;
using Pixiview.Utils;
using Xamarin.Forms;
namespace Pixiview
{
public partial class App : Application
{
public const string TitleButton = nameof(TitleButton);
public const string TitleLabel = nameof(TitleLabel);
public const string WindowColor = nameof(WindowColor);
public const string TextColor = nameof(TextColor);
public const string MainColor = nameof(MainColor);
public const string MainTextColor = nameof(MainTextColor);
public const string IconLightFontFamily = nameof(IconLightFontFamily);
public const string IconRegularFontFamily = nameof(IconRegularFontFamily);
public const string IconSolidFontFamily = nameof(IconSolidFontFamily);
public const string IconLeft = nameof(IconLeft);
public const string FontSizeTitle = nameof(FontSizeTitle);
public const string FontSizeTitleIcon = nameof(FontSizeTitleIcon);
//public const string Horizon10 = nameof(Horizon10);
public App()
{
InitializeComponent();
InitResources();
}
private void InitResources()
{
var p = DependencyService.Get<IEnvironmentService>().GetEnvironment();
Resources.Add(IconLightFontFamily, p.IconLightFontFamily);
Resources.Add(IconRegularFontFamily, p.IconRegularFontFamily);
Resources.Add(IconSolidFontFamily, p.IconSolidFontFamily);
Resources.Add(IconLeft, p.IconLeft);
Resources.Add(FontSizeTitle, StyleDefinition.FontSizeTitle);
Resources.Add(FontSizeTitleIcon, StyleDefinition.FontSizeTitleIcon);
//Resources.Add(Horizon10, StyleDefinition.Horizon10);
}
protected override void OnStart()
{
MainPage = UIFactory.CreateNavigationPage(new MainPage());
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
}
}
}

3
Pixiview/AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,3 @@
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]

18
Pixiview/MainPage.xaml Normal file
View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<u:AdaptedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:u="clr-namespace:Pixiview.UI"
mc:Ignorable="d"
x:Class="Pixiview.MainPage">
<NavigationPage.TitleView>
<u:NavigationTitle Title="Startup Name Generator"
IsLeftButtonVisible="True"
LeftButtonClicked="NavigationTitle_LeftButtonClicked"
RightButtonClicked="NavigationTitle_RightButtonClicked"/>
</NavigationPage.TitleView>
<Grid>
</Grid>
</u:AdaptedPage>

34
Pixiview/MainPage.xaml.cs Normal file
View File

@@ -0,0 +1,34 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using Pixiview.UI;
using Pixiview.Utils;
namespace Pixiview
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : AdaptedPage
{
public MainPage()
{
InitializeComponent();
BindingContext = this;
}
public override void OnLoad()
{
Debug.WriteLine(Stores.PersonalFolder);
}
void NavigationTitle_RightButtonClicked(object sender, EventArgs e)
{
}
void NavigationTitle_LeftButtonClicked(object sender, EventArgs e)
{
DisplayAlert("title", "message", "Ok");
}
}
}

21
Pixiview/Pixiview.csproj Normal file
View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.6.0.726" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="UI\" />
<Folder Include="Utils\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,20 @@
using System;
using Xamarin.Forms;
namespace Pixiview.UI
{
public class AdaptedPage : ContentPage
{
public event EventHandler Load;
public AdaptedPage()
{
SetDynamicResource(BackgroundColorProperty, App.WindowColor);
}
public virtual void OnLoad()
{
Load?.Invoke(this, EventArgs.Empty);
}
}
}

View File

@@ -0,0 +1,104 @@
using System;
using Xamarin.Forms;
namespace Pixiview.UI
{
public class NavigationTitle : ContentView
{
public static readonly BindableProperty TitleProperty = BindableProperty.Create(
nameof(Title), typeof(string), typeof(NavigationTitle));
public static readonly BindableProperty IsLeftButtonVisibleProperty = BindableProperty.Create(
nameof(IsLeftButtonVisible), typeof(bool), typeof(NavigationTitle));
public static readonly BindableProperty IsRightButtonVisibleProperty = BindableProperty.Create(
nameof(IsRightButtonVisible), typeof(bool), typeof(NavigationTitle));
public static readonly BindableProperty RightButtonTextProperty = BindableProperty.Create(
nameof(RightButtonText), typeof(string), typeof(NavigationTitle));
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public bool IsLeftButtonVisible
{
get => (bool)GetValue(IsLeftButtonVisibleProperty);
set => SetValue(IsLeftButtonVisibleProperty, value);
}
public bool IsRightButtonVisible
{
get => (bool)GetValue(IsRightButtonVisibleProperty);
set => SetValue(IsRightButtonVisibleProperty, value);
}
public string RightButtonText
{
get => (string)GetValue(RightButtonTextProperty);
set => SetValue(RightButtonTextProperty, value);
}
public event EventHandler LeftButtonClicked;
public event EventHandler RightButtonClicked;
public NavigationTitle()
{
BindingContext = this;
var left = GetLinkButton(nameof(IsLeftButtonVisible),
padding: StyleDefinition.HorizonRight10);
left.SetDynamicResource(Button.FontFamilyProperty, App.IconRegularFontFamily);
left.SetDynamicResource(Button.TextProperty, App.IconLeft);
left.Clicked += Left_Clicked;
var title = new Label();
title.SetDynamicResource(StyleProperty, App.TitleLabel);
title.SetBinding(Label.TextProperty, nameof(Title));
Grid.SetColumnSpan(title, 3);
var right = GetLinkButton(nameof(IsRightButtonVisible),
text: nameof(RightButtonText),
horizon: LayoutOptions.End,
padding: StyleDefinition.HorizonLeft10);
right.Clicked += Right_Clicked;
Grid.SetColumn(right, 2);
Content = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition { Width = GridLength.Auto },
new ColumnDefinition(),
new ColumnDefinition { Width = GridLength.Auto }
},
ColumnSpacing = 0,
Children = { title, left, right }
};
}
private void Left_Clicked(object sender, EventArgs e)
{
LeftButtonClicked?.Invoke(sender, e);
}
private void Right_Clicked(object sender, EventArgs e)
{
RightButtonClicked?.Invoke(sender, e);
}
private Button GetLinkButton(string visibility, string text = null, LayoutOptions horizon = default, Thickness padding = default)
{
var button = new Button
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = horizon,
Padding = padding
};
button.SetBinding(IsVisibleProperty, visibility);
if (text != null)
{
button.SetBinding(Button.TextProperty, text);
}
button.SetDynamicResource(StyleProperty, App.TitleButton);
return button;
}
}
}

View File

@@ -0,0 +1,13 @@
using Xamarin.Forms;
namespace Pixiview.UI
{
public static class StyleDefinition
{
public static readonly double FontSizeTitle = 18.0;
public static readonly double FontSizeTitleIcon = 24.0;
public static readonly Thickness HorizonLeft10 = new Thickness(10, 0, 0, 0);
public static readonly Thickness HorizonRight10 = new Thickness(0, 0, 10, 0);
}
}

44
Pixiview/Utils/Stores.cs Normal file
View File

@@ -0,0 +1,44 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace Pixiview.Utils
{
public class Stores
{
public static readonly string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
//public static readonly string CacheFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
public const string ImageFolder = "images";
[SuppressMessage("Style", "IDE0063:Use simple 'using' statement", Justification = "<Pending>")]
public static async Task DownloadImage(string url)
{
var uri = new Uri(url);
var handler = new HttpClientHandler
{
Proxy = new WebProxy("10.0.10.100", 8088),
UseProxy = true
};
var client = new HttpClient(handler)
{
BaseAddress = new Uri($"{uri.Scheme}://{uri.Host}")
};
using (var request = new HttpRequestMessage(HttpMethod.Get, uri.PathAndQuery)
{
Version = new Version(2, 0)
})
{
request.Headers.Referrer = new Uri("https://www.pixiv.net/");
var file = Path.Combine(PersonalFolder, ImageFolder, Path.GetFileName(uri.LocalPath));
using (var response = await client.SendAsync(request))
using (var fs = File.OpenWrite(file))
{
await response.Content.CopyToAsync(fs);
}
}
}
}
}