From 5e7088c5520ae43c27a756d17b3d29a159c19f05 Mon Sep 17 00:00:00 2001 From: Guerra24 Date: Mon, 11 Nov 2019 02:46:06 -0600 Subject: [PATCH] Added stuff from #6 Ctrl+W to close tab (needs testing, delay may be too low) Show tags on hover (gridview/listview inside tooltip causes crash inside uwps xaml, needs alternative and meanwhile report bug, code commented) Bookmark button in archive's context menu. Auto-open reader (setting) Bookmark reminder modes (All, New only) Replaced/Added fade animations. --- LRReader.Shared/Internal/Settings.cs | 19 +++ LRReader.Shared/Internal/SettingsManager.cs | 21 +++ LRReader.Shared/Models/Main/Profile.cs | 5 +- LRReader.UWP.Core/Internal/Converters.cs | 20 +++ .../Resources/ThemeDictionary.xaml | 8 +- .../ViewModels/ArchivePageViewModel.cs | 74 +++++----- .../ViewModels/ArchivesPageViewModel.cs | 5 +- .../ViewModels/Base/ArchiveBaseViewModel.cs | 38 ++++- .../ViewModels/ViewModelLocator.cs | 8 +- .../Views/Items/ArchiveImage.xaml | 2 +- .../Views/Items/ArchiveImage.xaml.cs | 23 ++- .../Views/Items/ArchiveItem.xaml | 43 +++++- .../Views/Items/ArchiveItem.xaml.cs | 36 +++-- .../Views/Items/BookmarkedArchive.xaml | 32 ++++- .../Views/Items/BookmarkedArchive.xaml.cs | 86 ++++++++++- LRReader.UWP.Core/Views/Main/HostTabPage.xaml | 5 + .../Views/Main/HostTabPage.xaml.cs | 20 ++- .../Views/Tabs/Content/ArchiveTabContent.xaml | 15 +- .../Tabs/Content/ArchiveTabContent.xaml.cs | 134 ++++++++++-------- .../Tabs/Content/ArchivesTabContent.xaml.cs | 2 + .../Tabs/Content/Settings/ReaderPivot.xaml | 12 +- 21 files changed, 445 insertions(+), 163 deletions(-) diff --git a/LRReader.Shared/Internal/Settings.cs b/LRReader.Shared/Internal/Settings.cs index 060b9000..79066771 100644 --- a/LRReader.Shared/Internal/Settings.cs +++ b/LRReader.Shared/Internal/Settings.cs @@ -18,4 +18,23 @@ public interface ISettingsStorage T GetObjectRoamed(string key, T def); } + + public class StubSettingsStorage : ISettingsStorage + { + public T GetObjectLocal(string key) => GetObjectLocal(key, default); + + public T GetObjectLocal(string key, T def) => def; + + public T GetObjectRoamed(string key) => GetObjectRoamed(key, default); + + public T GetObjectRoamed(string key, T def) => def; + + public void StoreObjectLocal(string key, object obj) + { + } + + public void StoreObjectRoamed(string key, object obj) + { + } + } } diff --git a/LRReader.Shared/Internal/SettingsManager.cs b/LRReader.Shared/Internal/SettingsManager.cs index c56f8dc9..6366454c 100644 --- a/LRReader.Shared/Internal/SettingsManager.cs +++ b/LRReader.Shared/Internal/SettingsManager.cs @@ -114,6 +114,14 @@ public bool BookmarkReminder RaisePropertyChanged("BookmarkReminder"); } } + public BookmarkReminderMode BookmarkReminderMode + { + get => (BookmarkReminderMode) SettingsStorage.GetObjectRoamed("BookmarkReminderMode", (int) BookmarkReminderMode.New); + set + { + SettingsStorage.StoreObjectRoamed("BookmarkReminderMode", (int) value); + } + } public bool RemoveBookmark { get => SettingsStorage.GetObjectRoamed("RemoveBookmark", true); @@ -141,6 +149,15 @@ public bool OpenBookmarksStart RaisePropertyChanged("OpenBookmarksStart"); } } + public bool OpenReader + { + get => SettingsStorage.GetObjectRoamed("OpenReader", false); + set + { + SettingsStorage.StoreObjectRoamed("OpenReader", value); + RaisePropertyChanged("OpenReader"); + } + } public SettingsManager() { var profiles = SettingsStorage.GetObjectRoamed("Profiles"); @@ -212,4 +229,8 @@ public void SaveProfiles() SettingsStorage.StoreObjectRoamed("Profiles", JsonConvert.SerializeObject(Profiles)); } } + public enum BookmarkReminderMode + { + All, New + } } diff --git a/LRReader.Shared/Models/Main/Profile.cs b/LRReader.Shared/Models/Main/Profile.cs index 56e41fff..5bc3930a 100644 --- a/LRReader.Shared/Models/Main/Profile.cs +++ b/LRReader.Shared/Models/Main/Profile.cs @@ -18,7 +18,8 @@ public class ServerProfile : ObservableObject public List Bookmarks { get; set; } [JsonIgnore] - public bool HasApiKey { get => !string.IsNullOrEmpty(ServerApiKey); } + public bool HasApiKey => true; + //public bool HasApiKey { get => !string.IsNullOrEmpty(ServerApiKey); } [JsonIgnore] public string ServerAddressBrowser => ServerAddress.TrimEnd('/'); @@ -54,5 +55,7 @@ public void Update() [JsonIgnore] public int BookmarkProgressDisplay => page + 1; + [JsonIgnore] + public bool Bookmarked => totalPages >= 0; } } diff --git a/LRReader.UWP.Core/Internal/Converters.cs b/LRReader.UWP.Core/Internal/Converters.cs index c9de5b4d..a2a4822f 100644 --- a/LRReader.UWP.Core/Internal/Converters.cs +++ b/LRReader.UWP.Core/Internal/Converters.cs @@ -79,4 +79,24 @@ public object ConvertBack(object value, Type targetType, object parameter, strin return (value is Visibility && (Visibility)value == Visibility.Collapsed); } } + public class EnumConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, string language) + { + string parameterString = parameter as string; + if (parameterString == null || !Enum.IsDefined(value.GetType(), value)) + return DependencyProperty.UnsetValue; + object parameterValue = Enum.Parse(value.GetType(), parameterString); + + return parameterValue.Equals(value); + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + string parameterString = parameter as string; + if (parameterString == null) + return DependencyProperty.UnsetValue; + return Enum.Parse(targetType, parameterString); + } + } } diff --git a/LRReader.UWP.Core/Resources/ThemeDictionary.xaml b/LRReader.UWP.Core/Resources/ThemeDictionary.xaml index 3eb3b2f5..7a45a281 100644 --- a/LRReader.UWP.Core/Resources/ThemeDictionary.xaml +++ b/LRReader.UWP.Core/Resources/ThemeDictionary.xaml @@ -16,13 +16,15 @@ TintColor="{StaticResource BrushDeepBackgroundColor}" TintOpacity="0.6" /> #F2F2F2 - + #E5E5E5 + + @@ -38,13 +40,15 @@ TintColor="{StaticResource BrushDeepBackgroundColor}" TintOpacity="0.6" /> #171717 - + #1f1f1f + + diff --git a/LRReader.UWP.Core/ViewModels/ArchivePageViewModel.cs b/LRReader.UWP.Core/ViewModels/ArchivePageViewModel.cs index bb957828..a85db737 100644 --- a/LRReader.UWP.Core/ViewModels/ArchivePageViewModel.cs +++ b/LRReader.UWP.Core/ViewModels/ArchivePageViewModel.cs @@ -33,7 +33,6 @@ public bool LoadingImages } public ObservableCollection ArchiveImages = new ObservableCollection(); public ObservableCollection ArchiveImagesReader = new ObservableCollection(); - public ObservableCollection Tags = new ObservableCollection(); private bool _showReader = false; public bool ShowReader { @@ -58,7 +57,7 @@ public override bool Downloading } private bool _internalLoadingImages; - public async void Reload(bool animate) + public async Task Reload(bool animate) { ControlsEnabled = false; LoadTags(); @@ -68,14 +67,10 @@ public async void Reload(bool animate) ControlsEnabled = true; } - public void LoadTags() + public void ReloadBookmarkedObject() { - Tags.Clear(); - - foreach (var s in Archive.tags.Split(",")) - { - Tags.Add(s.Trim()); - } + BookmarkedArchive = Global.SettingsManager.Profile.Bookmarks.FirstOrDefault(b => b.archiveID.Equals(Archive.arcid)); + RaisePropertyChanged("Icon"); } public async Task LoadImages() @@ -109,56 +104,53 @@ await Task.Run(async () => _internalLoadingImages = false; } - public async void ClearNew() + public async Task ClearNew() { await Archive.ClearNew(); } - public async void CreateImageSets() + public void CreateImageSets() { ArchiveImagesReader.Clear(); List tmp = new List(); - await Task.Run(() => + for (int k = 0; k < ArchiveImages.Count; k++) { - for (int k = 0; k < ArchiveImages.Count; k++) + var i = new ArchiveImageSet(); + if (Global.SettingsManager.TwoPages) { - var i = new ArchiveImageSet(); - if (Global.SettingsManager.TwoPages) + if (Global.SettingsManager.ReadRTL) { - if (Global.SettingsManager.ReadRTL) - { - if (k == 0) - i.RightImage = ArchiveImages.ElementAt(k); - else if (k == ArchiveImages.Count - 1) - i.LeftImage = ArchiveImages.ElementAt(k); - else - { - i.RightImage = ArchiveImages.ElementAt(k); - i.LeftImage = ArchiveImages.ElementAt(++k); - } - } + if (k == 0) + i.RightImage = ArchiveImages.ElementAt(k); + else if (k == ArchiveImages.Count - 1) + i.LeftImage = ArchiveImages.ElementAt(k); else { - if (k == 0) - i.LeftImage = ArchiveImages.ElementAt(k); - else if (k == ArchiveImages.Count - 1) - i.RightImage = ArchiveImages.ElementAt(k); - else - { - i.LeftImage = ArchiveImages.ElementAt(k); - i.RightImage = ArchiveImages.ElementAt(++k); - } + i.RightImage = ArchiveImages.ElementAt(k); + i.LeftImage = ArchiveImages.ElementAt(++k); } } else { - i.LeftImage = ArchiveImages.ElementAt(k); + if (k == 0) + i.LeftImage = ArchiveImages.ElementAt(k); + else if (k == ArchiveImages.Count - 1) + i.RightImage = ArchiveImages.ElementAt(k); + else + { + i.LeftImage = ArchiveImages.ElementAt(k); + i.RightImage = ArchiveImages.ElementAt(++k); + } } - tmp.Add(i); } - if (Global.SettingsManager.ReadRTL) - tmp.Reverse(); - }); + else + { + i.LeftImage = ArchiveImages.ElementAt(k); + } + tmp.Add(i); + } + if (Global.SettingsManager.ReadRTL) + tmp.Reverse(); foreach (var i in tmp) { ArchiveImagesReader.Add(i); diff --git a/LRReader.UWP.Core/ViewModels/ArchivesPageViewModel.cs b/LRReader.UWP.Core/ViewModels/ArchivesPageViewModel.cs index 29d952b3..bb2e93d7 100644 --- a/LRReader.UWP.Core/ViewModels/ArchivesPageViewModel.cs +++ b/LRReader.UWP.Core/ViewModels/ArchivesPageViewModel.cs @@ -218,7 +218,10 @@ public async Task LoadPage(int page) await Task.Run(async () => { foreach (var a in resultPage.data) - await DispatcherHelper.RunAsync(() => ArchiveList.Add(a)); + { + var archive = ArchivesProvider.Archives.FirstOrDefault(b => b.arcid == a.arcid); + await DispatcherHelper.RunAsync(() => ArchiveList.Add(archive)); + } }); TotalArchives = resultPage.recordsFiltered; } diff --git a/LRReader.UWP.Core/ViewModels/Base/ArchiveBaseViewModel.cs b/LRReader.UWP.Core/ViewModels/Base/ArchiveBaseViewModel.cs index 6c625543..4bf5c0ed 100644 --- a/LRReader.UWP.Core/ViewModels/Base/ArchiveBaseViewModel.cs +++ b/LRReader.UWP.Core/ViewModels/Base/ArchiveBaseViewModel.cs @@ -5,6 +5,7 @@ using RestSharp; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Net; using System.Text; @@ -91,24 +92,38 @@ public BookmarkedArchive BookmarkedArchive if (value != null) { _bookmarkedArchive = value; - RaisePropertyChanged("Bookmarked"); - RaisePropertyChanged("Pages"); - RaisePropertyChanged("BookmarkedArchive"); } + else + { + _bookmarkedArchive = new BookmarkedArchive() { totalPages = -1 }; + } + RaisePropertyChanged("Bookmarked"); + RaisePropertyChanged("Pages"); + RaisePropertyChanged("BookmarkedArchive"); } } public bool Bookmarked { get { - return BookmarkedArchive.totalPages > 0; + return BookmarkedArchive.Bookmarked; } set { - if (value != BookmarkedArchive.totalPages > 0) + if (value != BookmarkedArchive.Bookmarked) { if (value) - Global.SettingsManager.Profile.Bookmarks.Add(BookmarkedArchive = new BookmarkedArchive() { archiveID = Archive.arcid, totalPages = Pages }); + { + var exist = Global.SettingsManager.Profile.Bookmarks.FirstOrDefault(b => b.archiveID.Equals(Archive.arcid)); + if (exist != null) + { + BookmarkedArchive = exist; + } + else + { + Global.SettingsManager.Profile.Bookmarks.Add(BookmarkedArchive = new BookmarkedArchive() { archiveID = Archive.arcid, totalPages = Pages }); + } + } else { Global.SettingsManager.Profile.Bookmarks.RemoveAll(b => b.archiveID.Equals(Archive.arcid)); @@ -160,6 +175,17 @@ public SymbolIconSource Icon { get => new SymbolIconSource() { Symbol = Bookmarked ? Symbol.Favorite : Symbol.Pictures }; } + public ObservableCollection Tags = new ObservableCollection(); + + public void LoadTags() + { + Tags.Clear(); + + foreach (var s in Archive.tags.Split(",")) + { + Tags.Add(s.Trim()); + } + } public async Task DownloadArchive() { diff --git a/LRReader.UWP.Core/ViewModels/ViewModelLocator.cs b/LRReader.UWP.Core/ViewModels/ViewModelLocator.cs index 0e75880c..8a57a0be 100644 --- a/LRReader.UWP.Core/ViewModels/ViewModelLocator.cs +++ b/LRReader.UWP.Core/ViewModels/ViewModelLocator.cs @@ -7,6 +7,7 @@ using GalaSoft.MvvmLight.Ioc; using GalaSoft.MvvmLight.Views; using LRReader.Internal; +using LRReader.Shared.Internal; using Windows.Storage; namespace LRReader.ViewModels @@ -15,7 +16,12 @@ public class ViewModelLocator { public ViewModelLocator() { - +#if DEBUG + if (ViewModelBase.IsInDesignModeStatic) + { + Global.SettingsStorage = new StubSettingsStorage(); + } +#endif Global.Init(); // Init global static data SimpleIoc.Default.Register(); diff --git a/LRReader.UWP.Core/Views/Items/ArchiveImage.xaml b/LRReader.UWP.Core/Views/Items/ArchiveImage.xaml index b7b8bff3..f392b44b 100644 --- a/LRReader.UWP.Core/Views/Items/ArchiveImage.xaml +++ b/LRReader.UWP.Core/Views/Items/ArchiveImage.xaml @@ -11,7 +11,7 @@ mc:Ignorable="d"> - + diff --git a/LRReader.UWP.Core/Views/Items/ArchiveImage.xaml.cs b/LRReader.UWP.Core/Views/Items/ArchiveImage.xaml.cs index f294925d..245629b4 100644 --- a/LRReader.UWP.Core/Views/Items/ArchiveImage.xaml.cs +++ b/LRReader.UWP.Core/Views/Items/ArchiveImage.xaml.cs @@ -1,5 +1,6 @@ using GalaSoft.MvvmLight; using LRReader.Internal; +using Microsoft.Toolkit.Uwp.UI.Animations; using System; using System.Collections.Generic; using System.Diagnostics; @@ -16,6 +17,7 @@ using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Media.Animation; using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Xaml.Navigation; @@ -40,21 +42,25 @@ private async void UserControl_DataContextChanged(FrameworkElement sender, DataC string n = args.NewValue as string; if (!_oldUrl.Equals(n)) { - Image.Visibility = Visibility.Collapsed; - Ring.Visibility = Visibility.Visible; + Image.Opacity = 0; + Ring.IsActive = true; Data.MissingImage = false; var image = await Global.ImageManager.DownloadImage(n); if (image != null) { image.DecodePixelWidth = 200; Image.Source = image; - } else + if (image.UriSource == null) + { + Ring.IsActive = false; + Image.Fade(value: 1.0f, duration: 250, easingMode: EasingMode.EaseIn).Start(); + } + } + else { Image.Source = null; Data.MissingImage = true; } - Image.Visibility = Visibility.Visible; - Ring.Visibility = Visibility.Collapsed; _oldUrl = n; } } @@ -64,6 +70,12 @@ private void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e) Data.MissingImage = true; } + private void Image_ImageOpened(object sender, RoutedEventArgs e) + { + Ring.IsActive = false; + Image.Fade(value: 1.0f, duration: 250, easingMode: EasingMode.EaseIn).Start(); + } + private class Container : ObservableObject { private bool _missingImage; @@ -77,6 +89,7 @@ public bool MissingImage } } } + } } diff --git a/LRReader.UWP.Core/Views/Items/ArchiveItem.xaml b/LRReader.UWP.Core/Views/Items/ArchiveItem.xaml index 5546e34c..efcb0276 100644 --- a/LRReader.UWP.Core/Views/Items/ArchiveItem.xaml +++ b/LRReader.UWP.Core/Views/Items/ArchiveItem.xaml @@ -7,6 +7,7 @@ xmlns:local="using:LRReader.Views.Items" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:media="using:Microsoft.Toolkit.Uwp.UI.Media" + xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" Width="200" d:DesignHeight="303" d:DesignWidth="200" @@ -15,11 +16,19 @@ + + + - - + + + @@ -60,7 +97,7 @@ x:Load="{x:Bind ViewModel.Bookmarked, Mode=OneWay}" Background="{ThemeResource GridOverGridBackground}"> - / + / .65) - Thumbnail.Stretch = Stretch.Uniform; - Thumbnail.Source = image; - Thumbnail.Visibility = Visibility.Visible; - Ring.Visibility = Visibility.Collapsed; - Title.Opacity = 1; - }*/ using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) { byte[] bytes = await Global.ImageManager.DownloadThumbnailRuntime(ViewModel.Archive.arcid); @@ -83,15 +72,15 @@ private async void UserControl_DataContextChanged(FrameworkElement sender, DataC if (Math.Abs(ActualHeight / ActualWidth - image.PixelHeight / image.PixelWidth) > .65) Thumbnail.Stretch = Stretch.Uniform; Thumbnail.Source = image; - Thumbnail.Visibility = Visibility.Visible; } else { ViewModel.MissingImage = true; } } - Ring.Visibility = Visibility.Collapsed; - Title.Opacity = 1; + Ring.IsActive = false; + Overlay.Fade(value: 1.0f, duration: 250, easingMode: EasingMode.EaseIn).Start(); + Title.Fade(value: 1.0f, duration: 250, easingMode: EasingMode.EaseIn).Start(); _oldID = ViewModel.Archive.arcid; } } @@ -144,5 +133,14 @@ private async void DownloadMenuItem_Click(object sender, RoutedEventArgs e) } } + private void Add_Click(object sender, RoutedEventArgs e) + { + ViewModel.Bookmarked = true; + } + + private void Remove_Click(object sender, RoutedEventArgs e) + { + ViewModel.Bookmarked = false; + } } } diff --git a/LRReader.UWP.Core/Views/Items/BookmarkedArchive.xaml b/LRReader.UWP.Core/Views/Items/BookmarkedArchive.xaml index c5513206..21048091 100644 --- a/LRReader.UWP.Core/Views/Items/BookmarkedArchive.xaml +++ b/LRReader.UWP.Core/Views/Items/BookmarkedArchive.xaml @@ -2,6 +2,7 @@ x:Class="LRReader.Views.Items.BookmarkedArchive" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:convrt="using:LRReader.Internal" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:LRReader.Views.Items" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -11,6 +12,29 @@ DataContextChanged="UserControl_DataContextChanged" mc:Ignorable="d"> + + + + + + + + + + + + + + + @@ -23,6 +47,9 @@ + + + @@ -36,8 +63,9 @@ ToolTipService.ToolTip="{x:Bind ViewModel.Archive.title, Mode=OneWay}" /> - / + FontSize="18" + Visibility="{x:Bind ViewModel.Bookmarked, Mode=OneWay}"> + / diff --git a/LRReader.UWP.Core/Views/Items/BookmarkedArchive.xaml.cs b/LRReader.UWP.Core/Views/Items/BookmarkedArchive.xaml.cs index ea0aa42b..16a82fb3 100644 --- a/LRReader.UWP.Core/Views/Items/BookmarkedArchive.xaml.cs +++ b/LRReader.UWP.Core/Views/Items/BookmarkedArchive.xaml.cs @@ -1,6 +1,7 @@ using LRReader.Internal; using LRReader.Shared.Models.Main; using LRReader.ViewModels.Items; +using LRReader.Views.Tabs; using System; using System.Collections.Generic; using System.IO; @@ -8,6 +9,9 @@ using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; +using Windows.Storage; +using Windows.Storage.Pickers; +using Windows.Storage.Provider; using Windows.Storage.Streams; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -45,19 +49,89 @@ private async void UserControl_DataContextChanged(FrameworkElement sender, DataC Title.Opacity = 0; Thumbnail.Source = null; Thumbnail.Visibility = Visibility.Collapsed; + ViewModel.MissingImage = false; using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) { byte[] bytes = await Global.ImageManager.DownloadThumbnailRuntime(ViewModel.Archive.arcid); - await stream.WriteAsync(bytes.AsBuffer()); - stream.Seek(0); - var image = new BitmapImage(); - await image.SetSourceAsync(stream); - Thumbnail.Source = image; + if (bytes != null) + { + await stream.WriteAsync(bytes.AsBuffer()); + stream.Seek(0); + var image = new BitmapImage(); + image.DecodePixelWidth = 200; + await image.SetSourceAsync(stream); + if (image.PixelHeight != 0 && image.PixelWidth != 0) + if (Math.Abs(ActualHeight / ActualWidth - image.PixelHeight / image.PixelWidth) > .65) + Thumbnail.Stretch = Stretch.Uniform; + Thumbnail.Source = image; + Thumbnail.Visibility = Visibility.Visible; + } + else + { + ViewModel.MissingImage = true; + } } - Thumbnail.Visibility = Visibility.Visible; Title.Opacity = 1; _oldID = ViewModel.Archive.arcid; } } + + private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e) + { + Global.EventManager.AddTab(new ArchiveTab(ViewModel.Archive), false); + } + + private async void EditMenuItem_Click(object sender, RoutedEventArgs e) + { + await Util.OpenInBrowser(new Uri(Global.SettingsManager.Profile.ServerAddressBrowser + "/edit?id=" + ViewModel.Archive.arcid)); + } + + private async void DownloadMenuItem_Click(object sender, RoutedEventArgs e) + { + ViewModel.Downloading = true; + var download = await ViewModel.DownloadArchive(); + if (download == null) + { + ViewModel.Downloading = false; + return; + } + + var savePicker = new FileSavePicker(); + savePicker.SuggestedStartLocation = PickerLocationId.Downloads; + savePicker.FileTypeChoices.Add(download.Type + " File", new List() { download.Type }); + savePicker.SuggestedFileName = download.Name; + + StorageFile file = await savePicker.PickSaveFileAsync(); + ViewModel.Downloading = false; + if (file != null) + { + CachedFileManager.DeferUpdates(file); + await FileIO.WriteBytesAsync(file, download.Data); + FileUpdateStatus status = + await CachedFileManager.CompleteUpdatesAsync(file); + if (status == FileUpdateStatus.Complete) + { + //save + } + else + { + // not saved + } + } + else + { + //cancel + } + } + + private void Add_Click(object sender, RoutedEventArgs e) + { + ViewModel.Bookmarked = true; + } + + private void Remove_Click(object sender, RoutedEventArgs e) + { + ViewModel.Bookmarked = false; + } } } diff --git a/LRReader.UWP.Core/Views/Main/HostTabPage.xaml b/LRReader.UWP.Core/Views/Main/HostTabPage.xaml index 8bb576f7..7246c368 100644 --- a/LRReader.UWP.Core/Views/Main/HostTabPage.xaml +++ b/LRReader.UWP.Core/Views/Main/HostTabPage.xaml @@ -9,8 +9,13 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{Binding HostTabPageInstace, Source={StaticResource Locator}}" + KeyboardAcceleratorPlacementMode="Hidden" mc:Ignorable="d"> + + + + TabViewControl.TabItems.Clear(); + public void CloseAllTabs() + { + foreach (var t in TabViewControl.TabItems) + { + if (t is ICustomTab tab) + tab.Unload(); + } + TabViewControl.TabItems.Clear(); + } public void CloseTabWithHeader(string header) { @@ -136,5 +144,15 @@ public void CloseTabWithHeader(string header) private TabViewItem GetTabFromHeader(object header) => TabViewControl.TabItems.FirstOrDefault(t => (t as TabViewItem).Header.Equals(header)) as TabViewItem; + private void CloseTab_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) + { + args.Handled = true; + var t = Data.CurrentTab; + if (!t.IsClosable) + return; + if (t is ICustomTab tab) + tab.Unload(); + TabViewControl.TabItems.Remove(t); + } } } diff --git a/LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml b/LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml index 89cf2423..8b9f8c9e 100644 --- a/LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml +++ b/LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml @@ -9,23 +9,12 @@ xmlns:items="using:LRReader.Views.Items" xmlns:local="using:LRReader.Views.Tabs.Content" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + Loaded="UserControl_Loaded" mc:Ignorable="d"> - - - - - - - - - - - - @@ -129,7 +118,7 @@ x:Name="FlipViewControl" Grid.RowSpan="2" d:IsHidden="True" Background="Transparent" FocusVisualPrimaryThickness="0" FocusVisualSecondaryThickness="0" ItemsSource="{x:Bind Data.ArchiveImagesReader, Mode=OneWay}" - Tapped="FlipView_Tapped" UseTouchAnimationsForAllNavigation="True" + Opacity="0" Tapped="FlipView_Tapped" UseTouchAnimationsForAllNavigation="True" Visibility="{x:Bind Data.ShowReader, Mode=OneWay}"> diff --git a/LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml.cs b/LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml.cs index a348518f..d45d93da 100644 --- a/LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml.cs +++ b/LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml.cs @@ -1,7 +1,9 @@ using LRReader.Internal; +using LRReader.Shared.Internal; using LRReader.Shared.Models.Main; using LRReader.ViewModels; using LRReader.Views.Items; +using Microsoft.Toolkit.Uwp.UI.Animations; using System; using System.Collections.Generic; using System.IO; @@ -33,20 +35,39 @@ public sealed partial class ArchiveTabContent : UserControl private int i; private bool _wasNew; + private bool _opened; public ArchiveTabContent() { this.InitializeComponent(); Data = new ArchivePageViewModel(); Global.EventManager.RebuildReaderImagesSetEvent += Data.CreateImageSets; - FadeOutReader.Begin(); // Hack to fade in correctly - FadeOutReader.Completed += FadeOutReader_Completed; - FadeOutContent.Completed += FadeOutContent_Completed; } - private void FadeOutContent_Completed(object sender, object e) + private void UserControl_Loaded(object sender, RoutedEventArgs e) { - FadeInReader.Begin(); + Data.ReloadBookmarkedObject(); + } + + public async void LoadArchive(Archive archive) + { + Data.Archive = archive; + await Data.Reload(true); + if (!_opened) + { + if (Global.SettingsManager.OpenReader) + { + if (Data.Bookmarked) + i = Data.BookmarkProgress; + OpenReader(); + } + _opened = true; + } + } + + private async void OpenReader() + { + Data.ShowReader = true; int count = Data.Pages; if (Global.SettingsManager.TwoPages) { @@ -73,59 +94,20 @@ private void FadeOutContent_Completed(object sender, object e) if (Data.Archive.IsNewArchive()) { - Data.ClearNew(); + await Data.ClearNew(); Data.Archive.isnew = "false"; _wasNew = true; } + await ImagesGrid.Fade(value: 0.0f, duration: 250).StartAsync(); + await FlipViewControl.Fade(value: 1.0f, duration: 250, easingMode: EasingMode.EaseIn).StartAsync(); FlipViewControl.Focus(FocusState.Programmatic); } - private void FadeOutReader_Completed(object sender, object e) + public async void CloseReader() { + await FlipViewControl.Fade(value: 0.0f, duration: 250).StartAsync(); Data.ShowReader = false; - FadeInContent.Begin(); - } - - public void LoadArchive(Archive archive) - { - Data.Archive = archive; - Data.Reload(true); - } - - private void ImagesGrid_ItemClick(object sender, ItemClickEventArgs e) - { - FadeOutContent.Begin(); - Data.ShowReader = true; - i = Data.ArchiveImages.IndexOf(e.ClickedItem as string); - } - - private void Continue_Click(object sender, RoutedEventArgs e) - { - FadeOutContent.Begin(); - Data.ShowReader = true; - i = Data.BookmarkProgress; - } - - private void FlipView_Tapped(object sender, TappedRoutedEventArgs e) - { - var point = e.GetPosition(FlipViewControl); - double distance = FlipViewControl.ActualWidth / 6.0; - if (point.X < distance) - { - if (FlipViewControl.SelectedIndex > 0) - --FlipViewControl.SelectedIndex; - } - else if (point.X > FlipViewControl.ActualWidth - distance) - { - if (FlipViewControl.SelectedIndex < FlipViewControl.Items.Count - 1) - ++FlipViewControl.SelectedIndex; - } - } - - private async void CloseButton_Click(object sender, RoutedEventArgs e) - { - if (Data.ShowReader) - FadeOutReader.Begin(); + await ImagesGrid.Fade(value: 1.0f, duration: 250, easingMode: EasingMode.EaseIn).StartAsync(); int conv = FlipViewControl.SelectedIndex; int count = Data.Pages; if (Global.SettingsManager.TwoPages) @@ -155,9 +137,11 @@ private async void CloseButton_Click(object sender, RoutedEventArgs e) Data.Bookmarked = false; } } - else + else if (!Data.Bookmarked) { - if (_wasNew && Global.SettingsManager.BookmarkReminder) + var mode = Global.SettingsManager.BookmarkReminderMode; + if (Global.SettingsManager.BookmarkReminder && + ((_wasNew && mode == BookmarkReminderMode.New) || mode == BookmarkReminderMode.All)) { var dialog = new ContentDialog { Title = "Bookmark archive?", PrimaryButtonText = "Yes", CloseButtonText = "No" }; var result = await dialog.ShowAsync(); @@ -170,6 +154,39 @@ private async void CloseButton_Click(object sender, RoutedEventArgs e) Data.BookmarkProgress = conv; } + private void ImagesGrid_ItemClick(object sender, ItemClickEventArgs e) + { + i = Data.ArchiveImages.IndexOf(e.ClickedItem as string); + OpenReader(); + } + + private void Continue_Click(object sender, RoutedEventArgs e) + { + i = Data.BookmarkProgress; + OpenReader(); + } + + private void CloseButton_Click(object sender, RoutedEventArgs e) + { + CloseReader(); + } + + private void FlipView_Tapped(object sender, TappedRoutedEventArgs e) + { + var point = e.GetPosition(FlipViewControl); + double distance = FlipViewControl.ActualWidth / 6.0; + if (point.X < distance) + { + if (FlipViewControl.SelectedIndex > 0) + --FlipViewControl.SelectedIndex; + } + else if (point.X > FlipViewControl.ActualWidth - distance) + { + if (FlipViewControl.SelectedIndex < FlipViewControl.Items.Count - 1) + ++FlipViewControl.SelectedIndex; + } + } + private async void EditButton_Click(object sender, RoutedEventArgs e) { await Util.OpenInBrowser(new Uri(Global.SettingsManager.Profile.ServerAddressBrowser + "/edit?id=" + Data.Archive.arcid)); @@ -213,22 +230,23 @@ private async void DonwloadButton_Click(object sender, RoutedEventArgs e) } } - private void RefreshContainer_RefreshRequested(RefreshContainer sender, RefreshRequestedEventArgs args) + private async void RefreshContainer_RefreshRequested(RefreshContainer sender, RefreshRequestedEventArgs args) { using (var deferral = args.GetDeferral()) { - Data.Reload(false); + await Data.Reload(false); } } - private void Refresh_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) + private async void Refresh_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) { - Data.Reload(true); + await Data.Reload(true); + args.Handled = true; } - private void RefreshButton_Click(object sender, RoutedEventArgs e) + private async void RefreshButton_Click(object sender, RoutedEventArgs e) { - Data.Reload(true); + await Data.Reload(true); } public void RemoveEvent() diff --git a/LRReader.UWP.Core/Views/Tabs/Content/ArchivesTabContent.xaml.cs b/LRReader.UWP.Core/Views/Tabs/Content/ArchivesTabContent.xaml.cs index 24c3c10f..6c24416e 100644 --- a/LRReader.UWP.Core/Views/Tabs/Content/ArchivesTabContent.xaml.cs +++ b/LRReader.UWP.Core/Views/Tabs/Content/ArchivesTabContent.xaml.cs @@ -134,12 +134,14 @@ private void RefreshContainer_RefreshRequested(RefreshContainer sender, RefreshR private void Refresh_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) { HandleSearch(); + args.Handled = true; } private async void RefreshFull_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) { await Data.Refresh(); await Data.LoadTagStats(); + args.Handled = true; } private async void PrevButton_Click(object sender, RoutedEventArgs e) diff --git a/LRReader.UWP.Core/Views/Tabs/Content/Settings/ReaderPivot.xaml b/LRReader.UWP.Core/Views/Tabs/Content/Settings/ReaderPivot.xaml index 563df6c0..35c3fec7 100644 --- a/LRReader.UWP.Core/Views/Tabs/Content/Settings/ReaderPivot.xaml +++ b/LRReader.UWP.Core/Views/Tabs/Content/Settings/ReaderPivot.xaml @@ -13,6 +13,7 @@ + @@ -47,6 +48,7 @@ VerticalAlignment="Center" Text="{x:Bind Data.SettingsManager.ZoomedFactor, Mode=OneWay}" /> + + ToolTipService.ToolTip="Ask to bookmark archive if closed half way through" /> + + + + + ToolTipService.ToolTip="Ask to remove bookmark when closed on last page" />