optimize: remove unnecessary bindable objects

This commit is contained in:
Tsanie Lily 2020-05-14 11:17:39 +08:00
parent f6dbec2fda
commit 08ad76d8de
16 changed files with 148 additions and 85 deletions

View File

@ -29,8 +29,8 @@
<string>com.apple.share-services</string>
</dict>
<key>CFBundleShortVersionString</key>
<string>1.0.513</string>
<string>1.0.514</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>4</string>
</dict>
</plist>

View File

@ -79,8 +79,8 @@
</dict>
</array>
<key>CFBundleShortVersionString</key>
<string>1.0.513</string>
<string>1.0.514</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>4</string>
</dict>
</plist>

View File

@ -20,6 +20,7 @@ namespace Pixiview.iOS.Renderers
if (renderer is ShellSectionRenderer sr && Element is AppShell shell)
{
shell.SetNavigationBarHeight(sr.NavigationBar.Frame.Height);
shell.SetStatusBarHeight(UIApplication.SharedApplication.StatusBarFrame.Height);
}
return renderer;
}

View File

@ -32,6 +32,7 @@ namespace Pixiview.iOS.Renderers
if (e.NewElement != null)
{
e.NewElement.BackgroundColor = Color.Default;
if (Control == null)
{
var blur = UIBlurEffect.FromStyle(UIBlurEffectStyle.SystemMaterial);

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Pixiview.Resources;
using Pixiview.Utils;
using Xamarin.Essentials;
@ -33,13 +31,9 @@ namespace Pixiview.Illust
});
}
protected override IEnumerable<IllustItem> DoGetIllustList(IllustItem[] data, ICommand command)
protected override IEnumerable<IllustItem> DoGetIllustList(IllustItem[] data)
{
return data.Select(i =>
{
i.IllustTapped = command;
return i;
});
return data;
}
protected override IllustItem[] DoLoadIllustData(bool force)

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Newtonsoft.Json;
using Pixiview.Resources;
using Pixiview.UI;
@ -56,12 +55,12 @@ namespace Pixiview.Illust
public IllustCollection IllustCollection { get; set; }
protected virtual bool IsFavoriteVisible => true;
protected virtual bool IsLazyload => false;
protected readonly Command<IllustItem> commandIllustImageTapped;
protected DateTime lastUpdated;
protected double topOffset;
private T illustData;
private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads };
private readonly Command<IllustItem> commandIllustImageTapped;
public IllustCollectionPage()
{
@ -71,6 +70,10 @@ namespace Pixiview.Illust
private void IllustImageTapped(IllustItem illust)
{
if (illust == null)
{
return;
}
Start(() => OnIllustImageTapped(illust));
}
@ -89,18 +92,11 @@ namespace Pixiview.Illust
if (lastUpdated != LastUpdated)
{
if (IsLazyload)
{
Device.StartTimer(TimeSpan.FromMilliseconds(200), () =>
{
StartLoad();
return false;
});
}
else
Device.StartTimer(TimeSpan.FromMilliseconds(200), () =>
{
StartLoad();
}
return false;
});
}
else if (IsFavoriteVisible && IllustCollection != null)
{
@ -133,6 +129,7 @@ namespace Pixiview.Illust
{
base.OnSizeAllocated(width, height);
int columns;
#if __IOS__
var oldMargin = PanelTopMargin;
Thickness newMargin;
if (StyleDefinition.IsFullscreenDevice)
@ -140,22 +137,26 @@ namespace Pixiview.Illust
newMargin = width > height ?
AppShell.HalfNavigationBarOffset :
AppShell.NavigationBarOffset;
topOffset = width > height ?
AppShell.NavigationBarOffset.Top :
AppShell.TotalBarOffset.Top;
}
else if (isPhone)
{
#if __IOS__
newMargin = width > height ?
StyleDefinition.TopOffset16 :
StyleDefinition.TopOffset32;
#elif __ANDROID__
newMargin = default;
#endif
topOffset = width > height ?
StyleDefinition.TopOffset32.Top :
AppShell.TotalBarOffset.Top;
}
else
{
// TODO ipad
newMargin = StyleDefinition.TopOffset32;
// ipad
newMargin = StyleDefinition.TopOffset37;
topOffset = AppShell.TotalBarOffset.Top;
}
#endif
if (width > height)
{
columns = isPhone ? 4 : 6;
@ -164,11 +165,13 @@ namespace Pixiview.Illust
{
columns = isPhone ? 2 : 4;
}
#if __IOS__
if (oldMargin != newMargin)
{
PanelTopMargin = newMargin;
OnPanelTopMarginChanged(oldMargin, newMargin);
}
#endif
if (Columns != columns)
{
Columns = columns;
@ -179,7 +182,7 @@ namespace Pixiview.Illust
#endregion
protected abstract T DoLoadIllustData(bool force);
protected abstract IEnumerable<IllustItem> DoGetIllustList(T data, ICommand command);
protected abstract IEnumerable<IllustItem> DoGetIllustList(T data);
protected virtual void OnIllustImageTapped(IllustItem illust)
{
var page = new ViewIllustPage(illust, IsFavoriteVisible);
@ -217,9 +220,11 @@ namespace Pixiview.Illust
Aspect = Aspect.AspectFill,
GestureRecognizers =
{
new TapGestureRecognizer()
.Binding(TapGestureRecognizer.CommandProperty, nameof(IllustItem.IllustTapped))
.Binding(TapGestureRecognizer.CommandParameterProperty, ".")
new TapGestureRecognizer
{
Command = commandIllustImageTapped
}
.Binding(TapGestureRecognizer.CommandParameterProperty, ".")
}
}
.Binding(Image.SourceProperty, nameof(IllustItem.Image));
@ -436,7 +441,7 @@ namespace Pixiview.Illust
lastUpdated = now;
}
var data = DoGetIllustList(illustData, commandIllustImageTapped).Where(i => i != null);
var data = DoGetIllustList(illustData).Where(i => i != null);
var collection = new IllustCollection(data);
if (IsFavoriteVisible)
@ -493,6 +498,13 @@ namespace Pixiview.Illust
#endregion
}
public enum ScrollDirection
{
Stop,
Up,
Down
}
public class IllustCollection : List<IllustItem>
{
private static IllustCollection empty;
@ -546,13 +558,29 @@ namespace Pixiview.Illust
Anime = 2
}
[JsonObject(MemberSerialization.OptIn)]
public class IllustItem : BindableObject
public interface IIllustUser
{
//public static readonly BindableProperty TitleProperty = BindableProperty.Create(
// nameof(Title), typeof(string), typeof(IllustItem));
//public static readonly BindableProperty RankTitleProperty = BindableProperty.Create(
// nameof(RankTitle), typeof(string), typeof(IllustItem));
string UserId { get; }
string UserName { get; }
ImageSource ProfileImage { get; }
}
[JsonObject(MemberSerialization.OptIn)]
public class IllustItem : BindableObject, IIllustUser
{
private static IllustItem empty;
public static IllustItem Empty
{
get
{
if (empty == null)
{
empty = new IllustItem();
}
return empty;
}
}
public static readonly BindableProperty ImageProperty = BindableProperty.Create(
nameof(Image), typeof(ImageSource), typeof(IllustItem));
public static readonly BindableProperty ProfileImageProperty = BindableProperty.Create(
@ -561,20 +589,10 @@ namespace Pixiview.Illust
nameof(ImageHeight), typeof(GridLength), typeof(IllustItem), GridLength.Auto);
public static readonly BindableProperty IsFavoriteProperty = BindableProperty.Create(
nameof(IsFavorite), typeof(bool), typeof(IllustItem));
//public static readonly BindableProperty IsPlayingProperty = BindableProperty.Create(
// nameof(IsPlaying), typeof(bool), typeof(IllustItem));
[JsonProperty]
public string Title { get; set; }
//{
// get => (string)GetValue(TitleProperty);
// set => SetValue(TitleProperty, value);
//}
public string RankTitle { get; set; }
//{
// get => (string)GetValue(RankTitleProperty);
// set => SetValue(RankTitleProperty, value);
//}
public ImageSource Image
{
get => (ImageSource)GetValue(ImageProperty);
@ -596,11 +614,6 @@ namespace Pixiview.Illust
set => SetValue(IsFavoriteProperty, value);
}
public bool IsPlaying { get; set; }
//{
// get => (bool)GetValue(IsPlayingProperty);
// set => SetValue(IsPlayingProperty, value);
//}
public ICommand IllustTapped { get; set; }
[JsonProperty]
public string Id { get; set; }

View File

@ -6,7 +6,7 @@
x:Class="Pixiview.OptionPage"
Title="{r:Text Option}">
<TableView Intent="Settings" VerticalOptions="Start"
BackgroundColor="{DynamicResource NavColor}">
BackgroundColor="{DynamicResource OptionBackColor}">
<TableRoot>
<TableSection Title="{r:Text Proxy}">
<u:OptionSwitchCell Title="{r:Text Enabled}"

View File

@ -50,16 +50,13 @@ namespace Pixiview.UI
public virtual void OnOrientationChanged(Orientation orientation)
{
#if __IOS__
var oldMargin = PageTopMargin;
Thickness newMargin;
switch (orientation)
{
case Orientation.Portrait:
#if __IOS__
newMargin = AppShell.TotalBarOffset;
#elif __ANDROID__
newMargin = default;
#endif
break;
case Orientation.PortraitUpsideDown:
case Orientation.Unknown:
@ -72,11 +69,7 @@ namespace Pixiview.UI
}
else
{
#if __IOS__
newMargin = isPhone ? StyleDefinition.TopOffset32 : AppShell.TotalBarOffset;
#elif __ANDROID__
newMargin = default;
#endif
}
break;
}
@ -85,9 +78,37 @@ namespace Pixiview.UI
PageTopMargin = newMargin;
OnPageTopMarginChanged(oldMargin, newMargin);
}
#endif
OrientationChanged?.Invoke(this, new OrientationEventArgs { CurrentOrientation = orientation });
}
#if __IOS__
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (PageTopMargin == default)
{
if (StyleDefinition.IsFullscreenDevice)
{
PageTopMargin = width > height ?
AppShell.NavigationBarOffset :
AppShell.TotalBarOffset;
}
else if (isPhone)
{
PageTopMargin = width > height ?
StyleDefinition.TopOffset32 :
AppShell.TotalBarOffset;
}
else
{
PageTopMargin = AppShell.TotalBarOffset;
}
}
}
#endif
public virtual void OnPageTopMarginChanged(Thickness old, Thickness @new)
{
PageTopMarginChanged?.Invoke(this, new ThicknessEventArgs

View File

@ -10,6 +10,7 @@ namespace Pixiview.UI
public static readonly Thickness ScreenBottomPadding;
public static readonly Thickness TopOffset16 = new Thickness(0, 16, 0, 0);
public static readonly Thickness TopOffset32 = new Thickness(0, 32, 0, 0);
public static readonly Thickness TopOffset37 = new Thickness(0, 37, 0, 0);
public static readonly Color ColorLightShadow = Color.FromRgba(0, 0, 0, 0x20);
public static readonly Color ColorDeepShadow = Color.FromRgba(0, 0, 0, 0x50);
public static readonly Color ColorRedBackground = Color.FromRgb(0xfd, 0x43, 0x63);
@ -42,13 +43,15 @@ namespace Pixiview.UI
public const string IconFavorite = "\uf02e";
public const string IconShare = "\uf35d";
public const string IconCaretDown = "\uf0d7";
public const string IconCaretUp = "\uf0d8";
//public const string IconCaretUp = "\uf0d8";
public const string IconCircleCheck = "\uf058";
public const string IconPlay = "\uf04b";
public const string IconMore = "\uf142";
static StyleDefinition()
{
if (IsFullscreenDevice)
_ = IsFullscreenDevice;
if (_isBottomPadding)
{
if (DeviceInfo.Idiom == DeviceIdiom.Phone)
{
@ -61,6 +64,7 @@ namespace Pixiview.UI
}
}
private static bool _isBottomPadding;
private static bool? _isFullscreenDevice;
public static bool IsFullscreenDevice
{
@ -78,6 +82,7 @@ namespace Pixiview.UI
{
// iPhone X
_isFullscreenDevice = true;
_isBottomPadding = true;
}
else if (model.StartsWith("iPhone"))
{
@ -85,7 +90,9 @@ namespace Pixiview.UI
if (vs.Length == 2 && int.TryParse(vs[0], out int main) && int.TryParse(vs[1], out int sub))
{
// iPhone X/XS/XR or iPhone 11
_isFullscreenDevice = (main == 10 && sub >= 6) || (main > 10);
var flag = (main == 10 && sub >= 6) || (main > 10);
_isFullscreenDevice = flag;
_isBottomPadding = flag;
}
else
{
@ -95,18 +102,21 @@ namespace Pixiview.UI
else if (model.StartsWith("iPad8,"))
{
// iPad 11-inch or 12.9-inch (3rd+)
_isFullscreenDevice = true;
//_isFullscreenDevice = true;
_isBottomPadding = true;
}
#if DEBUG
else
{
// iPad or Simulator
var name = DeviceInfo.Name;
_isFullscreenDevice = name.StartsWith("iPhone X")
var flag = name.StartsWith("iPhone X")
|| name.StartsWith("iPhone 11")
|| name.StartsWith("iPad Pro (11-inch)")
|| name.StartsWith("iPad Pro (12.9-inch) (3rd generation)")
|| name.StartsWith("iPad Pro (12.9-inch) (4th generation)");
_isFullscreenDevice = flag;
_isBottomPadding = flag;
}
#endif
}
@ -117,6 +127,7 @@ namespace Pixiview.UI
#else
// TODO:
_isFullscreenDevice = false;
_isBottomPadding = false;
#endif
if (_isFullscreenDevice == null)
{

View File

@ -34,8 +34,9 @@ namespace Pixiview.UI.Theme
Add(SubTextColor, Color.LightGray);
Add(CardBackgroundColor, Color.FromRgb(0x33, 0x33, 0x33));
Add(MaskColor, Color.FromRgba(0xff, 0xff, 0xff, 0x50));
Add(NavColor, Color.Black);
Add(NavColor, Color.FromRgb(0x11, 0x11, 0x11));
Add(NavSelectedColor, Color.FromRgb(0x22, 0x22, 0x22));
Add(OptionBackColor, Color.Black);
Add(OptionTintColor, Color.FromRgb(0x11, 0x11, 0x11));
}
}

View File

@ -36,6 +36,7 @@ namespace Pixiview.UI.Theme
Add(MaskColor, Color.FromRgba(0, 0, 0, 0x50));
Add(NavColor, Color.FromRgb(0xf0, 0xf0, 0xf0));
Add(NavSelectedColor, Color.LightGray);
Add(OptionBackColor, Color.FromRgb(0xf0, 0xf0, 0xf0));
Add(OptionTintColor, Color.White);
}
}

View File

@ -13,7 +13,9 @@ namespace Pixiview.UI.Theme
public const string FontIconOption = nameof(FontIconOption);
public const string FontIconFavorite = nameof(FontIconFavorite);
public const string FontIconShare = nameof(FontIconShare);
public const string FontIconMore = nameof(FontIconMore);
public const string IconCircleCheck = nameof(IconCircleCheck);
public const string IconCaretDown = nameof(IconCaretDown);
public const string StatusBarStyle = nameof(StatusBarStyle);
public const string WindowColor = nameof(WindowColor);
@ -24,6 +26,7 @@ namespace Pixiview.UI.Theme
public const string MaskColor = nameof(MaskColor);
public const string NavColor = nameof(NavColor);
public const string NavSelectedColor = nameof(NavSelectedColor);
public const string OptionBackColor = nameof(OptionBackColor);
public const string OptionTintColor = nameof(OptionTintColor);
public const string IconLightFontFamily = nameof(IconLightFontFamily);
@ -53,8 +56,10 @@ namespace Pixiview.UI.Theme
Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily));
Add(FontIconFavorite, GetSolidIcon(StyleDefinition.IconFavorite, solidFontFamily));
Add(FontIconShare, GetSolidIcon(StyleDefinition.IconShare, solidFontFamily));
Add(FontIconMore, GetSolidIcon(StyleDefinition.IconMore, regularFontFamily));
Add(IconCircleCheck, StyleDefinition.IconCircleCheck);
Add(IconCaretDown, StyleDefinition.IconCaretDown);
}
private FontImageSource GetSolidIcon(string icon, string family, Color color = default)

