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:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
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/iterable_extension.dart';
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
import 'package:nc_photos/snack_bar_manager.dart';
|
import 'package:nc_photos/snack_bar_manager.dart';
|
||||||
|
@ -61,6 +62,13 @@ class _AlbumDirPickerState extends State<AlbumDirPicker>
|
||||||
@override
|
@override
|
||||||
getAccount() => widget.account;
|
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) {
|
Widget _buildContent(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
|
@ -44,6 +44,9 @@ mixin DirPickerMixin<T extends StatefulWidget> on State<T> {
|
||||||
@protected
|
@protected
|
||||||
List<File> getPickedDirs() => UnmodifiableListView(_picks);
|
List<File> getPickedDirs() => UnmodifiableListView(_picks);
|
||||||
|
|
||||||
|
@protected
|
||||||
|
bool canPickDir(File file) => true;
|
||||||
|
|
||||||
void _initBloc() {
|
void _initBloc() {
|
||||||
_log.info("[_initBloc] Initialize bloc");
|
_log.info("[_initBloc] Initialize bloc");
|
||||||
_bloc = LsDirBloc();
|
_bloc = LsDirBloc();
|
||||||
|
@ -117,9 +120,11 @@ mixin DirPickerMixin<T extends StatefulWidget> on State<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildItem(BuildContext context, LsDirBlocItem item) {
|
Widget _buildItem(BuildContext context, LsDirBlocItem item) {
|
||||||
|
final canPick = canPickDir(item.file);
|
||||||
final pickState = _isItemPicked(item);
|
final pickState = _isItemPicked(item);
|
||||||
|
|
||||||
IconData iconData;
|
IconData iconData;
|
||||||
|
if (canPick) {
|
||||||
switch (pickState) {
|
switch (pickState) {
|
||||||
case _PickState.picked:
|
case _PickState.picked:
|
||||||
iconData = Icons.check_box;
|
iconData = Icons.check_box;
|
||||||
|
@ -132,10 +137,12 @@ mixin DirPickerMixin<T extends StatefulWidget> on State<T> {
|
||||||
iconData = Icons.check_box_outline_blank;
|
iconData = Icons.check_box_outline_blank;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
dense: true,
|
dense: true,
|
||||||
leading: IconButton(
|
leading: canPick
|
||||||
|
? IconButton(
|
||||||
icon: AnimatedSwitcher(
|
icon: AnimatedSwitcher(
|
||||||
duration: k.animationDurationShort,
|
duration: k.animationDurationShort,
|
||||||
transitionBuilder: (child, animation) =>
|
transitionBuilder: (child, animation) =>
|
||||||
|
@ -152,6 +159,10 @@ mixin DirPickerMixin<T extends StatefulWidget> on State<T> {
|
||||||
_pick(item);
|
_pick(item);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
)
|
||||||
|
: IconButton(
|
||||||
|
icon: Icon(null),
|
||||||
|
onPressed: null,
|
||||||
),
|
),
|
||||||
title: Text(path.basename(item.file.path)),
|
title: Text(path.basename(item.file.path)),
|
||||||
trailing:
|
trailing:
|
||||||
|
|
Loading…
Reference in a new issue