Prep work for viewing attachments
Todo: implement a ContentProvider for attachments
This commit is contained in:
@@ -26,7 +26,6 @@ import javax.mail.Address;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Part;
|
||||
|
||||
import i2p.bote.Util;
|
||||
import i2p.bote.android.util.BoteHelper;
|
||||
import i2p.bote.android.util.ContentAttachment;
|
||||
import i2p.bote.email.Email;
|
||||
@@ -170,10 +169,21 @@ public class ViewEmailFragment extends Fragment {
|
||||
Part part = parts.get(partIndex);
|
||||
if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
|
||||
ContentAttachment attachment = new ContentAttachment(part);
|
||||
final View a = getActivity().getLayoutInflater().inflate(R.layout.listitem_attachment, attachments, false);
|
||||
|
||||
View a = getActivity().getLayoutInflater().inflate(R.layout.listitem_attachment, attachments, false);
|
||||
((TextView)a.findViewById(R.id.filename)).setText(attachment.getFileName());
|
||||
((TextView)a.findViewById(R.id.size)).setText(attachment.getHumanReadableSize(getActivity()));
|
||||
a.findViewById(R.id.remove_attachment).setVisibility(View.GONE);
|
||||
|
||||
final Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(attachment.getUri());
|
||||
a.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(i);
|
||||
}
|
||||
});
|
||||
|
||||
attachments.addView(a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class ContentAttachment implements Attachment {
|
||||
private String mFileName;
|
||||
private long mSize;
|
||||
private DataHandler mDataHandler;
|
||||
private Uri mUri;
|
||||
|
||||
public ContentAttachment(ContentResolver cr, Uri uri) throws FileNotFoundException {
|
||||
// Get the content resolver instance for this context, and use it
|
||||
@@ -74,12 +75,15 @@ public class ContentAttachment implements Attachment {
|
||||
return mFileName;
|
||||
}
|
||||
});
|
||||
// mUri is not set here because uri is only usable by us.
|
||||
// Viewing attachments is only allowed once the email has been created.
|
||||
}
|
||||
|
||||
public ContentAttachment(final Part part) throws IOException, MessagingException {
|
||||
mFileName = part.getFileName();
|
||||
mSize = Util.getPartSize(part);
|
||||
mDataHandler = part.getDataHandler();
|
||||
// TODO: Set mUri
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,6 +117,10 @@ public class ContentAttachment implements Attachment {
|
||||
return mDataHandler;
|
||||
}
|
||||
|
||||
public Uri getUri() {
|
||||
return mUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clean() {
|
||||
if (mAttachmentPFD == null)
|
||||
|
||||
Reference in New Issue
Block a user