* Pixiview.iOS/Renderers/AdaptedPageRenderer.cs: fixed: status bar

hidden issue when startup with landscape

* Pixiview/MainPage.xaml:
* Pixiview/MainPage.xaml.cs: feature: add illust command

* Pixiview/UI/CardView.cs: feature: resize height when measure card
  view.

* Pixiview/Utils/Stores.cs: fixed: update working dirs
This commit is contained in:
Tsanie Lily 2020-05-05 15:04:18 +08:00
parent 1bbfdb6477
commit d40dfccc07
5 changed files with 80 additions and 23 deletions

View File

@ -54,12 +54,12 @@ namespace Pixiview.iOS.Renderers
{
if (style == UIStatusBarStyle.BlackOpaque)
{
UIApplication.SharedApplication.SetStatusBarHidden(true, UIStatusBarAnimation.Fade);
UIApplication.SharedApplication.SetStatusBarHidden(true, true);
}
else
{
UIApplication.SharedApplication.SetStatusBarStyle(style, true);
UIApplication.SharedApplication.SetStatusBarHidden(false, UIStatusBarAnimation.Fade);
UIApplication.SharedApplication.SetStatusBarHidden(false, true);
}
SetNeedsStatusBarAppearanceUpdate();
@ -93,6 +93,14 @@ namespace Pixiview.iOS.Renderers
if (lastOrientation != current)
{
lastOrientation = current;
if (current == UIDeviceOrientation.Portrait && UIApplication.SharedApplication.StatusBarHidden)
{
var style = ConvertStyle(StatusBar.GetStatusBarStyle(Element));
if (style != UIStatusBarStyle.BlackOpaque)
{
UIApplication.SharedApplication.SetStatusBarHidden(false, true);
}
}
if (Element is AdaptedPage page)
{
page.OnOrientationChanged((Orientation)lastOrientation);

View File

@ -3,6 +3,7 @@
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:p="clr-namespace:Pixiview"
xmlns:u="clr-namespace:Pixiview.UI"
xmlns:util="clr-namespace:Pixiview.Utils"
xmlns:r="clr-namespace:Pixiview.Resources"
@ -13,8 +14,7 @@
util:StatusBar.StatusBarStyle="{DynamicResource StatusBarStyle}">
<NavigationPage.TitleView>
<u:NavigationTitle Title="{r:Text Follow}"
IsLeftButtonVisible="True"
LeftButtonClicked="NavigationTitle_LeftButtonClicked"
IsRightButtonVisible="True"
RightButtonClicked="NavigationTitle_RightButtonClicked"/>
</NavigationPage.TitleView>
<Grid>
@ -23,14 +23,14 @@
HorizontalOptions="Fill" Column="{Binding Columns}"
Margin="16" RowSpacing="16" ColumnSpacing="16">
<u:FlowLayout.ItemTemplate>
<DataTemplate>
<DataTemplate x:DataType="p:IllustItem">
<u:CardView Padding="0" Margin="0" CornerRadius="10"
ShadowColor="#20000000"
ShadowOffset="2, 2"
BackgroundColor="{DynamicResource SubColor}">
<Grid HorizontalOptions="Fill">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="{Binding ImageHeight}"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
@ -39,7 +39,11 @@
CornerMasks="Top"
Source="{Binding Image}"
HorizontalOptions="Fill"
Aspect="AspectFit"/>
Aspect="AspectFit">
<u:RoundImage.GestureRecognizers>
<TapGestureRecognizer Command="{Binding IllustTapped}" CommandParameter="{Binding .}"/>
</u:RoundImage.GestureRecognizers>
</u:RoundImage>
<u:RoundLabel Text="R-18" BackgroundColor="#fd4363" Margin="6, 6, 0, 0"
Padding="6, 2" CornerRadius="4"
HorizontalOptions="Start" VerticalOptions="Start"

View File

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Pixiview.UI;
using Pixiview.Utils;
using Xamarin.Essentials;
@ -16,6 +17,8 @@ namespace Pixiview
[DesignTimeVisible(false)]
public partial class MainPage : AdaptedPage
{
#region - Properties -
public static readonly BindableProperty IllustsProperty = BindableProperty.Create(
nameof(Illusts), typeof(IllustCollection), typeof(MainPage));
public static readonly BindableProperty ColumnsProperty = BindableProperty.Create(
@ -51,7 +54,10 @@ namespace Pixiview
set => SetValue(LoadingProperty, value);
}
#endregion
private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads };
private readonly Command<IllustItem> commandIllustImageTapped;
private IllustData illustData;
private bool loaded;
@ -61,8 +67,11 @@ namespace Pixiview
InitializeComponent();
BindingContext = this;
commandIllustImageTapped = new Command<IllustItem>(OnIllustImageTapped);
}
#region - Overrides -
public override void OnLoad()
{
App.DebugPrint($"folder: {Stores.PersonalFolder}");
@ -83,6 +92,8 @@ namespace Pixiview
Connectivity.ConnectivityChanged -= Connectivity_ConnectivityChanged;
}
#endregion
private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
{
if (e.NetworkAccess == NetworkAccess.Internet || e.NetworkAccess == NetworkAccess.ConstrainedInternet)
@ -91,6 +102,8 @@ namespace Pixiview
}
}
#region - Illust Tasks -
async void DoLoadIllusts()
{
illustData = await Stores.LoadIllustData();
@ -109,14 +122,18 @@ namespace Pixiview
}
return new IllustItem
{
Id = illust.illustId,
ImageUrl = illust.urls.x360 ?? illust.url,
Title = illust.illustTitle,
IsRestrict = illust.xRestrict == 1,
ProfileUrl = illust.profileImageUrl,
UserId = illust.userId,
UserName = illust.userName,
Width = illust.width,
Height = illust.height,
PageCount = illust.pageCount
PageCount = illust.pageCount,
IllustTapped = commandIllustImageTapped
};
}).Where(i => i != null);
@ -156,7 +173,14 @@ namespace Pixiview
});
}
void Page_OrientationChanged(object sender, OrientationEventArgs e)
#endregion
private void OnIllustImageTapped(IllustItem illust)
{
DisplayAlert("title", $"open illust: {illust.Id}", "Ok");
}
private void Page_OrientationChanged(object sender, OrientationEventArgs e)
{
switch (e.CurrentOrientation)
{
@ -173,11 +197,7 @@ namespace Pixiview
}
}
void NavigationTitle_RightButtonClicked(object sender, EventArgs e)
{
}
void NavigationTitle_LeftButtonClicked(object sender, EventArgs e)
private void NavigationTitle_RightButtonClicked(object sender, EventArgs e)
{
DisplayAlert("title", "message", "Ok");
}
@ -212,6 +232,8 @@ namespace Pixiview
nameof(Image), typeof(ImageSource), typeof(IllustItem));
public static readonly BindableProperty ProfileImageProperty = BindableProperty.Create(
nameof(ProfileImage), typeof(ImageSource), typeof(IllustItem));
public static readonly BindableProperty ImageHeightProperty = BindableProperty.Create(
nameof(ImageHeight), typeof(GridLength), typeof(IllustItem), GridLength.Auto);
public ImageSource Image
{
@ -223,11 +245,19 @@ namespace Pixiview
get => (ImageSource)GetValue(ProfileImageProperty);
set => SetValue(ProfileImageProperty, value);
}
public GridLength ImageHeight
{
get => (GridLength)GetValue(ImageHeightProperty);
set => SetValue(ImageHeightProperty, value);
}
public ICommand IllustTapped { get; set; }
public string Id { get; set; }
public string ImageUrl { get; set; }
public string Title { get; set; }
public bool IsRestrict { get; set; }
public string ProfileUrl { get; set; }
public string UserId { get; set; }
public string UserName { get; set; }
public int Width { get; set; }
public int Height { get; set; }

