Added attachment errors

This commit is contained in:
M66B 2019-01-16 18:27:03 +00:00
parent 5493bdd3c9
commit 3907975eea
6 changed files with 1355 additions and 10 deletions

File diff suppressed because it is too large Load Diff

View File

@ -133,8 +133,14 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
progressbar.setVisibility(
attachment.progress == null || attachment.available ? View.GONE : View.VISIBLE);
tvDebug.setText(attachment.type + " " + attachment.disposition + " " + attachment.cid + " " + attachment.encryption);
tvDebug.setVisibility(debug ? View.VISIBLE : View.GONE);
if (debug)
tvDebug.setText(attachment.error +
"\n" + attachment.type +
" " + attachment.disposition +
" " + attachment.cid + " " + attachment.encryption);
else if (attachment.error != null)
tvDebug.setText(attachment.error);
tvDebug.setVisibility(debug || attachment.error != null ? View.VISIBLE : View.GONE);
}
@Override

View File

@ -49,7 +49,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 34,
version = 35,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -419,6 +419,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `raw` INTEGER");
}
})
.addMigrations(new Migration(34, 35) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `attachment` ADD COLUMN `error` TEXT");
}
})
.build();
}

View File

@ -64,15 +64,20 @@ public interface DaoAttachment {
void setMessage(long id, long message);
@Query("UPDATE attachment" +
" SET progress = :progress, available = 0" +
" SET error = NULL, progress = :progress, available = 0" +
" WHERE id = :id")
void setProgress(long id, Integer progress);
@Query("UPDATE attachment" +
" SET size = :size, progress = NULL, available = 1" +
" SET size = :size, error = NULL, progress = NULL, available = 1" +
" WHERE id = :id")
void setDownloaded(long id, Long size);
@Query("UPDATE attachment" +
" SET error = :error, progress = NULL, available = 0" +
" WHERE id = :id")
void setError(long id, String error);
@Query("UPDATE attachment" +
" SET cid = :cid" +
" WHERE id = :id")

View File

@ -69,6 +69,7 @@ public class EntityAttachment {
public Integer progress;
@NonNull
public Boolean available = false;
public String error;
boolean isInline() {
return (disposition != null && disposition.equalsIgnoreCase(Part.INLINE));

View File

@ -633,7 +633,7 @@ public class MessageHelper {
return result;
}
void downloadAttachment(Context context, DB db, long id, int sequence) throws MessagingException, IOException {
void downloadAttachment(Context context, DB db, long id, int sequence) throws IOException {
// Attachments of drafts might not have been uploaded yet
if (sequence > attachments.size()) {
Log.w("Attachment unavailable sequence=" + sequence + " size=" + attachments.size());
@ -642,7 +642,6 @@ public class MessageHelper {
// Get data
AttachmentPart apart = attachments.get(sequence - 1);
long total = apart.part.getSize();
File file = EntityAttachment.getFile(context, id);
// Download attachment
@ -654,6 +653,7 @@ public class MessageHelper {
os = new BufferedOutputStream(new FileOutputStream(file));
long size = 0;
long total = apart.part.getSize();
byte[] buffer = new byte[ATTACHMENT_BUFFER_SIZE];
for (int len = is.read(buffer); len != -1; len = is.read(buffer)) {
size += len;
@ -668,10 +668,10 @@ public class MessageHelper {
db.attachment().setDownloaded(id, size);
Log.i("Downloaded attachment size=" + size);
} catch (IOException ex) {
} catch (Throwable ex) {
Log.w(ex);
// Reset progress on failure
db.attachment().setProgress(id, null);
throw ex;
db.attachment().setError(id, Helper.formatThrowable(ex));
} finally {
if (os != null)
os.close();