Skip to content

Commit

Permalink
Add double-click to fullscreen in reader (#38) and fix profile path r…
Browse files Browse the repository at this point in the history
…eset when already in the default location (#37)
  • Loading branch information
Guerra24 committed Oct 23, 2023
1 parent 1e1910f commit 02ce35d
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 13 deletions.
4 changes: 4 additions & 0 deletions LRReader.Avalonia/Services/SettingsStorage.cs
Expand Up @@ -90,5 +90,9 @@ public void DeleteObjectRoamed(string key)
roamedSettings.Remove(key);
Save();
}

public bool ExistLocal(string key) => localSettings.ContainsKey(key);

public bool ExistRoamed(string key) => roamedSettings.ContainsKey(key);
}
}
4 changes: 2 additions & 2 deletions LRReader.Shared/LRReader.Shared.csproj
Expand Up @@ -3,15 +3,15 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.1;uap10.0.17763</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
<LangVersion>10.0</LangVersion>
<ExtrasUwpMetaPackageVersion>6.2.14</ExtrasUwpMetaPackageVersion>
<TargetPlatformVersion>10.0.22621.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.2" Condition="'$(TargetFramework)' == 'uap10.0.17763'" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.3" Condition="'$(TargetFramework)' == 'uap10.0.17763'" />
<PackageReference Include="Caching.dll" Version="2.0.0.1" />
<PackageReference Include="KeyedSemaphores" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
Expand Down
12 changes: 8 additions & 4 deletions LRReader.Shared/Services/Settings.cs
Expand Up @@ -351,9 +351,7 @@ public async Task Init()
SettingsStorage.DeleteObjectLocal(nameof(ProfilesPathLocation));
SettingsStorage.DeleteObjectLocal(nameof(ProfilesFileToken));

Profiles = new ObservableCollection<ServerProfile>();
await Files.StoreFileSafe(ProfilesPathLocation, "");
ProfilesFile = await StorageFile.GetFileFromPathAsync(ProfilesPathLocation);
ProfilesFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("Profiles.json", CreationCollisionOption.ReplaceExisting);
}

ProfilesPathLocation = ProfilesFile.Path;
Expand Down Expand Up @@ -502,6 +500,9 @@ public async Task ChangeProfilesLocation()
var file = await savePicker.PickSaveFileAsync();
if (file != null)
{
if (file.IsEqual(ProfilesFile))
return;

await ProfilesFile.MoveAndReplaceAsync(file);
StorageApplicationPermissions.FutureAccessList.Remove(ProfilesFileToken);
ProfilesFileToken = StorageApplicationPermissions.FutureAccessList.Add(file);
Expand All @@ -515,17 +516,20 @@ public async Task ChangeProfilesLocation()

public async Task ResetProfilesLocation()
{
if (Path.Combine(Files.Local, "Profiles.json").Equals(ProfilesPathLocation))
return;
#if WINDOWS_UWP
var original = await ApplicationData.Current.LocalFolder.CreateFileAsync("Profiles.json", CreationCollisionOption.ReplaceExisting);
await ProfilesFile.MoveAndReplaceAsync(original);
ProfilesFile = original;

StorageApplicationPermissions.FutureAccessList.Remove(ProfilesFileToken);

SettingsStorage.DeleteObjectLocal(nameof(ProfilesPathLocation));
SettingsStorage.DeleteObjectLocal(nameof(ProfilesFileToken));
#else
#endif
SettingsStorage.DeleteObjectLocal(nameof(ProfilesPathLocation));

OnPropertyChanged(nameof(ProfilesPathLocation));
}

Expand Down
7 changes: 7 additions & 0 deletions LRReader.Shared/Services/SettingsStorage.cs
Expand Up @@ -26,6 +26,9 @@ public interface ISettingsStorageService : IService
[return: NotNullIfNotNull("def")]
T? GetObjectRoamed<T>(T? def, [CallerMemberName] string? key = null);

bool ExistLocal(string key);
bool ExistRoamed(string key);

}

