@@ -44,12 +44,19 @@ class _NotificationsSettingsScreenState
4444 .get ('newsNotificationsEnabled' , defaultValue: false ) as bool ;
4545 int refreshInterval =
4646 Hive .box ('settings' ).get ('refreshInterval' , defaultValue: 6 ) as int ;
47+ String networkConnectionType = Hive .box ('settings' )
48+ .get ('networkConnectionType' , defaultValue: 'Wi-Fi' ) as String ;
49+
4750 Map durations = {
4851 2 : AppLocalizations .of (context)! .notifications2hours,
4952 6 : AppLocalizations .of (context)! .notifications6hours,
5053 12 : AppLocalizations .of (context)! .notifications12hours,
5154 24 : AppLocalizations .of (context)! .notifications24hours,
5255 };
56+ Map connections = {
57+ 'Wi-Fi' : AppLocalizations .of (context)! .wifi,
58+ 'Any' : AppLocalizations .of (context)! .anyNetwork,
59+ };
5360
5461 return Scaffold (
5562 appBar: AppBar (
@@ -97,15 +104,7 @@ class _NotificationsSettingsScreenState
97104 onChanged: notificationsEnabled
98105 ? (bool value) async {
99106 if (value) {
100- int refreshInterval = Hive .box ('settings' )
101- .get ('refreshInterval' , defaultValue: 6 ) as int ;
102- await Workmanager ().registerPeriodicTask (
103- 'newsLoader' ,
104- "Load news in background" ,
105- existingWorkPolicy: ExistingWorkPolicy .replace,
106- frequency: Duration (hours: refreshInterval),
107- initialDelay: Duration (hours: refreshInterval),
108- );
107+ await Notifications ().registerPeriodicTask ();
109108 } else {
110109 Workmanager ().cancelAll ();
111110 }
@@ -119,13 +118,48 @@ class _NotificationsSettingsScreenState
119118 }
120119 : null ,
121120 ),
121+ ListTile (
122+ title: Text (
123+ AppLocalizations .of (context)! .requiredNetworkConnection,
124+ ),
125+ enabled: notificationsEnabled && newsNotificationsEnabled,
126+ trailing: DropdownButton (
127+ value: networkConnectionType,
128+ onChanged: notificationsEnabled && newsNotificationsEnabled
129+ ? (String ? newValue) async {
130+ if (newValue != null ) {
131+ networkConnectionType = newValue;
132+ Hive .box ('settings' )
133+ .put ('networkConnectionType' , newValue);
134+ await Notifications ().registerPeriodicTask ();
135+
136+ setState (() {});
137+ }
138+ }
139+ : null ,
140+ items: < String > [
141+ 'Wi-Fi' ,
142+ 'Any' ,
143+ ].map <DropdownMenuItem <String >>(
144+ (String value) {
145+ return DropdownMenuItem <String >(
146+ value: value,
147+ child: Text (
148+ connections[value],
149+ style: TextStyle (
150+ fontSize: 12 ,
151+ ),
152+ ),
153+ );
154+ },
155+ ).toList (),
156+ ),
157+ ),
122158 ListTile (
123159 title: Text (
124160 AppLocalizations .of (context)! .refreshInterval,
125- style: TextStyle (),
126161 ),
127162 enabled: notificationsEnabled && newsNotificationsEnabled,
128- //onTap: () {},
129163 trailing: DropdownButton (
130164 value: refreshInterval,
131165 onChanged: notificationsEnabled && newsNotificationsEnabled
0 commit comments