Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c44cad5

Browse files
authoredDec 26, 2023
Merge pull request #1 from ksh-b/dev
fixes subscription selection issues
2 parents 84bec46 + 9e372b7 commit c44cad5

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed
 

‎lib/pages/subscription.dart

+28-22
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ class CategoryPopup extends StatefulWidget {
108108
}
109109

110110
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>
113113
String customCategory = "";
114114
TextEditingController customCategoryController = TextEditingController();
115115

116116
@override
117117
void initState() {
118118
setState(() {
119-
selectedSources = Hive.box("subscriptions").get("selected") ??
119+
selectedSubscriptions = Hive.box("subscriptions").get("selected") ??
120120
List<UserSubscription>.empty(growable: true);
121-
customSources = Hive.box("subscriptions").get("custom") ??
121+
customSubscriptions = Hive.box("subscriptions").get("custom") ??
122122
List<UserSubscription>.empty(growable: true);
123123
});
124124
super.initState();
@@ -169,8 +169,14 @@ class _CategoryPopupState extends State<CategoryPopup> {
169169
// All checkbox
170170
return CheckboxListTile(
171171
title: Text(subCategoryKey),
172-
value: selectedSources.contains(userSubscription),
172+
value: selectedSubscriptions.contains(userSubscription),
173173
onChanged: (value) {
174+
if (value!) {
175+
selectedSubscriptions.removeWhere((element) {
176+
return element.publisher ==
177+
userSubscription.publisher;
178+
});
179+
}
174180
updateList(value, userSubscription);
175181
},
176182
);
@@ -184,9 +190,9 @@ class _CategoryPopupState extends State<CategoryPopup> {
184190
// category checkbox
185191
return CheckboxListTile(
186192
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 == "/")
190196
.isNotEmpty
191197
? null
192198
: (value) {
@@ -197,23 +203,23 @@ class _CategoryPopupState extends State<CategoryPopup> {
197203
),
198204
ListView.builder(
199205
shrinkWrap: true,
200-
itemCount: customSources.length,
206+
itemCount: customSubscriptions.length,
201207
itemBuilder: (context, index) {
202208
return CheckboxListTile(
203209
secondary: IconButton(icon: const Icon(Icons.delete_forever), onPressed: () {
204-
var subscription = customSources[index];
210+
var subscription = customSubscriptions[index];
205211
setState(() {
206-
customSources.remove(subscription);
207-
selectedSources.remove(subscription);
212+
customSubscriptions.remove(subscription);
213+
selectedSubscriptions.remove(subscription);
208214
});
209215

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);
212218
}),
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]),
215221
onChanged: (value) {
216-
updateList(value, customSources[index]);
222+
updateList(value, customSubscriptions[index]);
217223
},
218224
);
219225
},),
@@ -248,14 +254,14 @@ class _CategoryPopupState extends State<CategoryPopup> {
248254
? IconButton(
249255
onPressed: () {
250256
setState(() {
251-
customSources.add(UserSubscription(
257+
customSubscriptions.add(UserSubscription(
252258
widget.newsSource,
253259
customCategory,
254260
));
255261
});
256262
Hive.box("subscriptions").put(
257263
"custom",
258-
customSources,
264+
customSubscriptions,
259265
);
260266
},
261267
icon: const Icon(Icons.save_alt))
@@ -274,7 +280,7 @@ class _CategoryPopupState extends State<CategoryPopup> {
274280
child: FilledButton(
275281
onPressed: () {
276282
Hive.box("subscriptions")
277-
.put("selected", selectedSources);
283+
.put("selected", selectedSubscriptions);
278284
Navigator.of(context).pop();
279285
widget.callback();
280286
},
@@ -302,9 +308,9 @@ class _CategoryPopupState extends State<CategoryPopup> {
302308
void updateList(bool? value, UserSubscription userSubscription) {
303309
setState(() {
304310
if (value!) {
305-
selectedSources.add(userSubscription);
311+
selectedSubscriptions.add(userSubscription);
306312
} else {
307-
selectedSources.remove(userSubscription);
313+
selectedSubscriptions.remove(userSubscription);
308314
}
309315
});
310316
}

0 commit comments

Comments
 (0)
Please sign in to comment.