Forward and Reply all

This commit is contained in:
str4d
2014-08-28 12:46:05 +00:00
parent 0e2a999c24
commit 28d0e73add
12 changed files with 121 additions and 47 deletions

2
TODO
View File

@@ -23,8 +23,6 @@ Features:
- Public address book lookup
- "Write email" link in address book
- Add optional CC: and BCC: fields
- Forward
- Reply all
- Attachments
- QR codes for identities
- "Empty trash" option in Trash folder

View File

@@ -19,14 +19,17 @@ public class NewEmailActivity extends ActionBarActivity implements
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
String quoteMsgFolder = null;
String quoteMsgId = null;
NewEmailFragment f;
Bundle args = getIntent().getExtras();
if (args != null) {
quoteMsgFolder = args.getString(NewEmailFragment.QUOTE_MSG_FOLDER);
quoteMsgId = args.getString(NewEmailFragment.QUOTE_MSG_ID);
String quoteMsgFolder = args.getString(NewEmailFragment.QUOTE_MSG_FOLDER);
String quoteMsgId = args.getString(NewEmailFragment.QUOTE_MSG_ID);
NewEmailFragment.QuoteMsgType quoteMsgType =
(NewEmailFragment.QuoteMsgType) args.getSerializable(NewEmailFragment.QUOTE_MSG_TYPE);
f = NewEmailFragment.newInstance(quoteMsgFolder, quoteMsgId, quoteMsgType);
} else {
f = new NewEmailFragment();
}
NewEmailFragment f = NewEmailFragment.newInstance(quoteMsgFolder, quoteMsgId);
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, f).commit();
}

View File

