@@ -7,6 +7,7 @@ import 'package:piwigo_ng/models/album_model.dart';
77import 'package:piwigo_ng/models/album_permission_model.dart' ;
88import 'package:piwigo_ng/models/group_model.dart' ;
99import 'package:piwigo_ng/models/user_model.dart' ;
10+ import 'package:piwigo_ng/network/albums.dart' ;
1011import 'package:piwigo_ng/network/api_error.dart' ;
1112import 'package:piwigo_ng/network/groups.dart' ;
1213import 'package:piwigo_ng/network/permissions.dart' ;
@@ -48,7 +49,6 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
4849 return ;
4950 }
5051 _admins = response.data;
51- print (_admins);
5252 }
5353
5454 Future <void > _getPermissions () async {
@@ -72,6 +72,33 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
7272 _groups = [..._groups, ..._allowedGroups].toSet ().toList ();
7373 }
7474
75+ Future <void > _onConfirmPermissions () async {
76+ ApiResponse editResult = await editAlbum (
77+ albumId: widget.album.id,
78+ status: _selectedMode,
79+ );
80+ if (! editResult.hasData || ! editResult.data) return ;
81+
82+ if (_selectedMode == AlbumStatus .private) {
83+ List <GroupModel > newGroups =
84+ _groups.where ((e) => ! _allowedGroups.contains (e)).toList ();
85+ List <GroupModel > removedGroups =
86+ _allowedGroups.where ((e) => ! _groups.contains (e)).toList ();
87+
88+ bool addSuccess = await addPermission (
89+ albumId: widget.album.id,
90+ groups: newGroups.map ((group) => group.id).toList (),
91+ );
92+
93+ bool removeSuccess = await removePermission (
94+ albumId: widget.album.id,
95+ groups: removedGroups.map ((group) => group.id).toList (),
96+ );
97+ }
98+
99+ Navigator .of (context).pop ();
100+ }
101+
75102 void _onChangeMode (AlbumStatus ? mode) {
76103 if (mode == null ) return ;
77104 setState (() {
@@ -102,56 +129,67 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
102129 appBar: AppBar (
103130 title: Text (appStrings.categoryPrivacy),
104131 ),
105- body: ListView (
106- padding: const EdgeInsets .symmetric (
107- vertical: 16.0 ,
108- ),
132+ body: Column (
109133 children: [
110- Text (
111- appStrings.categoryPrivacy_subtitle (widget.album.name),
112- textAlign: TextAlign .center,
113- ),
114- Padding (
115- padding: const EdgeInsets .symmetric (
116- vertical: 8.0 ,
117- ),
118- child: Column (
134+ Expanded (
135+ child: ListView (
136+ padding: const EdgeInsets .symmetric (
137+ vertical: 16.0 ,
138+ ),
119139 children: [
120- RadioListTile <AlbumStatus >(
121- value: AlbumStatus .public,
122- groupValue: _selectedMode,
123- activeColor: Theme .of (context).colorScheme.secondary,
124- title: Text (appStrings.categoryPrivacyMode_public),
125- subtitle: Text (appStrings.categoryPrivacyMode_publicMessage),
126- onChanged: _onChangeMode,
140+ Text (
141+ appStrings.categoryPrivacy_subtitle (widget.album.name),
142+ textAlign: TextAlign .center,
143+ ),
144+ Padding (
145+ padding: const EdgeInsets .symmetric (
146+ vertical: 8.0 ,
147+ ),
148+ child: Column (
149+ children: [
150+ RadioListTile <AlbumStatus >(
151+ value: AlbumStatus .public,
152+ groupValue: _selectedMode,
153+ activeColor: Theme .of (context).colorScheme.secondary,
154+ title: Text (appStrings.categoryPrivacyMode_public),
155+ subtitle:
156+ Text (appStrings.categoryPrivacyMode_publicMessage),
157+ onChanged: _onChangeMode,
158+ ),
159+ RadioListTile (
160+ value: AlbumStatus .private,
161+ groupValue: _selectedMode,
162+ activeColor: Theme .of (context).colorScheme.secondary,
163+ title: Text (appStrings.categoryPrivacyMode_private),
164+ subtitle:
165+ Text (appStrings.categoryPrivacyMode_privateMessage),
166+ onChanged: _onChangeMode,
167+ ),
168+ ],
169+ ),
127170 ),
128- RadioListTile (
129- value: AlbumStatus .private,
130- groupValue: _selectedMode,
131- activeColor: Theme .of (context).colorScheme.secondary,
132- title: Text (appStrings.categoryPrivacyMode_private),
133- subtitle: Text (appStrings.categoryPrivacyMode_privateMessage),
134- onChanged: _onChangeMode,
171+ AnimatedSize (
172+ duration: const Duration (milliseconds: 300 ),
173+ reverseDuration: const Duration (milliseconds: 150 ),
174+ curve: Curves .ease,
175+ alignment: Alignment .topCenter,
176+ child: SizedBox (
177+ height: _selectedMode == AlbumStatus .public ? .0 : null ,
178+ child: _privateSection,
179+ ),
135180 ),
136181 ],
137182 ),
138183 ),
139- AnimatedSize (
140- duration: const Duration (milliseconds: 300 ),
141- reverseDuration: const Duration (milliseconds: 150 ),
142- curve: Curves .ease,
143- alignment: Alignment .topCenter,
144- child: SizedBox (
145- height: _selectedMode == AlbumStatus .public ? .0 : null ,
146- child: _privateSection,
147- ),
148- ),
149- PiwigoButton (
150- margin: const EdgeInsets .symmetric (
184+ Padding (
185+ padding: const EdgeInsets .symmetric (
151186 horizontal: 24.0 ,
152187 vertical: 16.0 ,
153188 ),
154- text: appStrings.alertConfirmButton,
189+ child: PiwigoButton (
190+ onPressed: _onConfirmPermissions,
191+ text: appStrings.alertConfirmButton,
192+ ),
155193 ),
156194 ],
157195 ),
@@ -179,22 +217,14 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
179217 child: FutureBuilder (
180218 future: _permissionsFuture,
181219 builder: (context, snapshot) {
182- if (snapshot.connectionState == ConnectionState .done) {
183- return Wrap (
184- spacing: 8.0 ,
185- runSpacing: .0 ,
186- children: List .generate (_groups.length, (index) {
187- GroupModel group = _groups[index];
188- return PiwigoChip (
189- onRemove: () => _onRemoveGroup (index),
190- label: group.name,
191- );
192- }),
193- );
220+ switch (snapshot.connectionState) {
221+ case ConnectionState .done:
222+ return _buildGroupPermissions;
223+ default :
224+ return Center (
225+ child: CircularProgressIndicator (),
226+ );
194227 }
195- return Center (
196- child: CircularProgressIndicator (),
197- );
198228 },
199229 ),
200230 ),
@@ -206,7 +236,6 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
206236 switch (snapshot.connectionState) {
207237 case ConnectionState .done:
208238 return _buildUserPermissions;
209- case ConnectionState .waiting:
210239 default :
211240 return Center (
212241 child: CircularProgressIndicator (),
@@ -220,6 +249,20 @@ class _AlbumPrivacyPageState extends State<AlbumPrivacyPage> {
220249 );
221250 }
222251
252+ Widget get _buildGroupPermissions {
253+ return Wrap (
254+ spacing: 8.0 ,
255+ runSpacing: .0 ,
256+ children: List .generate (_groups.length, (index) {
257+ GroupModel group = _groups[index];
258+ return PiwigoChip (
259+ onRemove: () => _onRemoveGroup (index),
260+ label: group.name,
261+ );
262+ }),
263+ );
264+ }
265+
223266 Widget get _buildUserPermissions {
224267 if (_admins == null ) {
225268 return Text (appStrings.none);
0 commit comments