public class StubSettingsStorageService : ISettingsStorageService
Expand Down Expand Up @@ -57,5 +60,9 @@ public void StoreObjectRoamed(object obj, [CallerMemberName] string? key = null)

[return: NotNullIfNotNull("def")]
public T? GetObjectRoamed<T>(T? def, [CallerMemberName] string? key = null) => def;

public bool ExistLocal(string key) => false;

public bool ExistRoamed(string key) => false;
}
}
2 changes: 1 addition & 1 deletion LRReader.UWP.Installer/LRReader.UWP.Installer.csproj
Expand Up @@ -33,7 +33,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.22621.755" />
<PackageReference Include="WPF-UI">
<Version>3.0.0-preview.6</Version>
<Version>3.0.0-preview.8</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions LRReader.UWP/LRReader.UWP.csproj
Expand Up @@ -431,7 +431,7 @@
<Version>8.0.230907</Version>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter.Crashes">
<Version>5.0.2</Version>
<Version>5.0.3</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
Expand All @@ -449,7 +449,7 @@
<Version>2.8.2-prerelease.220830001</Version>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2">
<Version>1.0.2045.28</Version>
<Version>1.0.2088.41</Version>
</PackageReference>
<PackageReference Include="Nullable">
<Version>1.3.1</Version>
Expand Down
4 changes: 4 additions & 0 deletions LRReader.UWP/Services/SettingsStorage.cs
Expand Up @@ -39,5 +39,9 @@ public class SettingsStorageService : ISettingsStorageService
public void DeleteObjectLocal(string key) => localSettings.Values.Remove(key);

public void DeleteObjectRoamed(string key) => roamedSettings.Values.Remove(key);

public bool ExistLocal(string key) => localSettings.Values.ContainsKey(key);

public bool ExistRoamed(string key) => roamedSettings.Values.ContainsKey(key);
}
}
6 changes: 6 additions & 0 deletions LRReader.UWP/Views/Root.xaml.cs
Expand Up @@ -30,12 +30,18 @@ public void ChangeTheme(AppTheme theme)
{
case AppTheme.System:
RequestedTheme = ElementTheme.Default;
if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 13))
((TenMicaBrush)Background).ThemeForced = false;
break;
case AppTheme.Dark:
RequestedTheme = ElementTheme.Dark;
if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 13))
((TenMicaBrush)Background).ForcedTheme = ApplicationTheme.Dark;
break;
case AppTheme.Light:
RequestedTheme = ElementTheme.Light;
if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 13))
((TenMicaBrush)Background).ForcedTheme = ApplicationTheme.Light;
break;
}
}
Expand Down
34 changes: 34 additions & 0 deletions LRReader.UWP/Views/Tabs/Content/ArchiveTabContent.xaml
Expand Up @@ -157,6 +157,7 @@
x:Name="ScrollViewer" Grid.RowSpan="2" ui:ScrollViewerExtensions.EnableMiddleClickScrolling="True"
HorizontalAnchorRatio="0.5" HorizontalScrollBarVisibility="Auto" KeyboardAcceleratorPlacementMode="Hidden"
PointerPressed="ScrollViewer_PointerPressed" RightTapped="ScrollViewer_RightTapped" SizeChanged="ScrollViewer_SizeChanged"
DoubleTapped="ScrollViewer_DoubleTapped"
Tapped="ScrollViewer_Tapped" VerticalAnchorRatio="0.01" VerticalScrollBarVisibility="Auto"
ViewChanged="ScrollViewer_ViewChanged"
Visibility="{x:Bind Data.ShowReader, Mode=OneWay}">
Expand All @@ -180,6 +181,39 @@
</Grid>
</ContentControl>
</ScrollViewer>
<!--<Grid Height="300" VerticalAlignment="Bottom" Background="{ThemeResource SystemControlAcrylicElementMediumHighBrush}" x:Load="{x:Bind Data.ShowReader, Mode=OneWay}">
<ListView ItemsSource="{x:Bind Data.ArchiveImages}"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.IsHorizontalRailEnabled="True">
<ListView.ItemTemplate>
<DataTemplate>
<items:ArchiveImage />
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="5" />
</Style>
</ListView.ItemContainerStyle>
</ListView>-->
<!--<muxc:ItemsRepeater ItemsSource="{x:Bind Data.ArchiveImages}">
<muxc:ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="main:ImagePageSet">
<items:ArchiveImage DataContext="{x:Bind}" />
</DataTemplate>
</muxc:ItemsRepeater.ItemTemplate>
<muxc:ItemsRepeater.Layout>
<muxc:StackLayout Orientation="Horizontal" />
</muxc:ItemsRepeater.Layout>
</muxc:ItemsRepeater>-->
<!--</Grid>-->
<!--<Border x:Name="LeftHitTargetOverlay" Background="#40FF0000" BorderThickness="2" BorderBrush="#90FF0000" HorizontalAlignment="Left" IsHitTestVisible="False" />
<Border x:Name="RightHitTargetOverlay" Background="#40FF0000" BorderThickness="2" BorderBrush="#90FF0000" HorizontalAlignment="Right" IsHitTestVisible="False" />-->
<Button
Grid.RowSpan="2" Width="38" Height="38"
HorizontalAlignment="Right" VerticalAlignment="Top" Background="Transparent"
Expand Down
35 changes: 31 additions & 4 deletions LRReader.UWP/Views/Tabs/Content/ArchiveTabContent.xaml.cs
Expand Up @@ -21,6 +21,7 @@
using Windows.Storage.Provider;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
Expand Down Expand Up @@ -481,25 +482,47 @@ private void ScrollViewer_PointerPressed(object sender, PointerRoutedEventArgs e
_changePage = pointerPoint.Properties.IsLeftButtonPressed || pointerPoint.Properties.IsRightButtonPressed;
}

