Skip to content

Commit d92cb83

Browse files
committed
Fixes to groups and tags selected
1 parent 0d3500c commit d92cb83

7 files changed

Lines changed: 93 additions & 73 deletions

File tree

lib/components/cards/album_card.dart

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,13 @@ class AlbumCardContent extends StatelessWidget {
222222
child: Column(
223223
crossAxisAlignment: CrossAxisAlignment.center,
224224
children: [
225-
Text(
225+
AutoSizeText(
226226
album.name,
227+
maxLines: 1,
227228
textAlign: TextAlign.center,
228-
softWrap: true,
229-
maxLines: 2,
229+
maxFontSize:
230+
Theme.of(context).textTheme.titleLarge!.fontSize!,
231+
minFontSize: 10.0,
230232
overflow: TextOverflow.ellipsis,
231233
style: Theme.of(context).textTheme.titleLarge,
232234
),
@@ -236,26 +238,27 @@ class AlbumCardContent extends StatelessWidget {
236238
child: Align(
237239
alignment: Alignment.bottomCenter,
238240
child: Builder(builder: (context) {
239-
if (isCommentValid(album.comment)) {
240-
return const SizedBox();
241-
}
242241
return AutoSizeText(
243242
album.comment ?? '',
244-
softWrap: true,
245-
maxLines: 10,
246-
overflow: TextOverflow.ellipsis,
243+
maxFontSize:
244+
Theme.of(context).textTheme.bodySmall!.fontSize!,
245+
minFontSize: 10.0,
246+
overflow: TextOverflow.fade,
247247
style: Theme.of(context).textTheme.bodySmall,
248248
);
249249
}),
250250
),
251251
),
252252
),
253-
FittedBox(
254-
fit: BoxFit.fitWidth,
255-
child: Text(
256-
appStrings.imageCount(album.nbTotalImages),
257-
style: Theme.of(context).textTheme.labelSmall,
258-
),
253+
AutoSizeText(
254+
appStrings.imageCount(album.nbTotalImages),
255+
maxLines: 1,
256+
textAlign: TextAlign.center,
257+
maxFontSize:
258+
Theme.of(context).textTheme.labelSmall!.fontSize!,
259+
minFontSize: 8.0,
260+
overflow: TextOverflow.ellipsis,
261+
style: Theme.of(context).textTheme.labelSmall,
259262
),
260263
],
261264
),

lib/components/lists/select_model_list.dart

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,54 @@ class SelectModelList<T> extends StatefulWidget {
2323
}
2424

2525
class _SelectModelListState<T> extends State<SelectModelList<T>> {
26+
static const Duration kAnimationDuration = Duration(milliseconds: 300);
2627
final GlobalKey<AnimatedListState> _selectedListKey =
2728
GlobalKey<AnimatedListState>();
2829
final GlobalKey<AnimatedListState> _unselectedListKey =
2930
GlobalKey<AnimatedListState>();
3031

31-
void _onTapItem(T item) {
32-
if (widget.selected.contains(item)) {
32+
void _onTapItem(T item, bool selected) {
33+
if (selected) {
34+
if (widget.unselected.contains(item)) return;
3335
_onDeselect(item);
3436
} else {
37+
if (widget.selected.contains(item)) return;
3538
_onSelect(item);
3639
}
3740
}
3841

3942
void _onSelect(T item) async {
4043
int oldIndex = widget.unselected.indexOf(item);
44+
int? newIndex = widget.onSelect?.call(item);
45+
4146
_unselectedListKey.currentState?.removeItem(
4247
oldIndex,
4348
(_, animation) => _buildItem(item, animation, false),
44-
duration: const Duration(milliseconds: 150),
49+
duration: kAnimationDuration,
4550
);
4651

47-
int? newIndex = widget.onSelect?.call(item);
4852
newIndex ??= widget.selected.indexOf(item);
49-
_selectedListKey.currentState?.insertItem(newIndex);
53+
_selectedListKey.currentState?.insertItem(
54+
newIndex,
55+
duration: kAnimationDuration,
56+
);
5057
}
5158

5259
void _onDeselect(T item) async {
5360
int oldIndex = widget.selected.indexOf(item);
61+
int? newIndex = widget.onDeselect?.call(item);
62+
5463
_selectedListKey.currentState?.removeItem(
5564
oldIndex,
5665
(_, animation) => _buildItem(item, animation, true),
57-
duration: const Duration(milliseconds: 150),
66+
duration: kAnimationDuration,
5867
);
59-
60-
int? newIndex = widget.onDeselect?.call(item);
61-
await Future.delayed(const Duration(milliseconds: 100));
68+
// await Future.delayed(const Duration(milliseconds: 10));
6269
newIndex ??= widget.unselected.indexOf(item);
63-
_unselectedListKey.currentState?.insertItem(newIndex);
70+
_unselectedListKey.currentState?.insertItem(
71+
newIndex,
72+
duration: kAnimationDuration,
73+
);
6474
}
6575

6676
@override
@@ -117,9 +127,14 @@ class _SelectModelListState<T> extends State<SelectModelList<T>> {
117127
);
118128
}
119129

120-
_buildItem(T item, Animation<double> animation, bool selected) {
130+
Widget _buildItem(
131+
T item,
132+
Animation<double> animation,
133+
bool selected,
134+
) {
121135
return SizeTransition(
122-
sizeFactor: animation,
136+
sizeFactor: animation.drive(
137+
Tween(begin: .0, end: 1.0).chain(CurveTween(curve: Curves.ease))),
123138
child: ListTile(
124139
key: ObjectKey(item),
125140
visualDensity: VisualDensity.compact,
@@ -130,7 +145,7 @@ class _SelectModelListState<T> extends State<SelectModelList<T>> {
130145
trailing: selected
131146
? Icon(Icons.remove_circle_outline, color: Colors.red)
132147
: Icon(Icons.add_circle_outline, color: Colors.green),
133-
onTap: () => _onTapItem(item),
148+
onTap: () => _onTapItem(item, selected),
134149
),
135150
);
136151
}

lib/components/modals/select_groups_modal.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
33
import 'package:piwigo_ng/components/buttons/piwigo_button.dart';
44
import 'package:piwigo_ng/components/lists/select_model_list.dart';
55
import 'package:piwigo_ng/models/group_model.dart';
6-
import 'package:piwigo_ng/network/api_error.dart';
76
import 'package:piwigo_ng/network/groups.dart';
87
import 'package:piwigo_ng/utils/localizations.dart';
9-
import 'package:pull_to_refresh/pull_to_refresh.dart';
108

119
class SelectGroupsModal extends StatefulWidget {
1210
const SelectGroupsModal({
@@ -22,12 +20,8 @@ class SelectGroupsModal extends StatefulWidget {
2220

2321
class _SelectGroupsModalState extends State<SelectGroupsModal> {
2422
final ScrollController _scrollController = ScrollController();
25-
final RefreshController _refreshController =
26-
RefreshController(initialRefresh: false);
2723
late final Future _groupsFuture;
2824

29-
PagingModel _paging = PagingModel();
30-
3125
List<GroupModel> _selectedGroupList = [];
3226
List<GroupModel>? _groupList = [];
3327

@@ -151,6 +145,9 @@ Future<List<GroupModel>?> showSelectGroupModal(
151145
]) async {
152146
return showMaterialModalBottomSheet<List<GroupModel>>(
153147
context: context,
148+
shape: RoundedRectangleBorder(
149+
borderRadius: BorderRadius.vertical(top: Radius.circular(30.0)),
150+
),
154151
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
155152
builder: (context) => SelectGroupsModal(
156153
selectedGroups: selectedGroups,

lib/components/modals/select_tags_modal.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import 'package:piwigo_ng/utils/localizations.dart';
1212
class SelectTagsModal extends StatefulWidget {
1313
const SelectTagsModal({
1414
Key? key,
15-
this.selectedTags = const [],
15+
this.selectedTags,
1616
}) : super(key: key);
1717

18-
final List<TagModel> selectedTags;
18+
final List<TagModel>? selectedTags;
1919

2020
@override
2121
_SelectTagsModalState createState() => _SelectTagsModalState();
@@ -30,7 +30,7 @@ class _SelectTagsModalState extends State<SelectTagsModal> {
3030

3131
@override
3232
void initState() {
33-
_selectedTagList = List.from(widget.selectedTags);
33+
_selectedTagList = List.from(widget.selectedTags ?? []);
3434
super.initState();
3535
_tagsFuture = _onRefresh();
3636
}
@@ -174,3 +174,19 @@ class _SelectTagsModalState extends State<SelectTagsModal> {
174174
);
175175
}
176176
}
177+
178+
Future<List<TagModel>?> showSelectTagsModal(
179+
BuildContext context, [
180+
List<TagModel>? selectedTags,
181+
]) async {
182+
return showMaterialModalBottomSheet<List<TagModel>>(
183+
context: context,
184+
shape: RoundedRectangleBorder(
185+
borderRadius: BorderRadius.vertical(top: Radius.circular(30.0)),
186+
),
187+
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
188+
builder: (context) => SelectTagsModal(
189+
selectedTags: selectedTags,
190+
),
191+
);
192+
}

lib/views/album/album_privacy_page.dart

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,21 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
188188
],
189189
),
190190
),
191+
Divider(
192+
color: Theme.of(context).disabledColor,
193+
),
194+
SwitchListTile(
195+
value: _recursive,
196+
onChanged: (value) => setState(() {
197+
_recursive = value;
198+
}),
199+
title: Text(appStrings.categoryPrivacyRecursive),
200+
subtitle: Text(appStrings.categoryPrivacyRecursive_message),
201+
),
191202
Padding(
192203
padding: const EdgeInsets.symmetric(
193-
horizontal: 24.0,
194204
vertical: 16.0,
205+
horizontal: 24.0,
195206
),
196207
child: PiwigoButton(
197208
onPressed: _onConfirmPermissions,
@@ -218,7 +229,7 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
218229
IconButton(
219230
tooltip: appStrings.categoryPrivacyGroups_add,
220231
onPressed: _onSelectGroups,
221-
icon: Icon(Icons.add_circle),
232+
icon: Icon(Icons.edit),
222233
),
223234
],
224235
child: FutureBuilder(
@@ -251,17 +262,6 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
251262
},
252263
),
253264
),
254-
FormSection(
255-
title: appStrings.categoryPrivacyRecursive,
256-
child: SwitchListTile(
257-
contentPadding: EdgeInsets.zero,
258-
value: _recursive,
259-
onChanged: (value) => setState(() {
260-
_recursive = value;
261-
}),
262-
subtitle: Text(appStrings.categoryPrivacyRecursive_message),
263-
),
264-
),
265265
],
266266
),
267267
);
@@ -274,17 +274,15 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
274274
children: List.generate(_groups.length, (index) {
275275
GroupModel group = _groups[index];
276276
return PiwigoChip(
277-
onRemove: () => _onRemoveGroup(index),
278277
label: group.name,
278+
backgroundColor: Theme.of(context).chipTheme.backgroundColor,
279+
foregroundColor: Theme.of(context).textTheme.bodyMedium?.color,
279280
);
280281
}),
281282
);
282283
}
283284

284285
Widget get _buildUserPermissions {
285-
if (_allowedUsers.isEmpty) {
286-
return Text(appStrings.none);
287-
}
288286
return Column(
289287
crossAxisAlignment: CrossAxisAlignment.start,
290288
children: [

lib/views/image/edit_image_page.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'dart:math';
22

33
import 'package:flutter/material.dart';
4-
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
54
import 'package:piwigo_ng/components/buttons/animated_piwigo_button.dart';
65
import 'package:piwigo_ng/components/cards/image_details_card.dart';
76
import 'package:piwigo_ng/components/cards/piwigo_chip.dart';
@@ -197,21 +196,15 @@ class _EditImagePageState extends State<EditImagePage> {
197196
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
198197
title: appStrings.tagsAdd_title,
199198
onTapTitle: () {
200-
showMaterialModalBottomSheet<List<TagModel>>(
201-
context: context,
202-
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
203-
builder: (context) => SelectTagsModal(
204-
selectedTags: _tags,
205-
),
206-
).then((value) {
199+
showSelectTagsModal(context, _tags).then((value) {
207200
if (value is! List<TagModel>) return;
208201
setState(() {
209202
_tags = value;
210203
});
211204
});
212205
},
213206
actions: [
214-
const Icon(Icons.add_circle),
207+
const Icon(Icons.edit),
215208
],
216209
child: ClipRRect(
217210
borderRadius: BorderRadius.circular(10),
@@ -222,7 +215,10 @@ class _EditImagePageState extends State<EditImagePage> {
222215
TagModel tag = _tags[index];
223216
return PiwigoChip(
224217
label: tag.name,
225-
onRemove: () => _onDeselectTag(tag),
218+
backgroundColor:
219+
Theme.of(context).chipTheme.backgroundColor,
220+
foregroundColor:
221+
Theme.of(context).textTheme.bodyMedium?.color,
226222
);
227223
}),
228224
),

lib/views/upload/upload_page.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:piwigo_ng/components/buttons/animated_piwigo_button.dart';
99
import 'package:piwigo_ng/components/cards/image_details_card.dart';
1010
import 'package:piwigo_ng/components/cards/piwigo_chip.dart';
1111
import 'package:piwigo_ng/components/fields/app_field.dart';
12-
import 'package:piwigo_ng/components/modals/piwigo_modal.dart';
1312
import 'package:piwigo_ng/components/modals/select_tags_modal.dart';
1413
import 'package:piwigo_ng/components/sections/form_section.dart';
1514
import 'package:piwigo_ng/models/tag_model.dart';
@@ -296,20 +295,15 @@ class _UploadGalleryViewPage extends State<UploadPage>
296295
FormSection(
297296
title: appStrings.tagsAdd_title,
298297
onTapTitle: () {
299-
showPiwigoModal<List<TagModel>>(
300-
context: context,
301-
builder: (_) => SelectTagsModal(
302-
selectedTags: _tags,
303-
),
304-
).then((value) {
298+
showSelectTagsModal(context, _tags).then((value) {
305299
if (value is! List<TagModel>) return;
306300
setState(() {
307301
_tags = value;
308302
});
309303
});
310304
},
311305
actions: [
312-
const Icon(Icons.add_circle),
306+
const Icon(Icons.edit),
313307
],
314308
child: Wrap(
315309
spacing: 8.0,
@@ -318,7 +312,8 @@ class _UploadGalleryViewPage extends State<UploadPage>
318312
TagModel tag = _tags[index];
319313
return PiwigoChip(
320314
label: tag.name,
321-
onRemove: () => _onDeselectTag(tag),
315+
backgroundColor: Theme.of(context).chipTheme.backgroundColor,
316+
foregroundColor: Theme.of(context).textTheme.bodyMedium?.color,
322317
);
323318
}),
324319
),

0 commit comments

Comments
 (0)