Skip to content

Commit 4449aca

Browse files
Add issuer/account display option for tokens
1 parent deb856d commit 4449aca

File tree

9 files changed

+209
-48
lines changed

9 files changed

+209
-48
lines changed

lib/Screens/Setting/setting_appearance_screen.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class _AppearanceSettingScreenState
7575
super.initState();
7676
}
7777

78+
@override
79+
void onLocaleChanged(Locale newLocale) {
80+
super.onLocaleChanged(newLocale);
81+
}
82+
7883
scrollToSetAutoBackupPassword() {
7984
if (_setAutoBackupPasswordKey.currentContext != null) {
8085
Scrollable.ensureVisible(
@@ -246,6 +251,15 @@ class _AppearanceSettingScreenState
246251
});
247252
},
248253
),
254+
InlineSelectionItem<SelectionItemModel<IssuerAndAccountShowOption>>(
255+
title: appLocalizations.issuerAndAccountShowOption,
256+
selections: IssuerAndAccountShowOption.options,
257+
hint: appLocalizations.selectIssuerAndAccountShowOption,
258+
selected: appProvider.issuerAndAccountShowOption.selectionItemModel,
259+
onChanged: (item) {
260+
appProvider.issuerAndAccountShowOption = item!.value;
261+
},
262+
),
249263
],
250264
);
251265
}

lib/Screens/Token/token_layout.dart

Lines changed: 104 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,24 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
245245
contextMenu: _buildContextMenuButtons(),
246246
child: Selector<AppProvider, bool>(
247247
selector: (context, provider) => provider.dragToReorder,
248-
builder: (context, dragToReorder, child) => GestureDetector(
249-
onLongPress: dragToReorder && !ResponsiveUtil.isDesktop()
250-
? () {
251-
showContextMenu();
252-
HapticFeedback.lightImpact();
253-
}
254-
: null,
255-
child: PressableAnimation(child: _buildBody()),
248+
builder: (context, dragToReorder, child) =>
249+
Selector<AppProvider, IssuerAndAccountShowOption>(
250+
selector: (context, provider) => provider.issuerAndAccountShowOption,
251+
builder: (context, issuerAndAccountShowOption, child) {
252+
return GestureDetector(
253+
onLongPress: dragToReorder && !ResponsiveUtil.isDesktop()
254+
? () {
255+
showContextMenu();
256+
HapticFeedback.lightImpact();
257+
}
258+
: null,
259+
child: PressableAnimation(
260+
child: _buildBody(
261+
issuerAndAccountShowOption: issuerAndAccountShowOption,
262+
),
263+
),
264+
);
265+
}
256266
),
257267
),
258268
);
@@ -351,12 +361,18 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
351361
);
352362
}
353363

354-
_buildBody() {
364+
_buildBody({
365+
required IssuerAndAccountShowOption issuerAndAccountShowOption,
366+
}) {
355367
switch (widget.layoutType) {
356368
case LayoutType.Simple:
357-
return _buildSimpleLayout();
369+
return _buildSimpleLayout(
370+
issuerAndAccountShowOption: issuerAndAccountShowOption,
371+
);
358372
case LayoutType.Compact:
359-
return _buildCompactLayout();
373+
return _buildCompactLayout(
374+
issuerAndAccountShowOption: issuerAndAccountShowOption,
375+
);
360376
// case LayoutType.Tile:
361377
// return _buildSlidable(
362378
// startExtentRatio: 0.23,
@@ -366,13 +382,17 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
366382
case LayoutType.List:
367383
return _buildSlidable(
368384
simple: true,
369-
child: _buildListLayout(),
385+
child: _buildListLayout(
386+
issuerAndAccountShowOption: issuerAndAccountShowOption,
387+
),
370388
);
371389
case LayoutType.Spotlight:
372390
return _buildSlidable(
373391
startExtentRatio: 0.21,
374392
endExtentRatio: 0.8,
375-
child: _buildSpotlightLayout(),
393+
child: _buildSpotlightLayout(
394+
issuerAndAccountShowOption: issuerAndAccountShowOption,
395+
),
376396
);
377397
}
378398
}
@@ -528,7 +548,7 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
528548
icon: Icon(
529549
LucideIcons.eye,
530550
size: 20,
531-
color: color ?? ChewieTheme.labelMedium?.color,
551+
color: color ?? ChewieTheme.labelMedium.color,
532552
),
533553
)
534554
: emptyWidget,
@@ -561,7 +581,7 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
561581
icon: Icon(
562582
Icons.refresh_rounded,
563583
size: 20,
564-
color: color ?? ChewieTheme.labelMedium?.color,
584+
color: color ?? ChewieTheme.labelMedium.color,
565585
),
566586
)
567587
: emptyWidget,
@@ -712,7 +732,9 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
712732
}
713733
}
714734

715-
_buildSimpleLayout() {
735+
_buildSimpleLayout({
736+
required IssuerAndAccountShowOption issuerAndAccountShowOption,
737+
}) {
716738
return ClickableWrapper(
717739
child: Material(
718740
color: widget.token.pinned
@@ -741,7 +763,9 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
741763
const SizedBox(width: 8),
742764
Expanded(
743765
child: Text(
744-
widget.token.issuer,
766+
issuerAndAccountShowOption.isOnlyShowAccount
767+
? widget.token.account
768+
: widget.token.issuer,
745769
maxLines: 1,
746770
overflow: TextOverflow.ellipsis,
747771
style: Theme.of(context)
@@ -780,7 +804,9 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
780804
);
781805
}
782806

783-
_buildCompactLayout() {
807+
_buildCompactLayout({
808+
required IssuerAndAccountShowOption issuerAndAccountShowOption,
809+
}) {
784810
return ClickableWrapper(
785811
child: Material(
786812
color: widget.token.pinned
@@ -809,21 +835,33 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
809835
child: Column(
810836
crossAxisAlignment: CrossAxisAlignment.start,
811837
children: [
812-
Text(
813-
widget.token.issuer,
814-
maxLines: 1,
815-
overflow: TextOverflow.ellipsis,
816-
style: Theme.of(context)
817-
.textTheme
818-
.titleMedium
819-
?.apply(fontWeightDelta: 2),
820-
),
821-
Text(
822-
widget.token.account,
823-
maxLines: 1,
824-
overflow: TextOverflow.ellipsis,
825-
style: ChewieTheme.bodySmall,
826-
),
838+
if (issuerAndAccountShowOption.showIssuer)
839+
Text(
840+
widget.token.issuer,
841+
maxLines: 1,
842+
overflow: TextOverflow.ellipsis,
843+
style: Theme.of(context)
844+
.textTheme
845+
.titleMedium
846+
?.apply(fontWeightDelta: 2),
847+
),
848+
if (issuerAndAccountShowOption.showBoth)
849+
Text(
850+
widget.token.account,
851+
maxLines: 1,
852+
overflow: TextOverflow.ellipsis,
853+
style: ChewieTheme.bodySmall,
854+
),
855+
if (issuerAndAccountShowOption.isOnlyShowAccount)
856+
Text(
857+
widget.token.account,
858+
maxLines: 1,
859+
overflow: TextOverflow.ellipsis,
860+
style: Theme.of(context)
861+
.textTheme
862+
.titleMedium
863+
?.apply(fontWeightDelta: 2),
864+
),
827865
],
828866
),
829867
),
@@ -845,7 +883,7 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
845883
padding: const EdgeInsets.all(4),
846884
icon: Icon(
847885
LucideIcons.ellipsisVertical,
848-
color: ChewieTheme.labelSmall?.color,
886+
color: ChewieTheme.labelSmall.color,
849887
size: 20,
850888
),
851889
onTap: showContextMenu,
@@ -868,7 +906,9 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
868906
);
869907
}
870908

871-
_buildSpotlightLayout() {
909+
_buildSpotlightLayout({
910+
required IssuerAndAccountShowOption issuerAndAccountShowOption,
911+
}) {
872912
return ClickableWrapper(
873913
child: Material(
874914
color: widget.token.pinned
@@ -902,22 +942,35 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
902942
mainAxisSize: MainAxisSize.min,
903943
mainAxisAlignment: MainAxisAlignment.center,
904944
children: [
905-
Text(
906-
widget.token.issuer,
907-
maxLines: 1,
908-
overflow: TextOverflow.ellipsis,
909-
style: Theme.of(context)
910-
.textTheme
911-
.titleMedium
912-
?.apply(fontWeightDelta: 2),
913-
),
914-
if (widget.token.account.isNotEmpty)
945+
if (issuerAndAccountShowOption.showIssuer)
946+
Text(
947+
widget.token.issuer,
948+
maxLines: 1,
949+
overflow: TextOverflow.ellipsis,
950+
style: Theme.of(context)
951+
.textTheme
952+
.titleMedium
953+
?.apply(fontWeightDelta: 2),
954+
),
955+
if (widget.token.account.isNotEmpty &&
956+
issuerAndAccountShowOption.showBoth)
915957
Text(
916958
widget.token.account,
917959
maxLines: 1,
918960
overflow: TextOverflow.ellipsis,
919961
style: ChewieTheme.bodySmall,
920962
),
963+
if (widget.token.account.isNotEmpty &&
964+
issuerAndAccountShowOption.isOnlyShowAccount)
965+
Text(
966+
widget.token.account,
967+
maxLines: 1,
968+
overflow: TextOverflow.ellipsis,
969+
style: Theme.of(context)
970+
.textTheme
971+
.titleMedium
972+
?.apply(fontWeightDelta: 2),
973+
),
921974
Container(
922975
constraints: const BoxConstraints(
923976
maxHeight: 45, minHeight: 45),
@@ -945,7 +998,9 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
945998
);
946999
}
9471000

948-
_buildListLayout() {
1001+
_buildListLayout({
1002+
required IssuerAndAccountShowOption issuerAndAccountShowOption,
1003+
}) {
9491004
return ClickableWrapper(
9501005
child: Material(
9511006
color: widget.token.pinned
@@ -967,7 +1022,9 @@ class TokenLayoutState extends BaseDynamicState<TokenLayout>
9671022
const SizedBox(width: 8),
9681023
Expanded(
9691024
child: Text(
970-
widget.token.issuer,
1025+
issuerAndAccountShowOption.isOnlyShowAccount
1026+
? widget.token.account
1027+
: widget.token.issuer,
9711028
maxLines: 1,
9721029
overflow: TextOverflow.ellipsis,
9731030
style: Theme.of(context)

lib/Utils/app_provider.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,58 @@ enum AutoLockTime {
9191
}
9292
}
9393

94+
enum IssuerAndAccountShowOption implements DropdownMixin {
95+
both,
96+
issuer,
97+
account;
98+
99+
bool get isOnlyIssuer => this == IssuerAndAccountShowOption.issuer;
100+
101+
bool get isOnlyShowAccount => this == IssuerAndAccountShowOption.account;
102+
103+
bool get showIssuer =>
104+
this == IssuerAndAccountShowOption.both ||
105+
this == IssuerAndAccountShowOption.issuer;
106+
107+
bool get showAccount =>
108+
this == IssuerAndAccountShowOption.both ||
109+
this == IssuerAndAccountShowOption.account;
110+
111+
bool get showBoth => this == IssuerAndAccountShowOption.both;
112+
113+
String get label {
114+
switch (this) {
115+
case IssuerAndAccountShowOption.issuer:
116+
return appLocalizations.onlyShowIssuer;
117+
case IssuerAndAccountShowOption.account:
118+
return appLocalizations.onlyShowAccount;
119+
case IssuerAndAccountShowOption.both:
120+
return appLocalizations.showIssuerAndAccount;
121+
}
122+
}
123+
124+
static List<SelectionItemModel<IssuerAndAccountShowOption>> get options {
125+
return IssuerAndAccountShowOption.values
126+
.map(
127+
(e) => SelectionItemModel<IssuerAndAccountShowOption>(e.display, e))
128+
.toList();
129+
}
130+
131+
SelectionItemModel<IssuerAndAccountShowOption> get selectionItemModel {
132+
return SelectionItemModel<IssuerAndAccountShowOption>(display, this);
133+
}
134+
135+
static IssuerAndAccountShowOption fromInt(int value) {
136+
return IssuerAndAccountShowOption.values[value.clamp(0, values.length - 1)];
137+
}
138+
139+
@override
140+
String get display => label;
141+
142+
@override
143+
String get selection => display;
144+
}
145+
94146
class AutoLockOption implements DropdownMixin {
95147
final String label;
96148
final AutoLockTime autoLockTime;
@@ -146,6 +198,23 @@ class AppProvider with ChangeNotifier {
146198
FocusNode shortcutFocusNode = FocusNode();
147199
FocusNode searchFocusNode = FocusNode();
148200

201+
IssuerAndAccountShowOption _issuerAndAccountShowOption =
202+
IssuerAndAccountShowOption.fromInt(ChewieHiveUtil.getInt(
203+
CloudOTPHiveUtil.issuerAndAccountShowOptionKey,
204+
defaultValue: 0));
205+
206+
IssuerAndAccountShowOption get issuerAndAccountShowOption =>
207+
_issuerAndAccountShowOption;
208+
209+
set issuerAndAccountShowOption(IssuerAndAccountShowOption value) {
210+
if (value != _issuerAndAccountShowOption) {
211+
_issuerAndAccountShowOption = value;
212+
ChewieHiveUtil.put(
213+
CloudOTPHiveUtil.issuerAndAccountShowOptionKey, value.index);
214+
notifyListeners();
215+
}
216+
}
217+
149218
final List<AutoBackupLog> _autoBackupLogs = [];
150219

151220
List<AutoBackupLog> get autoBackupLogs => _autoBackupLogs;

lib/Utils/hive_util.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CloudOTPHiveUtil {
4848
static const String autoHideCodeKey = "autoHideCode";
4949
static const String defaultHideCodeKey = "defaultHideCode";
5050
static const String showEyeKey = "showEye";
51+
static const String issuerAndAccountShowOptionKey = "issuerAndAccountShowOption";
5152

5253
//Appearance
5354
static const String showCloudBackupButtonKey = "showCloudBackupButton";

lib/l10n/intl_en.arb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@
130130
"hideProgressBarTip": "Hide the countdown progress bar of the token",
131131
"showEye": "Show view icon",
132132
"showEyeTip": "When the view icon is displayed, the code can only be displayed by clicking on the view icon; when it is not displayed, click on the token to display the code",
133+
"issuerAndAccountShowOption": "Issuer/Account Display Option",
134+
"selectIssuerAndAccountShowOption": "Select Issuer/Account Display Option",
135+
"showIssuerAndAccount": "Default",
136+
"onlyShowAccount": "Show Account Only",
137+
"onlyShowIssuer": "Show Issuer Only",
133138
"copyTimes": "Copy Times",
134139
"currentCopyTimes": "Current Copy Times: {times}",
135140
"currentCounter": "Current Count: {counter}",

0 commit comments

Comments
 (0)