mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-13 18:58:53 +01:00
Remember prev choice in new collection dialog
This commit is contained in:
parent
301c8bb404
commit
e56df922bb
3 changed files with 34 additions and 1 deletions
|
@ -382,6 +382,18 @@ class AccountPref {
|
|||
}
|
||||
}
|
||||
|
||||
int? getLastNewCollectionType() =>
|
||||
provider.getInt(PrefKey.lastNewCollectionType);
|
||||
int getLastNewCollectionTypeOr(int def) => getLastNewCollectionType() ?? def;
|
||||
Future<bool> setLastNewCollectionType(int? value) {
|
||||
if (value == null) {
|
||||
return _remove(PrefKey.lastNewCollectionType);
|
||||
} else {
|
||||
return _set<int>(PrefKey.lastNewCollectionType, value,
|
||||
(key, value) => provider.setInt(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _set<T>(PrefKey key, T value,
|
||||
Future<bool> Function(PrefKey key, T value) setFn) async {
|
||||
if (await setFn(key, value)) {
|
||||
|
@ -621,6 +633,7 @@ enum PrefKey {
|
|||
isEnableMemoryAlbum,
|
||||
touchRootEtag,
|
||||
accountLabel,
|
||||
lastNewCollectionType,
|
||||
}
|
||||
|
||||
extension on PrefKey {
|
||||
|
@ -710,6 +723,8 @@ extension on PrefKey {
|
|||
return "touchRootEtag";
|
||||
case PrefKey.accountLabel:
|
||||
return "accountLabel";
|
||||
case PrefKey.lastNewCollectionType:
|
||||
return "lastNewCollectionType";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ class _Bloc extends Bloc<_Event, _State> {
|
|||
required this.account,
|
||||
required Set<_ProviderOption> supportedProviders,
|
||||
}) : super(_State.init(
|
||||
account: account,
|
||||
supportedProviders: supportedProviders,
|
||||
)) {
|
||||
on<_FormEvent>(_onFormEvent);
|
||||
|
@ -63,6 +64,8 @@ class _Bloc extends Bloc<_Event, _State> {
|
|||
contentProvider: _buildProvider(),
|
||||
),
|
||||
));
|
||||
unawaited(AccountPref.of(account)
|
||||
.setLastNewCollectionType(state.formValue.provider.index));
|
||||
}
|
||||
|
||||
CollectionContentProvider _buildProvider() {
|
||||
|
|
|
@ -25,11 +25,26 @@ class _State {
|
|||
});
|
||||
|
||||
factory _State.init({
|
||||
required Account account,
|
||||
required Set<_ProviderOption> supportedProviders,
|
||||
}) {
|
||||
final prevType =
|
||||
AccountPref.of(account).getLastNewCollectionType()?.run((t) {
|
||||
try {
|
||||
return _ProviderOption.values[t];
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
var provider = prevType ?? _ProviderOption.ncAlbum;
|
||||
if (!supportedProviders.contains(provider)) {
|
||||
provider = _ProviderOption.appAlbum;
|
||||
}
|
||||
return _State(
|
||||
supportedProviders: supportedProviders,
|
||||
formValue: const _FormValue(),
|
||||
formValue: _FormValue(
|
||||
provider: provider,
|
||||
),
|
||||
showDialog: true,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue