added sync preferences
This commit is contained in:
@@ -104,6 +104,9 @@ public final class Constants {
|
||||
public static final String PROXY_PORT = "proxyPort";
|
||||
public static final String PROXY_TYPE = "proxyType";
|
||||
public static final String THEME = "theme";
|
||||
// keyserver sync settings
|
||||
public static final String SYNC_CONTACTS = "syncContacts";
|
||||
public static final String SYNC_KEYSERVER = "syncKeyserver";
|
||||
|
||||
public static final class Theme {
|
||||
public static final String LIGHT = "light";
|
||||
|
||||
@@ -162,6 +162,12 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
postponeSync();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSyncCanceled() {
|
||||
super.onSyncCanceled();
|
||||
cancelUpdates(KeyserverSyncAdapterService.this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -402,7 +408,9 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* will cancel an update already in progress
|
||||
* will cancel an update already in progress. We send an Intent to cancel it instead of simply
|
||||
* modifying a static variable sync the service is running in a process that is different from
|
||||
* the default application process where the UI code runs.
|
||||
*
|
||||
* @param context used to send an Intent to the service requesting cancellation.
|
||||
*/
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
@@ -31,6 +32,7 @@ import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
@@ -467,11 +469,69 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This fragment shows the keyserver/contacts sync preferences
|
||||
*/
|
||||
public static class SyncSettingsFragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.sync_preferences);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// this needs to be done in onResume since the user can change sync values from Android
|
||||
// settings and we need to reflect that change when the user navigates back
|
||||
AccountManager manager = AccountManager.get(getActivity());
|
||||
final Account account = manager.getAccountsByType(Constants.ACCOUNT_TYPE)[0];
|
||||
// for keyserver sync
|
||||
initializeSyncCheckBox(
|
||||
(CheckBoxPreference) findPreference(Constants.Pref.SYNC_KEYSERVER),
|
||||
account,
|
||||
Constants.PROVIDER_AUTHORITY
|
||||
);
|
||||
// for contacts sync
|
||||
initializeSyncCheckBox(
|
||||
(CheckBoxPreference) findPreference(Constants.Pref.SYNC_CONTACTS),
|
||||
account,
|
||||
ContactsContract.AUTHORITY
|
||||
);
|
||||
}
|
||||
|
||||
private void initializeSyncCheckBox(CheckBoxPreference syncCheckBox, final Account account,
|
||||
final String authority) {
|
||||
boolean syncEnabled = ContentResolver.getSyncAutomatically(account, authority);
|
||||
syncCheckBox.setChecked(syncEnabled);
|
||||
|
||||
syncCheckBox.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean syncEnabled = (Boolean) newValue;
|
||||
if (syncEnabled) {
|
||||
ContentResolver.setSyncAutomatically(account, authority, true);
|
||||
} else {
|
||||
// disable syncs
|
||||
ContentResolver.setSyncAutomatically(account, authority, false);
|
||||
// cancel any ongoing/pending syncs
|
||||
ContentResolver.cancelSync(account, authority);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
return AdvancedPrefsFragment.class.getName().equals(fragmentName)
|
||||
|| CloudSearchPrefsFragment.class.getName().equals(fragmentName)
|
||||
|| ProxyPrefsFragment.class.getName().equals(fragmentName)
|
||||
|| GuiPrefsFragment.class.getName().equals(fragmentName)
|
||||
|| SyncSettingsFragment.class.getName().equals(fragmentName)
|
||||
|| super.isValidFragment(fragmentName);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<string name="section_passphrase_cache">"Password/PIN Handling"</string>
|
||||
<string name="section_proxy_settings">"Proxy Settings"</string>
|
||||
<string name="section_gui">"Interface"</string>
|
||||
<string name="section_sync_settings">"Sync Settings"</string>
|
||||
<string name="section_certify">"Confirm"</string>
|
||||
<string name="section_actions">"Actions"</string>
|
||||
<string name="section_share_key">"Key"</string>
|
||||
@@ -175,6 +176,11 @@
|
||||
<string name="pref_keybase">"keybase.io"</string>
|
||||
<string name="pref_keybase_summary">"Search keys on keybase.io"</string>
|
||||
|
||||
<string name="label_sync_settings_keyserver_title">"Automatically update keys"</string>
|
||||
<string name="label_sync_settings_keyserver_summary">"Updates keys older than a week, from the preferred keyserver"</string>
|
||||
<string name="label_sync_settings_contacts_title">"Sync Contacts with Keys"</string>
|
||||
<string name="label_sync_settings_contacts_summary">"Associates contacts with imported keys, based on email, completely offline"</string>
|
||||
|
||||
<!-- Proxy Preferences -->
|
||||
<string name="pref_proxy_tor_title">"Enable Tor"</string>
|
||||
<string name="pref_proxy_tor_summary">"Requires Orbot to be installed"</string>
|
||||
|
||||
@@ -11,4 +11,7 @@
|
||||
<header
|
||||
android:fragment="org.sufficientlysecure.keychain.ui.SettingsActivity$ProxyPrefsFragment"
|
||||
android:title="@string/section_proxy_settings" />
|
||||
<header
|
||||
android:fragment="org.sufficientlysecure.keychain.ui.SettingsActivity$SyncSettingsFragment"
|
||||
android:title="@string/section_sync_settings" />
|
||||
</preference-headers>
|
||||
|
||||
12
OpenKeychain/src/main/res/xml/sync_preferences.xml
Normal file
12
OpenKeychain/src/main/res/xml/sync_preferences.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<CheckBoxPreference
|
||||
android:key="syncKeyserver"
|
||||
android:persistent="false"
|
||||
android:title="@string/label_sync_settings_keyserver_title"
|
||||
android:summary="@string/label_sync_settings_keyserver_summary" />
|
||||
<CheckBoxPreference
|
||||
android:key="syncContacts"
|
||||
android:persistent="false"
|
||||
android:title="@string/label_sync_settings_contacts_title"
|
||||
android:summary="@string/label_sync_settings_contacts_summary" />
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user