mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 17:26:18 +01:00
151 lines
4.4 KiB
Dart
151 lines
4.4 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:nc_photos/account.dart';
|
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
|
import 'package:nc_photos/k.dart' as k;
|
|
import 'package:nc_photos/snack_bar_manager.dart';
|
|
import 'package:nc_photos/theme.dart';
|
|
import 'package:nc_photos/widget/dir_picker_mixin.dart';
|
|
|
|
class RootPickerArguments {
|
|
RootPickerArguments(this.account);
|
|
|
|
final Account account;
|
|
}
|
|
|
|
class RootPicker extends StatefulWidget {
|
|
static const routeName = "/root-picker";
|
|
|
|
RootPicker({
|
|
Key key,
|
|
@required this.account,
|
|
}) : super(key: key);
|
|
|
|
RootPicker.fromArgs(RootPickerArguments args, {Key key})
|
|
: this(
|
|
key: key,
|
|
account: args.account,
|
|
);
|
|
|
|
@override
|
|
createState() => _RootPickerState();
|
|
|
|
final Account account;
|
|
}
|
|
|
|
class _RootPickerState extends State<RootPicker>
|
|
with DirPickerMixin<RootPicker> {
|
|
@override
|
|
build(BuildContext context) {
|
|
return AppTheme(
|
|
child: Scaffold(
|
|
body: _buildContent(context),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
getPickerRoot() => api_util.getWebdavRootUrlRelative(widget.account);
|
|
|
|
@override
|
|
getAccount() => widget.account;
|
|
|
|
Widget _buildContent(BuildContext context) {
|
|
return SafeArea(
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context).rootPickerHeaderText,
|
|
style: Theme.of(context).textTheme.headline5,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Align(
|
|
alignment: AlignmentDirectional.topStart,
|
|
child: Text(
|
|
AppLocalizations.of(context).rootPickerSubHeaderText,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: buildDirPicker(context),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
if (!ModalRoute.of(context).isFirst)
|
|
TextButton(
|
|
onPressed: () => _onSkipPressed(context),
|
|
child: Text(AppLocalizations.of(context).skipButtonLabel),
|
|
)
|
|
else
|
|
Container(),
|
|
ElevatedButton(
|
|
onPressed: () => _onConfirmPressed(context),
|
|
child: Text(AppLocalizations.of(context).confirmButtonLabel),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _onSkipPressed(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
content: Text(AppLocalizations.of(context)
|
|
.rootPickerSkipConfirmationDialogContent),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child:
|
|
Text(MaterialLocalizations.of(context).cancelButtonLabel),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop(true);
|
|
},
|
|
child: Text(MaterialLocalizations.of(context).okButtonLabel),
|
|
),
|
|
],
|
|
)).then((value) {
|
|
if (value == true) {
|
|
// default is to include all files, so we just return the same account
|
|
Navigator.of(context).pop(widget.account);
|
|
}
|
|
});
|
|
}
|
|
|
|
void _onConfirmPressed(BuildContext context) {
|
|
final roots = getPickedDirs().map((e) => e.strippedPath).toList();
|
|
if (roots.isEmpty) {
|
|
SnackBarManager().showSnackBar(SnackBar(
|
|
content:
|
|
Text(AppLocalizations.of(context).rootPickerListEmptyNotification),
|
|
duration: k.snackBarDurationNormal,
|
|
));
|
|
return;
|
|
}
|
|
final newAccount = widget.account.copyWith(roots: roots);
|
|
_log.info("[_onConfirmPressed] Account is good: $newAccount");
|
|
Navigator.of(context).pop(newAccount);
|
|
}
|
|
|
|
static final _log = Logger("widget.root_picker._RootPickerState");
|
|
}
|