1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Fixes issue 1522

Added option to automatically show images in message view (always, if sender is in contacts, never).
Patch by paulkilroy (thanks!)

Includes bugfix for the "Show pictures" on orientation change code introduced earlier.
This commit is contained in:
cketti 2010-08-07 22:38:08 +00:00
parent 9d45470b40
commit 43fb202d43
6 changed files with 209 additions and 98 deletions

View File

@ -165,6 +165,18 @@
<item>ALWAYS</item>
</string-array>
<string-array name="account_settings_show_pictures_entries">
<item>@string/account_settings_show_pictures_never</item>
<item>@string/account_settings_show_pictures_only_from_contacts</item>
<item>@string/account_settings_show_pictures_always</item>
</string-array>
<string-array name="account_settings_show_pictures_values">
<item>NEVER</item>
<item>ONLY_FROM_CONTACTS</item>
<item>ALWAYS</item>
</string-array>
<string-array name="account_settings_searchable_entries">
<item>@string/account_settings_searchable_all</item>
<item>@string/account_settings_searchable_displayable</item>
@ -506,7 +518,6 @@
<item>@string/date_format_iso8601</item>
</string-array>
<string-array name="font_entries">
<item>@string/font_size_tiniest</item>
<item>@string/font_size_tiny</item>

View File

@ -505,6 +505,11 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="account_settings_enable_move_buttons_summary">Show the Archive, Move, and Spam buttons.</string>
<string name="account_settings_hide_move_buttons_label">Scroll move buttons</string>
<string name="account_settings_show_pictures_label">Show pictures automatically</string>
<string name="account_settings_show_pictures_never">Never</string>
<string name="account_settings_show_pictures_only_from_contacts">Only from contacts</string>
<string name="account_settings_show_pictures_always">Always</string>
<string name="account_settings_composition">Writing messages</string>
<string name="account_settings_sync">Syncing folders</string>
<string name="account_settings_folders">Folders</string>

View File

@ -30,6 +30,7 @@
android:key="account_default"
android:title="@string/account_settings_default_label"
android:summary="@string/account_settings_default_summary" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/account_settings_message_lists">
@ -45,14 +46,14 @@
android:key="chip_color"
android:singleLine="true"
android:title="@string/account_settings_color_label"
android:summary="@string/account_settings_color_summary"
/>
android:summary="@string/account_settings_color_summary" />
<Preference
android:key="led_color"
android:singleLine="true"
android:title="@string/account_settings_led_color_label"
android:summary="@string/account_settings_led_color_summary"
/>
android:summary="@string/account_settings_led_color_summary" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/account_settings_message_view">
@ -78,9 +79,17 @@
android:entryValues="@array/account_settings_hide_move_buttons_values"
android:dialogTitle="@string/account_settings_hide_move_buttons_label" />
<ListPreference
android:key="show_pictures_enum"
android:title="@string/account_settings_show_pictures_label"
android:entries="@array/account_settings_show_pictures_entries"
android:entryValues="@array/account_settings_show_pictures_values"
android:dialogTitle="@string/account_settings_show_pictures_label" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/account_settings_sync">
<ListPreference
android:key="account_check_frequency"
android:title="@string/account_settings_mail_check_frequency_label"
@ -139,8 +148,7 @@
<PreferenceScreen
android:key="incoming"
android:title="@string/account_settings_incoming_label"
android:summary="@string/account_settings_incoming_summary"
/>
android:summary="@string/account_settings_incoming_summary" />
</PreferenceCategory>
@ -150,8 +158,8 @@
android:key="account_setup_auto_expand_folder"
android:singleLine="true"
android:title="@string/account_setup_auto_expand_folder"
android:summary=""
/>
android:summary="" />
<ListPreference
android:key="folder_display_mode"
android:title="@string/account_settings_folder_display_mode_label"
@ -181,22 +189,17 @@
<PreferenceScreen
android:key="composition"
android:summary="@string/account_settings_composition_summary"
android:title="@string/account_settings_composition_label"
/>
android:title="@string/account_settings_composition_label" />
<PreferenceScreen
android:key="manage_identities"
android:title="@string/account_settings_identities_label"
android:summary="@string/account_settings_identities_summary"
/>
android:summary="@string/account_settings_identities_summary" />
<PreferenceScreen
android:key="outgoing"
android:title="@string/account_settings_outgoing_label"
android:summary="@string/account_settings_outgoing_summary"
/>
android:summary="@string/account_settings_outgoing_summary" />
<EditTextPreference
android:key="account_quote_prefix"
@ -221,6 +224,7 @@
android:title="@string/account_settings_crypto_auto_signature"
android:summary="@string/account_settings_crypto_auto_signature_summary"
android:dependency="crypto_app"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/account_settings_notifications">
@ -253,6 +257,7 @@
android:defaultValue="false"
android:title="@string/account_settings_vibrate_enable"
android:summary="@string/account_settings_vibrate_summary" />
<ListPreference
android:dependency="account_vibrate"
android:key="account_vibrate_pattern"
@ -260,6 +265,7 @@
android:entries="@array/account_settings_vibrate_pattern_entries"
android:entryValues="@array/account_settings_vibrate_pattern_values"
android:dialogTitle="@string/account_settings_vibrate_pattern_label" />
<EditTextPreference
android:dependency="account_vibrate"
android:key="account_vibrate_times"
@ -274,6 +280,7 @@
android:title="@string/account_settings_notify_sync_label"
android:defaultValue="true"
android:summary="@string/account_settings_notify_sync_summary" />
<CheckBoxPreference
android:key="notification_opens_unread"
android:title="@string/account_settings_notification_opens_unread_label"

