Synchronized sorting states between list view and gallery view

Introduced shared sorting state logic to maintain consistent sorting order when switching between gallery and list views (game name, last updated, size, popularity, asc and desc)
This commit is contained in:
jp64k
2025-12-30 22:12:29 +01:00
parent f363550351
commit 84ddce1423
3 changed files with 130 additions and 0 deletions

View File

@@ -24,6 +24,8 @@ public class FastGalleryPanel : Control
// Sorting
private SortField _currentSortField = SortField.Name;
private SortDirection _currentSortDirection = SortDirection.Ascending;
public SortField CurrentSortField => _currentSortField;
public SortDirection CurrentSortDirection => _currentSortDirection;
private readonly Panel _sortPanel;
private readonly List<Button> _sortButtons;
private Label _sortStatusLabel;
@@ -399,6 +401,14 @@ public class FastGalleryPanel : Control
Invalidate();
}
public void SetSortState(SortField field, SortDirection direction)
{
_currentSortField = field;
_currentSortDirection = direction;
UpdateSortButtonStyles();
ApplySort();
}
private int ParsePopularity(string popStr)
{
if (string.IsNullOrEmpty(popStr))

View File

@@ -49,6 +49,9 @@ namespace AndroidSideloader
public bool DeviceConnected = false;
public static string currremotesimple = "";
#endif
// Shared sort state between Gallery and List views
private SortField _sharedSortField = SortField.Name;
private SortDirection _sharedSortDirection = SortDirection.Ascending;
private const int BottomMargin = 8;
private const int RightMargin = 12;
private const int PanelSpacing = 10;
@@ -4675,6 +4678,12 @@ If the problem persists, visit our Telegram (https://t.me/VRPirates) or Discord
SortOrder.Ascending;
}
// Update shared sort state
_sharedSortField = ColumnIndexToSortField(e.Column);
_sharedSortDirection = lvwColumnSorter.Order == SortOrder.Ascending
? SortDirection.Ascending
: SortDirection.Descending;
// Suspend drawing during sort
gamesListView.BeginUpdate();
try
@@ -6161,6 +6170,42 @@ function onYouTubeIframeAPIReady() {
}
}
// Capture current sort state before switching
if (isGalleryView && _fastGallery != null)
{
// Save gallery sort state
_sharedSortField = _fastGallery.CurrentSortField;
_sharedSortDirection = _fastGallery.CurrentSortDirection;
// Flip popularity direction when going from gallery to list due to flipped underlying logic
// Gallery: Descending = Most Popular first
// List: Ascending = Most Popular first
if (_sharedSortField == SortField.Popularity)
{
_sharedSortDirection = _sharedSortDirection == SortDirection.Ascending
? SortDirection.Descending
: SortDirection.Ascending;
}
}
else if (!isGalleryView && _listViewRenderer != null && lvwColumnSorter != null)
{
// Save list view sort state
_sharedSortField = ColumnIndexToSortField(lvwColumnSorter.SortColumn);
_sharedSortDirection = lvwColumnSorter.Order == SortOrder.Ascending
? SortDirection.Ascending
: SortDirection.Descending;
// Flip popularity direction when going from list to gallery due to flipped underlying logic
// List: Ascending = Most Popular first
// Gallery: Descending = Most Popular first
if (_sharedSortField == SortField.Popularity)
{
_sharedSortDirection = _sharedSortDirection == SortDirection.Ascending
? SortDirection.Descending
: SortDirection.Ascending;
}
}
isGalleryView = !isGalleryView;
// Save user preference
@@ -6191,9 +6236,48 @@ function onYouTubeIframeAPIReady() {
gamesGalleryView.Visible = false;
gamesListView.Visible = true;
CleanupGalleryView();
// Apply shared sort state to list view
ApplySortToListView();
}
}
private SortField ColumnIndexToSortField(int columnIndex)
{
switch (columnIndex)
{
case 0: return SortField.Name;
case 4: return SortField.LastUpdated;
case 5: return SortField.Size;
case 6: return SortField.Popularity;
default: return SortField.Name;
}
}
private int SortFieldToColumnIndex(SortField field)
{
switch (field)
{
case SortField.Name: return 0;
case SortField.LastUpdated: return 4;
case SortField.Size: return 5;
case SortField.Popularity: return 6;
default: return 0;
}
}
private void ApplySortToListView()
{
if (_listViewRenderer == null || lvwColumnSorter == null) return;
int columnIndex = SortFieldToColumnIndex(_sharedSortField);
SortOrder order = _sharedSortDirection == SortDirection.Ascending
? SortOrder.Ascending
: SortOrder.Descending;
_listViewRenderer.ApplySort(columnIndex, order);
}
private void PopulateGalleryView()
{
// If _galleryDataSource was already set (by search or filter), use it
@@ -6239,6 +6323,10 @@ function onYouTubeIframeAPIReady() {
_fastGallery.TileClicked += FastGallery_TileClicked;
_fastGallery.TileDoubleClicked += FastGallery_TileDoubleClicked;
_fastGallery.TileDeleteClicked += FastGallery_TileDeleteClicked;
_fastGallery.SortChanged += FastGallery_SortChanged;
// Apply current shared sort state to gallery
_fastGallery.SetSortState(_sharedSortField, _sharedSortDirection);
gamesGalleryView.Controls.Add(_fastGallery);
_fastGallery.Anchor = AnchorStyles.None;
@@ -6256,6 +6344,16 @@ function onYouTubeIframeAPIReady() {
await UninstallGameAsync(item);
}
private void FastGallery_SortChanged(object sender, SortField field)
{
// Update shared state from gallery
if (_fastGallery != null)
{
_sharedSortField = _fastGallery.CurrentSortField;
_sharedSortDirection = _fastGallery.CurrentSortDirection;
}
}
private void GamesGalleryView_Resize(object sender, EventArgs e)
{
if (_fastGallery != null && !_fastGallery.IsDisposed)

View File

@@ -1187,6 +1187,28 @@ namespace AndroidSideloader
_listView.RedrawItems(_marqueeSelectedIndex, _marqueeSelectedIndex, true);
}
public void ApplySort(int columnIndex, SortOrder order)
{
if (_columnSorter == null) return;
_columnSorter.SortColumn = columnIndex;
_columnSorter.Order = order;
_listView.BeginUpdate();
try
{
_listView.Sort();
}
finally
{
_listView.EndUpdate();
}
// Invalidate header to update sort indicators
_listView.Invalidate(new Rectangle(0, 0, _listView.ClientSize.Width,
_listView.Font.Height + 8));
}
private static float Ease(float p)
{
p = Clamp01(p);