From a51b608e5e5bc0513c1ff4400aaf2c8fb9388675 Mon Sep 17 00:00:00 2001 From: ligi Date: Thu, 29 Jan 2015 16:36:15 +0100 Subject: [PATCH] Reduce MessageCompos LOC --- .../com/fsck/k9/activity/MessageCompose.java | 54 ++++--------------- .../com/fsck/k9/helper/SimpleTextWatcher.java | 22 ++++++++ 2 files changed, 32 insertions(+), 44 deletions(-) create mode 100644 k9mail/src/main/java/com/fsck/k9/helper/SimpleTextWatcher.java diff --git a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java index a75b3ebd6..c3e05d5d3 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java @@ -88,6 +88,7 @@ import com.fsck.k9.crypto.PgpData; import com.fsck.k9.fragment.ProgressDialogFragment; import com.fsck.k9.helper.ContactItem; import com.fsck.k9.helper.Contacts; +import com.fsck.k9.helper.SimpleTextWatcher; import com.fsck.k9.mail.filter.Base64; import com.fsck.k9.helper.HtmlConverter; import com.fsck.k9.helper.IdentityHelper; @@ -615,63 +616,28 @@ public class MessageCompose extends K9Activity implements OnClickListener, } }); - TextWatcher watcher = new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int before, int after) { - /* do nothing */ - } - + TextWatcher draftNeedsChangingTextWatcher = new SimpleTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { mDraftNeedsSaving = true; } - - @Override - public void afterTextChanged(android.text.Editable s) { /* do nothing */ } }; - // For watching changes to the To:, Cc:, and Bcc: fields for auto-encryption on a matching - // address. - TextWatcher recipientWatcher = new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int before, int after) { - /* do nothing */ - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - mDraftNeedsSaving = true; - } - - @Override - public void afterTextChanged(android.text.Editable s) { - /* do nothing */ - } - }; - - TextWatcher sigwatcher = new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int before, int after) { - /* do nothing */ - } - + TextWatcher signTextWatcher = new SimpleTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { mDraftNeedsSaving = true; mSignatureChanged = true; } - - @Override - public void afterTextChanged(android.text.Editable s) { /* do nothing */ } }; - mToView.addTextChangedListener(recipientWatcher); - mCcView.addTextChangedListener(recipientWatcher); - mBccView.addTextChangedListener(recipientWatcher); - mSubjectView.addTextChangedListener(watcher); + mToView.addTextChangedListener(draftNeedsChangingTextWatcher); + mCcView.addTextChangedListener(draftNeedsChangingTextWatcher); + mBccView.addTextChangedListener(draftNeedsChangingTextWatcher); + mSubjectView.addTextChangedListener(draftNeedsChangingTextWatcher); - mMessageContentView.addTextChangedListener(watcher); - mQuotedText.addTextChangedListener(watcher); + mMessageContentView.addTextChangedListener(draftNeedsChangingTextWatcher); + mQuotedText.addTextChangedListener(draftNeedsChangingTextWatcher); /* Yes, there really are people who ship versions of android without a contact picker */ if (mContacts.hasContactPicker()) { @@ -759,7 +725,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, mSignatureView = lowerSignature; upperSignature.setVisibility(View.GONE); } - mSignatureView.addTextChangedListener(sigwatcher); + mSignatureView.addTextChangedListener(signTextWatcher); if (!mIdentity.getSignatureUse()) { mSignatureView.setVisibility(View.GONE); diff --git a/k9mail/src/main/java/com/fsck/k9/helper/SimpleTextWatcher.java b/k9mail/src/main/java/com/fsck/k9/helper/SimpleTextWatcher.java new file mode 100644 index 000000000..94c2cc7b4 --- /dev/null +++ b/k9mail/src/main/java/com/fsck/k9/helper/SimpleTextWatcher.java @@ -0,0 +1,22 @@ +package com.fsck.k9.helper; + +import android.text.Editable; +import android.text.TextWatcher; + +/** + * all methods empty - but this way we can have TextWatchers with less boilder-plate where + * we just override the methods we want and not always al 3 + */ +public class SimpleTextWatcher implements TextWatcher { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + } +}