Browse Source

Refactoring

main
M66B 6 years ago
parent
commit
3ef26e5e46
7 changed files with 27 additions and 27 deletions
  1. +2
    -6
      app/src/main/java/eu/faircode/email/AdapterAttachment.java
  2. +10
    -0
      app/src/main/java/eu/faircode/email/EntityAttachment.java
  3. +7
    -4
      app/src/main/java/eu/faircode/email/EntityMessage.java
  4. +1
    -3
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  5. +5
    -9
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  6. +1
    -2
      app/src/main/java/eu/faircode/email/MessageHelper.java
  7. +1
    -3
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 2
- 6
app/src/main/java/eu/faircode/email/AdapterAttachment.java View File

@ -132,10 +132,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
@Override @Override
protected Void onLoad(Context context, Bundle args) { protected Void onLoad(Context context, Bundle args) {
DB.getInstance(context).attachment().deleteAttachment(attachment.id); DB.getInstance(context).attachment().deleteAttachment(attachment.id);
File dir = new File(context.getFilesDir(), "attachments");
File file = new File(dir, attachment.id.toString());
file.delete();
EntityAttachment.getFile(context, attachment.id).delete();
return null; return null;
} }
}.load(context, owner, args); }.load(context, owner, args);
@ -143,8 +140,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
} else { } else {
if (attachment.available) { if (attachment.available) {
// Build file name // Build file name
File dir = new File(context.getFilesDir(), "attachments");
File file = new File(dir, attachment.id.toString());
File file = EntityAttachment.getFile(context, attachment.id);
// https://developer.android.com/reference/android/support/v4/content/FileProvider // https://developer.android.com/reference/android/support/v4/content/FileProvider
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file); Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);


+ 10
- 0
app/src/main/java/eu/faircode/email/EntityAttachment.java View File

@ -19,6 +19,10 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B) Copyright 2018 by Marcel Bokhorst (M66B)
*/ */
import android.content.Context;
import java.io.File;
import javax.mail.BodyPart; import javax.mail.BodyPart;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -60,6 +64,12 @@ public class EntityAttachment {
@Ignore @Ignore
BodyPart part; BodyPart part;
static File getFile(Context context, Long id) {
File dir = new File(context.getFilesDir(), "attachments");
dir.mkdir();
return new File(dir, Long.toString(id));
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof EntityAttachment) { if (obj instanceof EntityAttachment) {


+ 7
- 4
app/src/main/java/eu/faircode/email/EntityMessage.java View File

@ -108,10 +108,14 @@ public class EntityMessage {
return sb.toString(); return sb.toString();
} }
void write(Context context, String body) throws IOException {
static File getFile(Context context, Long id) {
File dir = new File(context.getFilesDir(), "messages"); File dir = new File(context.getFilesDir(), "messages");
dir.mkdir(); dir.mkdir();
File file = new File(dir, id.toString());
return new File(dir, id.toString());
}
void write(Context context, String body) throws IOException {
File file = getFile(context, id);
BufferedWriter out = null; BufferedWriter out = null;
try { try {
out = new BufferedWriter(new FileWriter(file)); out = new BufferedWriter(new FileWriter(file));
@ -131,8 +135,7 @@ public class EntityMessage {
} }
static String read(Context context, Long id) throws IOException { static String read(Context context, Long id) throws IOException {
File dir = new File(context.getFilesDir(), "messages");
File file = new File(dir, id.toString());
File file = getFile(context, id);
BufferedReader in = null; BufferedReader in = null;
try { try {
in = new BufferedReader(new FileReader(file)); in = new BufferedReader(new FileReader(file));


+ 1
- 3
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -495,9 +495,7 @@ public class FragmentCompose extends FragmentEx {
} }
try { try {
File dir = new File(context.getFilesDir(), "attachments");
dir.mkdir();
File file = new File(dir, Long.toString(attachment.id));
File file = EntityAttachment.getFile(context, attachment.id);
InputStream is = null; InputStream is = null;
OutputStream os = null; OutputStream os = null;


+ 5
- 9
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -714,15 +714,11 @@ public class FragmentMessage extends FragmentEx {
try { try {
db.beginTransaction(); db.beginTransaction();
if (debug && BuildConfig.DEBUG)
db.message().deleteMessage(id);
else {
db.message().setMessageUiHide(id, true);
EntityMessage message = db.message().getMessage(id);
EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
EntityOperation.queue(db, message, EntityOperation.MOVE, trash.id);
}
db.message().setMessageUiHide(id, true);
EntityMessage message = db.message().getMessage(id);
EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
EntityOperation.queue(db, message, EntityOperation.MOVE, trash.id);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {


+ 1
- 2
app/src/main/java/eu/faircode/email/MessageHelper.java View File

@ -129,8 +129,7 @@ public class MessageHelper {
BodyPart bpAttachment = new MimeBodyPart(); BodyPart bpAttachment = new MimeBodyPart();
bpAttachment.setFileName(attachment.name); bpAttachment.setFileName(attachment.name);
File dir = new File(context.getFilesDir(), "attachments");
File file = new File(dir, attachment.id.toString());
File file = EntityAttachment.getFile(context, attachment.id);
FileDataSource dataSource = new FileDataSource(file); FileDataSource dataSource = new FileDataSource(file);
dataSource.setFileTypeMap(new FileTypeMap() { dataSource.setFileTypeMap(new FileTypeMap() {
@Override @Override


+ 1
- 3
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -1010,9 +1010,7 @@ public class ServiceSynchronize extends LifecycleService {
EntityAttachment a = helper.getAttachments().get(sequence - 1); EntityAttachment a = helper.getAttachments().get(sequence - 1);
// Build filename // Build filename
File dir = new File(getFilesDir(), "attachments");
dir.mkdir();
File file = new File(dir, Long.toString(attachment.id));
File file = EntityAttachment.getFile(this, attachment.id);
// Download attachment // Download attachment
InputStream is = null; InputStream is = null;


Loading…
Cancel
Save