View File

@ -92,6 +92,7 @@ public class Account implements BaseAccount
private boolean mNotifySync;
private HideButtons mHideMessageViewButtons;
private HideButtons mHideMessageViewMoveButtons;
private ShowPictures mShowPictures;
private boolean mEnableMoveButtons;
private boolean mIsSignatureBeforeQuotedText;
private String mExpungePolicy = EXPUNGE_IMMEDIATELY;
@ -131,6 +132,11 @@ public class Account implements BaseAccount
NEVER, ALWAYS, KEYBOARD_AVAILABLE;
}
public enum ShowPictures
{
NEVER, ALWAYS, ONLY_FROM_CONTACTS;
}
public enum Searchable
{
ALL, DISPLAYABLE, NONE
@ -160,6 +166,7 @@ public class Account implements BaseAccount
mFolderTargetMode = FolderMode.NOT_SECOND_CLASS;
mHideMessageViewButtons = HideButtons.NEVER;
mHideMessageViewMoveButtons = HideButtons.NEVER;
mShowPictures = ShowPictures.NEVER;
mEnableMoveButtons = false;
mRingtoneUri = "content://settings/system/notification_sound";
mIsSignatureBeforeQuotedText = false;
@ -303,6 +310,16 @@ public class Account implements BaseAccount
mHideMessageViewMoveButtons = HideButtons.NEVER;
}
try
{
mShowPictures = ShowPictures.valueOf(prefs.getString(mUuid + ".showPicturesEnum",
ShowPictures.NEVER.name()));
}
catch (Exception e)
{
mShowPictures = ShowPictures.NEVER;
}
mEnableMoveButtons = prefs.getBoolean(mUuid + ".enableMoveButtons", false);
mRingtoneUri = prefs.getString(mUuid + ".ringtone",
@ -506,6 +523,7 @@ public class Account implements BaseAccount
editor.putBoolean(mUuid + ".ring", mRing);
editor.putString(mUuid + ".hideButtonsEnum", mHideMessageViewButtons.name());
editor.putString(mUuid + ".hideMoveButtonsEnum", mHideMessageViewMoveButtons.name());
editor.putString(mUuid + ".showPicturesEnum", mShowPictures.name());
editor.putBoolean(mUuid + ".enableMoveButtons", mEnableMoveButtons);
editor.putString(mUuid + ".ringtone", mRingtoneUri);
editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name());
@ -1008,6 +1026,16 @@ public class Account implements BaseAccount
mHideMessageViewMoveButtons = hideMessageViewButtons;
}
public synchronized ShowPictures getShowPictures()
{
return mShowPictures;
}
public synchronized void setShowPictures(ShowPictures showPictures)
{
mShowPictures = showPictures;
}
public synchronized FolderMode getFolderTargetMode()
{
return mFolderTargetMode;

View File

@ -55,6 +55,9 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.database.Cursor;
import com.fsck.k9.Account;
import com.fsck.k9.FontSizes;
@ -1669,12 +1672,19 @@ public class MessageView extends K9Activity implements OnClickListener
setLoadPictures(true);
}
/**
* Enable/disable image loading of the WebView. But always hide the
* "Show pictures" button!
*
* @param enable true, if (network) images should be loaded.
* false, otherwise.
*/
private void setLoadPictures(boolean enable)
{
K9.setBlockNetworkLoads(mMessageContentView.getSettings(), !enable);
mMessageContentView.getSettings().setBlockNetworkImage(!enable);
mShowPictures = enable;
mHandler.showShowPictures(!enable);
mHandler.showShowPictures(false);
}
public void onClick(View view)
@ -2148,9 +2158,42 @@ public class MessageView extends K9Activity implements OnClickListener
updateDecryptLayout();
}
});
if (mShowPictures == false)
// TODO: Only check for external (non inline) images
final boolean hasPictures = text.contains("<img");
// If the message contains pictures and the "Show pictures"
// button wasn't already pressed...
if (hasPictures && (mShowPictures == false))
{
mHandler.showShowPictures(text.contains("<img"));
boolean forceShowPictures = false;
if (account.getShowPictures() == Account.ShowPictures.ALWAYS)
{
forceShowPictures = true;
}
else if (account.getShowPictures() == Account.ShowPictures.ONLY_FROM_CONTACTS)
{
// TODO: change to _COUNT for speed
Cursor c = getContentResolver().query(Data.CONTENT_URI, new String[]{Data._ID},
Data.MIMETYPE + "='" + Email.CONTENT_ITEM_TYPE + "' AND "
+ Data.DATA1 + "=? AND "
+ Data.IN_VISIBLE_GROUP + "='1'",
new String[] { message.getFrom()[0].getAddress() }, null);
if ((c != null) && (c.getCount() > 0))
{
forceShowPictures = true;
}
}
if (forceShowPictures)
{
onShowPictures();
}
else
{
mHandler.showShowPictures(true);
}
}
}
else

View File

@ -44,6 +44,7 @@ public class AccountSettings extends K9PreferenceActivity
private static final String PREFERENCE_DEFAULT = "account_default";
private static final String PREFERENCE_HIDE_BUTTONS = "hide_buttons_enum";
private static final String PREFERENCE_HIDE_MOVE_BUTTONS = "hide_move_buttons_enum";
private static final String PREFERENCE_SHOW_PICTURES = "show_pictures_enum";
private static final String PREFERENCE_ENABLE_MOVE_BUTTONS = "enable_move_buttons";
private static final String PREFERENCE_NOTIFY = "account_notify";
private static final String PREFERENCE_NOTIFY_SELF = "account_notify_self";
@ -84,6 +85,7 @@ public class AccountSettings extends K9PreferenceActivity
private CheckBoxPreference mAccountNotifySelf;
private ListPreference mAccountHideButtons;
private ListPreference mAccountHideMoveButtons;
private ListPreference mAccountShowPictures;
private CheckBoxPreference mAccountEnableMoveButtons;
private CheckBoxPreference mAccountNotifySync;
private CheckBoxPreference mAccountVibrate;
@ -124,10 +126,9 @@ public class AccountSettings extends K9PreferenceActivity
boolean isPushCapable = false;
boolean isExpungeCapable = false;
Store store = null;
try
{
store = mAccount.getRemoteStore();
final Store store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
isExpungeCapable = store.isExpungeCapable();
}
@ -383,6 +384,21 @@ public class AccountSettings extends K9PreferenceActivity
}
});
mAccountShowPictures = (ListPreference) findPreference(PREFERENCE_SHOW_PICTURES);
mAccountShowPictures.setValue("" + mAccount.getShowPictures());
mAccountShowPictures.setSummary(mAccountShowPictures.getEntry());
mAccountShowPictures.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
public boolean onPreferenceChange(Preference preference, Object newValue)
{
final String summary = newValue.toString();
int index = mAccountShowPictures.findIndexOfValue(summary);
mAccountShowPictures.setSummary(mAccountShowPictures.getEntries()[index]);
mAccountShowPictures.setValue(summary);
return false;
}
});
mAccountNotify = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY);
mAccountNotify.setChecked(mAccount.isNotifyNewMail());
@ -633,6 +649,7 @@ public class AccountSettings extends K9PreferenceActivity
mAccount.setHideMessageViewButtons(Account.HideButtons.valueOf(mAccountHideButtons.getValue()));
mAccount.setHideMessageViewMoveButtons(Account.HideButtons.valueOf(mAccountHideMoveButtons.getValue()));
mAccount.setShowPictures(Account.ShowPictures.valueOf(mAccountShowPictures.getValue()));
mAccount.setEnableMoveButtons(mAccountEnableMoveButtons.isChecked());
mAccount.setAutoExpandFolderName(reverseTranslateFolder(mAutoExpandFolder.getSummary().toString()));
mAccount.save(Preferences.getPreferences(this));