Let a tap on the phone's host list mean connect

Choosing a machine raised the connect bar over the bottom of the list: a
password box, CONNECT, EDIT, MOVE and DELETE. Five controls in the way of the
one thing a tap on a machine's name obviously means.

So the gestures split. A tap connects. A long press raises the bar, with all
five. The pencil in the phone's header — its only persistent chrome — edits
whichever host is chosen, which is the one of the five common enough to be worth
a control that is always in the same place.

The flag doing it is the desktop's own IsHostPaneOpen rather than a second one.
That head made exactly this move when a selection stopped opening its drawer, and
the question both are asking is "has somebody asked about this host" — answering
it twice is how two heads come to disagree about what a selection means.

One tap cannot finish: a host that authenticates with a typed password has
nowhere on a list to be given one. That tap raises the bar with the box in it and
says so, and a second tap with the box filled in connects. The branch is in the
view model rather than in the head, because "can this machine be reached without
asking for anything" is the same question the bar's own password box answers, and
a copy of it in a view would be a second reading of a binding chain that has one.

Two mechanics worth knowing. Avalonia raises Tapped on release whatever the press
lasted, so a long press would open the bar and then connect — one touch firing
both gestures — which is why HostsScreen tracks the hold and swallows the tap it
precedes. And Holding only fires once IsHoldingEnabled is set, so that and the
handler are attached together rather than one in markup and one in code.

ConnectToRecent now opens the pane rather than selecting the row. On the phone it
has to: a selection alone raises nothing now, so going back to a recent machine
would land on a screen with nothing to press.
This commit is contained in:
jaap-jan committed 2026-08-05 08:43:33 +02:00
1 parent 69bc9e270b
commit 746711da9d
8 files changed
+412 -26

No files matched your search

@@ -1,10 +1,109 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using DodoSSH.Client.Shell.ViewModels;
namespace DodoSSH.Client.Android.Views;
/// <summary>Design 02 — the host list, and the connect bar that replaces the desktop's right column.</summary>
/// <remarks>
/// <para>
/// ◆ <b>Two gestures on one list, and this file is the whole of the difference between them.</b> A tap on a
/// host connects to it; a long press asks about it, which is what raises the bar. Why they were split is on
/// the screen itself; what is here is the mechanics, and there are two of them worth knowing.
/// </para>
/// <para>
/// The handlers are on the <c>ListBox</c> rather than on the row, and the row stays a plain <c>Grid</c>.
/// A button as the item template swallows the press before the list sees it — <c>FilesScreen</c> writes that
/// out at length — leaving nothing selected and every control that reads the selection doing nothing. Both
/// events fire after the list has moved its selection, which is what lets these read it.
/// </para>
/// </remarks>
internal sealed partial class HostsScreen : UserControl
{
public HostsScreen() => AvaloniaXamlLoader.Load(this);
/// <summary>
/// Whether the press that is about to end was long enough to have meant something else.
/// </summary>
/// <remarks>
/// Avalonia raises <c>Tapped</c> on release whatever the press lasted, so without this a long press
/// would open the bar and then connect — the two gestures firing one after the other on one touch, which
/// is the one outcome that would make both of them untrustworthy. Set when the hold starts and cleared
/// by the tap it suppresses, so it never survives the gesture that set it.
/// </remarks>
private bool held;
/// <remarks>
/// The long press is attached here rather than in the markup so that it sits beside the property that
/// makes it fire at all. <see cref="InputElement.IsHoldingEnabledProperty"/> is set rather than assumed:
/// it is the whole of the gesture, and a default that changed would take it away silently — every tap
/// would go on working and nothing would ever open the bar again.
/// </remarks>
public HostsScreen()
{
AvaloniaXamlLoader.Load(this);
InputElement.SetIsHoldingEnabled(Rows, true);
Rows.Holding += OnRowHeld;
}
/// <summary>
/// Connects to the row that was tapped.
/// </summary>
/// <remarks>
/// <para>
/// Guarded on the selection being a host rather than on what was under the finger. A tap on a group
/// heading moves the list's selection and the view model bounces it straight back to whatever was chosen
/// before — see <c>VaultViewModel.SelectedSidebarRow</c> — so reading the selection here answers "a host,
/// or nothing" without this file needing to know that rule. The cost of getting it wrong is connecting to
/// a machine the user was not pointing at.
/// </para>
/// <para>
/// Fire-and-forget, as the desktop grid's activation is: the command reports its own failures onto the
/// status line — an unknown host key, a refused password — and awaiting it here would be an event handler
/// returning a task nothing observes.
/// </para>
/// </remarks>
private void OnRowTapped(object? sender, TappedEventArgs e)
{
if (held)
{
held = false;
return;
}
if (DataContext is VaultViewModel { SelectedHost: { } row } vault)
{
_ = vault.ConnectToRowCommand.ExecuteAsync(row);
}
}
/// <summary>
/// Raises the bar about the row that was held.
/// </summary>
/// <remarks>
/// <para>
/// On <see cref="HoldingState.Started"/> rather than on completion, so the bar is up while the finger is
/// still down. A long press that showed nothing until release would be a gesture with no way to tell it
/// had been recognised, and the only feedback available on this list is the thing it does.
/// </para>
/// <para>
/// It goes through <c>OpenHostPaneCommand</c>, which is the desktop's own "ask about this host" — the two
/// heads raise different furniture from one flag rather than keeping a selection rule each.
/// </para>
/// </remarks>
private void OnRowHeld(object? sender, HoldingRoutedEventArgs e)
{
if (e.HoldingState != HoldingState.Started)
{
return;
}
held = true;
if (DataContext is VaultViewModel { SelectedHost: { } row } vault)
{
vault.OpenHostPaneCommand.Execute(row);
}
}
}