-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue#69] Update Preference page UI + clean up preference code reduc…
…e boilerplat
- Loading branch information
Showing
17 changed files
with
207 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,21 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:copy_with_extension/copy_with_extension.dart'; | ||
import 'package:flutter_password_saver/domain/model/account_preference.dart'; | ||
|
||
part 'account_preference_entity.g.dart'; | ||
|
||
@CopyWith() | ||
class AccountPreferenceEntity { | ||
static const keyRequireLogin = 'requireLogin'; | ||
static const keyEnableDarkMode = 'enableDarkMode'; | ||
static const keyLanguageCode = 'languageCode'; | ||
static const keyShowAccName = 'showAccName'; | ||
static const keyRequirePassOnForeground = 'requirePassOnForeground'; | ||
static const keyAllowSearchAccName = 'allowSearchAccName'; | ||
|
||
AccountPreferenceEntity({ | ||
required this.requireLogin, | ||
required this.enableDarkMode, | ||
required this.languageCode, | ||
required this.showAccName, | ||
required this.allowSearchAccName, | ||
required this.requirePassOnForeground, | ||
required this.items, | ||
}); | ||
|
||
final bool requireLogin; | ||
final bool enableDarkMode; | ||
final String languageCode; | ||
final bool showAccName; | ||
final bool allowSearchAccName; | ||
final bool requirePassOnForeground; | ||
final List<AccountPreferenceItem> items; | ||
|
||
factory AccountPreferenceEntity.fromAccountPreference( | ||
AccountPreference preference) { | ||
return AccountPreferenceEntity( | ||
// Require login | ||
requireLogin: preference.getItemValue(PreferenceName.requirePass) ?? | ||
AccountPreference.requireLoginDefault, | ||
// Dark mode | ||
enableDarkMode: preference.getItemValue(PreferenceName.enableDarkMode) ?? | ||
AccountPreference.enableDarkModeDefault, | ||
// Language code | ||
languageCode: preference.getItemValue(PreferenceName.languageCode) ?? | ||
AccountPreference.languageCodeDefault, | ||
// Show acc name always | ||
showAccName: preference.getItemValue(PreferenceName.showAccName) ?? | ||
AccountPreference.showAccountNameDefault, | ||
// Allow user to search account name too | ||
allowSearchAccName: | ||
preference.getItemValue(PreferenceName.allowSearchAccName) ?? | ||
AccountPreference.allowSearchAccNameDefault, | ||
requirePassOnForeground: | ||
preference.getItemValue(PreferenceName.requirePassOnForeground) ?? | ||
AccountPreference.requirePassOnForeground, | ||
); | ||
} | ||
AccountPreference toModel() => AccountPreference(items: items); | ||
|
||
AccountPreference toModel() => AccountPreference( | ||
items: [ | ||
AccountPreferenceItem( | ||
name: PreferenceName.requirePass, | ||
value: requireLogin, | ||
), | ||
AccountPreferenceItem( | ||
name: PreferenceName.enableDarkMode, | ||
value: enableDarkMode, | ||
), | ||
AccountPreferenceItem( | ||
name: PreferenceName.languageCode, | ||
value: languageCode, | ||
), | ||
AccountPreferenceItem( | ||
name: PreferenceName.showAccName, | ||
value: showAccName, | ||
), | ||
AccountPreferenceItem( | ||
name: PreferenceName.allowSearchAccName, | ||
value: allowSearchAccName, | ||
), | ||
AccountPreferenceItem( | ||
name: PreferenceName.requirePassOnForeground, | ||
value: requirePassOnForeground, | ||
), | ||
], | ||
); | ||
dynamic getItemValue(AppPreferenceEnum prefEnum) { | ||
return items.firstWhereOrNull((element) => element.name == prefEnum) ?? | ||
prefEnum.defaultValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.