|
1 | 1 | import 'package:clipboard/clipboard.dart';
|
2 | 2 | import 'package:contained_tab_bar_view/contained_tab_bar_view.dart';
|
| 3 | +import 'package:flood_mobile/Api/client_api.dart'; |
3 | 4 | import 'package:flood_mobile/Api/feeds_contents_api.dart';
|
4 | 5 | import 'package:flood_mobile/Api/update_feed_api.dart';
|
5 | 6 | import 'package:flood_mobile/Model/single_feed_and_response_model.dart';
|
@@ -693,60 +694,79 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
|
693 | 694 | width: 150,
|
694 | 695 | height: 50,
|
695 | 696 | child: ElevatedButton(
|
696 |
| - onPressed: () { |
697 |
| - if (_feedformKey.currentState! |
698 |
| - .validate() == |
699 |
| - true) { |
700 |
| - setState(() { |
701 |
| - if (isUpdateFeedSelected == |
702 |
| - false) { |
703 |
| - FeedsApi.addFeeds( |
704 |
| - type: "feed", |
705 |
| - id: "43", |
706 |
| - label: labelController |
707 |
| - .text, |
708 |
| - feedurl: |
709 |
| - urlController.text, |
710 |
| - interval: int.parse( |
711 |
| - intervalController |
712 |
| - .text), |
713 |
| - count: 0, |
714 |
| - context: context, |
715 |
| - ); |
716 |
| - } |
717 |
| - final addFeedSnackbar = |
718 |
| - addFloodSnackBar( |
719 |
| - SnackbarType |
720 |
| - .information, |
721 |
| - 'New Feed added successfully', |
722 |
| - 'Dismiss'); |
723 |
| - |
724 |
| - ScaffoldMessenger.of( |
725 |
| - context) |
726 |
| - .showSnackBar( |
727 |
| - addFeedSnackbar); |
728 |
| - FeedsApi |
729 |
| - .listAllFeedsAndRules( |
730 |
| - context: context); |
731 |
| - clearFeedsFields(); |
732 |
| - if (isUpdateFeedSelected) { |
733 |
| - UpdateFeedApi.updateFeed( |
| 697 | + onPressed: () async { |
| 698 | + if (await ClientApi |
| 699 | + .checkClientOnline( |
| 700 | + context)) { |
| 701 | + if (_feedformKey.currentState! |
| 702 | + .validate() == |
| 703 | + true) { |
| 704 | + setState(() { |
| 705 | + if (isUpdateFeedSelected == |
| 706 | + false) { |
| 707 | + FeedsApi.addFeeds( |
734 | 708 | type: "feed",
|
735 | 709 | id: updateFeedId,
|
736 | 710 | label: labelController
|
737 | 711 | .text,
|
738 | 712 | feedurl: urlController
|
739 | 713 | .text,
|
740 |
| - context: context, |
741 | 714 | interval: int.parse(
|
742 | 715 | intervalController
|
743 | 716 | .text),
|
744 |
| - count: 1); |
| 717 | + count: 0, |
| 718 | + context: context, |
| 719 | + ); |
| 720 | + } |
| 721 | + final addFeedSnackbar = |
| 722 | + addFloodSnackBar( |
| 723 | + SnackbarType |
| 724 | + .information, |
| 725 | + 'New Feed added successfully', |
| 726 | + 'Dismiss'); |
| 727 | + |
| 728 | + ScaffoldMessenger.of( |
| 729 | + context) |
| 730 | + .showSnackBar( |
| 731 | + addFeedSnackbar); |
745 | 732 | FeedsApi
|
746 | 733 | .listAllFeedsAndRules(
|
747 | 734 | context: context);
|
748 |
| - } |
749 |
| - }); |
| 735 | + clearFeedsFields(); |
| 736 | + if (isUpdateFeedSelected) { |
| 737 | + UpdateFeedApi.updateFeed( |
| 738 | + type: "feed", |
| 739 | + id: updateFeedId, |
| 740 | + label: |
| 741 | + labelController |
| 742 | + .text, |
| 743 | + feedurl: |
| 744 | + urlController |
| 745 | + .text, |
| 746 | + context: context, |
| 747 | + interval: int.parse( |
| 748 | + intervalController |
| 749 | + .text), |
| 750 | + count: 1); |
| 751 | + FeedsApi |
| 752 | + .listAllFeedsAndRules( |
| 753 | + context: |
| 754 | + context); |
| 755 | + } |
| 756 | + }); |
| 757 | + } |
| 758 | + } else { |
| 759 | + final connectionCheckSnackbar = |
| 760 | + addFloodSnackBar( |
| 761 | + SnackbarType.caution, |
| 762 | + 'Please check your backend connection', |
| 763 | + 'Dismiss'); |
| 764 | + |
| 765 | + ScaffoldMessenger.of(context) |
| 766 | + .clearSnackBars(); |
| 767 | + ScaffoldMessenger.of(context) |
| 768 | + .showSnackBar( |
| 769 | + connectionCheckSnackbar); |
750 | 770 | }
|
751 | 771 | },
|
752 | 772 | style: ElevatedButton.styleFrom(
|
@@ -2209,59 +2229,78 @@ class _RSSFeedHomePageState extends State<RSSFeedHomePage>
|
2209 | 2229 | width: 150,
|
2210 | 2230 | height: 50,
|
2211 | 2231 | child: ElevatedButton(
|
2212 |
| - onPressed: () { |
2213 |
| - if (_rulesformKey.currentState! |
2214 |
| - .validate() == |
2215 |
| - true) { |
2216 |
| - setState(() { |
2217 |
| - isNewDownloadRules = true; |
2218 |
| - RulesApi.addRules( |
2219 |
| - type: "rule", |
2220 |
| - label: |
2221 |
| - labelRulesController |
2222 |
| - .text, |
2223 |
| - feedIDs: [ |
2224 |
| - feedidgetter( |
2225 |
| - applicableFeedSelected |
2226 |
| - .toString(), |
2227 |
| - model |
2228 |
| - .rssFeedsList) |
2229 |
| - .toString() |
2230 |
| - ], |
2231 |
| - field: "test", |
2232 |
| - matchpattern: |
2233 |
| - matchpatternController |
2234 |
| - .text, |
2235 |
| - excludepattern: |
2236 |
| - excludepatternController |
2237 |
| - .text, |
2238 |
| - destination: |
2239 |
| - destinationController |
2240 |
| - .text, |
2241 |
| - tags: [ |
2242 |
| - tagsController.text |
2243 |
| - ], |
2244 |
| - startOnLoad: startOnLoad, |
2245 |
| - isBasePath: useAsBasePath, |
2246 |
| - count: 0, |
2247 |
| - context: context, |
2248 |
| - ); |
2249 |
| - final addRuleSnackbar = |
2250 |
| - addFloodSnackBar( |
2251 |
| - SnackbarType |
2252 |
| - .information, |
2253 |
| - 'New Rule added successfully', |
2254 |
| - 'Dismiss'); |
| 2232 | + onPressed: () async { |
| 2233 | + if (await ClientApi |
| 2234 | + .checkClientOnline( |
| 2235 | + context)) { |
| 2236 | + if (_rulesformKey |
| 2237 | + .currentState! |
| 2238 | + .validate() == |
| 2239 | + true) { |
| 2240 | + setState(() { |
| 2241 | + isNewDownloadRules = true; |
| 2242 | + RulesApi.addRules( |
| 2243 | + type: "rule", |
| 2244 | + label: |
| 2245 | + labelRulesController |
| 2246 | + .text, |
| 2247 | + feedIDs: [ |
| 2248 | + feedidgetter( |
| 2249 | + applicableFeedSelected |
| 2250 | + .toString(), |
| 2251 | + model |
| 2252 | + .rssFeedsList) |
| 2253 | + .toString() |
| 2254 | + ], |
| 2255 | + field: "test", |
| 2256 | + matchpattern: |
| 2257 | + matchpatternController |
| 2258 | + .text, |
| 2259 | + excludepattern: |
| 2260 | + excludepatternController |
| 2261 | + .text, |
| 2262 | + destination: |
| 2263 | + destinationController |
| 2264 | + .text, |
| 2265 | + tags: [ |
| 2266 | + tagsController.text |
| 2267 | + ], |
| 2268 | + startOnLoad: |
| 2269 | + startOnLoad, |
| 2270 | + isBasePath: |
| 2271 | + useAsBasePath, |
| 2272 | + count: 0, |
| 2273 | + context: context, |
| 2274 | + ); |
| 2275 | + final addRuleSnackbar = |
| 2276 | + addFloodSnackBar( |
| 2277 | + SnackbarType |
| 2278 | + .information, |
| 2279 | + 'New Rule added successfully', |
| 2280 | + 'Dismiss'); |
2255 | 2281 |
|
2256 |
| - ScaffoldMessenger.of( |
2257 |
| - context) |
2258 |
| - .showSnackBar( |
2259 |
| - addRuleSnackbar); |
2260 |
| - FeedsApi |
2261 |
| - .listAllFeedsAndRules( |
2262 |
| - context: context); |
2263 |
| - clearDownloadRulesFields(); |
2264 |
| - }); |
| 2282 | + ScaffoldMessenger.of( |
| 2283 | + context) |
| 2284 | + .showSnackBar( |
| 2285 | + addRuleSnackbar); |
| 2286 | + FeedsApi |
| 2287 | + .listAllFeedsAndRules( |
| 2288 | + context: context); |
| 2289 | + clearDownloadRulesFields(); |
| 2290 | + }); |
| 2291 | + } |
| 2292 | + } else { |
| 2293 | + final connectionCheckSnackbar = |
| 2294 | + addFloodSnackBar( |
| 2295 | + SnackbarType.caution, |
| 2296 | + 'Please check your backend connection', |
| 2297 | + 'Dismiss'); |
| 2298 | + |
| 2299 | + ScaffoldMessenger.of(context) |
| 2300 | + .clearSnackBars(); |
| 2301 | + ScaffoldMessenger.of(context) |
| 2302 | + .showSnackBar( |
| 2303 | + connectionCheckSnackbar); |
2265 | 2304 | }
|
2266 | 2305 | },
|
2267 | 2306 | style: ElevatedButton.styleFrom(
|
|
0 commit comments