|
@@ -81,8 +81,6 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
|
|
|
context,
|
|
|
{'enableCollect': value},
|
|
|
);
|
|
|
-
|
|
|
- setState(() {});
|
|
|
},
|
|
|
),
|
|
|
),
|
|
@@ -170,7 +168,6 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
|
|
|
"Viewers can still take screenshots or save a copy of your photos using external tools",
|
|
|
);
|
|
|
}
|
|
|
- setState(() {});
|
|
|
},
|
|
|
),
|
|
|
),
|
|
@@ -190,23 +187,33 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
|
|
|
value: isPasswordEnabled,
|
|
|
onChanged: (enablePassword) async {
|
|
|
if (enablePassword) {
|
|
|
- final inputResult =
|
|
|
- await _displayLinkPasswordInput(context);
|
|
|
- if (inputResult != null &&
|
|
|
- inputResult == 'ok' &&
|
|
|
- _textFieldController.text.trim().isNotEmpty) {
|
|
|
- final propToUpdate = await _getEncryptedPassword(
|
|
|
- _textFieldController.text,
|
|
|
- );
|
|
|
- await _updateUrlSettings(context, propToUpdate);
|
|
|
- }
|
|
|
+ showTextInputDialog(
|
|
|
+ context,
|
|
|
+ title: "Set a password",
|
|
|
+ submitButtonLabel: "Lock",
|
|
|
+ hintText: "Enter password",
|
|
|
+ isPasswordInput: true,
|
|
|
+ alwaysShowSuccessState: true,
|
|
|
+ onSubmit: (String password) async {
|
|
|
+ if (password.trim().isNotEmpty) {
|
|
|
+ final propToUpdate =
|
|
|
+ await _getEncryptedPassword(
|
|
|
+ password,
|
|
|
+ );
|
|
|
+ await _updateUrlSettings(
|
|
|
+ context,
|
|
|
+ propToUpdate,
|
|
|
+ showProgressDialog: false,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ );
|
|
|
} else {
|
|
|
await _updateUrlSettings(
|
|
|
context,
|
|
|
{'disablePassword': true},
|
|
|
);
|
|
|
}
|
|
|
- setState(() {});
|
|
|
},
|
|
|
),
|
|
|
),
|
|
@@ -242,72 +249,6 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- final TextEditingController _textFieldController = TextEditingController();
|
|
|
-
|
|
|
- Future<String?> _displayLinkPasswordInput(BuildContext context) async {
|
|
|
- _textFieldController.clear();
|
|
|
- return showDialog<String>(
|
|
|
- context: context,
|
|
|
- builder: (context) {
|
|
|
- bool passwordVisible = false;
|
|
|
- return StatefulBuilder(
|
|
|
- builder: (context, setState) {
|
|
|
- return AlertDialog(
|
|
|
- title: const Text('Enter password'),
|
|
|
- content: TextFormField(
|
|
|
- autofillHints: const [AutofillHints.newPassword],
|
|
|
- decoration: InputDecoration(
|
|
|
- hintText: "Password",
|
|
|
- contentPadding: const EdgeInsets.all(12),
|
|
|
- suffixIcon: IconButton(
|
|
|
- icon: Icon(
|
|
|
- passwordVisible ? Icons.visibility : Icons.visibility_off,
|
|
|
- color: Colors.white.withOpacity(0.5),
|
|
|
- size: 20,
|
|
|
- ),
|
|
|
- onPressed: () {
|
|
|
- passwordVisible = !passwordVisible;
|
|
|
- setState(() {});
|
|
|
- },
|
|
|
- ),
|
|
|
- ),
|
|
|
- obscureText: !passwordVisible,
|
|
|
- controller: _textFieldController,
|
|
|
- autofocus: true,
|
|
|
- autocorrect: false,
|
|
|
- keyboardType: TextInputType.visiblePassword,
|
|
|
- onChanged: (_) {
|
|
|
- setState(() {});
|
|
|
- },
|
|
|
- ),
|
|
|
- actions: <Widget>[
|
|
|
- TextButton(
|
|
|
- child: Text(
|
|
|
- 'Cancel',
|
|
|
- style: Theme.of(context).textTheme.subtitle2,
|
|
|
- ),
|
|
|
- onPressed: () {
|
|
|
- Navigator.pop(context, 'cancel');
|
|
|
- },
|
|
|
- ),
|
|
|
- TextButton(
|
|
|
- child:
|
|
|
- Text('Ok', style: Theme.of(context).textTheme.subtitle2),
|
|
|
- onPressed: () {
|
|
|
- if (_textFieldController.text.trim().isEmpty) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Navigator.pop(context, 'ok');
|
|
|
- },
|
|
|
- ),
|
|
|
- ],
|
|
|
- );
|
|
|
- },
|
|
|
- );
|
|
|
- },
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
Future<Map<String, dynamic>> _getEncryptedPassword(String pass) async {
|
|
|
assert(
|
|
|
Sodium.cryptoPwhashAlgArgon2id13 == Sodium.cryptoPwhashAlgDefault,
|
|
@@ -331,19 +272,24 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
|
|
|
}
|
|
|
|
|
|
Future<void> _updateUrlSettings(
|
|
|
- BuildContext context,
|
|
|
- Map<String, dynamic> prop,
|
|
|
- ) async {
|
|
|
- final dialog = createProgressDialog(context, "Please wait...");
|
|
|
- await dialog.show();
|
|
|
+ BuildContext context, Map<String, dynamic> prop,
|
|
|
+ {bool showProgressDialog = true}) async {
|
|
|
+ final dialog = showProgressDialog
|
|
|
+ ? createProgressDialog(context, "Please wait...")
|
|
|
+ : null;
|
|
|
+ await dialog?.show();
|
|
|
try {
|
|
|
await CollectionsService.instance
|
|
|
.updateShareUrl(widget.collection!, prop);
|
|
|
- await dialog.hide();
|
|
|
+ await dialog?.hide();
|
|
|
showShortToast(context, "Album updated");
|
|
|
+ if (mounted) {
|
|
|
+ setState(() {});
|
|
|
+ }
|
|
|
} catch (e) {
|
|
|
- await dialog.hide();
|
|
|
+ await dialog?.hide();
|
|
|
await showGenericErrorDialog(context: context);
|
|
|
+ rethrow;
|
|
|
}
|
|
|
}
|
|
|
}
|