Added attachment errors

pull/147/head
M66B 6 years ago
parent 5493bdd3c9
commit 3907975eea

File diff suppressed because it is too large Load Diff

@ -133,8 +133,14 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
progressbar.setVisibility( progressbar.setVisibility(
attachment.progress == null || attachment.available ? View.GONE : View.VISIBLE); attachment.progress == null || attachment.available ? View.GONE : View.VISIBLE);
tvDebug.setText(attachment.type + " " + attachment.disposition + " " + attachment.cid + " " + attachment.encryption); if (debug)
tvDebug.setVisibility(debug ? View.VISIBLE : View.GONE); 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 @Override

@ -49,7 +49,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 34, version = 35,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -419,6 +419,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `raw` INTEGER"); 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(); .build();
} }

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

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

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

Loading…
Cancel
Save