New email: If the user has typed anything, confirm when they navigate away
This commit is contained in:
@@ -42,6 +42,12 @@ public class NewEmailActivity extends ActionBarActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
NewEmailFragment f = (NewEmailFragment) getSupportFragmentManager().findFragmentById(R.id.container);
|
||||||
|
f.onBackPressed();
|
||||||
|
}
|
||||||
|
|
||||||
// NewEmailFragment.Callbacks
|
// NewEmailFragment.Callbacks
|
||||||
|
|
||||||
public void onTaskFinished() {
|
public void onTaskFinished() {
|
||||||
@@ -49,4 +55,9 @@ public class NewEmailActivity extends ActionBarActivity implements
|
|||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressAllowed() {
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,30 @@
|
|||||||
package i2p.bote.android;
|
package i2p.bote.android;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.tokenautocomplete.FilteredArrayAdapter;
|
||||||
|
|
||||||
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -12,9 +37,6 @@ import javax.mail.Message;
|
|||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
|
|
||||||
import com.tokenautocomplete.FilteredArrayAdapter;
|
|
||||||
|
|
||||||
import net.i2p.data.DataFormatException;
|
|
||||||
import i2p.bote.I2PBote;
|
import i2p.bote.I2PBote;
|
||||||
import i2p.bote.android.util.BoteHelper;
|
import i2p.bote.android.util.BoteHelper;
|
||||||
import i2p.bote.android.util.ContactsCompletionView;
|
import i2p.bote.android.util.ContactsCompletionView;
|
||||||
@@ -24,35 +46,22 @@ import i2p.bote.email.Email;
|
|||||||
import i2p.bote.email.EmailIdentity;
|
import i2p.bote.email.EmailIdentity;
|
||||||
import i2p.bote.fileencryption.PasswordException;
|
import i2p.bote.fileencryption.PasswordException;
|
||||||
import i2p.bote.packet.dht.Contact;
|
import i2p.bote.packet.dht.Contact;
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
public class NewEmailFragment extends Fragment {
|
public class NewEmailFragment extends Fragment {
|
||||||
private Callbacks mCallbacks = sDummyCallbacks;
|
private Callbacks mCallbacks = sDummyCallbacks;
|
||||||
|
|
||||||
public interface Callbacks {
|
public interface Callbacks {
|
||||||
public void onTaskFinished();
|
public void onTaskFinished();
|
||||||
|
|
||||||
|
public void onBackPressAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Callbacks sDummyCallbacks = new Callbacks() {
|
private static Callbacks sDummyCallbacks = new Callbacks() {
|
||||||
public void onTaskFinished() {}
|
public void onTaskFinished() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onBackPressAllowed() {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,11 +80,13 @@ public class NewEmailFragment extends Fragment {
|
|||||||
|
|
||||||
public static final String QUOTE_MSG_FOLDER = "sender";
|
public static final String QUOTE_MSG_FOLDER = "sender";
|
||||||
public static final String QUOTE_MSG_ID = "recipient";
|
public static final String QUOTE_MSG_ID = "recipient";
|
||||||
|
|
||||||
public static enum QuoteMsgType {
|
public static enum QuoteMsgType {
|
||||||
REPLY,
|
REPLY,
|
||||||
REPLY_ALL,
|
REPLY_ALL,
|
||||||
FORWARD
|
FORWARD
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String QUOTE_MSG_TYPE = "type";
|
public static final String QUOTE_MSG_TYPE = "type";
|
||||||
|
|
||||||
private String mSenderKey;
|
private String mSenderKey;
|
||||||
@@ -86,6 +97,7 @@ public class NewEmailFragment extends Fragment {
|
|||||||
ContactsCompletionView mRecipients;
|
ContactsCompletionView mRecipients;
|
||||||
EditText mSubject;
|
EditText mSubject;
|
||||||
EditText mContent;
|
EditText mContent;
|
||||||
|
boolean mDirty;
|
||||||
|
|
||||||
public static NewEmailFragment newInstance(String quoteMsgFolder, String quoteMsgId,
|
public static NewEmailFragment newInstance(String quoteMsgFolder, String quoteMsgId,
|
||||||
QuoteMsgType quoteMsgType) {
|
QuoteMsgType quoteMsgType) {
|
||||||
@@ -106,7 +118,7 @@ public class NewEmailFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.fragment_new_email, container, false);
|
return inflater.inflate(R.layout.fragment_new_email, container, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,20 +201,22 @@ public class NewEmailFragment extends Fragment {
|
|||||||
mask = mask.toLowerCase(Locale.US);
|
mask = mask.toLowerCase(Locale.US);
|
||||||
return obj.getName().toLowerCase(Locale.US).startsWith(mask) || obj.getAddress().toLowerCase(Locale.US).startsWith(mask);
|
return obj.getName().toLowerCase(Locale.US).startsWith(mask) || obj.getAddress().toLowerCase(Locale.US).startsWith(mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View v;
|
View v;
|
||||||
if (convertView == null)
|
if (convertView == null)
|
||||||
v = ((LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
|
v = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
|
||||||
.inflate(R.layout.listitem_contact, parent, false);
|
.inflate(R.layout.listitem_contact, parent, false);
|
||||||
else
|
else
|
||||||
v = convertView;
|
v = convertView;
|
||||||
setViewContent(v, position);
|
setViewContent(v, position);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setViewContent(View v, int position) {
|
private void setViewContent(View v, int position) {
|
||||||
Person person = getItem(position);
|
Person person = getItem(position);
|
||||||
((TextView)v.findViewById(R.id.contact_name)).setText(person.getName());
|
((TextView) v.findViewById(R.id.contact_name)).setText(person.getName());
|
||||||
ImageView picView = (ImageView) v.findViewById(R.id.contact_picture);
|
ImageView picView = (ImageView) v.findViewById(R.id.contact_picture);
|
||||||
Bitmap picture = person.getPicture();
|
Bitmap picture = person.getPicture();
|
||||||
if (picture == null) {
|
if (picture == null) {
|
||||||
@@ -238,10 +252,10 @@ public class NewEmailFragment extends Fragment {
|
|||||||
quotation.append("\n\n");
|
quotation.append("\n\n");
|
||||||
quotation.append(getResources().getString(
|
quotation.append(getResources().getString(
|
||||||
hide ? R.string.response_quote_wrote_hide
|
hide ? R.string.response_quote_wrote_hide
|
||||||
: R.string.response_quote_wrote,
|
: R.string.response_quote_wrote,
|
||||||
origFrom));
|
origFrom));
|
||||||
String[] lines = origContent.split("\r?\n|\r");
|
String[] lines = origContent.split("\r?\n|\r");
|
||||||
for (String line: lines)
|
for (String line : lines)
|
||||||
quotation = quotation.append("\n> ").append(line);
|
quotation = quotation.append("\n> ").append(line);
|
||||||
mContent.setText(quotation);
|
mContent.setText(quotation);
|
||||||
}
|
}
|
||||||
@@ -249,6 +263,23 @@ public class NewEmailFragment extends Fragment {
|
|||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mRecipients.setPrefix(getResources().getString(R.string.email_to) + " ");
|
mRecipients.setPrefix(getResources().getString(R.string.email_to) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextWatcher dirtyWatcher = new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
mDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mSubject.addTextChangedListener(dirtyWatcher);
|
||||||
|
mContent.addTextChangedListener(dirtyWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Person extractPerson(String recipient) {
|
private Person extractPerson(String recipient) {
|
||||||
@@ -295,15 +326,36 @@ public class NewEmailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_send_email:
|
case R.id.action_send_email:
|
||||||
if (sendEmail())
|
if (sendEmail())
|
||||||
mCallbacks.onTaskFinished();
|
mCallbacks.onTaskFinished();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
case android.R.id.home:
|
||||||
return super.onOptionsItemSelected(item);
|
if (mDirty) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setTitle(R.string.stop_composing_email)
|
||||||
|
.setMessage(R.string.all_changes_will_be_discarded)
|
||||||
|
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
dialogInterface.dismiss();
|
||||||
|
getActivity().onNavigateUp();
|
||||||
|
}
|
||||||
|
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
dialogInterface.cancel();
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +366,7 @@ public class NewEmailFragment extends Fragment {
|
|||||||
EmailIdentity sender = (EmailIdentity) mSpinner.getSelectedItem();
|
EmailIdentity sender = (EmailIdentity) mSpinner.getSelectedItem();
|
||||||
InternetAddress ia = new InternetAddress(
|
InternetAddress ia = new InternetAddress(
|
||||||
sender == null ? "Anonymous" :
|
sender == null ? "Anonymous" :
|
||||||
BoteHelper.getNameAndDestination(sender.getKey()));
|
BoteHelper.getNameAndDestination(sender.getKey()));
|
||||||
email.setFrom(ia);
|
email.setFrom(ia);
|
||||||
// We must continue to set "Sender:" even with only one mailbox
|
// We must continue to set "Sender:" even with only one mailbox
|
||||||
// in "From:", which is against RFC 2822 but required for older
|
// in "From:", which is against RFC 2822 but required for older
|
||||||
@@ -370,7 +422,7 @@ public class NewEmailFragment extends Fragment {
|
|||||||
|
|
||||||
public IdentityAdapter(Context context) {
|
public IdentityAdapter(Context context) {
|
||||||
super(context, android.R.layout.simple_spinner_item);
|
super(context, android.R.layout.simple_spinner_item);
|
||||||
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Collection<EmailIdentity> identities = I2PBote.getInstance().getIdentities().getAll();
|
Collection<EmailIdentity> identities = I2PBote.getInstance().getIdentities().getAll();
|
||||||
@@ -427,7 +479,7 @@ public class NewEmailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getDropDownView (int position, View convertView, ViewGroup parent) {
|
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||||
View v;
|
View v;
|
||||||
if (convertView == null)
|
if (convertView == null)
|
||||||
v = mInflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent, false);
|
v = mInflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent, false);
|
||||||
@@ -447,4 +499,25 @@ public class NewEmailFragment extends Fragment {
|
|||||||
text.setText(identity.getPublicName());
|
text.setText(identity.getPublicName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onBackPressed() {
|
||||||
|
if (mDirty) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setTitle(R.string.stop_composing_email)
|
||||||
|
.setMessage(R.string.all_changes_will_be_discarded)
|
||||||
|
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
dialogInterface.dismiss();
|
||||||
|
mCallbacks.onBackPressAllowed();
|
||||||
|
}
|
||||||
|
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
dialogInterface.cancel();
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
|
} else
|
||||||
|
mCallbacks.onBackPressAllowed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,8 @@
|
|||||||
<string name="subject">Subject</string>
|
<string name="subject">Subject</string>
|
||||||
<string name="compose_email">Compose email</string>
|
<string name="compose_email">Compose email</string>
|
||||||
<string name="add_one_recipient">Add at least one recipient.</string>
|
<string name="add_one_recipient">Add at least one recipient.</string>
|
||||||
|
<string name="stop_composing_email">Stop composing email?</string>
|
||||||
|
<string name="all_changes_will_be_discarded">All changes will be discarded.</string>
|
||||||
<string name="email_queued_for_sending">Email queued for sending</string>
|
<string name="email_queued_for_sending">Email queued for sending</string>
|
||||||
<string name="subject_prefix_fwd">Fwd:</string>
|
<string name="subject_prefix_fwd">Fwd:</string>
|
||||||
<string name="subject_prefix_fwd_hide" translatable="false">Fwd:</string>
|
<string name="subject_prefix_fwd_hide" translatable="false">Fwd:</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user