View File

@ -33,6 +33,15 @@ namespace Pixiview.UI
get => (Size)GetValue(ShadowOffsetProperty);
set => SetValue(ShadowOffsetProperty, value);
}
protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
{
if (BindingContext is IllustItem illust)
{
illust.ImageHeight = widthConstraint * illust.Height / illust.Width;
}
return base.OnMeasure(widthConstraint, heightConstraint);
}
}
}

View File

@ -14,8 +14,9 @@ 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 static readonly string CacheFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
private const string imageFolder = "img-master";
private const string previewFolder = "img-preview";
private const string thumbFolder = "img-thumb";
private const string userFolder = "user-profile";
private const string illustFile = "illust.json";
@ -88,25 +89,30 @@ namespace Pixiview.Utils
public static ImageSource LoadIllustImage(string url)
{
return LoadImage(url, imageFolder);
return LoadImage(url, PersonalFolder, imageFolder);
}
public static ImageSource LoadPreviewImage(string url)
{
return LoadImage(url, PersonalFolder, previewFolder);
}
public static ImageSource LoadThumbnailImage(string url)
{
return LoadImage(url, thumbFolder);
return LoadImage(url, CacheFolder, thumbFolder);
}
public static ImageSource LoadUserProfileImage(string url)
{
return LoadImage(url, userFolder);
return LoadImage(url, CacheFolder, userFolder);
}
public static ImageSource LoadImage(string url, string folder)
private static ImageSource LoadImage(string url, string working, string folder)
{
var file = Path.Combine(PersonalFolder, folder, Path.GetFileName(url));
var file = Path.Combine(working, folder, Path.GetFileName(url));
if (!File.Exists(file))
{
file = DownloadImage(url, folder);
file = DownloadImage(url, working, folder);
}
if (file != null)
{
@ -115,11 +121,11 @@ namespace Pixiview.Utils
return null;
}
public static string DownloadImage(string url, string folder)
private static string DownloadImage(string url, string working, string folder)
{
try
{
var directory = Path.Combine(PersonalFolder, folder);
var directory = Path.Combine(working, folder);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);