private void ScrollViewer_RightTapped(object sender, RightTappedRoutedEventArgs e) => HandleTapped(e.GetPosition(ScrollViewer));
private void ScrollViewer_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
var point = e.GetPosition(ScrollViewer);
double distance = ScrollViewer.ActualWidth / 6.0;
if (point.X > distance && point.X < ScrollViewer.ActualWidth - distance)
{
var AppView = ApplicationView.GetForCurrentView();
if (AppView.IsFullScreenMode)
{
AppView.ExitFullScreenMode();
}
else
{
AppView.TryEnterFullScreenMode();
}
e.Handled = true;
}
}

private void ScrollViewer_Tapped(object sender, TappedRoutedEventArgs e) => HandleTapped(e.GetPosition(ScrollViewer));
private void ScrollViewer_RightTapped(object sender, RightTappedRoutedEventArgs e) => e.Handled = HandleTapped(e.GetPosition(ScrollViewer));

private void HandleTapped(Point point)
private void ScrollViewer_Tapped(object sender, TappedRoutedEventArgs e) => e.Handled = HandleTapped(e.GetPosition(ScrollViewer));

private bool HandleTapped(Point point)
{
if (_changePage)
{
double distance = ScrollViewer.ActualWidth / 6.0;
if (point.X < distance)
{
PrevPage();
return true;
}
else if (point.X > ScrollViewer.ActualWidth - distance)
{
NextPage();
return true;
}
_changePage = false;
}
return false;
}

private void ReaderControl_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
Expand Down Expand Up @@ -589,7 +612,11 @@ private async void Preload(ReaderImageSet set)
await Service.Images.GetImageCached(set.RightImage);
}

private void ScrollViewer_SizeChanged(object sender, SizeChangedEventArgs e) => FitImages(Data.UseVerticalReader);
private void ScrollViewer_SizeChanged(object sender, SizeChangedEventArgs e)
{
FitImages(Data.UseVerticalReader);
//LeftHitTargetOverlay.Width = RightHitTargetOverlay.Width = ScrollViewer.ActualWidth / 6.0;
}

private void ReaderControl_SizeChanged(object sender, SizeChangedEventArgs e) => FitImages(true);

Expand Down

0 comments on commit 02ce35d

Please sign in to comment.