Bug 1398283 - Clean up Sync Preferences screen r=nalexander

MozReview-Commit-ID: GfdBBT2cSh7

--HG--
extra : rebase_source : 2e41f92a1e84ef119c85c10a716a0548c63fb6c3
This commit is contained in:
Grigory Kruglov 2017-09-18 19:24:36 -04:00
Родитель 8e6b1f7796
Коммит d5dc3841a3
5 изменённых файлов: 137 добавлений и 136 удалений

Просмотреть файл

@ -51,25 +51,24 @@
<!ENTITY fxaccount_getting_started_get_started 'Get started'>
<!ENTITY fxaccount_getting_started_old_firefox 'Using an older version of &syncBrand.shortName.label;?'>
<!ENTITY fxaccount_status_signed_in_as 'Signed in as'>
<!ENTITY fxaccount_status_manage_account 'Manage account'>
<!ENTITY fxaccount_status_auth_server 'Account server'>
<!ENTITY fxaccount_status_sync_now 'Sync now'>
<!ENTITY fxaccount_status_syncing2 'Syncing…'>
<!ENTITY fxaccount_status_device_name 'Device name'>
<!ENTITY fxaccount_status_sync_server 'Sync server'>
<!ENTITY fxaccount_status_sync '&syncBrand.shortName.label;'>
<!ENTITY fxaccount_status_sync_enabled '&syncBrand.shortName.label;: enabled'>
<!ENTITY fxaccount_status_needs_verification2 'Your account needs to be verified. Tap to resend verification email.'>
<!ENTITY fxaccount_status_needs_credentials 'Cannot connect. Tap to sign in.'>
<!ENTITY fxaccount_status_needs_upgrade 'You need to upgrade &brandShortName; to sign in.'>
<!ENTITY fxaccount_status_needs_master_sync_automatically_enabled '&syncBrand.shortName.label; is set up, but not syncing automatically. Toggle “Auto-sync data” in Android Settings &gt; Data Usage.'>
<!ENTITY fxaccount_status_needs_master_sync_automatically_enabled_v21 '&syncBrand.shortName.label; is set up, but not syncing automatically. Toggle “Auto-sync data” in the menu of Android Settings &gt; Accounts.'>
<!ENTITY fxaccount_status_needs_finish_migrating 'Tap to sign in to your new Firefox Account.'>
<!ENTITY fxaccount_status_choose_what 'Choose what to sync'>
<!ENTITY fxaccount_status_bookmarks 'Bookmarks'>
<!ENTITY fxaccount_status_history 'History'>
<!ENTITY fxaccount_status_passwords2 'Logins'>
<!ENTITY fxaccount_status_tabs 'Open tabs'>
<!ENTITY fxaccount_status_additional_settings 'Additional Settings'>
<!ENTITY fxaccount_status_legal 'Legal' >
<!-- Localization note: when tapped, the following two strings link to
external web pages. Compare fxaccount_policy_{linktos,linkprivacy}:
@ -77,7 +76,6 @@
the two uses differently. -->
<!ENTITY fxaccount_status_linktos2 'Terms of service'>
<!ENTITY fxaccount_status_linkprivacy2 'Privacy notice'>
<!ENTITY fxaccount_status_more 'More&ellipsis;'>
<!ENTITY fxaccount_remove_account 'Disconnect&ellipsis;'>
<!ENTITY fxaccount_remove_account_dialog_title2 'Disconnect from Sync?'>

Просмотреть файл

