Fix folders outside of the roots could be picked

This commit is contained in:
Ming Ming 2021-07-02 01:07:37 +08:00
parent 7386a69d79
commit 5ba39ecc0a
2 changed files with 48 additions and 29 deletions

View file

@ -5,6 +5,7 @@ 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/entity/file.dart';
import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
@ -61,6 +62,13 @@ class _AlbumDirPickerState extends State<AlbumDirPicker>
@override
getAccount() => widget.account;
@override
canPickDir(File dir) {
final root = api_util.getWebdavRootUrlRelative(widget.account);
return widget.account.roots
.any((r) => dir.path == "$root/$r" || dir.path.startsWith("$root/$r/"));
}
Widget _buildContent(BuildContext context) {
return SafeArea(
child: Column(

View file

@ -44,6 +44,9 @@ mixin DirPickerMixin<T extends StatefulWidget> on State<T> {
@protected
List<File> getPickedDirs() => UnmodifiableListView(_picks);
@protected
bool canPickDir(File file) => true;
void _initBloc() {
_log.info("[_initBloc] Initialize bloc");
_bloc = LsDirBloc();
@ -117,9 +120,11 @@ mixin DirPickerMixin<T extends StatefulWidget> on State<T> {
}
Widget _buildItem(BuildContext context, LsDirBlocItem item) {
final canPick = canPickDir(item.file);
final pickState = _isItemPicked(item);
IconData iconData;
if (canPick) {
switch (pickState) {
case _PickState.picked:
iconData = Icons.check_box;
@ -132,10 +137,12 @@ mixin DirPickerMixin<T extends StatefulWidget> on State<T> {
iconData = Icons.check_box_outline_blank;
break;
}
}
return ListTile(
dense: true,
leading: IconButton(
leading: canPick
? IconButton(
icon: AnimatedSwitcher(
duration: k.animationDurationShort,
transitionBuilder: (child, animation) =>
@ -152,6 +159,10 @@ mixin DirPickerMixin<T extends StatefulWidget> on State<T> {
_pick(item);
}
},
)
: IconButton(
icon: Icon(null),
onPressed: null,
),
title: Text(path.basename(item.file.path)),
trailing: