From 04f0958f072474fc684e0a4dcd6da82da766dcbc Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 28 Feb 2014 07:29:55 +0000 Subject: [PATCH] Fully display emails --- res/layout/fragment_view_email.xml | 111 ++++++++++++++++++++++++++-- res/values/strings.xml | 5 ++ src/i2p/bote/ViewEmailFragment.java | 57 ++++++++++++-- src/i2p/bote/util/BoteHelper.java | 14 ++++ 4 files changed, 175 insertions(+), 12 deletions(-) diff --git a/res/layout/fragment_view_email.xml b/res/layout/fragment_view_email.xml index 5cc88a0..2ceadda 100644 --- a/res/layout/fragment_view_email.xml +++ b/res/layout/fragment_view_email.xml @@ -3,9 +3,110 @@ android:layout_width="match_parent" android:layout_height="match_parent" > - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index f9761ab..56e6d6f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -14,4 +14,9 @@ Folder is empty Folder does not exist + + From: + To: + Sent: + Received: diff --git a/src/i2p/bote/ViewEmailFragment.java b/src/i2p/bote/ViewEmailFragment.java index 4407b38..c2245ea 100644 --- a/src/i2p/bote/ViewEmailFragment.java +++ b/src/i2p/bote/ViewEmailFragment.java @@ -1,5 +1,10 @@ package i2p.bote; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.text.DateFormat; + +import javax.mail.Address; import javax.mail.MessagingException; import i2p.bote.email.Email; @@ -10,6 +15,7 @@ import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.TextView; public class ViewEmailFragment extends Fragment { @@ -39,27 +45,64 @@ public class ViewEmailFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_view_email, container, false); - TextView subject = (TextView) v.findViewById(R.id.email_subject); try { Email e = BoteHelper.getEmail(mFolderName, mMessageId); if (e != null) { - subject.setText(e.getSubject()); + displayEmail(e, v); } else { + TextView subject = (TextView) v.findViewById(R.id.email_subject); subject.setText("Email not found"); } } catch (PasswordException e) { // TODO: Handle e.printStackTrace(); - } catch (MessagingException e) { - // TODO Handle - e.printStackTrace(); } return v; } - public String getMessageId() { - return mMessageId; + private void displayEmail(Email email, View v) { + TextView subject = (TextView) v.findViewById(R.id.email_subject); + TextView sender = (TextView) v.findViewById(R.id.email_sender); + LinearLayout recipients = (LinearLayout) v.findViewById(R.id.email_recipients); + TextView sent = (TextView) v.findViewById(R.id.email_sent); + TextView received = (TextView) v.findViewById(R.id.email_received); + TextView content = (TextView) v.findViewById(R.id.email_content); + + try { + subject.setText(email.getSubject()); + + sender.setText(BoteHelper.getDisplayAddress( + email.getOneFromAddress())); + + for (Address recipient : email.getToAddresses()) { + TextView tv = new TextView(getActivity()); + tv.setText(BoteHelper.getDisplayAddress(recipient.toString())); + recipients.addView(tv); + } + + if (email.getSentDate() != null) + sent.setText(DateFormat.getInstance().format( + email.getSentDate())); + + if (email.getReceivedDate() != null) + received.setText(DateFormat.getInstance().format( + email.getReceivedDate())); + + content.setText(email.getText()); + } catch (MessagingException e) { + // TODO Handle + e.printStackTrace(); + } catch (PasswordException 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(); + } } } diff --git a/src/i2p/bote/util/BoteHelper.java b/src/i2p/bote/util/BoteHelper.java index 799b3ad..25cba14 100644 --- a/src/i2p/bote/util/BoteHelper.java +++ b/src/i2p/bote/util/BoteHelper.java @@ -1,6 +1,10 @@ package i2p.bote.util; +import java.io.IOException; import java.security.GeneralSecurityException; + +import javax.mail.MessagingException; + import android.content.Context; import i2p.bote.R; @@ -42,4 +46,14 @@ public class BoteHelper extends GeneralHelper { return displayName; } + + public static String getDisplayAddress(String address) throws PasswordException, IOException, GeneralSecurityException, MessagingException { + String fullAdr = getNameAndDestination(address); + String emailDest = extractEmailDestination(fullAdr); + String name = extractName(fullAdr); + + return (emailDest == null ? address + : (name.isEmpty() ? emailDest.substring(0, 10) + : name + " <" + emailDest.substring(0, 10) + "...>")); + } }