2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.activity;
|
2009-06-08 23:11:35 -04:00
|
|
|
|
2009-12-09 22:16:42 -05:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.KeyEvent;
|
2010-02-08 12:47:00 -05:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
2009-12-09 22:16:42 -05:00
|
|
|
import android.widget.EditText;
|
2010-02-08 12:47:00 -05:00
|
|
|
import android.widget.LinearLayout;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.Account;
|
2010-03-03 23:00:30 -05:00
|
|
|
import com.fsck.k9.Identity;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.Preferences;
|
|
|
|
import com.fsck.k9.R;
|
2009-12-09 22:16:42 -05:00
|
|
|
import java.util.List;
|
2009-06-08 23:11:35 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class EditIdentity extends K9Activity
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
public static final String EXTRA_IDENTITY = "com.fsck.k9.EditIdentity_identity";
|
|
|
|
public static final String EXTRA_IDENTITY_INDEX = "com.fsck.k9.EditIdentity_identity_index";
|
|
|
|
public static final String EXTRA_ACCOUNT = "com.fsck.k9.EditIdentity_account";
|
2009-06-08 23:11:35 -04:00
|
|
|
|
|
|
|
private Account mAccount;
|
2010-03-03 23:00:30 -05:00
|
|
|
private Identity mIdentity;
|
2009-06-08 23:11:35 -04:00
|
|
|
private int mIdentityIndex;
|
|
|
|
private EditText mDescriptionView;
|
2010-02-08 12:47:00 -05:00
|
|
|
private CheckBox mSignatureUse;
|
2009-06-08 23:11:35 -04:00
|
|
|
private EditText mSignatureView;
|
2010-02-08 12:47:00 -05:00
|
|
|
private LinearLayout mSignatureLayout;
|
2009-06-08 23:11:35 -04:00
|
|
|
private EditText mEmailView;
|
|
|
|
// private EditText mAlwaysBccView;
|
|
|
|
private EditText mNameView;
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
mIdentity = (Identity)getIntent().getSerializableExtra(EXTRA_IDENTITY);
|
2009-06-08 23:11:35 -04:00
|
|
|
mIdentityIndex = getIntent().getIntExtra(EXTRA_IDENTITY_INDEX, -1);
|
2010-03-03 23:00:30 -05:00
|
|
|
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
|
|
|
|
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
2009-06-08 23:11:35 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
if (mIdentityIndex == -1)
|
|
|
|
{
|
2010-03-03 23:00:30 -05:00
|
|
|
mIdentity = new Identity();
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setContentView(R.layout.edit_identity);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're being reloaded we override the original account with the one
|
|
|
|
* we saved
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_IDENTITY))
|
|
|
|
{
|
2010-03-03 23:00:30 -05:00
|
|
|
mIdentity = (Identity)savedInstanceState.getSerializable(EXTRA_IDENTITY);
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
mDescriptionView = (EditText)findViewById(R.id.description);
|
|
|
|
mDescriptionView.setText(mIdentity.getDescription());
|
|
|
|
|
|
|
|
mNameView = (EditText)findViewById(R.id.name);
|
|
|
|
mNameView.setText(mIdentity.getName());
|
|
|
|
|
|
|
|
mEmailView = (EditText)findViewById(R.id.email);
|
|
|
|
mEmailView.setText(mIdentity.getEmail());
|
|
|
|
|
|
|
|
// mAccountAlwaysBcc = (EditText)findViewById(R.id.bcc);
|
|
|
|
// mAccountAlwaysBcc.setText(mIdentity.getAlwaysBcc());
|
|
|
|
|
2010-02-08 12:47:00 -05:00
|
|
|
mSignatureLayout = (LinearLayout)findViewById(R.id.signature_layout);
|
|
|
|
mSignatureUse = (CheckBox)findViewById(R.id.signature_use);
|
2009-06-08 23:11:35 -04:00
|
|
|
mSignatureView = (EditText)findViewById(R.id.signature);
|
2010-02-08 12:47:00 -05:00
|
|
|
mSignatureUse.setChecked(mIdentity.getSignatureUse());
|
2010-04-29 00:59:14 -04:00
|
|
|
mSignatureUse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
|
|
|
{
|
2010-02-08 12:47:00 -05:00
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
|
|
{
|
|
|
|
if (isChecked)
|
|
|
|
{
|
|
|
|
mSignatureLayout.setVisibility(View.VISIBLE);
|
|
|
|
mSignatureView.setText(mIdentity.getSignature());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mSignatureLayout.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (mSignatureUse.isChecked())
|
|
|
|
{
|
|
|
|
mSignatureView.setText(mIdentity.getSignature());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mSignatureLayout.setVisibility(View.GONE);
|
|
|
|
}
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onResume()
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private void saveIdentity()
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
|
|
|
|
mIdentity.setDescription(mDescriptionView.getText().toString());
|
|
|
|
mIdentity.setEmail(mEmailView.getText().toString());
|
|
|
|
// mIdentity.setAlwaysBcc(mAccountAlwaysBcc.getText().toString());
|
|
|
|
mIdentity.setName(mNameView.getText().toString());
|
2010-02-08 12:47:00 -05:00
|
|
|
mIdentity.setSignatureUse(mSignatureUse.isChecked());
|
2009-06-08 23:11:35 -04:00
|
|
|
mIdentity.setSignature(mSignatureView.getText().toString());
|
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
List<Identity> identities = mAccount.getIdentities();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (mIdentityIndex == -1)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
identities.add(mIdentity);
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
identities.remove(mIdentityIndex);
|
|
|
|
identities.add(mIdentityIndex, mIdentity);
|
|
|
|
}
|
|
|
|
|
|
|
|
mAccount.save(Preferences.getPreferences(getApplication().getApplicationContext()));
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
|
|
|
{
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
saveIdentity();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onSaveInstanceState(Bundle outState)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
outState.putSerializable(EXTRA_IDENTITY, mIdentity);
|
|
|
|
}
|
|
|
|
}
|