@@ -52,7 +52,7 @@ public class NewEmailFragment extends Fragment {
public void onTaskFinished();
}
private static Callbacks sDummyCallbacks = new Callbacks() {
public void onTaskFinished() {};
public void onTaskFinished() {}
};
@Override
@@ -71,6 +71,12 @@ public class NewEmailFragment extends Fragment {
public static final String QUOTE_MSG_FOLDER = "sender";
public static final String QUOTE_MSG_ID = "recipient";
public static enum QuoteMsgType {
REPLY,
REPLY_ALL,
FORWARD
}
public static final String QUOTE_MSG_TYPE = "type";
private String mSenderKey;
@@ -81,11 +87,13 @@ public class NewEmailFragment extends Fragment {
EditText mSubject;
EditText mContent;
public static NewEmailFragment newInstance(String quoteMsgFolder, String quoteMsgId) {
public static NewEmailFragment newInstance(String quoteMsgFolder, String quoteMsgId,
QuoteMsgType quoteMsgType) {
NewEmailFragment f = new NewEmailFragment();
Bundle args = new Bundle();
args.putString(QUOTE_MSG_FOLDER, quoteMsgFolder);
args.putString(QUOTE_MSG_ID, quoteMsgId);
args.putSerializable(QUOTE_MSG_TYPE, quoteMsgType);
f.setArguments(args);
return f;
}
@@ -106,39 +114,45 @@ public class NewEmailFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mSpinner = (Spinner) view.findViewById(R.id.sender_spinner);
mRecipients = (ContactsCompletionView) view.findViewById(R.id.recipients);
mSubject = (EditText) view.findViewById(R.id.subject);
mContent = (EditText) view.findViewById(R.id.message);
String quoteMsgFolder = getArguments().getString(QUOTE_MSG_FOLDER);
String quoteMsgId = getArguments().getString(QUOTE_MSG_ID);
Email origEmail = null;
String recipientName = null;
String recipientAddr = null;
Bitmap recipientPic = null;
QuoteMsgType quoteMsgType = (QuoteMsgType) getArguments().getSerializable(QUOTE_MSG_TYPE);
boolean hide = I2PBote.getInstance().getConfiguration().getHideLocale();
List<Person> recipients = new ArrayList<Person>();
String origSubject = null;
String origContent = null;
String origFrom = null;
try {
origEmail = BoteHelper.getEmail(quoteMsgFolder, quoteMsgId);
Email origEmail = BoteHelper.getEmail(quoteMsgFolder, quoteMsgId);
if (origEmail != null) {
mSenderKey = BoteHelper.extractEmailDestination(
BoteHelper.getOneLocalRecipient(origEmail).toString());
String recipient = BoteHelper.getNameAndDestination(
origEmail.getReplyAddress(I2PBote.getInstance().getIdentities()));
recipientName = BoteHelper.extractName(recipient);
recipientAddr = BoteHelper.extractEmailDestination(recipient);
if (recipientAddr == null) { // Assume external address
recipientAddr = recipient;
if (recipientName.isEmpty())
recipientName = recipientAddr;
} else {
if (recipientName.isEmpty()) // Dest with no name
recipientName = recipientAddr.substring(0, 5);
recipientPic = BoteHelper.getPictureForDestination(recipientAddr);
if (quoteMsgType == QuoteMsgType.REPLY) {
String recipient = BoteHelper.getNameAndDestination(
origEmail.getReplyAddress(I2PBote.getInstance().getIdentities()));
recipients.add(extractPerson(recipient));
} else if (quoteMsgType == QuoteMsgType.REPLY_ALL) {
// TODO don't include our address
// What happens if an email is received by multiple local identities?
for (Address address : origEmail.getAllAddresses(true)) {
recipients.add(extractPerson(address.toString()));
}
}
origSubject = origEmail.getSubject();
origContent = origEmail.getText();
origFrom = BoteHelper.getShortSenderName(origEmail.getOneFromAddress(), 50);
}
} catch (PasswordException e) {
// TODO Auto-generated catch block
// Should not happen, we cannot get to this page without authenticating
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
@@ -151,11 +165,12 @@ public class NewEmailFragment extends Fragment {
e.printStackTrace();
}
mSpinner = (Spinner) view.findViewById(R.id.sender_spinner);
// Set up identities spinner
IdentityAdapter identities = new IdentityAdapter(getActivity());
mSpinner.setAdapter(identities);
mSpinner.setSelection(mDefaultPos);
// Set up contacts auto-complete
List<Person> contacts = new ArrayList<Person>();
try {
for (Contact contact : I2PBote.getInstance().getAddressBook().getAll()) {
@@ -192,21 +207,24 @@ public class NewEmailFragment extends Fragment {
}
};
mRecipients = (ContactsCompletionView) view.findViewById(R.id.recipients);
mRecipients.setAdapter(mAdapter);
if (recipientAddr != null) {
mRecipients.addObject(new Person(recipientName, recipientAddr, recipientPic));
for (Person recipient : recipients) {
mRecipients.addObject(recipient);
}
mSubject = (EditText) view.findViewById(R.id.subject);
mContent = (EditText) view.findViewById(R.id.message);
boolean hide = I2PBote.getInstance().getConfiguration().getHideLocale();
if (origSubject != null) {
String responsePrefix = getResources().getString(
hide ? R.string.response_prefix_re_hide
: R.string.response_prefix_re);
if (!origSubject.startsWith(responsePrefix))
origSubject = responsePrefix + " " + origSubject;
String subjectPrefix;
if (quoteMsgType == QuoteMsgType.FORWARD) {
subjectPrefix = getResources().getString(
hide ? R.string.subject_prefix_fwd_hide
: R.string.subject_prefix_fwd);
} else {
subjectPrefix = getResources().getString(
hide ? R.string.response_prefix_re_hide
: R.string.response_prefix_re);
}
if (!origSubject.startsWith(subjectPrefix))
origSubject = subjectPrefix + " " + origSubject;
mSubject.setText(origSubject);
}
if (origContent != null) {
@@ -227,6 +245,31 @@ public class NewEmailFragment extends Fragment {
}
}
private Person extractPerson(String recipient) {
String recipientName = BoteHelper.extractName(recipient);
String recipientAddr = BoteHelper.extractEmailDestination(recipient);
if (recipientAddr == null) { // Assume external address
recipientAddr = recipient;
if (recipientName.isEmpty())
recipientName = recipientAddr;
return new Person(recipientName, recipientAddr, null, true);
} else {
if (recipientName.isEmpty()) // Dest with no name
recipientName = recipientAddr.substring(0, 5);
Bitmap recipientPic = null;
try {
recipientPic = BoteHelper.getPictureForDestination(recipientAddr);
} catch (PasswordException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
return new Person(recipientName, recipientAddr, recipientPic);
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.new_email, menu);

View File

@@ -144,15 +144,29 @@ public class ViewEmailFragment extends Fragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_reply:
Intent nei = new Intent(getActivity(), NewEmailActivity.class);
nei.putExtra(NewEmailFragment.QUOTE_MSG_FOLDER, mFolderName);
nei.putExtra(NewEmailFragment.QUOTE_MSG_ID, mMessageId);
startActivity(nei);
return true;
case R.id.action_reply:
case R.id.action_reply_all:
case R.id.action_forward:
Intent nei = new Intent(getActivity(), NewEmailActivity.class);
nei.putExtra(NewEmailFragment.QUOTE_MSG_FOLDER, mFolderName);
nei.putExtra(NewEmailFragment.QUOTE_MSG_ID, mMessageId);
NewEmailFragment.QuoteMsgType type = null;
switch (item.getItemId()) {
case R.id.action_reply:
type = NewEmailFragment.QuoteMsgType.REPLY;
break;
case R.id.action_reply_all:
type = NewEmailFragment.QuoteMsgType.REPLY_ALL;
break;
case R.id.action_forward:
type = NewEmailFragment.QuoteMsgType.FORWARD;
}
nei.putExtra(NewEmailFragment.QUOTE_MSG_TYPE, type);
startActivity(nei);
return true;
default:
return super.onOptionsItemSelected(item);
default:
return super.onOptionsItemSelected(item);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -8,4 +8,16 @@
android:title="@string/reply"
i2pandroid:showAsAction="ifRoom"/>
<item
android:id="@+id/action_reply_all"
android:icon="@drawable/ic_social_reply_all"
android:title="@string/reply_all"
i2pandroid:showAsAction="ifRoom"/>
<item
android:id="@+id/action_forward"
android:icon="@drawable/ic_social_forward"
android:title="@string/forward"
i2pandroid:showAsAction="ifRoom"/>
</menu>

View File

@@ -102,11 +102,15 @@
<string name="email_received">Received:</string>
<string name="email_status">Status:</string>
<string name="reply">Reply</string>
<string name="reply_all">Reply all</string>
<string name="forward">Forward</string>
<string name="compose">Compose</string>
<string name="subject">Subject</string>
<string name="compose_email">Compose email</string>
<string name="add_one_recipient">Add at least one recipient.</string>
<string name="email_queued_for_sending">Email queued for sending</string>
<string name="subject_prefix_fwd">Fwd:</string>
<string name="subject_prefix_fwd_hide" translatable="false">Fwd:</string>
<string name="response_prefix_re">Re:</string>
<string name="response_prefix_re_hide" translatable="false">Re:</string>
<!-- Used in email replies above quoted text, like "Bob wrote:" -->