Browse Source

Fixed attachment observing

main
M66B 6 years ago
parent
commit
a4b843ecd5
5 changed files with 43 additions and 28 deletions
  1. +12
    -3
      app/src/main/java/eu/faircode/email/DaoAttachment.java
  2. +4
    -2
      app/src/main/java/eu/faircode/email/DaoMessage.java
  3. +14
    -12
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  4. +12
    -11
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  5. +1
    -0
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 12
- 3
app/src/main/java/eu/faircode/email/DaoAttachment.java View File

@ -29,12 +29,21 @@ import androidx.room.Update;
@Dao
public interface DaoAttachment {
@Query("SELECT id, message, sequence, name, type, size, progress" +
@Query("SELECT attachment.id, attachment.message, sequence, name, type, size, progress" +
", (NOT content IS NULL) as content" +
" FROM attachment" +
" WHERE message = :message" +
" WHERE message = :id" +
" ORDER BY sequence")
LiveData<List<TupleAttachment>> liveAttachments(long id);
@Query("SELECT attachment.id, attachment.message, sequence, name, type, size, progress" +
", (NOT content IS NULL) as content" +
" FROM attachment" +
" JOIN message ON message.id = attachment.message" +
" WHERE folder = :folder" +
" AND msgid = :msgid" +
" ORDER BY sequence")
LiveData<List<TupleAttachment>> liveAttachments(long message);
LiveData<List<TupleAttachment>> liveAttachments(long folder, String msgid);
@Query("SELECT * FROM attachment" +
" WHERE message = :message" +


+ 4
- 2
app/src/main/java/eu/faircode/email/DaoMessage.java View File

@ -103,8 +103,10 @@ public interface DaoMessage {
" WHERE message.id = :id")
LiveData<TupleMessageEx> liveMessage(long id);
@Query("SELECT * FROM message WHERE msgid = :msgid")
LiveData<EntityMessage> liveMessageByMsgId(String msgid);
@Query("SELECT * FROM message" +
" WHERE folder = :folder" +
" AND msgid = :msgid")
LiveData<EntityMessage> liveMessageByMsgId(long folder, String msgid);
@Query("SELECT uid FROM message WHERE folder = :folder AND received >= :received AND NOT uid IS NULL")
List<Long> getUids(long folder, long received);


+ 14
- 12
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -585,12 +585,25 @@ public class FragmentCompose extends FragmentEx {
return draft;
}
@Override
protected void onLoaded(Bundle args, EntityMessage draft) {
FragmentCompose.this.draft = draft;
Log.i(Helper.TAG, "Loaded draft id=" + draft.id + " msgid=" + draft.msgid);
DB.getInstance(getContext()).message().liveMessageByMsgId(draft.msgid).observe(getViewLifecycleOwner(), new Observer<EntityMessage>() {
DB db = DB.getInstance(getContext());
db.attachment().liveAttachments(draft.folder, draft.msgid).observe(getViewLifecycleOwner(),
new Observer<List<TupleAttachment>>() {
@Override
public void onChanged(@Nullable List<TupleAttachment> attachments) {
if (attachments != null)
adapter.set(attachments);
grpAttachments.setVisibility(attachments != null && attachments.size() > 0 ? View.VISIBLE : View.GONE);
}
});
db.message().liveMessageByMsgId(draft.folder, draft.msgid).observe(getViewLifecycleOwner(), new Observer<EntityMessage>() {
boolean observed = false;
@Override
@ -606,17 +619,6 @@ public class FragmentCompose extends FragmentEx {
DB db = DB.getInstance(getContext());
db.attachment().liveAttachments(draft.id).removeObservers(getViewLifecycleOwner());
db.attachment().liveAttachments(draft.id).observe(getViewLifecycleOwner(),
new Observer<List<TupleAttachment>>() {
@Override
public void onChanged(@Nullable List<TupleAttachment> attachments) {
if (attachments != null)
adapter.set(attachments);
grpAttachments.setVisibility(attachments != null && attachments.size() > 0 ? View.VISIBLE : View.GONE);
}
});
// Set controls only once
if (observed)
return;


+ 12
- 11
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -275,17 +275,6 @@ public class FragmentMessage extends FragmentEx {
tvFrom.setTextColor(colorUnseen);
tvTime.setTextColor(colorUnseen);
db.attachment().liveAttachments(id).removeObservers(getViewLifecycleOwner());
db.attachment().liveAttachments(id).observe(getViewLifecycleOwner(),
new Observer<List<TupleAttachment>>() {
@Override
public void onChanged(@Nullable List<TupleAttachment> attachments) {
if (attachments != null)
adapter.set(attachments);
grpAttachments.setVisibility(attachments != null && attachments.size() > 0 ? View.VISIBLE : View.GONE);
}
});
tvError.setText(message.error);
tvError.setVisibility(message.error == null ? View.GONE : View.VISIBLE);
@ -350,6 +339,18 @@ public class FragmentMessage extends FragmentEx {
grpReady.setVisibility(View.VISIBLE);
}
});
// Observe attachments
db.attachment().liveAttachments(id).observe(getViewLifecycleOwner(),
new Observer<List<TupleAttachment>>() {
@Override
public void onChanged(@Nullable List<TupleAttachment> attachments) {
if (attachments != null)
adapter.set(attachments);
grpAttachments.setVisibility(attachments != null && attachments.size() > 0 ? View.VISIBLE : View.GONE);
}
});
}
@Override


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

@ -1185,6 +1185,7 @@ public class ServiceSynchronize extends LifecycleService {
DB db = DB.getInstance(this);
try {
int result = 0;
db.beginTransaction();
// Find message by uid (fast, no headers required)


Loading…
Cancel
Save