Fully display emails

This commit is contained in:
str4d
2014-02-28 07:29:55 +00:00
parent b5d32c0cc3
commit 04f0958f07
4 changed files with 175 additions and 12 deletions

View File

@@ -3,9 +3,110 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/email_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:orientation="vertical" >
<TextView
android:id="@+id/email_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Subject"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginBottom="5dp" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:text="@string/email_from" />
<TextView
android:id="@+id/email_sender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sender" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:text="@string/email_to" />
<LinearLayout
android:id="@+id/email_recipients"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:text="@string/email_sent" />
<TextView
android:id="@+id/email_sent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Datetime" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:text="@string/email_received" />
<TextView
android:id="@+id/email_received"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Datetime" />
</TableRow>
</TableLayout>
</LinearLayout>
<TextView
android:id="@+id/email_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Content" />
</LinearLayout>
</ScrollView>

View File

@@ -14,4 +14,9 @@
<string name="folder_empty">Folder is empty</string>
<string name="folder_does_not_exist">Folder does not exist</string>
<string name="email_from">From:</string>
<string name="email_to">To:</string>
<string name="email_sent">Sent:</string>
<string name="email_received">Received:</string>
</resources>

View File

@@ -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();
}
}
}

View File

@@ -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) + "...>"));
}
}