mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Fix folders outside of the roots could be picked
This commit is contained in:
parent
7386a69d79
commit
5ba39ecc0a
2 changed files with 48 additions and 29 deletions
|
@ -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(
|
||||
|
|
|
@ -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,42 +120,50 @@ 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;
|
||||
switch (pickState) {
|
||||
case _PickState.picked:
|
||||
iconData = Icons.check_box;
|
||||
break;
|
||||
case _PickState.childPicked:
|
||||
iconData = Icons.indeterminate_check_box;
|
||||
break;
|
||||
case _PickState.notPicked:
|
||||
default:
|
||||
iconData = Icons.check_box_outline_blank;
|
||||
break;
|
||||
if (canPick) {
|
||||
switch (pickState) {
|
||||
case _PickState.picked:
|
||||
iconData = Icons.check_box;
|
||||
break;
|
||||
case _PickState.childPicked:
|
||||
iconData = Icons.indeterminate_check_box;
|
||||
break;
|
||||
case _PickState.notPicked:
|
||||
default:
|
||||
iconData = Icons.check_box_outline_blank;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
dense: true,
|
||||
leading: IconButton(
|
||||
icon: AnimatedSwitcher(
|
||||
duration: k.animationDurationShort,
|
||||
transitionBuilder: (child, animation) =>
|
||||
ScaleTransition(child: child, scale: animation),
|
||||
child: Icon(
|
||||
iconData,
|
||||
key: ValueKey(pickState),
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (pickState == _PickState.picked) {
|
||||
_unpick(item);
|
||||
} else {
|
||||
_pick(item);
|
||||
}
|
||||
},
|
||||
),
|
||||
leading: canPick
|
||||
? IconButton(
|
||||
icon: AnimatedSwitcher(
|
||||
duration: k.animationDurationShort,
|
||||
transitionBuilder: (child, animation) =>
|
||||
ScaleTransition(child: child, scale: animation),
|
||||
child: Icon(
|
||||
iconData,
|
||||
key: ValueKey(pickState),
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (pickState == _PickState.picked) {
|
||||
_unpick(item);
|
||||
} else {
|
||||
_pick(item);
|
||||
}
|
||||
},
|
||||
)
|
||||
: IconButton(
|
||||
icon: Icon(null),
|
||||
onPressed: null,
|
||||
),
|
||||
title: Text(path.basename(item.file.path)),
|
||||
trailing:
|
||||
item.children.isNotEmpty ? const Icon(Icons.arrow_forward_ios) : null,
|
||||
|
|
Loading…
Reference in a new issue