fix: sort codes correctly based on pinning status

This commit is contained in:
Prateek Sunal 2024-04-26 15:23:05 +05:30
parent b516bc8a52
commit 5cc25c6ef7
3 changed files with 58 additions and 28 deletions

View file

@ -423,5 +423,6 @@
"invalidEndpointMessage": "Sorry, the endpoint you entered is invalid. Please enter a valid endpoint and try again.",
"endpointUpdatedMessage": "Endpoint updated successfully",
"customEndpoint": "Connected to {endpoint}",
"pinText": "Pin"
"pinText": "Pin",
"unpinText": "Unpin"
}

View file

@ -105,6 +105,7 @@ class Code {
_getType(uri),
_getCounter(uri),
rawData,
display: display,
);
} catch (e) {
// if account name contains # without encoding,
@ -150,7 +151,7 @@ class Code {
Map<String, dynamic> toExportJson() {
return {
'rawData': rawData,
'display': display?.toJson(),
if (display != null) 'display': display?.toJson(),
};
}
@ -236,7 +237,8 @@ class Code {
other.secret == secret &&
other.counter == counter &&
other.type == type &&
other.rawData == rawData;
other.rawData == rawData &&
other.display == display;
}
@override
@ -251,6 +253,11 @@ class Code {
rawData.hashCode ^
display.hashCode;
}
@override
String toString() {
return 'Code(account: $account, issuer: $issuer, digits: $digits, period: $period, secret: $secret, algorithm: $algorithm, type: $type, counter: $counter, rawData: $rawData, display: $display)';
}
}
enum Type {

View file

@ -99,7 +99,7 @@ class _CodeWidgetState extends State<CodeWidget> {
onSelected: () => _onShowQrPressed(null),
),
MenuItem(
label: l10n.pinText,
label: widget.code.isPinned ? l10n.unpinText : l10n.pinText,
icon: widget.code.isPinned
? Icons.push_pin
: Icons.push_pin_outlined,
@ -156,7 +156,7 @@ class _CodeWidgetState extends State<CodeWidget> {
icon: widget.code.isPinned
? Icons.push_pin
: Icons.push_pin_outlined,
label: l10n.pinText,
label: widget.code.isPinned ? l10n.unpinText : l10n.pinText,
padding: const EdgeInsets.only(left: 4, right: 0),
spacing: 8,
),
@ -202,7 +202,16 @@ class _CodeWidgetState extends State<CodeWidget> {
return ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Container(
color: Theme.of(context).colorScheme.codeCardBackgroundColor,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.codeCardBackgroundColor,
boxShadow: [
BoxShadow(
color: Theme.of(context).colorScheme.shadow,
blurRadius: 8,
offset: const Offset(0, 4),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
@ -233,34 +242,47 @@ class _CodeWidgetState extends State<CodeWidget> {
Widget _getCardContents(AppLocalizations l10n) {
return SizedBox(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
child: Stack(
children: [
if (widget.code.type == Type.totp)
CodeTimerProgress(
period: widget.code.period,
),
const SizedBox(
height: 16,
),
Row(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
_shouldShowLargeIcon ? _getIcon() : const SizedBox.shrink(),
Expanded(
child: Column(
children: [
_getTopRow(),
const SizedBox(height: 4),
_getBottomRow(l10n),
],
if (widget.code.type == Type.totp)
CodeTimerProgress(
period: widget.code.period,
),
const SizedBox(
height: 16,
),
Row(
children: [
_shouldShowLargeIcon ? _getIcon() : const SizedBox.shrink(),
Expanded(
child: Column(
children: [
_getTopRow(),
const SizedBox(height: 4),
_getBottomRow(l10n),
],
),
),
],
),
const SizedBox(
height: 20,
),
],
),
const SizedBox(
height: 20,
),
if (widget.code.isPinned)
const Positioned(
right: 4,
top: 4,
child: Icon(
Icons.push_pin,
size: 12,
),
),
],
),
);