Prefer updating an object instead of replacing it. This preserves the
selection in the UI list. Also make renaming atomic as it should be. Now
the only possibility for data loss is if the old file can be opened but
not written to.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Caching the actual profile object is important when the fragment is on
an activity's back stack: when it is shown again, onCreateView will be
called with profile already set and the service already connected. In
this case, there is no later notification from which to bind the
profile, so the existing object needs to be bound there.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This has no visible changes at the moment, but will allow most functions
to pass around strings instead of Profile objects, obviating the need to
implement serialization for them. It also trades some naive linear
searches for the binary search in SimpleArrayMap.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Since the conversion to a sequential list (to implement ListAdapter)
depends on the implementation detail that ObservableArrayMap is backed
by an array, we can't use the ObservableMap interface here.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This is designed for tablets, but for testing purposes, it is currently
enabled for all devices in landscape orientation.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This is required for a future two-fragment tablet layout, and simplifies
the code a bit since the profile detail (view/edit) will be implemented
as fragments anyway.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This should help discourage editing a Profile without making a copy
first, since the caller has to keep track of the old Profile as well.
ProfileAdder has been updated to prevent adding duplicate profiles. It
checks once in the constructor, so the caller can catch the exception
and pass the error back to the UI. It checks again in the worker thread
to prevent any race from happening if a profile is added twice quickly.
Either the file exists, or it doesn't.
Additionally, this change solves the race condition when the old
profile is removed before it is updated; previously this would lead
to the profile being re-added. Now, ProfileRemover will fail and the
profile will stay removed.
Finally, updating a profile's name should now work correctly. There were
previously multiple bugs with that (the old profile wasn't removed, the
new one could duplicate a name, the new one could overwrite some random
other one, etc.).
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This allows retrieving the public key and generating keypairs, both of
which will be exposed in the UI.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>