Skip to content

Commit

Permalink
Added stuff from #6
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Guerra24 committed Nov 11, 2019
1 parent 393231c commit 5e7088c
Show file tree
Hide file tree
Showing 21 changed files with 445 additions and 163 deletions.
19 changes: 19 additions & 0 deletions LRReader.Shared/Internal/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,23 @@ public interface ISettingsStorage

T GetObjectRoamed<T>(string key, T def);
}

public class StubSettingsStorage : ISettingsStorage
{
public T GetObjectLocal<T>(string key) => GetObjectLocal<T>(key, default);

public T GetObjectLocal<T>(string key, T def) => def;

public T GetObjectRoamed<T>(string key) => GetObjectRoamed<T>(key, default);

public T GetObjectRoamed<T>(string key, T def) => def;

public void StoreObjectLocal(string key, object obj)
{
}

public void StoreObjectRoamed(string key, object obj)
{
}
}
}
21 changes: 21 additions & 0 deletions LRReader.Shared/Internal/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<string>("Profiles");
Expand Down Expand Up @@ -212,4 +229,8 @@ public void SaveProfiles()
SettingsStorage.StoreObjectRoamed("Profiles", JsonConvert.SerializeObject(Profiles));
}
}
public enum BookmarkReminderMode
{
All, New
}
}
5 changes: 4 additions & 1 deletion LRReader.Shared/Models/Main/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class ServerProfile : ObservableObject
public List<BookmarkedArchive> 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('/');
Expand Down Expand Up @@ -54,5 +55,7 @@ public void Update()

[JsonIgnore]
public int BookmarkProgressDisplay => page + 1;
[JsonIgnore]
public bool Bookmarked => totalPages >= 0;
}
}
20 changes: 20 additions & 0 deletions LRReader.UWP.Core/Internal/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
8 changes: 6 additions & 2 deletions LRReader.UWP.Core/Resources/ThemeDictionary.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
TintColor="{StaticResource BrushDeepBackgroundColor}"
TintOpacity="0.6" />
<Color x:Key="ColorNavTop">#F2F2F2</Color>
<SolidColorBrush x:Key="BrushItemGridBackground" Color="#E5E5E5" />
<Color x:Key="BrushItemGridBackgroundColor">#E5E5E5</Color>
<SolidColorBrush x:Key="BrushItemGridBackground" Color="{ThemeResource BrushItemGridBackgroundColor}" />
<SolidColorBrush x:Key="BrushTagBackground" Color="#CCCCCC" />
<AcrylicBrush
x:Key="TitlebarBackground" BackgroundSource="HostBackdrop"
FallbackColor="{ThemeResource ColorNavTop}"
TintColor="{ThemeResource SystemChromeMediumColor}"
TintOpacity=".5" />
<SolidColorBrush x:Key="GridViewItemPlaceholderBackground" Color="{ThemeResource BrushItemGridBackgroundColor}" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="BrushText" Color="White" />
Expand All @@ -38,13 +40,15 @@
TintColor="{StaticResource BrushDeepBackgroundColor}"
TintOpacity="0.6" />
<Color x:Key="ColorNavTop">#171717</Color>
<SolidColorBrush x:Key="BrushItemGridBackground" Color="#1f1f1f" />
<Color x:Key="BrushItemGridBackgroundColor">#1f1f1f</Color>
<SolidColorBrush x:Key="BrushItemGridBackground" Color="{ThemeResource BrushItemGridBackgroundColor}" />
<SolidColorBrush x:Key="BrushTagBackground" Color="#333333" />
<AcrylicBrush
x:Key="TitlebarBackground" BackgroundSource="HostBackdrop"
FallbackColor="{ThemeResource ColorNavTop}"
TintColor="{ThemeResource SystemChromeMediumColor}"
TintOpacity=".5" />
<SolidColorBrush x:Key="GridViewItemPlaceholderBackground" Color="{ThemeResource BrushItemGridBackgroundColor}" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
74 changes: 33 additions & 41 deletions LRReader.UWP.Core/ViewModels/ArchivePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public bool LoadingImages
}
public ObservableCollection<string> ArchiveImages = new ObservableCollection<string>();
public ObservableCollection<ArchiveImageSet> ArchiveImagesReader = new ObservableCollection<ArchiveImageSet>();
public ObservableCollection<string> Tags = new ObservableCollection<string>();
private bool _showReader = false;
public bool ShowReader
{
Expand All @@ -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();
Expand All @@ -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()
Expand Down Expand Up @@ -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<ArchiveImageSet> tmp = new List<ArchiveImageSet>();
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);
Expand Down
5 changes: 4 additions & 1 deletion LRReader.UWP.Core/ViewModels/ArchivesPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
38 changes: 32 additions & 6 deletions LRReader.UWP.Core/ViewModels/Base/ArchiveBaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -160,6 +175,17 @@ public SymbolIconSource Icon
{
get => new SymbolIconSource() { Symbol = Bookmarked ? Symbol.Favorite : Symbol.Pictures };
}
public ObservableCollection<string> Tags = new ObservableCollection<string>();

public void LoadTags()
{
Tags.Clear();

foreach (var s in Archive.tags.Split(","))
{
Tags.Add(s.Trim());
}
}

public async Task<DownloadPayload> DownloadArchive()
{
Expand Down
8 changes: 7 additions & 1 deletion LRReader.UWP.Core/ViewModels/ViewModelLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<ArchivesPageViewModel>();
Expand Down
2 changes: 1 addition & 1 deletion LRReader.UWP.Core/Views/Items/ArchiveImage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mc:Ignorable="d">

<Grid Width="200" Height="282" Background="{ThemeResource BrushItemGridBackground}">
<Image Name="Image" ImageFailed="Image_ImageFailed" />
<Image Name="Image" ImageFailed="Image_ImageFailed" ImageOpened="Image_ImageOpened" />
<Grid x:Name="MissingImageGrid" x:Load="{x:Bind Data.MissingImage, Mode=OneWay}">
<FontIcon FontFamily="Segoe MDL2 Assets" FontSize="34" Glyph="&#xE8CD;" />
</Grid>
Expand Down
Loading

0 comments on commit 5e7088c

Please sign in to comment.