Make sure OATH layout changes correctly when mixed layout is not

applicable
This commit is contained in:
Elias Bonnici 2024-07-04 13:05:27 +02:00
parent e45506427a
commit e846b9c301
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF
3 changed files with 21 additions and 14 deletions

View File

@ -438,8 +438,7 @@ class _FidoUnlockedPageState extends ConsumerState<_FidoUnlockedPage> {
// between icons
padding: const EdgeInsets.only(left: 17.0),
child: Container(
color:
Theme.of(context).colorScheme.background,
color: Theme.of(context).colorScheme.surface,
width: 1,
height: 45,
),

View File

@ -48,30 +48,38 @@ final oathLayoutProvider =
final favorites = ref.watch(favoritesProvider);
final pinnedCreds =
credentials.where((entry) => favorites.contains(entry.credential.id));
return OathLayoutNotfier(
'OATH_STATE_LAYOUT', ref.watch(prefProvider), pinnedCreds.isNotEmpty);
return OathLayoutNotfier('OATH_STATE_LAYOUT', ref.watch(prefProvider),
credentials, pinnedCreds.toList());
});
class OathLayoutNotfier extends StateNotifier<OathLayout> {
final String _key;
final SharedPreferences _prefs;
OathLayoutNotfier(this._key, this._prefs, bool _hasPinned)
: super(_fromName(_prefs.getString(_key), _hasPinned));
OathLayoutNotfier(this._key, this._prefs, List<OathPair> credentials,
List<OathPair> pinnedCredentials)
: super(
_fromName(_prefs.getString(_key), credentials, pinnedCredentials));
void setLayout(OathLayout layout) {
state = layout;
_prefs.setString(_key, layout.name);
}
static OathLayout _fromName(String? name, bool hasPinned) {
static OathLayout _fromName(String? name, List<OathPair> credentials,
List<OathPair> pinnedCredentials) {
final layout = OathLayout.values.firstWhere(
(element) => element.name == name,
orElse: () => OathLayout.list,
);
// Default to list view if current key does not have
// pinned credentials
if (layout == OathLayout.mixed && !hasPinned) {
return OathLayout.list;
if (layout == OathLayout.mixed) {
if (pinnedCredentials.isEmpty) {
return OathLayout.list;
}
if (pinnedCredentials.length == credentials.length) {
return OathLayout.grid;
}
}
return layout;
}

View File

@ -402,10 +402,11 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
final pinnedCreds = credentials
.where((entry) => favorites.contains(entry.credential.id));
final availableLayouts = pinnedCreds.isNotEmpty
final availableLayouts = pinnedCreds.isEmpty ||
pinnedCreds.length == credentials.length
? OathLayout.values
: OathLayout.values
.where((element) => element != OathLayout.mixed);
.where((element) => element != OathLayout.mixed)
: OathLayout.values;
final oathLayout = ref.watch(oathLayoutProvider);
return Padding(
@ -462,8 +463,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
// between icons
padding: const EdgeInsets.only(left: 17.0),
child: Container(
color:
Theme.of(context).colorScheme.background,
color: Theme.of(context).colorScheme.surface,
width: 1,
height: 45,
),