convert EditIdentity to Kotlin
This commit is contained in:
parent
f60477cba6
commit
0aec40bf21
2 changed files with 106 additions and 132 deletions
|
@ -1,132 +0,0 @@
|
|||
package com.fsck.k9.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Identity;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.ui.R;
|
||||
import java.util.List;
|
||||
|
||||
public class EditIdentity extends K9Activity {
|
||||
|
||||
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";
|
||||
|
||||
private Account mAccount;
|
||||
private Identity mIdentity;
|
||||
private int mIdentityIndex;
|
||||
private EditText mDescriptionView;
|
||||
private CheckBox mSignatureUse;
|
||||
private EditText mSignatureView;
|
||||
private LinearLayout mSignatureLayout;
|
||||
private EditText mEmailView;
|
||||
// private EditText mAlwaysBccView;
|
||||
private EditText mNameView;
|
||||
private EditText mReplyTo;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mIdentity = (Identity)getIntent().getSerializableExtra(EXTRA_IDENTITY);
|
||||
mIdentityIndex = getIntent().getIntExtra(EXTRA_IDENTITY_INDEX, -1);
|
||||
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
|
||||
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
||||
|
||||
if (mIdentityIndex == -1) {
|
||||
mIdentity = new Identity();
|
||||
}
|
||||
|
||||
setLayout(R.layout.edit_identity);
|
||||
|
||||
/*
|
||||
* If we're being reloaded we override the original account with the one
|
||||
* we saved
|
||||
*/
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_IDENTITY)) {
|
||||
mIdentity = (Identity)savedInstanceState.getSerializable(EXTRA_IDENTITY);
|
||||
}
|
||||
|
||||
mDescriptionView = findViewById(R.id.description);
|
||||
mDescriptionView.setText(mIdentity.getDescription());
|
||||
|
||||
mNameView = findViewById(R.id.name);
|
||||
mNameView.setText(mIdentity.getName());
|
||||
|
||||
mEmailView = findViewById(R.id.email);
|
||||
mEmailView.setText(mIdentity.getEmail());
|
||||
|
||||
mReplyTo = findViewById(R.id.reply_to);
|
||||
mReplyTo.setText(mIdentity.getReplyTo());
|
||||
|
||||
// mAccountAlwaysBcc = (EditText)findViewById(R.id.bcc);
|
||||
// mAccountAlwaysBcc.setText(mIdentity.getAlwaysBcc());
|
||||
|
||||
mSignatureLayout = findViewById(R.id.signature_layout);
|
||||
mSignatureUse = findViewById(R.id.signature_use);
|
||||
mSignatureView = findViewById(R.id.signature);
|
||||
mSignatureUse.setChecked(mIdentity.getSignatureUse());
|
||||
mSignatureUse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveIdentity() {
|
||||
|
||||
mIdentity.setDescription(mDescriptionView.getText().toString());
|
||||
mIdentity.setEmail(mEmailView.getText().toString());
|
||||
// mIdentity.setAlwaysBcc(mAccountAlwaysBcc.getText().toString());
|
||||
mIdentity.setName(mNameView.getText().toString());
|
||||
mIdentity.setSignatureUse(mSignatureUse.isChecked());
|
||||
mIdentity.setSignature(mSignatureView.getText().toString());
|
||||
|
||||
if (mReplyTo.getText().length() == 0) {
|
||||
mIdentity.setReplyTo(null);
|
||||
} else {
|
||||
mIdentity.setReplyTo(mReplyTo.getText().toString());
|
||||
}
|
||||
|
||||
List<Identity> identities = mAccount.getIdentities();
|
||||
if (mIdentityIndex == -1) {
|
||||
identities.add(mIdentity);
|
||||
} else {
|
||||
identities.remove(mIdentityIndex);
|
||||
identities.add(mIdentityIndex, mIdentity);
|
||||
}
|
||||
|
||||
Preferences.getPreferences(getApplicationContext()).saveAccount(mAccount);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
saveIdentity();
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putSerializable(EXTRA_IDENTITY, mIdentity);
|
||||
}
|
||||
}
|
106
app/ui/src/main/java/com/fsck/k9/activity/EditIdentity.kt
Normal file
106
app/ui/src/main/java/com/fsck/k9/activity/EditIdentity.kt
Normal file
|
@ -0,0 +1,106 @@
|
|||
package com.fsck.k9.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.Identity
|
||||
import com.fsck.k9.Preferences
|
||||
import com.fsck.k9.ui.R
|
||||
import kotlinx.android.synthetic.main.edit_identity.*
|
||||
|
||||
class EditIdentity : K9Activity() {
|
||||
private lateinit var mAccount: Account
|
||||
private lateinit var mIdentity: Identity
|
||||
private var mIdentityIndex: Int = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
mIdentity = intent.getSerializableExtra(EXTRA_IDENTITY) as Identity
|
||||
mIdentityIndex = intent.getIntExtra(EXTRA_IDENTITY_INDEX, -1)
|
||||
val accountUuid = intent.getStringExtra(EXTRA_ACCOUNT)
|
||||
mAccount = Preferences.getPreferences(this).getAccount(accountUuid)
|
||||
|
||||
if (mIdentityIndex == -1) {
|
||||
mIdentity = Identity()
|
||||
}
|
||||
|
||||
setLayout(R.layout.edit_identity)
|
||||
|
||||
/*
|
||||
* If we're being reloaded we override the original account with the one
|
||||
* we saved
|
||||
*/
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_IDENTITY)) {
|
||||
mIdentity = savedInstanceState.getSerializable(EXTRA_IDENTITY) as Identity
|
||||
}
|
||||
|
||||
description.setText(mIdentity.description)
|
||||
name.setText(mIdentity.name)
|
||||
email.setText(mIdentity.email)
|
||||
reply_to.setText(mIdentity.replyTo)
|
||||
|
||||
// mAccountAlwaysBcc = (EditText)findViewById(R.id.bcc);
|
||||
// mAccountAlwaysBcc.setText(mIdentity.getAlwaysBcc());
|
||||
|
||||
signature_use.isChecked = mIdentity.signatureUse
|
||||
signature_use.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
signature_layout.visibility = View.VISIBLE
|
||||
signature.setText(mIdentity.signature)
|
||||
} else {
|
||||
signature_layout.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
if (signature_use.isChecked) {
|
||||
signature.setText(mIdentity.signature)
|
||||
} else {
|
||||
signature_layout.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveIdentity() {
|
||||
|
||||
mIdentity.description = description.text.toString()
|
||||
mIdentity.email = email.text.toString()
|
||||
// mIdentity.setAlwaysBcc(mAccountAlwaysBcc.getText().toString());
|
||||
mIdentity.name = name.text.toString()
|
||||
mIdentity.signatureUse = signature_use.isChecked
|
||||
mIdentity.signature = signature.text.toString()
|
||||
|
||||
if (reply_to.text.isEmpty()) {
|
||||
mIdentity.replyTo = null
|
||||
} else {
|
||||
mIdentity.replyTo = reply_to.text.toString()
|
||||
}
|
||||
|
||||
val identities = mAccount.identities
|
||||
if (mIdentityIndex == -1) {
|
||||
identities.add(mIdentity)
|
||||
} else {
|
||||
identities.removeAt(mIdentityIndex)
|
||||
identities.add(mIdentityIndex, mIdentity)
|
||||
}
|
||||
|
||||
Preferences.getPreferences(applicationContext).saveAccount(mAccount)
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
saveIdentity()
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
public override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putSerializable(EXTRA_IDENTITY, mIdentity)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_IDENTITY = "com.fsck.k9.EditIdentity_identity"
|
||||
const val EXTRA_IDENTITY_INDEX = "com.fsck.k9.EditIdentity_identity_index"
|
||||
const val EXTRA_ACCOUNT = "com.fsck.k9.EditIdentity_account"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue