Loading app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java +20 −12 Original line number Diff line number Diff line Loading @@ -7,9 +7,10 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.SwitchPreference; import androidx.annotation.Nullable; import android.util.Log; import android.widget.Toast; import androidx.annotation.Nullable; import at.bitfire.cert4android.CustomCertManager; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.util.Notes; Loading @@ -30,21 +31,28 @@ public class PreferencesFragment extends PreferenceFragment { } }); final SwitchPreference themePref = (SwitchPreference) findPreference(getString(R.string.pref_key_theme)); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); final SwitchPreference themePref = (SwitchPreference) findPreference(getString(R.string.pref_key_theme)); themePref.setSummary(sp.getBoolean(getString(R.string.pref_key_theme), false) ? getString(R.string.pref_value_theme_dark) : getString(R.string.pref_value_theme_light)); themePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { themePref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { Boolean darkTheme = (Boolean) newValue; Notes.setAppTheme(darkTheme); getActivity().setResult(Activity.RESULT_OK); getActivity().finish(); return true; }); final SwitchPreference wifiOnlyPref = (SwitchPreference) findPreference(getString(R.string.pref_key_wifi_only)); wifiOnlyPref.setSummary(sp.getBoolean(getString(R.string.pref_key_wifi_only), false) ? getString(R.string.pref_value_wifi_and_mobile) : getString(R.string.pref_value_wifi_only)); wifiOnlyPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { Boolean syncOnWifiOnly = (Boolean) newValue; wifiOnlyPref.setSummary(sp.getBoolean(getString(R.string.pref_key_wifi_only), false) ? getString(R.string.pref_value_wifi_and_mobile) : getString(R.string.pref_value_wifi_only)); Log.v("Notes", "syncOnWifiOnly: " + syncOnWifiOnly); return true; } }); } } app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java +10 −1 Original line number Diff line number Diff line Loading @@ -142,7 +142,16 @@ public class NoteServerSyncHelper { * @return true if sync is possible, otherwise false. */ public boolean isSyncPossible() { return networkConnected && isConfigured(appContext) && cert4androidReady; boolean onlyWifiGuard = true; if( PreferenceManager.getDefaultSharedPreferences(this.appContext) .getBoolean("wifiOnly", false) && !((ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) { onlyWifiGuard = false; Log.d(NoteServerSyncHelper.class.getSimpleName(), "Network available, but no wifi."); } return networkConnected && isConfigured(appContext) && cert4androidReady && onlyWifiGuard; } public CustomCertManager getCustomCertManager() { Loading app/src/main/res/drawable/ic_wifi_black_24dp.xml 0 → 100644 +5 −0 Original line number Diff line number Diff line <vector android:autoMirrored="true" android:height="24dp" android:tint="#666666" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FF000000" android:pathData="M1,9l2,2c4.97,-4.97 13.03,-4.97 18,0l2,-2C16.93,2.93 7.08,2.93 1,9zM9,17l3,3 3,-3c-1.65,-1.66 -4.34,-1.66 -6,0zM5,13l2,2c2.76,-2.76 7.24,-2.76 10,0l2,-2C15.14,9.14 8.87,9.14 5,13z"/> </vector> app/src/main/res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ <string name="settings_submitting">Connecting …</string> <string name="settings_note_mode">Display mode for Notes</string> <string name="settings_theme_title">Theme</string> <string name="settings_theme_wifi_only">Sync</string> <string name="settings_cert_category">Manage certificates</string> <string name="settings_cert_trust_system">Trust system certificates</string> <string name="settings_cert_trust_system_on">System and user-added CAs will be trusted (recommended)</string> Loading Loading @@ -139,6 +140,7 @@ <string name="pref_key_reset_trust" translatable="false">resetTrust</string> <string name="pref_key_note_mode" translatable="false">noteMode</string> <string name="pref_key_theme" translatable="false">darkTheme</string> <string name="pref_key_wifi_only" translatable="false">wifiOnly</string> <string name="pref_key_last_note_mode" translatable="false">lastNoteMode</string> <string name="pref_value_mode_edit" translatable="false">edit</string> <string name="pref_value_mode_preview" translatable="false">preview</string> Loading @@ -146,6 +148,8 @@ <string name="pref_value_mode_note" translatable="false">note</string> <string name="pref_value_theme_light">Light</string> <string name="pref_value_theme_dark">Dark</string> <string name="pref_value_wifi_only">Sync only on Wi-Fi</string> <string name="pref_value_wifi_and_mobile">Sync on Wi-Fi and mobile data</string> <!-- Array: note modes --> <string-array name="noteMode_entries"> Loading app/src/main/res/xml/preferences.xml +7 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,13 @@ android:summary="%s" android:title="@string/settings_theme_title" /> <SwitchPreference android:defaultValue="@string/pref_value_wifi_and_mobile" android:icon="@drawable/ic_insert_link_black_24dp" android:key="@string/pref_key_wifi_only" android:summary="%s" android:title="@string/settings_theme_wifi_only" /> <PreferenceScreen android:key="@string/pref_key_certs" android:persistent="false" Loading Loading
app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java +20 −12 Original line number Diff line number Diff line Loading @@ -7,9 +7,10 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.SwitchPreference; import androidx.annotation.Nullable; import android.util.Log; import android.widget.Toast; import androidx.annotation.Nullable; import at.bitfire.cert4android.CustomCertManager; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.util.Notes; Loading @@ -30,21 +31,28 @@ public class PreferencesFragment extends PreferenceFragment { } }); final SwitchPreference themePref = (SwitchPreference) findPreference(getString(R.string.pref_key_theme)); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); final SwitchPreference themePref = (SwitchPreference) findPreference(getString(R.string.pref_key_theme)); themePref.setSummary(sp.getBoolean(getString(R.string.pref_key_theme), false) ? getString(R.string.pref_value_theme_dark) : getString(R.string.pref_value_theme_light)); themePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { themePref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { Boolean darkTheme = (Boolean) newValue; Notes.setAppTheme(darkTheme); getActivity().setResult(Activity.RESULT_OK); getActivity().finish(); return true; }); final SwitchPreference wifiOnlyPref = (SwitchPreference) findPreference(getString(R.string.pref_key_wifi_only)); wifiOnlyPref.setSummary(sp.getBoolean(getString(R.string.pref_key_wifi_only), false) ? getString(R.string.pref_value_wifi_and_mobile) : getString(R.string.pref_value_wifi_only)); wifiOnlyPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { Boolean syncOnWifiOnly = (Boolean) newValue; wifiOnlyPref.setSummary(sp.getBoolean(getString(R.string.pref_key_wifi_only), false) ? getString(R.string.pref_value_wifi_and_mobile) : getString(R.string.pref_value_wifi_only)); Log.v("Notes", "syncOnWifiOnly: " + syncOnWifiOnly); return true; } }); } }
app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java +10 −1 Original line number Diff line number Diff line Loading @@ -142,7 +142,16 @@ public class NoteServerSyncHelper { * @return true if sync is possible, otherwise false. */ public boolean isSyncPossible() { return networkConnected && isConfigured(appContext) && cert4androidReady; boolean onlyWifiGuard = true; if( PreferenceManager.getDefaultSharedPreferences(this.appContext) .getBoolean("wifiOnly", false) && !((ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) { onlyWifiGuard = false; Log.d(NoteServerSyncHelper.class.getSimpleName(), "Network available, but no wifi."); } return networkConnected && isConfigured(appContext) && cert4androidReady && onlyWifiGuard; } public CustomCertManager getCustomCertManager() { Loading
app/src/main/res/drawable/ic_wifi_black_24dp.xml 0 → 100644 +5 −0 Original line number Diff line number Diff line <vector android:autoMirrored="true" android:height="24dp" android:tint="#666666" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FF000000" android:pathData="M1,9l2,2c4.97,-4.97 13.03,-4.97 18,0l2,-2C16.93,2.93 7.08,2.93 1,9zM9,17l3,3 3,-3c-1.65,-1.66 -4.34,-1.66 -6,0zM5,13l2,2c2.76,-2.76 7.24,-2.76 10,0l2,-2C15.14,9.14 8.87,9.14 5,13z"/> </vector>
app/src/main/res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ <string name="settings_submitting">Connecting …</string> <string name="settings_note_mode">Display mode for Notes</string> <string name="settings_theme_title">Theme</string> <string name="settings_theme_wifi_only">Sync</string> <string name="settings_cert_category">Manage certificates</string> <string name="settings_cert_trust_system">Trust system certificates</string> <string name="settings_cert_trust_system_on">System and user-added CAs will be trusted (recommended)</string> Loading Loading @@ -139,6 +140,7 @@ <string name="pref_key_reset_trust" translatable="false">resetTrust</string> <string name="pref_key_note_mode" translatable="false">noteMode</string> <string name="pref_key_theme" translatable="false">darkTheme</string> <string name="pref_key_wifi_only" translatable="false">wifiOnly</string> <string name="pref_key_last_note_mode" translatable="false">lastNoteMode</string> <string name="pref_value_mode_edit" translatable="false">edit</string> <string name="pref_value_mode_preview" translatable="false">preview</string> Loading @@ -146,6 +148,8 @@ <string name="pref_value_mode_note" translatable="false">note</string> <string name="pref_value_theme_light">Light</string> <string name="pref_value_theme_dark">Dark</string> <string name="pref_value_wifi_only">Sync only on Wi-Fi</string> <string name="pref_value_wifi_and_mobile">Sync on Wi-Fi and mobile data</string> <!-- Array: note modes --> <string-array name="noteMode_entries"> Loading
app/src/main/res/xml/preferences.xml +7 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,13 @@ android:summary="%s" android:title="@string/settings_theme_title" /> <SwitchPreference android:defaultValue="@string/pref_value_wifi_and_mobile" android:icon="@drawable/ic_insert_link_black_24dp" android:key="@string/pref_key_wifi_only" android:summary="%s" android:title="@string/settings_theme_wifi_only" /> <PreferenceScreen android:key="@string/pref_key_certs" android:persistent="false" Loading