Implemented send button action with sender as dummy recipient
This commit is contained in:
@@ -2,8 +2,10 @@ package i2p.bote;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class NewEmailActivity extends ActionBarActivity {
|
||||
public class NewEmailActivity extends ActionBarActivity implements
|
||||
NewEmailFragment.Callbacks {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -17,4 +19,12 @@ public class NewEmailActivity extends ActionBarActivity {
|
||||
.add(android.R.id.content, f).commit();
|
||||
}
|
||||
}
|
||||
|
||||
// NewEmailFragment.Callbacks
|
||||
|
||||
public void onTaskFinished() {
|
||||
Toast.makeText(this, R.string.email_queued_for_sending,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,20 @@ package i2p.bote;
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
|
||||
import i2p.bote.email.Attachment;
|
||||
import i2p.bote.email.Email;
|
||||
import i2p.bote.email.EmailIdentity;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.util.BoteHelper;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -16,12 +27,40 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.MultiAutoCompleteTextView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class NewEmailFragment extends Fragment {
|
||||
private Callbacks mCallbacks = sDummyCallbacks;
|
||||
|
||||
public interface Callbacks {
|
||||
public void onTaskFinished();
|
||||
}
|
||||
private static Callbacks sDummyCallbacks = new Callbacks() {
|
||||
public void onTaskFinished() {};
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
if (!(activity instanceof Callbacks))
|
||||
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
||||
mCallbacks = (Callbacks) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mCallbacks = sDummyCallbacks;
|
||||
}
|
||||
|
||||
Spinner mSpinner;
|
||||
int mDefaultPos;
|
||||
MultiAutoCompleteTextView mRecipients;
|
||||
EditText mSubject;
|
||||
EditText mContent;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -40,9 +79,16 @@ public class NewEmailFragment extends Fragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mSpinner = (Spinner) view.findViewById(R.id.sender_spinner);
|
||||
IdentityAdapter adapter = new IdentityAdapter(getActivity());
|
||||
mSpinner.setAdapter(adapter);
|
||||
IdentityAdapter identities = new IdentityAdapter(getActivity());
|
||||
mSpinner.setAdapter(identities);
|
||||
mSpinner.setSelection(mDefaultPos);
|
||||
|
||||
mRecipients = (MultiAutoCompleteTextView) view.findViewById(R.id.recipients);
|
||||
mRecipients.setAdapter(null); // TODO: Implement
|
||||
mRecipients.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
||||
|
||||
mSubject = (EditText) view.findViewById(R.id.subject);
|
||||
mContent = (EditText) view.findViewById(R.id.message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +100,8 @@ public class NewEmailFragment extends Fragment {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_send_email:
|
||||
// TODO Handle
|
||||
sendEmail();
|
||||
mCallbacks.onTaskFinished();
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -62,6 +109,48 @@ public class NewEmailFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendEmail() {
|
||||
Email email = new Email(I2PBote.getInstance().getConfiguration().getIncludeSentTime());
|
||||
try {
|
||||
// Set sender
|
||||
EmailIdentity sender = (EmailIdentity) mSpinner.getSelectedItem();
|
||||
InternetAddress ia = new InternetAddress(
|
||||
sender == null ? "Anonymous" :
|
||||
BoteHelper.getNameAndDestination(sender.getKey()));
|
||||
email.setFrom(ia);
|
||||
// We must continue to set "Sender:" even with only one mailbox
|
||||
// in "From:", which is against RFC 2822 but required for older
|
||||
// Bote versions to see a sender (and validate the signature).
|
||||
email.setSender(ia);
|
||||
|
||||
// TODO: Implement properly
|
||||
email.addRecipient(Message.RecipientType.TO, ia);
|
||||
|
||||
email.setSubject(mSubject.getText().toString(), "UTF-8");
|
||||
|
||||
// Set the text and add attachments
|
||||
email.setContent(mContent.getText().toString(), (List<Attachment>) null);
|
||||
|
||||
// Send the email
|
||||
I2PBote.getInstance().sendEmail(email);
|
||||
} catch (PasswordException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (DataFormatException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (MessagingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (GeneralSecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private class IdentityAdapter extends ArrayAdapter<EmailIdentity> {
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user