mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-31 07:10:14 -05:00
Avoid creating new objects for handling click events
This commit is contained in:
parent
9f42ff61d3
commit
ec6645bf6a
@ -10,6 +10,7 @@ import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
@ -33,7 +34,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.text.DateFormat;
|
||||
|
||||
public class MessageHeader extends ScrollView {
|
||||
public class MessageHeader extends ScrollView implements OnClickListener {
|
||||
private Context mContext;
|
||||
private TextView mFromView;
|
||||
private TextView mDateView;
|
||||
@ -54,7 +55,6 @@ public class MessageHeader extends ScrollView {
|
||||
private Account mAccount;
|
||||
private FontSizes mFontSizes = K9.getFontSizes();
|
||||
private Contacts mContacts;
|
||||
private View mAdditionalHeadersArea;
|
||||
private ImageView mShowAdditionalHeadersIcon;
|
||||
|
||||
/**
|
||||
@ -91,7 +91,6 @@ public class MessageHeader extends ScrollView {
|
||||
mDateView = (TextView) findViewById(R.id.date);
|
||||
mTimeView = (TextView) findViewById(R.id.time);
|
||||
mFlagged = (CheckBox) findViewById(R.id.flagged);
|
||||
mAdditionalHeadersArea = findViewById(R.id.show_additional_headers_area);
|
||||
mShowAdditionalHeadersIcon = (ImageView) findViewById(R.id.show_additional_headers_icon);
|
||||
|
||||
|
||||
@ -109,26 +108,33 @@ public class MessageHeader extends ScrollView {
|
||||
((TextView) findViewById(R.id.to_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTo());
|
||||
((TextView) findViewById(R.id.cc_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewCC());
|
||||
|
||||
mAdditionalHeadersArea.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onShowAdditionalHeaders();
|
||||
}
|
||||
});
|
||||
findViewById(R.id.show_additional_headers_area).setOnClickListener(this);
|
||||
mFromView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
mFromView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mMessage != null) {
|
||||
try {
|
||||
final Address senderEmail = mMessage.getFrom()[0];
|
||||
mContacts.createContact(senderEmail);
|
||||
} catch (Exception e) {
|
||||
Log.e(K9.LOG_TAG, "Couldn't create contact", e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.show_additional_headers_area: {
|
||||
onShowAdditionalHeaders();
|
||||
break;
|
||||
}
|
||||
});
|
||||
case R.id.from: {
|
||||
onAddSenderToContacts();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onAddSenderToContacts() {
|
||||
if (mMessage != null) {
|
||||
try {
|
||||
final Address senderEmail = mMessage.getFrom()[0];
|
||||
mContacts.createContact(senderEmail);
|
||||
} catch (Exception e) {
|
||||
Log.e(K9.LOG_TAG, "Couldn't create contact", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnFlagListener(OnClickListener listener) {
|
||||
|
@ -12,6 +12,7 @@ import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import com.fsck.k9.Account;
|
||||
@ -29,7 +30,7 @@ import com.fsck.k9.mail.store.LocalStore;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SingleMessageView extends LinearLayout {
|
||||
public class SingleMessageView extends LinearLayout implements OnClickListener {
|
||||
private boolean mScreenReaderEnabled;
|
||||
private MessageCryptoView mCryptoView;
|
||||
private MessageWebView mMessageContentView;
|
||||
@ -65,39 +66,13 @@ public class SingleMessageView extends LinearLayout {
|
||||
mHiddenAttachments.setVisibility(View.GONE);
|
||||
mShowHiddenAttachments = (Button) findViewById(R.id.show_hidden_attachments);
|
||||
mShowHiddenAttachments.setVisibility(View.GONE);
|
||||
mShowHiddenAttachments.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
mShowHiddenAttachments.setVisibility(View.GONE);
|
||||
mHiddenAttachments.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
mCryptoView = (MessageCryptoView) findViewById(R.id.layout_decrypt);
|
||||
mCryptoView.setActivity(activity);
|
||||
mCryptoView.setupChildViews();
|
||||
mShowPicturesAction = findViewById(R.id.show_pictures);
|
||||
mShowMessageAction = findViewById(R.id.show_message);
|
||||
mShowMessageAction.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showShowMessageAction(false);
|
||||
showAttachments(false);
|
||||
showMessageWebView(true);
|
||||
showShowAttachmentsAction(true);
|
||||
}
|
||||
});
|
||||
|
||||
mShowAttachmentsAction = findViewById(R.id.show_attachments);
|
||||
mShowAttachmentsAction.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showMessageWebView(false);
|
||||
showShowAttachmentsAction(false);
|
||||
showShowMessageAction(true);
|
||||
showAttachments(true);
|
||||
}
|
||||
});
|
||||
|
||||
mShowPictures = false;
|
||||
|
||||
@ -126,6 +101,46 @@ public class SingleMessageView extends LinearLayout {
|
||||
mMessageContentView.wrapSetTitleBar(mTitleBarHeaderContainer);
|
||||
}
|
||||
|
||||
mShowHiddenAttachments.setOnClickListener(this);
|
||||
mShowMessageAction.setOnClickListener(this);
|
||||
mShowAttachmentsAction.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.show_hidden_attachments: {
|
||||
onShowHiddenAttachments();
|
||||
break;
|
||||
}
|
||||
case R.id.show_message: {
|
||||
onShowMessage();
|
||||
break;
|
||||
}
|
||||
case R.id.show_attachments: {
|
||||
onShowAttachments();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onShowHiddenAttachments() {
|
||||
mShowHiddenAttachments.setVisibility(View.GONE);
|
||||
mHiddenAttachments.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void onShowMessage() {
|
||||
showShowMessageAction(false);
|
||||
showAttachments(false);
|
||||
showMessageWebView(true);
|
||||
showShowAttachmentsAction(true);
|
||||
}
|
||||
|
||||
private void onShowAttachments() {
|
||||
showMessageWebView(false);
|
||||
showShowAttachmentsAction(false);
|
||||
showShowMessageAction(true);
|
||||
showAttachments(true);
|
||||
}
|
||||
|
||||
public SingleMessageView(Context context, AttributeSet attrs) {
|
||||
|
Loading…
Reference in New Issue
Block a user