mirror of
https://github.com/tgeorgiadis/quiver-launcher.git
synced 2026-11-22 21:50:52 -05:00
The App Catalog now reads the website's public REST API: search, sort, platform, console and type filters, cards with paging, and an app details panel with how it runs for players, recent reviews, the README, and Add or Remove. Reviews are written on the website. The community lists, catalog sources, review diffs, catalog badges and prompts, and the shared platform index are removed. One Advanced setting keeps a player's own JSON list (a file or URL), and a list added in an earlier version carries over. Tests for removed code and low-value tests are removed; the API mapping, adding to the library, the settings upgrade and controller navigation through Browse are covered.
423 lines
15 KiB
C#
423 lines
15 KiB
C#
using Avalonia;
|
|
using Avalonia.Animation;
|
|
using Avalonia.Animation.Easings;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls.Presenters;
|
|
using Avalonia.Controls.Primitives;
|
|
using Avalonia.Input;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Layout;
|
|
using Avalonia.Media;
|
|
using Avalonia.Threading;
|
|
using QuiverLauncher.Services;
|
|
|
|
namespace QuiverLauncher.Views;
|
|
/// <summary>View-side mobile arrangement and temporary attachment ownership.</summary>
|
|
public sealed class MobileShellLayout : IDisposable
|
|
{
|
|
private readonly UserControl _root;
|
|
private readonly LibraryToolbarView _toolbar;
|
|
private readonly LauncherSession _session;
|
|
private readonly Action _updateHeader;
|
|
private readonly MobileInsetsController _insets;
|
|
private bool _attached, _disposed;
|
|
private int _attachment;
|
|
private readonly SplitView MainSplitView;
|
|
private readonly Grid MainGrid;
|
|
private readonly Border SidebarPanel;
|
|
private readonly Grid MobileNavDrawerHost;
|
|
private readonly Grid MobileNavOverlay;
|
|
private readonly Grid HeaderTitleColumn;
|
|
private readonly TextBlock HeaderTitleText;
|
|
private readonly Button MobileSearchToggleButton;
|
|
private readonly Button MobileNavButton;
|
|
private readonly StackPanel SidebarNavPanel;
|
|
private readonly ScrollViewer SidebarBodyScroller;
|
|
private readonly StackPanel SidebarBodyHost;
|
|
private readonly LibraryView LibraryPanel;
|
|
private readonly BrowseView BrowsePanel;
|
|
private readonly SettingsView SettingsPanel;
|
|
private readonly LibraryFiltersView LibraryFiltersPanel;
|
|
private readonly AppEntryEditorView EntryFormOverlay;
|
|
private readonly AppUpdateReviewView AppUpdatesReviewPanel;
|
|
private readonly ModsView ModsPanel;
|
|
private readonly Border _navDimmer;
|
|
private readonly MobileEdgeSwipe _edgeSwipe;
|
|
private readonly TranslateTransform _drawerTranslation = new();
|
|
public MobileShellLayout(UserControl root, LauncherSession session, Action updateHeader)
|
|
{
|
|
_root = root;
|
|
_toolbar = root.FindControl<LibraryToolbarView>("LibraryToolbar")!;
|
|
_session = session;
|
|
_updateHeader = updateHeader;
|
|
MainSplitView = root.FindControl<SplitView>("MainSplitView")!;
|
|
MainGrid = root.FindControl<Grid>("MainGrid")!;
|
|
SidebarPanel = root.FindControl<Border>("SidebarPanel")!;
|
|
MobileNavDrawerHost = root.FindControl<Grid>("MobileNavDrawerHost")!;
|
|
MobileNavOverlay = root.FindControl<Grid>("MobileNavOverlay")!;
|
|
HeaderTitleColumn = root.FindControl<Grid>("HeaderTitleColumn")!;
|
|
HeaderTitleText = root.FindControl<TextBlock>("HeaderTitleText")!;
|
|
MobileSearchToggleButton = root.FindControl<Button>("MobileSearchToggleButton")!;
|
|
MobileNavButton = root.FindControl<Button>("MobileNavButton")!;
|
|
SidebarNavPanel = root.FindControl<StackPanel>("SidebarNavPanel")!;
|
|
SidebarBodyScroller = root.FindControl<ScrollViewer>("SidebarBodyScroller")!;
|
|
SidebarBodyHost = root.FindControl<StackPanel>("SidebarBodyHost")!;
|
|
LibraryPanel = root.FindControl<LibraryView>("LibraryPanel")!;
|
|
BrowsePanel = root.FindControl<BrowseView>("BrowsePanel")!;
|
|
SettingsPanel = root.FindControl<SettingsView>("SettingsPanel")!;
|
|
LibraryFiltersPanel = root.FindControl<LibraryFiltersView>("LibraryFiltersPanel")!;
|
|
EntryFormOverlay = root.FindControl<AppEntryEditorView>("EntryFormOverlay")!;
|
|
AppUpdatesReviewPanel = root.FindControl<AppUpdateReviewView>("AppUpdatesReviewPanel")!;
|
|
ModsPanel = root.FindControl<ModsView>("ModsPanel")!;
|
|
_insets = new MobileInsetsController(root, () =>
|
|
{
|
|
ApplyMobileHeaderChrome();
|
|
EntryFormOverlay.FitAvailableHeight();
|
|
});
|
|
MobileNavButton.Click += MobileNavButton_Click;
|
|
MobileSearchToggleButton.Click += MobileSearchToggleButton_Click;
|
|
_toolbar.SearchLostFocus += LibrarySearchTextBox_LostFocus;
|
|
_navDimmer = root.FindControl<Border>("MobileNavDimmer")!;
|
|
_navDimmer.PointerPressed += MobileNavDimmer_PointerPressed;
|
|
((Control)MobileNavDrawerHost.Parent!).RenderTransform = _drawerTranslation;
|
|
_edgeSwipe = new MobileEdgeSwipe(root, () => CanOpenNavigation,
|
|
() => IsMobileNavOpen = true);
|
|
}
|
|
|
|
public bool CanOpenNavigation =>
|
|
PlatformCapabilities.IsMobile && !_disposed && !_session.IsClosed && !IsMobileNavOpen &&
|
|
!_root.FindControl<Control>("MessagePromptOverlay")!.IsVisible &&
|
|
!EntryFormOverlay.IsVisible &&
|
|
!_root.FindControl<Control>("TagEditOverlay")!.IsVisible &&
|
|
!_root.FindControl<Control>("DisplayFilterOverlay")!.IsVisible;
|
|
|
|
public void Attach()
|
|
{
|
|
if (_disposed || _session.IsClosed)
|
|
return;
|
|
if (!_attached)
|
|
{
|
|
_root.SizeChanged += SizeChanged;
|
|
if (PlatformCapabilities.IsMobile)
|
|
_edgeSwipe.Attach();
|
|
_attached = true;
|
|
++_attachment;
|
|
}
|
|
|
|
_insets.Attach();
|
|
if (PlatformCapabilities.IsMobile)
|
|
Post(() =>
|
|
{
|
|
var insets = TopLevel.GetTopLevel(_root)?.InsetsManager;
|
|
if (insets != null)
|
|
_insets.ApplySafeAreaPadding(insets.SafeAreaPadding);
|
|
LibraryPanel.FitMobileLibraryCardWidth();
|
|
}, DispatcherPriority.Loaded);
|
|
}
|
|
|
|
public void Detach()
|
|
{
|
|
_attached = false;
|
|
++_attachment;
|
|
_root.SizeChanged -= SizeChanged;
|
|
_edgeSwipe.Dispose();
|
|
_insets.Detach();
|
|
}
|
|
|
|
private void SizeChanged(object? sender, SizeChangedEventArgs e)
|
|
{
|
|
EntryFormOverlay.FitAvailableHeight();
|
|
if (!PlatformCapabilities.IsMobile)
|
|
return;
|
|
_insets.Refresh();
|
|
ApplyMobileHeaderChrome();
|
|
LibraryPanel.FitMobileLibraryCardWidth();
|
|
}
|
|
|
|
private void Post(Action action, DispatcherPriority priority)
|
|
{
|
|
var attachment = _attachment;
|
|
Dispatcher.UIThread.Post(() =>
|
|
{
|
|
if (!_disposed && !_session.IsClosed && attachment == _attachment)
|
|
action();
|
|
}, priority);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_disposed)
|
|
return;
|
|
_disposed = true;
|
|
Detach();
|
|
_insets.Dispose();
|
|
MobileNavButton.Click -= MobileNavButton_Click;
|
|
MobileSearchToggleButton.Click -= MobileSearchToggleButton_Click;
|
|
_toolbar.SearchLostFocus -= LibrarySearchTextBox_LostFocus;
|
|
_navDimmer.PointerPressed -= MobileNavDimmer_PointerPressed;
|
|
}
|
|
|
|
private bool _mobileTopBarReparented;
|
|
private bool _mobileSidebarBodyReparented;
|
|
public bool IsSearchOpen;
|
|
private bool _isMobileNavOpen;
|
|
public bool IsMobileNavOpen
|
|
{
|
|
get => _isMobileNavOpen;
|
|
set
|
|
{
|
|
if (_isMobileNavOpen == value)
|
|
return;
|
|
_isMobileNavOpen = value;
|
|
if (!PlatformCapabilities.IsMobile)
|
|
return;
|
|
if (MainSplitView != null)
|
|
MainSplitView.IsPaneOpen = false;
|
|
if (MobileNavOverlay != null)
|
|
{
|
|
_drawerTranslation.Transitions = null;
|
|
_drawerTranslation.X = value ? -264 : 0;
|
|
MobileNavOverlay.IsVisible = value;
|
|
if (value)
|
|
Post(() =>
|
|
{
|
|
if (!IsMobileNavOpen) return;
|
|
_drawerTranslation.Transitions = new Transitions
|
|
{
|
|
new DoubleTransition { Property = TranslateTransform.XProperty,
|
|
Duration = TimeSpan.FromMilliseconds(180), Easing = new CubicEaseOut() }
|
|
};
|
|
_drawerTranslation.X = 0;
|
|
}, DispatcherPriority.Loaded);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ApplyMobileShell()
|
|
{
|
|
if (!PlatformCapabilities.IsMobile)
|
|
return;
|
|
_root.Classes.Set("mobile", true);
|
|
if (SidebarPanel != null && MobileNavDrawerHost != null)
|
|
MoveControlTo(SidebarPanel, MobileNavDrawerHost);
|
|
BypassMobileSplitView();
|
|
ApplyMobileContentInsets();
|
|
if (SettingsPanel != null)
|
|
{
|
|
SettingsPanel.Width = double.NaN;
|
|
SettingsPanel.MaxWidth = 520;
|
|
SettingsPanel.HorizontalAlignment = HorizontalAlignment.Stretch;
|
|
}
|
|
|
|
ReparentMobileTopBar();
|
|
ReparentMobileSidebarBody();
|
|
LibraryPanel.ApplyMobileLayout();
|
|
}
|
|
|
|
private void BypassMobileSplitView()
|
|
{
|
|
if (MainSplitView == null || MainGrid == null)
|
|
return;
|
|
if (MainSplitView.Parent is not Panel host)
|
|
return;
|
|
if (ReferenceEquals(MainGrid.Parent, host))
|
|
return;
|
|
MainSplitView.IsPaneOpen = false;
|
|
MainSplitView.Content = null;
|
|
MainSplitView.Pane = null;
|
|
MainSplitView.IsVisible = false;
|
|
host.Children.Insert(0, MainGrid);
|
|
}
|
|
|
|
private void ApplyMobileContentInsets()
|
|
{
|
|
var content = new Thickness(8, 8, 8, 8);
|
|
LibraryPanel.ApplyContentInsets(content);
|
|
if (BrowsePanel != null)
|
|
{
|
|
BrowsePanel.Margin = content;
|
|
BrowsePanel.ApplyMobileLayout();
|
|
}
|
|
if (AppUpdatesReviewPanel != null)
|
|
AppUpdatesReviewPanel.Margin = content;
|
|
if (ModsPanel != null)
|
|
ModsPanel.Margin = content;
|
|
}
|
|
|
|
private void ReparentMobileTopBar()
|
|
{
|
|
if (_mobileTopBarReparented)
|
|
return;
|
|
_toolbar.MoveSearchTo(HeaderTitleColumn);
|
|
if (HeaderTitleColumn != null)
|
|
HeaderTitleColumn.Margin = new Thickness(8, 0, 4, 0);
|
|
if (HeaderTitleText != null)
|
|
HeaderTitleText.Margin = new Thickness(0);
|
|
_mobileTopBarReparented = true;
|
|
ApplyMobileSearchChrome();
|
|
ApplyMobileHeaderChrome();
|
|
}
|
|
|
|
private static void MoveControlTo(Control? control, Panel? destination, int column = 0, Dock dock = Dock.Left, int insertIndex = -1)
|
|
{
|
|
if (control == null || destination == null || ReferenceEquals(control.Parent, destination))
|
|
return;
|
|
DetachFromParent(control);
|
|
if (insertIndex >= 0 && insertIndex <= destination.Children.Count)
|
|
destination.Children.Insert(insertIndex, control);
|
|
else
|
|
destination.Children.Add(control);
|
|
if (destination is Grid)
|
|
{
|
|
Grid.SetColumn(control, column);
|
|
Grid.SetRow(control, 0);
|
|
}
|
|
else if (destination is DockPanel)
|
|
{
|
|
DockPanel.SetDock(control, dock);
|
|
}
|
|
}
|
|
|
|
private void ReparentMobileSidebarBody()
|
|
{
|
|
if (_mobileSidebarBodyReparented)
|
|
return;
|
|
var nav = SidebarNavPanel;
|
|
var filters = LibraryFiltersPanel;
|
|
var scroller = SidebarBodyScroller;
|
|
var host = SidebarBodyHost;
|
|
if (nav == null || filters == null || scroller == null || host == null)
|
|
return;
|
|
MoveControlTo(nav, host);
|
|
MoveControlTo(filters, host);
|
|
filters.ApplyMobileLayout();
|
|
scroller.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
|
|
scroller.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
|
|
scroller.IsScrollInertiaEnabled = true;
|
|
scroller.IsVisible = true;
|
|
_mobileSidebarBodyReparented = true;
|
|
}
|
|
|
|
private static void DetachFromParent(Control control)
|
|
{
|
|
if (control.Parent is SplitView split && ReferenceEquals(split.Pane, control))
|
|
{
|
|
split.Pane = null;
|
|
return;
|
|
}
|
|
|
|
switch (control.Parent)
|
|
{
|
|
case Panel panel:
|
|
panel.Children.Remove(control);
|
|
break;
|
|
case Decorator decorator:
|
|
decorator.Child = null;
|
|
break;
|
|
case ContentPresenter presenter:
|
|
presenter.Content = null;
|
|
break;
|
|
case ContentControl contentControl:
|
|
contentControl.Content = null;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public bool IsMobileLandscape
|
|
{
|
|
get
|
|
{
|
|
if (!PlatformCapabilities.IsMobile)
|
|
return false;
|
|
var size = TopLevel.GetTopLevel(_root)?.ClientSize ?? default;
|
|
if (size.Width > 1 && size.Height > 1)
|
|
return size.Width > size.Height;
|
|
return _root.Bounds.Width > _root.Bounds.Height && _root.Bounds.Width > 1;
|
|
}
|
|
}
|
|
|
|
private void ApplyMobileHeaderChrome()
|
|
{
|
|
if (!PlatformCapabilities.IsMobile)
|
|
return;
|
|
var landscape = IsMobileLandscape;
|
|
_root.Classes.Set("mobile-landscape", landscape);
|
|
if (HeaderTitleText != null)
|
|
HeaderTitleText.FontSize = landscape ? 14 : 18;
|
|
if (HeaderTitleColumn != null)
|
|
HeaderTitleColumn.MinHeight = landscape ? 28 : 44;
|
|
_updateHeader();
|
|
}
|
|
|
|
public void CloseMobileNav()
|
|
{
|
|
if (PlatformCapabilities.IsMobile)
|
|
IsMobileNavOpen = false;
|
|
}
|
|
|
|
private void MobileNavButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
IsMobileNavOpen = !IsMobileNavOpen;
|
|
}
|
|
|
|
private void MobileSearchToggleButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (IsSearchOpen)
|
|
{
|
|
if (!_toolbar.HasQuery)
|
|
CloseMobileSearch();
|
|
return;
|
|
}
|
|
|
|
OpenMobileSearch();
|
|
}
|
|
|
|
private void OpenMobileSearch()
|
|
{
|
|
IsSearchOpen = true;
|
|
ApplyMobileSearchChrome();
|
|
Post(() => _toolbar.FocusSearch(), DispatcherPriority.Input);
|
|
}
|
|
|
|
public void CloseMobileSearch()
|
|
{
|
|
if (!IsSearchOpen)
|
|
return;
|
|
IsSearchOpen = false;
|
|
ApplyMobileSearchChrome();
|
|
}
|
|
|
|
public void ApplyMobileSearchChrome()
|
|
{
|
|
if (!PlatformCapabilities.IsMobile)
|
|
return;
|
|
var open = IsSearchOpen;
|
|
_updateHeader();
|
|
_toolbar.SetSearchVisible(open);
|
|
var hasQuery = _toolbar.HasQuery;
|
|
if (MobileSearchToggleButton != null)
|
|
MobileSearchToggleButton.Opacity = hasQuery ? 1 : 0.92;
|
|
}
|
|
|
|
private void LibrarySearchTextBox_LostFocus(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (!PlatformCapabilities.IsMobile || !IsSearchOpen)
|
|
return;
|
|
Post(() =>
|
|
{
|
|
if (!PlatformCapabilities.IsMobile || !IsSearchOpen)
|
|
return;
|
|
if (_toolbar.SearchContainsFocus)
|
|
return;
|
|
if (!_toolbar.HasQuery)
|
|
CloseMobileSearch();
|
|
}, DispatcherPriority.Input);
|
|
}
|
|
|
|
private void MobileNavDimmer_PointerPressed(object? sender, PointerPressedEventArgs e)
|
|
{
|
|
CloseMobileNav();
|
|
e.Handled = true;
|
|
}
|
|
}
|