Browse Source

Fix attachment updates

Download progress
main
M66B 6 years ago
parent
commit
242be4c511
5 changed files with 31 additions and 8 deletions
  1. +2
    -1
      app/src/main/java/eu/faircode/email/AdapterAttachment.java
  2. +2
    -1
      app/src/main/java/eu/faircode/email/DaoAttachment.java
  3. +16
    -0
      app/src/main/java/eu/faircode/email/EntityAttachment.java
  4. +10
    -5
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  5. +1
    -1
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

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

@ -267,7 +267,8 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
if (attachment.progress != null)
holder.tvProgress.setText(String.format("%d %%", attachment.progress));
holder.tvProgress.setVisibility(attachment.progress == null ? View.GONE : View.VISIBLE);
holder.tvProgress.setVisibility(
attachment.progress == null || attachment.content != null ? View.GONE : View.VISIBLE);
if (attachment.content == null) {
if (attachment.progress == null) {


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

@ -19,6 +19,7 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
@ -30,7 +31,7 @@ import java.util.List;
@Dao
public interface DaoAttachment {
@Query("SELECT * FROM attachment WHERE message = :message")
List<EntityAttachment> getAttachments(long message);
LiveData<List<EntityAttachment>> liveAttachments(long message);
@Query("SELECT * FROM attachment WHERE message = :message AND sequence = :sequence")
EntityAttachment getAttachment(long message, int sequence);


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

@ -58,4 +58,20 @@ public class EntityAttachment {
@Ignore
BodyPart part;
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityAttachment) {
EntityAttachment other = (EntityAttachment) obj;
return (this.message.equals(other.message) &&
this.sequence.equals(other.sequence) &&
(this.name == null ? other.name == null : this.name.equals(other.name)) &&
this.type.equals(other.type) &&
(this.size == null ? other.size == null : this.size.equals(other.size)) &&
(this.progress == null ? other.progress == null : this.progress.equals(other.progress)) &&
(this.content == null ? other.content == null : other.content != null));
} else
return false;
}
}

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

@ -231,6 +231,16 @@ public class FragmentMessage extends Fragment {
tvSubject.setTypeface(null, visibility);
tvCount.setTypeface(null, visibility);
DB.getInstance(getContext()).attachment().liveAttachments(id).removeObservers(FragmentMessage.this);
DB.getInstance(getContext()).attachment().liveAttachments(id).observe(FragmentMessage.this,
new Observer<List<EntityAttachment>>() {
@Override
public void onChanged(@Nullable List<EntityAttachment> attachments) {
adapter.set(attachments);
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
}
});
top_navigation.getMenu().findItem(R.id.action_thread).setVisible(message.count > 1);
MenuItem actionSeen = top_navigation.getMenu().findItem(R.id.action_seen);
@ -454,7 +464,6 @@ public class FragmentMessage extends Fragment {
result.hasTrash = (db.folder().getFolderByType(message.account, EntityFolder.TYPE_TRASH) != null);
result.hasJunk = (db.folder().getFolderByType(message.account, EntityFolder.TYPE_JUNK) != null);
result.hasArchive = (db.folder().getFolderByType(message.account, EntityFolder.TYPE_ARCHIVE) != null);
result.attachments = db.attachment().getAttachments(id);
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
result.ex = ex;
@ -481,9 +490,6 @@ public class FragmentMessage extends Fragment {
? null
: Helper.localizeFolderName(getContext(), data.folder.name));
adapter.set(data.attachments);
grpAttachments.setVisibility(data.attachments.size() > 0 ? View.VISIBLE : View.GONE);
boolean outbox = EntityFolder.TYPE_OUTBOX.equals(data.folder.type);
bottom_navigation.setTag(data.folder.type); // trash or delete
@ -505,6 +511,5 @@ public class FragmentMessage extends Fragment {
boolean hasTrash;
boolean hasJunk;
boolean hasArchive;
List<EntityAttachment> attachments;
}
}

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

@ -731,7 +731,7 @@ public class ServiceSynchronize extends LifecycleService {
}
// Store attachment data
attachment.progress = 100;
attachment.progress = null;
attachment.content = os.toByteArray();
db.attachment().updateAttachment(attachment);
Log.i(Helper.TAG, "Downloaded bytes=" + attachment.content.length);


Loading…
Cancel
Save