Use "show pictures" code from UnifiedEmail
Bug: 9320770 Change-Id: I701a93e2f09b8405a2c4bc56f7793f5abadbcd1e
This commit is contained in:
parent
0ec8c365e7
commit
38f22dbf08
@ -1160,17 +1160,10 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
|
||||
<!-- General preference: Text zoom. Value is "huge" (+2) [CHAR LIMIT=32] -->
|
||||
<string name="general_preference_text_zoom_huge">Huge</string>
|
||||
|
||||
<!-- Settings screen, title used to clear the setting for the list of
|
||||
senders to automatically show pictures for [CHAR LIMIT=80] -->
|
||||
<string name="general_preferences_clear_trusted_senders_title"
|
||||
>Ask to show pictures</string>
|
||||
<!-- Settings screen, summary for clearing the settings for the list of
|
||||
senders to automatically show pictures for [CHAR LIMIT=160] -->
|
||||
<string name="general_preferences_clear_trusted_senders_summary"
|
||||
>Pictures in messages won\'t be shown automatically</string>
|
||||
<!-- Message shown in toast when the user taps to clear the lsit of senders
|
||||
to automatically show pictures for [CHAR LIMIT=80] -->
|
||||
<string name="trusted_senders_cleared">\"Show pictures\" cleared.</string>
|
||||
|
||||
<!-- Generic string for "current position" / "total number" [CHAR LIMIT=12] -->
|
||||
<string name="position_of_count"><xliff:g example="1">%1$d</xliff:g> of <xliff:g
|
||||
|
@ -70,9 +70,4 @@
|
||||
android:title="@string/preference_swipe_title_delete"
|
||||
android:summary="@string/preference_swipe_description" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="clear_trusted_senders"
|
||||
android:title="@string/general_preferences_clear_trusted_senders_title"
|
||||
android:summary="@string/general_preferences_clear_trusted_senders_summary" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@ -27,7 +27,9 @@ import com.android.mail.utils.LogUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Preferences {
|
||||
@ -84,13 +86,6 @@ public class Preferences {
|
||||
|
||||
private final SharedPreferences mSharedPreferences;
|
||||
|
||||
/**
|
||||
* A set of trusted senders for whom images and external resources should automatically be
|
||||
* loaded for.
|
||||
* Lazilly created.
|
||||
*/
|
||||
private HashSet<String> mTrustedSenders = null;
|
||||
|
||||
private Preferences(Context context) {
|
||||
mSharedPreferences = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
|
||||
}
|
||||
@ -263,45 +258,15 @@ public class Preferences {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not a sender should be trusted and images should automatically be
|
||||
* shown for messages by that sender.
|
||||
* @deprecated This has been moved to {@link com.android.mail.preferences.MailPrefs}, and is only here for migration.
|
||||
*/
|
||||
public boolean shouldShowImagesFor(String email) {
|
||||
if (mTrustedSenders == null) {
|
||||
try {
|
||||
mTrustedSenders = parseEmailSet(mSharedPreferences.getString(TRUSTED_SENDERS, ""));
|
||||
} catch (JSONException e) {
|
||||
// Something went wrong, and the data is corrupt. Just clear it to be safe.
|
||||
LogUtils.w(Logging.LOG_TAG, "Trusted sender set corrupted. Clearing");
|
||||
mSharedPreferences.edit().putString(TRUSTED_SENDERS, "").apply();
|
||||
mTrustedSenders = new HashSet<String>();
|
||||
}
|
||||
@Deprecated
|
||||
public Set<String> getWhitelistedSenderAddresses() {
|
||||
try {
|
||||
return parseEmailSet(mSharedPreferences.getString(TRUSTED_SENDERS, ""));
|
||||
} catch (JSONException e) {
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
return mTrustedSenders.contains(email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a sender as trusted so that images from that sender will automatically be shown.
|
||||
*/
|
||||
public void setSenderAsTrusted(String email) {
|
||||
if (!mTrustedSenders.contains(email)) {
|
||||
mTrustedSenders.add(email);
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putString(TRUSTED_SENDERS, packEmailSet(mTrustedSenders))
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all trusted senders asynchronously.
|
||||
*/
|
||||
public void clearTrustedSenders() {
|
||||
mTrustedSenders = new HashSet<String>();
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putString(TRUSTED_SENDERS, packEmailSet(mTrustedSenders))
|
||||
.apply();
|
||||
}
|
||||
|
||||
HashSet<String> parseEmailSet(String serialized) throws JSONException {
|
||||
|
@ -33,6 +33,7 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.KeyEvent;
|
||||
@ -51,8 +52,11 @@ import com.android.emailcommon.service.ServiceProxy;
|
||||
import com.android.emailcommon.utility.IntentUtilities;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
import com.android.mail.providers.Folder;
|
||||
import com.android.mail.providers.UIProvider;
|
||||
import com.android.mail.providers.UIProvider.EditSettingsExtras;
|
||||
import com.android.mail.ui.FeedbackEnabledActivity;
|
||||
import com.android.mail.utils.LogUtils;
|
||||
import com.android.mail.utils.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -71,7 +75,7 @@ import java.util.List;
|
||||
* sense to use a loader for the accounts list, because it would provide better support for
|
||||
* dealing with accounts being added/deleted and triggering the header reload.
|
||||
*/
|
||||
public class AccountSettings extends PreferenceActivity {
|
||||
public class AccountSettings extends PreferenceActivity implements FeedbackEnabledActivity {
|
||||
/*
|
||||
* Intent to open account settings for account=1
|
||||
adb shell am start -a android.intent.action.EDIT \
|
||||
@ -284,6 +288,10 @@ public class AccountSettings extends PreferenceActivity {
|
||||
case R.id.add_new_account:
|
||||
onAddNewAccount();
|
||||
break;
|
||||
case R.id.feedback_menu_item:
|
||||
final Uri feedbackUri = Utils.getValidUri(getString(R.string.email_feedback_uri));
|
||||
Utils.sendFeedback(this, feedbackUri, false /* reportingProblem */);
|
||||
break;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@ -883,4 +891,9 @@ public class AccountSettings extends PreferenceActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getActivityContext() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,15 @@ import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.widget.Toast;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.email.Preferences;
|
||||
import com.android.email.R;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.mail.preferences.MailPrefs;
|
||||
import com.android.mail.utils.Utils;
|
||||
import com.android.mail.ui.settings.ClearPictureApprovalsDialogFragment;
|
||||
|
||||
public class GeneralPreferences extends EmailPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
@ -39,7 +41,6 @@ public class GeneralPreferences extends EmailPreferenceFragment implements
|
||||
private static final String PREFERENCE_KEY_CONFIRM_DELETE = "confirm_delete";
|
||||
private static final String PREFERENCE_KEY_CONFIRM_SEND = "confirm_send";
|
||||
private static final String PREFERENCE_KEY_CONV_LIST_ICON = "conversation_list_icon";
|
||||
private static final String PREFERENCE_KEY_CLEAR_TRUSTED_SENDERS = "clear_trusted_senders";
|
||||
|
||||
private MailPrefs mMailPrefs;
|
||||
private Preferences mPreferences;
|
||||
@ -121,12 +122,7 @@ public class GeneralPreferences extends EmailPreferenceFragment implements
|
||||
}
|
||||
mSettingsChanged = true;
|
||||
String key = preference.getKey();
|
||||
if (key.equals(PREFERENCE_KEY_CLEAR_TRUSTED_SENDERS)) {
|
||||
mPreferences.clearTrustedSenders();
|
||||
Toast.makeText(
|
||||
getActivity(), R.string.trusted_senders_cleared, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
} else if (PREFERENCE_KEY_CONFIRM_DELETE.equals(key)) {
|
||||
if (PREFERENCE_KEY_CONFIRM_DELETE.equals(key)) {
|
||||
mPreferences.setConfirmDelete(mConfirmDelete.isChecked());
|
||||
return true;
|
||||
} else if (PREFERENCE_KEY_CONFIRM_SEND.equals(key)) {
|
||||
@ -189,4 +185,29 @@ public class GeneralPreferences extends EmailPreferenceFragment implements
|
||||
mTextZoom.setSummary(summary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.clear();
|
||||
inflater.inflate(R.menu.general_prefs_fragment_menu, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.clear_picture_approvals_menu_item:
|
||||
clearDisplayImages();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void clearDisplayImages() {
|
||||
final ClearPictureApprovalsDialogFragment fragment =
|
||||
ClearPictureApprovalsDialogFragment.newInstance();
|
||||
fragment.show(getActivity().getFragmentManager(),
|
||||
ClearPictureApprovalsDialogFragment.FRAGMENT_TAG);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2210,10 +2210,10 @@ public class EmailProvider extends ContentProvider {
|
||||
}
|
||||
Address[] fromList = Address.unpack(msg.mFrom);
|
||||
int autoShowImages = 0;
|
||||
Preferences prefs = Preferences.getPreferences(context);
|
||||
final MailPrefs mailPrefs = MailPrefs.get(context);
|
||||
for (Address sender : fromList) {
|
||||
String email = sender.getAddress();
|
||||
if (prefs.shouldShowImagesFor(email)) {
|
||||
final String email = sender.getAddress();
|
||||
if (mailPrefs.getDisplayImagesFromSender(email)) {
|
||||
autoShowImages = 1;
|
||||
break;
|
||||
}
|
||||
@ -3875,10 +3875,10 @@ public class EmailProvider extends ContentProvider {
|
||||
}
|
||||
} else if (columnName.equals(UIProvider.MessageColumns.ALWAYS_SHOW_IMAGES)) {
|
||||
Address[] fromList = Address.unpack(message.mFrom);
|
||||
Preferences prefs = Preferences.getPreferences(getContext());
|
||||
final MailPrefs mailPrefs = MailPrefs.get(getContext());
|
||||
for (Address sender : fromList) {
|
||||
String email = sender.getAddress();
|
||||
prefs.setSenderAsTrusted(email);
|
||||
final String email = sender.getAddress();
|
||||
mailPrefs.setDisplayImagesFromSender(email, null);
|
||||
}
|
||||
} else if (columnName.equals(UIProvider.ConversationColumns.VIEWED) ||
|
||||
columnName.equals(UIProvider.ConversationOperations.Parameters.SUPPRESS_UNDO)) {
|
||||
|
@ -31,6 +31,7 @@ import com.android.mail.utils.LogUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Migrates Email settings to UnifiedEmail
|
||||
@ -65,10 +66,10 @@ public class PreferenceMigrator extends BasePreferenceMigrator {
|
||||
|
||||
protected static void migrate(final Context context, final int oldVersion, final int newVersion,
|
||||
final List<Account> accounts) {
|
||||
final Preferences preferences = Preferences.getPreferences(context);
|
||||
final MailPrefs mailPrefs = MailPrefs.get(context);
|
||||
if (oldVersion < 1) {
|
||||
// Move global settings
|
||||
final Preferences preferences = Preferences.getPreferences(context);
|
||||
final MailPrefs mailPrefs = MailPrefs.get(context);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
final boolean hasSwipeDelete = preferences.hasSwipeDelete();
|
||||
@ -139,5 +140,12 @@ public class PreferenceMigrator extends BasePreferenceMigrator {
|
||||
folderPreferences.commit();
|
||||
}
|
||||
}
|
||||
|
||||
if (oldVersion < 2) {
|
||||
@SuppressWarnings("deprecation")
|
||||
final Set<String> whitelistedAddresses = preferences.getWhitelistedSenderAddresses();
|
||||
mailPrefs.setSenderWhitelist(whitelistedAddresses);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user