Add minimize on copy
This commit is contained in:
parent
5c6eaa9fb9
commit
8dc06464c7
4 changed files with 60 additions and 8 deletions
|
@ -332,5 +332,6 @@
|
|||
"showLargeIcons": "Show large icons",
|
||||
"shouldHideCode": "Hide codes",
|
||||
"focusOnSearchBar": "Focus search on app start",
|
||||
"confirmUpdatingkey": "Are you sure you want to update the secret key?"
|
||||
"confirmUpdatingkey": "Are you sure you want to update the secret key?",
|
||||
"minimizeAppOnCopy": "Minimize app on copy"
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ class PreferenceService {
|
|||
static const kShouldShowLargeIconsKey = "should_show_large_icons";
|
||||
static const kShouldHideCodesKey = "should_hide_codes";
|
||||
static const kShouldAutoFocusOnSearchBar = "should_auto_focus_on_search_bar";
|
||||
static const kShouldMinimizeOnCopy = "should_minimize_on_copy";
|
||||
|
||||
Future<void> init() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
|
@ -64,4 +65,16 @@ class PreferenceService {
|
|||
await _prefs.setBool(kShouldAutoFocusOnSearchBar, value);
|
||||
Bus.instance.fire(IconsChangedEvent());
|
||||
}
|
||||
|
||||
bool shouldMinimizeOnCopy() {
|
||||
if (_prefs.containsKey(kShouldMinimizeOnCopy)) {
|
||||
return _prefs.getBool(kShouldMinimizeOnCopy)!;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setShouldMinimizeOnCopy(bool value) async {
|
||||
await _prefs.setBool(kShouldMinimizeOnCopy, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:clipboard/clipboard.dart';
|
||||
import 'package:ente_auth/core/configuration.dart';
|
||||
|
@ -17,6 +18,7 @@ import 'package:ente_auth/utils/totp_util.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:move_to_background/move_to_background.dart';
|
||||
|
||||
class CodeWidget extends StatefulWidget {
|
||||
final Code code;
|
||||
|
@ -141,7 +143,7 @@ class _CodeWidgetState extends State<CodeWidget> {
|
|||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
onTap: () {
|
||||
_copyToClipboard();
|
||||
_copyCurrentOTPToClipboard();
|
||||
},
|
||||
onDoubleTap: isMaskingEnabled
|
||||
? () {
|
||||
|
@ -153,7 +155,7 @@ class _CodeWidgetState extends State<CodeWidget> {
|
|||
}
|
||||
: null,
|
||||
onLongPress: () {
|
||||
_copyToClipboard();
|
||||
_copyCurrentOTPToClipboard();
|
||||
},
|
||||
child: _getCardContents(l10n),
|
||||
),
|
||||
|
@ -328,17 +330,34 @@ class _CodeWidgetState extends State<CodeWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
void _copyToClipboard() {
|
||||
FlutterClipboard.copy(_getCurrentOTP())
|
||||
.then((value) => showToast(context, context.l10n.copiedToClipboard));
|
||||
void _copyCurrentOTPToClipboard() async {
|
||||
_copyToClipboard(
|
||||
_getCurrentOTP(),
|
||||
confirmationMessage: context.l10n.copiedToClipboard,
|
||||
);
|
||||
}
|
||||
|
||||
void _copyNextToClipboard() {
|
||||
FlutterClipboard.copy(_getNextTotp()).then(
|
||||
(value) => showToast(context, context.l10n.copiedNextToClipboard),
|
||||
_copyToClipboard(
|
||||
_getNextTotp(),
|
||||
confirmationMessage: context.l10n.copiedNextToClipboard,
|
||||
);
|
||||
}
|
||||
|
||||
void _copyToClipboard(
|
||||
String content, {
|
||||
required String confirmationMessage,
|
||||
}) async {
|
||||
final shouldMinimizeOnCopy =
|
||||
PreferenceService.instance.shouldMinimizeOnCopy();
|
||||
|
||||
await FlutterClipboard.copy(content);
|
||||
showToast(context, confirmationMessage);
|
||||
if (Platform.isAndroid && shouldMinimizeOnCopy) {
|
||||
MoveToBackground.moveTaskToBack();
|
||||
}
|
||||
}
|
||||
|
||||
void _onNextHotpTapped() {
|
||||
if (widget.code.type == Type.hotp) {
|
||||
CodeStore.instance
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:ente_auth/app/view/app.dart';
|
||||
import 'package:ente_auth/core/logging/super_logging.dart';
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
|
@ -120,6 +122,23 @@ class _AdvancedSectionWidgetState extends State<AdvancedSectionWidget> {
|
|||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
if (Platform.isAndroid) ...[
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.minimizeAppOnCopy,
|
||||
),
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () => PreferenceService.instance.shouldMinimizeOnCopy(),
|
||||
onChanged: () async {
|
||||
await PreferenceService.instance.setShouldMinimizeOnCopy(
|
||||
!PreferenceService.instance.shouldMinimizeOnCopy(),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue