diff --git a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs index 9a4d45c..da6d078 100644 --- a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs +++ b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs @@ -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); diff --git a/Pixiview/MainPage.xaml b/Pixiview/MainPage.xaml index caf028f..648fc7d 100644 --- a/Pixiview/MainPage.xaml +++ b/Pixiview/MainPage.xaml @@ -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}"> @@ -23,14 +23,14 @@ HorizontalOptions="Fill" Column="{Binding Columns}" Margin="16" RowSpacing="16" ColumnSpacing="16"> - + - + @@ -39,7 +39,11 @@ CornerMasks="Top" Source="{Binding Image}" HorizontalOptions="Fill" - Aspect="AspectFit"/> + Aspect="AspectFit"> + + + + SetValue(LoadingProperty, value); } + #endregion + private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads }; + private readonly Command commandIllustImageTapped; private IllustData illustData; private bool loaded; @@ -61,8 +67,11 @@ namespace Pixiview InitializeComponent(); BindingContext = this; + commandIllustImageTapped = new Command(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; } diff --git a/Pixiview/UI/CardView.cs b/Pixiview/UI/CardView.cs index 9c253fc..ac3aaa8 100644 --- a/Pixiview/UI/CardView.cs +++ b/Pixiview/UI/CardView.cs @@ -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); + } } } diff --git a/Pixiview/Utils/Stores.cs b/Pixiview/Utils/Stores.cs index 341f8a0..b7cb81f 100644 --- a/Pixiview/Utils/Stores.cs +++ b/Pixiview/Utils/Stores.cs @@ -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);