View File

@ -50,6 +50,10 @@ namespace Pixiview.Utils
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Droid.MainActivity.Main.SetStatusBarColor(color.ToAndroid());
Droid.MainActivity.Main.Window.DecorView.SystemUiVisibility =
App.CurrentTheme == Xamarin.Essentials.AppTheme.Dark ?
Android.Views.StatusBarVisibility.Visible :
(Android.Views.StatusBarVisibility)Android.Views.SystemUiFlags.LightStatusBar;
}
#endif
}

View File

@ -34,6 +34,12 @@ namespace Pixiview.Utils
Grid.SetColumn(view, column);
return view;
}
public static T GridColumnSpan<T>(this T view, int columnSpan) where T : BindableObject
{
Grid.SetColumnSpan(view, columnSpan);
return view;
}
}
public static class Screen

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Pixiview.Illust;
using Xamarin.Forms;
namespace Pixiview.Utils
{
@ -44,7 +45,7 @@ namespace Pixiview.Utils
public string x540;
}
public IllustItem ConvertToItem()
public IllustItem ConvertToItem(ImageSource image = null)
{
return new IllustItem
{
@ -52,6 +53,7 @@ namespace Pixiview.Utils
Title = illustTitle,
RankTitle = illustTitle,
IllustType = (IllustType)illustType,
Image = image,
ImageUrl = urls?.x360 ?? url,
IsRestrict = xRestrict == 1,
ProfileUrl = profileImageUrl,

View File

@ -16,7 +16,7 @@ namespace Pixiview.Utils
public static readonly string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
#if __IOS__
public static readonly string CacheFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
#elif __ANDROID__
#else
public static readonly string CacheFolder = FileSystem.CacheDirectory;
#endif
@ -153,7 +153,7 @@ namespace Pixiview.Utils
}
else
{
App.DebugError("read", $"file not found: {file}");
//App.DebugError("read", $"file not found: {file}");
return default;
}
try
@ -434,16 +434,18 @@ namespace Pixiview.Utils
//public const string AcceptEncoding = "gzip, deflate";
public const string AcceptLanguage = "zh-cn";
//public const string UserId = "53887721";
//public const string Cookie =
// "PHPSESSID=5sn8n049j5c18l0tlj91qrjhesgddhjv; " +
// "a_type=0; b_type=1; c_type=29; d_type=2; " +
// "p_ab_d_id=1021624041; p_ab_id=2; p_ab_id_2=0; " +
// "privacy_policy_agreement=2; " +
// "login_ever=yes; " +
// "__cfduid=d84153bf70ae67315a8bc297299d39eb61588856027; " +
// "first_visit_datetime_pc=2020-05-07+21%3A53%3A47; " +
// "yuid_b=MYkIJXc";
#if !TEST
public const string UserId = "53887721";
public const string Cookie =
"PHPSESSID=5sn8n049j5c18l0tlj91qrjhesgddhjv; " +
"a_type=0; b_type=1; c_type=29; d_type=2; " +
"p_ab_d_id=1021624041; p_ab_id=2; p_ab_id_2=0; " +
"privacy_policy_agreement=2; " +
"login_ever=yes; " +
"__cfduid=d84153bf70ae67315a8bc297299d39eb61588856027; " +
"first_visit_datetime_pc=2020-05-07+21%3A53%3A47; " +
"yuid_b=MYkIJXc";
#else
public const string UserId = "2603358";
public const string Cookie =
"PHPSESSID=2603358_VHyGPeRaz7LpeoFkRsHvjXIpApCMb56a; " +
@ -454,6 +456,7 @@ namespace Pixiview.Utils
"__cfduid=d9fa2d4d1ddd30db85ebb519f9855d2561587806747; " +
"first_visit_datetime_pc=2019-10-29+22%3A05%3A30; " +
"yuid_b=NgcXQWQ";
#endif
public static string GetThumbnailUrl(string url)
{