share settings, UI adjust

This commit is contained in:
Tsanie Lily 2020-05-08 20:14:51 +08:00
parent ca46fd35fe
commit 2558c1a75f
12 changed files with 96 additions and 48 deletions

View File

@ -22,6 +22,7 @@
"idiom": "iphone" "idiom": "iphone"
}, },
{ {
"filename": "pixiv.png",
"scale": "1x", "scale": "1x",
"idiom": "iphone" "idiom": "iphone"
}, },

View File

@ -21,7 +21,7 @@
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>MinimumOSVersion</key> <key>MinimumOSVersion</key>
<string>11.0</string> <string>13.0</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>Pixiview</string> <string>Pixiview</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
@ -46,5 +46,9 @@
<string>UIStatusBarStyleDefault</string> <string>UIStatusBarStyleDefault</string>
<key>NSPhotoLibraryUsageDescription</key> <key>NSPhotoLibraryUsageDescription</key>
<string>需要访问您的图片库</string> <string>需要访问您的图片库</string>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
</dict> </dict>
</plist> </plist>

View File

@ -6,7 +6,6 @@ using Pixiview.iOS.Services;
using Pixiview.Resources; using Pixiview.Resources;
using Pixiview.Utils; using Pixiview.Utils;
using UIKit; using UIKit;
using Xamarin.Essentials;
using Xamarin.Forms; using Xamarin.Forms;
[assembly: Dependency(typeof(EnvironmentService))] [assembly: Dependency(typeof(EnvironmentService))]
@ -28,30 +27,32 @@ namespace Pixiview.iOS.Services
#region - Theme - #region - Theme -
/*
[SuppressMessage("Code Notifications", "XI0002:Notifies you from using newer Apple APIs when targeting an older OS version", Justification = "<Pending>")] [SuppressMessage("Code Notifications", "XI0002:Notifies you from using newer Apple APIs when targeting an older OS version", Justification = "<Pending>")]
public OSAppTheme GetApplicationTheme() public AppTheme GetApplicationTheme()
{ {
if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
{ {
var currentController = Platform.GetCurrentUIViewController(); var currentController = Platform.GetCurrentUIViewController();
if (currentController == null) if (currentController == null)
{ {
return OSAppTheme.Unspecified; return AppTheme.Unspecified;
} }
var style = currentController.TraitCollection.UserInterfaceStyle; var style = currentController.TraitCollection.UserInterfaceStyle;
if (style == UIUserInterfaceStyle.Dark) if (style == UIUserInterfaceStyle.Dark)
{ {
return OSAppTheme.Dark; return AppTheme.Dark;
} }
else if (style == UIUserInterfaceStyle.Light) else if (style == UIUserInterfaceStyle.Light)
{ {
return OSAppTheme.Light; return AppTheme.Light;
} }
} }
return OSAppTheme.Unspecified; return AppTheme.Unspecified;
} }
//*/
public void SetStatusBarStyle(StatusBarStyles style) public void SetStatusBarStyle(StatusBarStyles style)
{ {

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using Pixiview.Resources; using Pixiview.Resources;
using Pixiview.UI.Theme; using Pixiview.UI.Theme;
using Pixiview.Utils; using Pixiview.Utils;
using Xamarin.Essentials;
using Xamarin.Forms; using Xamarin.Forms;
namespace Pixiview namespace Pixiview
@ -11,7 +12,7 @@ namespace Pixiview
public class App : Application public class App : Application
{ {
// public properties // public properties
public static OSAppTheme CurrentTheme { get; private set; } public static AppTheme CurrentTheme { get; private set; }
public static PlatformCulture CurrentCulture { get; private set; } public static PlatformCulture CurrentCulture { get; private set; }
public static Dictionary<string, object> ExtraResources { get; private set; } public static Dictionary<string, object> ExtraResources { get; private set; }
@ -28,7 +29,8 @@ namespace Pixiview
{ ThemeBase.IconLeft, p.IconLeft } { ThemeBase.IconLeft, p.IconLeft }
}; };
var theme = service.GetApplicationTheme(); //var theme = service.GetApplicationTheme();
var theme = AppInfo.RequestedTheme;
SetTheme(theme, true); SetTheme(theme, true);
} }
@ -39,7 +41,7 @@ namespace Pixiview
CurrentCulture = new PlatformCulture(ci.Name.ToLower()); CurrentCulture = new PlatformCulture(ci.Name.ToLower());
} }
private void SetTheme(OSAppTheme theme, bool force = false) private void SetTheme(AppTheme theme, bool force = false)
{ {
if (force || theme != CurrentTheme) if (force || theme != CurrentTheme)
{ {
@ -51,7 +53,7 @@ namespace Pixiview
} }
DebugPrint($"application theme: {theme}"); DebugPrint($"application theme: {theme}");
ThemeBase themeInstance; ThemeBase themeInstance;
if (theme == OSAppTheme.Dark) if (theme == AppTheme.Dark)
{ {
themeInstance = DarkTheme.Instance; themeInstance = DarkTheme.Instance;
} }
@ -80,7 +82,8 @@ namespace Pixiview
protected override void OnResume() protected override void OnResume()
{ {
var theme = DependencyService.Get<IEnvironmentService>().GetApplicationTheme(); //var theme = DependencyService.Get<IEnvironmentService>().GetApplicationTheme();
var theme = AppInfo.RequestedTheme;
SetTheme(theme); SetTheme(theme);
} }

View File

@ -294,7 +294,7 @@ namespace Pixiview.Illust
TextColor = StyleDefinition.ColorRedBackground, TextColor = StyleDefinition.ColorRedBackground,
Text = StyleDefinition.IconLove Text = StyleDefinition.IconLove
} }
.Binding(IsVisibleProperty, nameof(IllustItem.IsFavorite)) .Binding(IsVisibleProperty, IsFavoriteVisible ? nameof(IllustItem.IsFavorite) : null)
.DynamicResource(Label.FontFamilyProperty, ThemeBase.IconSolidFontFamily) .DynamicResource(Label.FontFamilyProperty, ThemeBase.IconSolidFontFamily)
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Pixiview.UI; using Pixiview.UI;
using Pixiview.Utils; using Pixiview.Utils;
@ -16,7 +17,7 @@ namespace Pixiview.Illust
private static void OnSegmentIndexPropertyChanged(BindableObject obj, object oldValue, object newValue) private static void OnSegmentIndexPropertyChanged(BindableObject obj, object oldValue, object newValue)
{ {
var page = (RecommendsPage)obj; var page = (RecommendsPage)obj;
page.DoLoadIllusts(); Task.Run(() => page.DoLoadIllusts());
} }
public int SegmentIndex public int SegmentIndex
@ -25,8 +26,6 @@ namespace Pixiview.Illust
set => SetValue(SegmentIndexProperty, value); set => SetValue(SegmentIndexProperty, value);
} }
private IllustData illustData;
public RecommendsPage() public RecommendsPage()
{ {
totalBarOffset = new Thickness(0, AppShell.TotalBarOffset.Top + 40, 0, 0); totalBarOffset = new Thickness(0, AppShell.TotalBarOffset.Top + 40, 0, 0);
@ -103,11 +102,7 @@ namespace Pixiview.Illust
protected override IllustData DoLoadIllustData(bool force) protected override IllustData DoLoadIllustData(bool force)
{ {
if (illustData != null && !force) var illustData = Stores.LoadIllustData(force);
{
return illustData;
}
illustData = Stores.LoadIllustData(force);
return illustData; return illustData;
} }

View File

@ -255,43 +255,68 @@ namespace Pixiview.Illust
private async void Illust_LongPressed(IllustDetailItem item) private async void Illust_LongPressed(IllustDetailItem item)
{ {
var share = ResourceHelper.Share;
string[] extras;
var preview = Stores.GetPreviewImagePath(item.PreviewUrl);
if (string.IsNullOrEmpty(preview))
{
extras = new string[0];
}
else
{
extras = new[] { share };
}
var saveOriginal = ResourceHelper.SaveOriginal; var saveOriginal = ResourceHelper.SaveOriginal;
var result = await DisplayActionSheet( var result = await DisplayActionSheet(
IllustItem.Title, IllustItem.Title,
ResourceHelper.Cancel, ResourceHelper.Cancel,
saveOriginal); saveOriginal,
extras);
if (result == saveOriginal) if (result == saveOriginal)
{ {
if (Stores.CheckIllustImage(item.OriginalUrl)) SaveOriginalImage(item);
}
else if (result == share)
{
await Share.RequestAsync(new ShareFileRequest
{ {
var flag = await DisplayAlert(ResourceHelper.Operation, Title = IllustItem.Title,
ResourceHelper.AlreadySavedQuestion, File = new ShareFile(preview)
ResourceHelper.Yes, });
ResourceHelper.No); }
if (!flag) }
{
return;
}
}
var status = await Permissions.CheckStatusAsync<Permissions.Photos>(); private async void SaveOriginalImage(IllustDetailItem item)
if (status != PermissionStatus.Granted) {
{ if (Stores.CheckIllustImage(item.OriginalUrl))
status = await Permissions.RequestAsync<Permissions.Photos>(); {
if (status != PermissionStatus.Granted) var flag = await DisplayAlert(ResourceHelper.Operation,
{ ResourceHelper.AlreadySavedQuestion,
App.DebugPrint("access denied to gallery."); ResourceHelper.Yes,
return; ResourceHelper.No);
} if (!flag)
}
if (item == null || item.Downloading)
{ {
return; return;
} }
item.Downloading = true;
_ = Task.Run(() => DoLoadOriginalImage(item));
} }
var status = await Permissions.CheckStatusAsync<Permissions.Photos>();
if (status != PermissionStatus.Granted)
{
status = await Permissions.RequestAsync<Permissions.Photos>();
if (status != PermissionStatus.Granted)
{
App.DebugPrint("access denied to gallery.");
return;
}
}
if (item == null || item.Downloading)
{
return;
}
item.Downloading = true;
_ = Task.Run(() => DoLoadOriginalImage(item));
} }
private void DoLoadOriginalImage(IllustDetailItem item) private void DoLoadOriginalImage(IllustDetailItem item)

View File

@ -16,6 +16,7 @@
<Preview>预览</Preview> <Preview>预览</Preview>
<Operation>操作</Operation> <Operation>操作</Operation>
<SaveOriginal>保存原图</SaveOriginal> <SaveOriginal>保存原图</SaveOriginal>
<Share>分享</Share>
<SaveSuccess>成功保存图片到照片库。</SaveSuccess> <SaveSuccess>成功保存图片到照片库。</SaveSuccess>
<AlreadySavedQuestion>原图已保存,是否继续?</AlreadySavedQuestion> <AlreadySavedQuestion>原图已保存,是否继续?</AlreadySavedQuestion>
</root> </root>

View File

@ -18,6 +18,7 @@ namespace Pixiview.Resources
public static string R18 => GetResource(nameof(R18)); public static string R18 => GetResource(nameof(R18));
public static string Operation => GetResource(nameof(Operation)); public static string Operation => GetResource(nameof(Operation));
public static string SaveOriginal => GetResource(nameof(SaveOriginal)); public static string SaveOriginal => GetResource(nameof(SaveOriginal));
public static string Share => GetResource(nameof(Share));
public static string SaveSuccess => GetResource(nameof(SaveSuccess)); public static string SaveSuccess => GetResource(nameof(SaveSuccess));
public static string AlreadySavedQuestion => GetResource(nameof(AlreadySavedQuestion)); public static string AlreadySavedQuestion => GetResource(nameof(AlreadySavedQuestion));

View File

@ -6,7 +6,14 @@ namespace Pixiview.Utils
{ {
public static T Binding<T>(this T view, BindableProperty property, string name) where T : BindableObject public static T Binding<T>(this T view, BindableProperty property, string name) where T : BindableObject
{ {
view.SetBinding(property, name); if (name == null)
{
view.SetValue(property, default(T));
}
else
{
view.SetBinding(property, name);
}
return view; return view;
} }

View File

@ -7,7 +7,7 @@ namespace Pixiview.Utils
{ {
EnvironmentParameter GetEnvironment(); EnvironmentParameter GetEnvironment();
OSAppTheme GetApplicationTheme(); //AppTheme GetApplicationTheme();
void SetStatusBarStyle(StatusBarStyles style); void SetStatusBarStyle(StatusBarStyles style);
void SetStatusBarColor(Color color); void SetStatusBarColor(Color color);

View File

@ -248,6 +248,16 @@ namespace Pixiview.Utils
return File.Exists(file); return File.Exists(file);
} }
public static string GetPreviewImagePath(string url)
{
var file = Path.Combine(PersonalFolder, previewFolder, Path.GetFileName(url));
if (File.Exists(file))
{
return file;
}
return null;
}
private static ImageSource LoadImage(string url, string working, string folder) private static ImageSource LoadImage(string url, string working, string folder)
{ {
var file = Path.Combine(working, folder, Path.GetFileName(url)); var file = Path.Combine(working, folder, Path.GetFileName(url));