... | ... |
@@ -8,12 +8,15 @@ import android.content.BroadcastReceiver; |
8 | 8 |
import android.content.Context; |
9 | 9 |
import android.content.Intent; |
10 | 10 |
import android.content.SharedPreferences; |
11 |
+import android.net.ConnectivityManager; |
|
12 |
+import android.net.NetworkInfo; |
|
11 | 13 |
import android.os.SystemClock; |
12 | 14 |
import android.preference.PreferenceManager; |
13 | 15 |
import android.support.v4.app.NotificationCompat; |
14 | 16 |
|
15 | 17 |
import app.librenews.io.librenews.R; |
16 | 18 |
|
19 |
+import static android.content.Context.CONNECTIVITY_SERVICE; |
|
17 | 20 |
import static app.librenews.io.librenews.controllers.DebugManager.sendDebugNotification; |
18 | 21 |
|
19 | 22 |
/** |
... | ... |
@@ -53,6 +56,14 @@ public class SyncManager { |
53 | 56 |
public static class RefreshBroadcastReceiver extends BroadcastReceiver { |
54 | 57 |
@Override |
55 | 58 |
public void onReceive(Context context, Intent intent) { |
59 |
+ if(PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).getBoolean("wifi_sync_only", false)) { |
|
60 |
+ ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE); |
|
61 |
+ int networkType = connManager.getActiveNetworkInfo().getType(); |
|
62 |
+ if(networkType != ConnectivityManager.TYPE_WIFI){ |
|
63 |
+ sendDebugNotification("Not on WiFi, not syncing...", context); |
|
64 |
+ return; |
|
65 |
+ } |
|
66 |
+ } |
|
56 | 67 |
sendDebugNotification("Syncing with server...", context); |
57 | 68 |
FlashManager flashManager = new FlashManager(context); |
58 | 69 |
flashManager.refresh(); |
... | ... |
@@ -39,5 +39,7 @@ |
39 | 39 |
<string name="how_to_use">You\'ll mostly interact with LibreNews through its notifications, as the app itself is just settings. \n\nYou\'ll probably get around 3 breaking news notifications per day, if you stick with the default settings.</string> |
40 | 40 |
<string name="final_notes_welcome_screen">LibreNews doesn\'t track you in any way, and doesn\'t have ads. It\'s completely open source, making the code free for anyone to see.</string> |
41 | 41 |
<string name="start_app">START LIBRENEWS</string> |
42 |
+ <string name="wifi_sync_only_label">WiFi sync only</string> |
|
43 |
+ <string name="wifi_sync_only_description">Whether LibreNews should sync only over WiFi (and not over cellular data). A LibreNews sync uses about 9 kB of data (less than 1% of a megabyte).</string> |
|
42 | 44 |
|
43 | 45 |
</resources> |
... | ... |
@@ -40,5 +40,7 @@ |
40 | 40 |
<string name="final_notes_welcome_screen">LibreNews doesn\'t track you in any way, and doesn\'t have ads. It\'s completely open source, making the code free for anyone to see.</string> |
41 | 41 |
<string name="start_app">START LIBRENEWS</string> |
42 | 42 |
<string name="status_text" formatted="false">syncing every {rate}</string> |
43 |
+ <string name="wifi_sync_only_label">WiFi sync only</string> |
|
44 |
+ <string name="wifi_sync_only_description">Whether LibreNews should sync only over WiFi (and not over cellular data). A LibreNews sync uses about 9 kB of data (less than 1% of a megabyte).</string> |
|
43 | 45 |
|
44 | 46 |
</resources> |
... | ... |
@@ -40,4 +40,6 @@ |
40 | 40 |
<string name="how_to_use">You\'ll mostly interact with LibreNews through its notifications, as the app itself is just settings. \n\nYou\'ll probably get around 3 breaking news notifications per day, if you stick with the default settings.</string> |
41 | 41 |
<string name="final_notes_welcome_screen">LibreNews doesn\'t track you in any way, and doesn\'t have ads. It\'s completely open source, making the code free for anyone to see.</string> |
42 | 42 |
<string name="start_app">START LIBRENEWS</string> |
43 |
+ <string name="wifi_sync_only_label">WiFi sync only</string> |
|
44 |
+ <string name="wifi_sync_only_description">Whether LibreNews should sync only over WiFi (and not over cellular data). A LibreNews sync uses about 9 kB of data (less than 1% of a megabyte).</string> |
|
43 | 45 |
</resources> |
... | ... |
@@ -16,6 +16,12 @@ |
16 | 16 |
android:key="automatically_refresh" |
17 | 17 |
android:summary="@string/auto_refresh_description" |
18 | 18 |
android:title="@string/auto_refresh_label" /> |
19 |
+ <SwitchPreference |
|
20 |
+ android:defaultValue="false" |
|
21 |
+ android:key="wifi_sync_only" |
|
22 |
+ android:summary="@string/wifi_sync_only_description" |
|
23 |
+ android:title="@string/wifi_sync_only_label" |
|
24 |
+ android:dependency="automatically_refresh"/> |
|
19 | 25 |
<ListPreference |
20 | 26 |
android:defaultValue="5" |
21 | 27 |
android:dependency="automatically_refresh" |