@ -13,13 +13,13 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.text.format.DateUtils;
@ -86,17 +86,10 @@ public class FxAccountStatusFragment
private static final String[] STAGES_TO_SYNC_ON_DEVICE_NAME_CHANGE = new String[] { "clients" };
// By default, the auth/account server preference is only shown when the
// account is configured to use a custom server. In debug mode, this is set.
private static boolean ALWAYS_SHOW_AUTH_SERVER = false;
protected PreferenceCategory additionalSettingsCategory;
protected PreferenceCategory errorStatesCategory;
// By default, the Sync server preference is only shown when the account is
// configured to use a custom Sync server. In debug mode, this is set.
private static boolean ALWAYS_SHOW_SYNC_SERVER = false;
protected PreferenceCategory accountCategory;
protected Preference profilePreference;
protected Preference manageAccountPreference;
protected Preference authServerPreference;
protected Preference removeAccountPreference;
@ -106,17 +99,13 @@ public class FxAccountStatusFragment
protected Preference needsMasterSyncAutomaticallyEnabledPreference;
protected Preference needsFinishMigratingPreference;
protected PreferenceCategory syncCategory;
protected CheckBoxPreference bookmarksPreference;
protected CheckBoxPreference historyPreference;
protected CheckBoxPreference tabsPreference;
protected CheckBoxPreference passwordsPreference;
protected CheckBoxPreference readingListPreference;
protected SwitchPreference bookmarksPreference;
protected SwitchPreference historyPreference;
protected SwitchPreference tabsPreference;
protected SwitchPreference passwordsPreference;
protected EditTextPreference deviceNamePreference;
protected Preference syncServerPreference;
protected Preference morePreference;
protected Preference syncNowPreference;
protected volatile AndroidFxAccount fxAccount;
@ -165,9 +154,10 @@ public class FxAccountStatusFragment
protected void addPreferences() {
addPreferencesFromResource(R.xml.fxaccount_status_prefscreen);
accountCategory = (PreferenceCategory) ensureFindPreference("signed_in_as_category");
errorStatesCategory = (PreferenceCategory) ensureFindPreference("error_state");
additionalSettingsCategory = (PreferenceCategory) ensureFindPreference("additional_settings");
profilePreference = ensureFindPreference("profile");
manageAccountPreference = ensureFindPreference("manage_account");
authServerPreference = ensureFindPreference("auth_server");
removeAccountPreference = ensureFindPreference("remove_account");
@ -177,23 +167,12 @@ public class FxAccountStatusFragment
needsMasterSyncAutomaticallyEnabledPreference = ensureFindPreference("needs_master_sync_automatically_enabled");
needsFinishMigratingPreference = ensureFindPreference("needs_finish_migrating");
syncCategory = (PreferenceCategory) ensureFindPreference("sync_category");
bookmarksPreference = (CheckBoxPreference) ensureFindPreference("bookmarks");
historyPreference = (CheckBoxPreference) ensureFindPreference("history");
tabsPreference = (CheckBoxPreference) ensureFindPreference("tabs");
passwordsPreference = (CheckBoxPreference) ensureFindPreference("passwords");
if (!FxAccountUtils.LOG_PERSONAL_INFORMATION) {
removeDebugButtons();
} else {
connectDebugButtons();
ALWAYS_SHOW_AUTH_SERVER = true;
ALWAYS_SHOW_SYNC_SERVER = true;
}
bookmarksPreference = (SwitchPreference) ensureFindPreference("bookmarks");
historyPreference = (SwitchPreference) ensureFindPreference("history");
tabsPreference = (SwitchPreference) ensureFindPreference("tabs");
passwordsPreference = (SwitchPreference) ensureFindPreference("passwords");
profilePreference.setOnPreferenceClickListener(this);
manageAccountPreference.setOnPreferenceClickListener(this);
removeAccountPreference.setOnPreferenceClickListener(this);
needsPasswordPreference.setOnPreferenceClickListener(this);
@ -209,13 +188,19 @@ public class FxAccountStatusFragment
deviceNamePreference.setOnPreferenceChangeListener(this);
syncServerPreference = ensureFindPreference("sync_server");
morePreference = ensureFindPreference("more");
morePreference.setOnPreferenceClickListener(this);
syncNowPreference = ensureFindPreference("sync_now");
syncNowPreference.setEnabled(true);
syncNowPreference.setOnPreferenceClickListener(this);
if (!FxAccountUtils.LOG_PERSONAL_INFORMATION) {
removeDebugButtons();
} else {
connectDebugButtons();
}
updateAdditionalPreferences();
ensureFindPreference("linktos").setOnPreferenceClickListener(this);
ensureFindPreference("linkprivacy").setOnPreferenceClickListener(this);
}
@ -232,11 +217,6 @@ public class FxAccountStatusFragment
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == profilePreference) {
ActivityUtils.openURLInFennec(getActivity().getApplicationContext(), "about:accounts?action=avatar");
return true;
}
if (preference == manageAccountPreference) {
ActivityUtils.openURLInFennec(getActivity().getApplicationContext(), "about:accounts?action=manage");
return true;
}
@ -287,11 +267,6 @@ public class FxAccountStatusFragment
return true;
}
if (preference == morePreference) {
getActivity().openOptionsMenu();
return true;
}
if (preference == syncNowPreference) {
if (fxAccount != null) {
fxAccount.requestImmediateSync(null, null);
@ -329,6 +304,22 @@ public class FxAccountStatusFragment
* single error preference to show; if null, hide all error preferences
*/
protected void showOnlyOneErrorPreference(Preference errorPreferenceToShow) {
final PreferenceScreen statusScreen = (PreferenceScreen) ensureFindPreference("status_screen");
final boolean showShowErrorState = errorPreferenceToShow != null;
final boolean currentlyShowingErrorState = null != findPreference(errorStatesCategory.getKey());
if (currentlyShowingErrorState != showShowErrorState) {
if (showShowErrorState) {
statusScreen.addPreference(errorStatesCategory);
} else {
statusScreen.removePreference(errorStatesCategory);
}
}
if (!showShowErrorState) {
return;
}
final Preference[] errorPreferences = new Preference[] {
this.needsPasswordPreference,
this.needsUpgradePreference,
@ -337,39 +328,35 @@ public class FxAccountStatusFragment
this.needsFinishMigratingPreference,
};
for (Preference errorPreference : errorPreferences) {
final boolean currentlyShown = null != findPreference(errorPreference.getKey());
final boolean currentlyShown = null != errorStatesCategory.findPreference(errorPreference.getKey());
final boolean shouldBeShown = errorPreference == errorPreferenceToShow;
if (currentlyShown == shouldBeShown) {
continue;
}
if (shouldBeShown) {
syncCategory.addPreference(errorPreference);
errorStatesCategory.addPreference(errorPreference);
} else {
syncCategory.removePreference(errorPreference);
errorStatesCategory.removePreference(errorPreference);
}
}
}
protected void showNeedsPassword() {
syncCategory.setTitle(R.string.fxaccount_status_sync);
showOnlyOneErrorPreference(needsPasswordPreference);
setCheckboxesEnabled(false);
}
protected void showNeedsUpgrade() {
syncCategory.setTitle(R.string.fxaccount_status_sync);
showOnlyOneErrorPreference(needsUpgradePreference);
setCheckboxesEnabled(false);
}
protected void showNeedsVerification() {
syncCategory.setTitle(R.string.fxaccount_status_sync);
showOnlyOneErrorPreference(needsVerificationPreference);
setCheckboxesEnabled(false);
}
protected void showNeedsMasterSyncAutomaticallyEnabled() {
syncCategory.setTitle(R.string.fxaccount_status_sync);
needsMasterSyncAutomaticallyEnabledPreference.setTitle(AppConstants.Versions.preLollipop ?
R.string.fxaccount_status_needs_master_sync_automatically_enabled :
R.string.fxaccount_status_needs_master_sync_automatically_enabled_v21);
@ -378,19 +365,17 @@ public class FxAccountStatusFragment
}
protected void showNeedsFinishMigrating() {
syncCategory.setTitle(R.string.fxaccount_status_sync);
showOnlyOneErrorPreference(needsFinishMigratingPreference);
setCheckboxesEnabled(false);
}
protected void showConnected() {
syncCategory.setTitle(R.string.fxaccount_status_sync_enabled);
showOnlyOneErrorPreference(null);
setCheckboxesEnabled(true);
}
protected class InnerSyncStatusDelegate implements SyncStatusListener {
protected final Runnable refreshRunnable = new Runnable() {
private class InnerSyncStatusDelegate implements SyncStatusListener {
/* package-private */ final Runnable refreshRunnable = new Runnable() {
@Override
public void run() {
refresh();
@ -519,8 +504,7 @@ public class FxAccountStatusFragment
profileAvatarTarget = new PicassoPreferenceIconTarget(getResources(), profilePreference, cornerRadius);
updateProfileInformation();
updateAuthServerPreference();
updateSyncServerPreference();
updateAdditionalPreferences();
try {
// There are error states determined by Android, not the login state
@ -648,31 +632,52 @@ public class FxAccountStatusFragment
handler.postDelayed(lastSyncedTimeUpdateRunnable, LAST_SYNCED_TIME_UPDATE_INTERVAL_IN_MILLISECONDS);
}
protected void updateAuthServerPreference() {
private void updateAdditionalPreferences() {
// Ensure we have fxAccount; it's set in refresh().
if (fxAccount == null) {
return;
}
// In debug mode, everything is shown. Otherwise, we show those that have been customized.
final String authServer = fxAccount.getAccountServerURI();
final boolean shouldBeShown = ALWAYS_SHOW_AUTH_SERVER || !FxAccountConstants.DEFAULT_AUTH_SERVER_ENDPOINT.equals(authServer);
final boolean currentlyShown = null != findPreference(authServerPreference.getKey());
if (currentlyShown != shouldBeShown) {
final String syncServer = fxAccount.getTokenServerURI();
final boolean inDebugMode = FxAccountUtils.LOG_PERSONAL_INFORMATION;
final boolean authServerCustomized = !FxAccountConstants.DEFAULT_AUTH_SERVER_ENDPOINT.equals(authServer);
final boolean syncServerCustomized = !FxAccountConstants.DEFAULT_TOKEN_SERVER_ENDPOINT.equals(syncServer);
final boolean shouldBeShown = inDebugMode || authServerCustomized || syncServerCustomized;
final boolean additionalSettingsCategoryCurrentlyShown = null != findPreference(additionalSettingsCategory.getKey());
if (shouldBeShown != additionalSettingsCategoryCurrentlyShown) {
final PreferenceScreen statusScreen = (PreferenceScreen) ensureFindPreference("status_screen");
if (shouldBeShown) {
accountCategory.addPreference(authServerPreference);
statusScreen.addPreference(additionalSettingsCategory);
} else {
accountCategory.removePreference(authServerPreference);
statusScreen.removePreference(additionalSettingsCategory);
return;
}
}
final boolean showAuthServerPref = authServerCustomized || inDebugMode;
final boolean authServerPrefCurrentlyShown = null != findPreference(authServerPreference.getKey());
if (authServerPrefCurrentlyShown != showAuthServerPref) {
if (showAuthServerPref) {
additionalSettingsCategory.addPreference(authServerPreference);
} else {
additionalSettingsCategory.removePreference(authServerPreference);
}
}
// Always set the summary, because on first run, the preference is visible,
// and the above block will be skipped if there is a custom value.
authServerPreference.setSummary(authServer);
}
protected void updateSyncServerPreference() {
final String syncServer = fxAccount.getTokenServerURI();
final boolean shouldBeShown = ALWAYS_SHOW_SYNC_SERVER || !FxAccountConstants.DEFAULT_TOKEN_SERVER_ENDPOINT.equals(syncServer);
final boolean currentlyShown = null != findPreference(syncServerPreference.getKey());
if (currentlyShown != shouldBeShown) {
if (shouldBeShown) {
syncCategory.addPreference(syncServerPreference);
final boolean showSyncServerPref = syncServerCustomized || inDebugMode;
final boolean syncServerPrefCurrentlyShown = null != findPreference(syncServerPreference.getKey());
if (syncServerPrefCurrentlyShown != showSyncServerPref) {
if (showSyncServerPref) {
additionalSettingsCategory.addPreference(syncServerPreference);
} else {
syncCategory.removePreference(syncServerPreference);
additionalSettingsCategory.removePreference(syncServerPreference);
}
}
// Always set the summary, because on first run, the preference is visible,

Просмотреть файл

@ -5,7 +5,7 @@
android:background="@color/fxaccount_error_preference_backgroundcolor"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize" >
android:paddingRight="?android:attr/scrollbarSize">
<LinearLayout
android:layout_width="wrap_content"
@ -28,8 +28,10 @@
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginStart="15dip"
android:layout_marginRight="15dip"
android:layout_marginEnd="6dip"
android:layout_marginTop="0dp"
android:layout_weight="1" >
<TextView

Просмотреть файл

@ -4,28 +4,8 @@
android:key="status_screen">
<PreferenceCategory
android:key="signed_in_as_category"
android:title="@string/fxaccount_status_signed_in_as" >
<Preference
android:editable="false"
android:key="profile"
android:icon="@drawable/sync_avatar_default"
android:persistent="false"
android:title="" />
<Preference
android:editable="false"
android:key="manage_account"
android:persistent="false"
android:title="@string/fxaccount_status_manage_account" />
<Preference
android:editable="false"
android:key="auth_server"
android:persistent="false"
android:title="@string/fxaccount_status_auth_server" />
</PreferenceCategory>
<PreferenceCategory
android:key="sync_category"
android:title="@string/fxaccount_status_sync" >
android:key="error_state">
<Preference
android:editable="false"
android:icon="@drawable/fxaccount_sync_error"
@ -61,56 +41,73 @@
android:layout="@layout/fxaccount_status_error_preference"
android:persistent="false"
android:title="@string/fxaccount_status_needs_finish_migrating" />
</PreferenceCategory>
<Preference
android:editable="false"
android:key="sync_now"
android:defaultValue=""
android:persistent="false"
android:title="@string/fxaccount_status_sync_now"
android:summary="" />
<Preference
android:editable="false"
android:key="profile"
android:icon="@drawable/sync_avatar_default"
android:persistent="false"
android:title="" />
<CheckBoxPreference
<Preference
android:editable="false"
android:key="sync_now"
android:defaultValue=""
android:persistent="false"
android:title="@string/fxaccount_status_sync_now"
android:summary="" />
<PreferenceCategory
android:title="@string/fxaccount_status_choose_what">
<SwitchPreference
android:key="bookmarks"
android:persistent="false"
android:title="@string/fxaccount_status_bookmarks" />
<CheckBoxPreference
<SwitchPreference
android:key="history"
android:persistent="false"
android:title="@string/fxaccount_status_history" />
<CheckBoxPreference
<SwitchPreference
android:key="tabs"
android:persistent="false"
android:title="@string/fxaccount_status_tabs" />
<CheckBoxPreference
<SwitchPreference
android:key="passwords"
android:persistent="false"
android:title="@string/fxaccount_status_passwords" />
</PreferenceCategory>
<EditTextPreference
android:singleLine="true"
android:key="device_name"
<EditTextPreference
android:singleLine="true"
android:key="device_name"
android:persistent="false"
android:title="@string/fxaccount_status_device_name" />
<org.mozilla.gecko.fxa.activities.CustomColorPreference
android:editable="false"
android:key="remove_account"
android:persistent="false"
gecko:titleColor="@color/rejection_red"
android:title="@string/fxaccount_remove_account" />
<PreferenceCategory
android:key="additional_settings"
android:title="@string/fxaccount_status_additional_settings">
<Preference
android:editable="false"
android:key="auth_server"
android:persistent="false"
android:title="@string/fxaccount_status_device_name" />
android:title="@string/fxaccount_status_auth_server" />
<Preference
android:editable="false"
android:key="sync_server"
android:persistent="false"
android:title="@string/fxaccount_status_sync_server" />
<org.mozilla.gecko.fxa.activities.CustomColorPreference
android:editable="false"
android:key="remove_account"
android:persistent="false"
gecko:titleColor="@color/rejection_red"
android:title="@string/fxaccount_remove_account" />
<Preference
android:editable="false"
android:key="more"
android:persistent="false"
android:title="@string/fxaccount_status_more" />
</PreferenceCategory>
<PreferenceCategory
android:key="legal_category"
android:title="@string/fxaccount_status_legal" >
@ -125,6 +122,7 @@
android:persistent="false"
android:title="@string/fxaccount_status_linkprivacy" />
</PreferenceCategory>
<PreferenceCategory
android:key="debug_category" >
<Preference android:key="debug_refresh" />

Просмотреть файл

@ -29,8 +29,6 @@
<string name="fxaccount_getting_started_get_started">&fxaccount_getting_started_get_started;</string>
<string name="fxaccount_status_activity_label">&syncBrand.shortName.label;</string>
<string name="fxaccount_status_signed_in_as">&fxaccount_status_signed_in_as;</string>
<string name="fxaccount_status_manage_account">&fxaccount_status_manage_account;</string>
<string name="fxaccount_status_auth_server">&fxaccount_status_auth_server;</string>
<string name="fxaccount_status_sync_now">&fxaccount_status_sync_now;</string>
<string name="fxaccount_status_syncing">&fxaccount_status_syncing2;</string>
@ -39,21 +37,21 @@
<string name="fxaccount_status_device_name">&fxaccount_status_device_name;</string>
<string name="fxaccount_status_sync_server">&fxaccount_status_sync_server;</string>
<string name="fxaccount_status_sync">&fxaccount_status_sync;</string>
<string name="fxaccount_status_sync_enabled">&fxaccount_status_sync_enabled;</string>
<string name="fxaccount_status_needs_verification">&fxaccount_status_needs_verification2;</string>
<string name="fxaccount_status_needs_credentials">&fxaccount_status_needs_credentials;</string>
<string name="fxaccount_status_needs_upgrade">&fxaccount_status_needs_upgrade;</string>
<string name="fxaccount_status_needs_master_sync_automatically_enabled">&fxaccount_status_needs_master_sync_automatically_enabled;</string>
<string name="fxaccount_status_needs_master_sync_automatically_enabled_v21">&fxaccount_status_needs_master_sync_automatically_enabled_v21;</string>
<string name="fxaccount_status_needs_finish_migrating">&fxaccount_status_needs_finish_migrating;</string>
<string name="fxaccount_status_choose_what">&fxaccount_status_choose_what;</string>
<string name="fxaccount_status_bookmarks">&fxaccount_status_bookmarks;</string>
<string name="fxaccount_status_history">&fxaccount_status_history;</string>
<string name="fxaccount_status_passwords">&fxaccount_status_passwords2;</string>
<string name="fxaccount_status_tabs">&fxaccount_status_tabs;</string>
<string name="fxaccount_status_additional_settings">&fxaccount_status_additional_settings;</string>
<string name="fxaccount_status_legal">&fxaccount_status_legal;</string>
<string name="fxaccount_status_linktos">&fxaccount_status_linktos2;</string>
<string name="fxaccount_status_linkprivacy">&fxaccount_status_linkprivacy2;</string>
<string name="fxaccount_status_more">&fxaccount_status_more;</string>
<string name="fxaccount_remove_account">&fxaccount_remove_account;</string>
<string name="fxaccount_label">&fxaccount_account_type_label;</string>