@@ -108,17 +108,17 @@ class CategoryPopup extends StatefulWidget {
108
108
}
109
109
110
110
class _CategoryPopupState extends State <CategoryPopup > {
111
- List selectedSources = []; // List<UserSubscription>
112
- List customSources = []; // List<UserSubscription>
111
+ List selectedSubscriptions = []; // List<UserSubscription>
112
+ List customSubscriptions = []; // List<UserSubscription>
113
113
String customCategory = "" ;
114
114
TextEditingController customCategoryController = TextEditingController ();
115
115
116
116
@override
117
117
void initState () {
118
118
setState (() {
119
- selectedSources = Hive .box ("subscriptions" ).get ("selected" ) ??
119
+ selectedSubscriptions = Hive .box ("subscriptions" ).get ("selected" ) ??
120
120
List <UserSubscription >.empty (growable: true );
121
- customSources = Hive .box ("subscriptions" ).get ("custom" ) ??
121
+ customSubscriptions = Hive .box ("subscriptions" ).get ("custom" ) ??
122
122
List <UserSubscription >.empty (growable: true );
123
123
});
124
124
super .initState ();
@@ -169,8 +169,14 @@ class _CategoryPopupState extends State<CategoryPopup> {
169
169
// All checkbox
170
170
return CheckboxListTile (
171
171
title: Text (subCategoryKey),
172
- value: selectedSources .contains (userSubscription),
172
+ value: selectedSubscriptions .contains (userSubscription),
173
173
onChanged: (value) {
174
+ if (value! ) {
175
+ selectedSubscriptions.removeWhere ((element) {
176
+ return element.publisher ==
177
+ userSubscription.publisher;
178
+ });
179
+ }
174
180
updateList (value, userSubscription);
175
181
},
176
182
);
@@ -184,9 +190,9 @@ class _CategoryPopupState extends State<CategoryPopup> {
184
190
// category checkbox
185
191
return CheckboxListTile (
186
192
title: Text (subCategoryKey),
187
- value: selectedSources .contains (userSubscription),
188
- onChanged: selectedSources
189
- .where ((element) => element.category == "/" )
193
+ value: selectedSubscriptions .contains (userSubscription),
194
+ onChanged: selectedSubscriptions
195
+ .where ((element) => element.publisher == userSubscription.publisher && element. category == "/" )
190
196
.isNotEmpty
191
197
? null
192
198
: (value) {
@@ -197,23 +203,23 @@ class _CategoryPopupState extends State<CategoryPopup> {
197
203
),
198
204
ListView .builder (
199
205
shrinkWrap: true ,
200
- itemCount: customSources .length,
206
+ itemCount: customSubscriptions .length,
201
207
itemBuilder: (context, index) {
202
208
return CheckboxListTile (
203
209
secondary: IconButton (icon: const Icon (Icons .delete_forever), onPressed: () {
204
- var subscription = customSources [index];
210
+ var subscription = customSubscriptions [index];
205
211
setState (() {
206
- customSources .remove (subscription);
207
- selectedSources .remove (subscription);
212
+ customSubscriptions .remove (subscription);
213
+ selectedSubscriptions .remove (subscription);
208
214
});
209
215
210
- Hive .box ("subscriptions" ).put ("custom" , customSources );
211
- Hive .box ("subscriptions" ).put ("selected" , selectedSources );
216
+ Hive .box ("subscriptions" ).put ("custom" , customSubscriptions );
217
+ Hive .box ("subscriptions" ).put ("selected" , selectedSubscriptions );
212
218
}),
213
- title: Text (convertString ((customSources [index] as UserSubscription ).category)),
214
- value: selectedSources .contains (customSources [index]),
219
+ title: Text (convertString ((customSubscriptions [index] as UserSubscription ).category)),
220
+ value: selectedSubscriptions .contains (customSubscriptions [index]),
215
221
onChanged: (value) {
216
- updateList (value, customSources [index]);
222
+ updateList (value, customSubscriptions [index]);
217
223
},
218
224
);
219
225
},),
@@ -248,14 +254,14 @@ class _CategoryPopupState extends State<CategoryPopup> {
248
254
? IconButton (
249
255
onPressed: () {
250
256
setState (() {
251
- customSources .add (UserSubscription (
257
+ customSubscriptions .add (UserSubscription (
252
258
widget.newsSource,
253
259
customCategory,
254
260
));
255
261
});
256
262
Hive .box ("subscriptions" ).put (
257
263
"custom" ,
258
- customSources ,
264
+ customSubscriptions ,
259
265
);
260
266
},
261
267
icon: const Icon (Icons .save_alt))
@@ -274,7 +280,7 @@ class _CategoryPopupState extends State<CategoryPopup> {
274
280
child: FilledButton (
275
281
onPressed: () {
276
282
Hive .box ("subscriptions" )
277
- .put ("selected" , selectedSources );
283
+ .put ("selected" , selectedSubscriptions );
278
284
Navigator .of (context).pop ();
279
285
widget.callback ();
280
286
},
@@ -302,9 +308,9 @@ class _CategoryPopupState extends State<CategoryPopup> {
302
308
void updateList (bool ? value, UserSubscription userSubscription) {
303
309
setState (() {
304
310
if (value! ) {
305
- selectedSources .add (userSubscription);
311
+ selectedSubscriptions .add (userSubscription);
306
312
} else {
307
- selectedSources .remove (userSubscription);
313
+ selectedSubscriptions .remove (userSubscription);
308
314
}
309
315
});
310
316
}
0 commit comments