Browse Source

Use linked drafts folder

Fixes #28
main
M66B 6 years ago
parent
commit
93f75af745
8 changed files with 28 additions and 70 deletions
  1. +4
    -4
      app/src/main/java/eu/faircode/email/AdapterFolder.java
  2. +1
    -1
      app/src/main/java/eu/faircode/email/ApplicationEx.java
  3. +4
    -6
      app/src/main/java/eu/faircode/email/DaoFolder.java
  4. +1
    -1
      app/src/main/java/eu/faircode/email/FragmentAbout.java
  5. +2
    -3
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  6. +15
    -7
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  7. +0
    -45
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  8. +1
    -3
      app/src/main/res/values/strings.xml

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

@ -68,9 +68,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
ivSync = itemView.findViewById(R.id.ivSync);
}
private void wire() {
private void wire(boolean properties) {
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
if (properties)
itemView.setOnLongClickListener(this);
}
private void unwire() {
@ -249,7 +250,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
TupleFolderEx folder = filtered.get(position);
holder.bindTo(folder);
holder.wire();
holder.wire(folder.account != null);
}
}

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

@ -43,7 +43,7 @@ public class ApplicationEx extends Application {
DB db = null;
try {
db = DB.getBlockingInstance(ApplicationEx.this);
EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
EntityFolder drafts = db.folder().getLocalDrafts();
if (drafts != null) {
Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode");
String body = ex + "\n" + Log.getStackTraceString(ex);


+ 4
- 6
app/src/main/java/eu/faircode/email/DaoFolder.java View File

@ -45,7 +45,7 @@ public interface DaoFolder {
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" WHERE folder.account = :account" +
" WHERE folder.account = :account OR folder.account IS NULL" +
" GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveFolders(long account);
@ -71,14 +71,12 @@ public interface DaoFolder {
" WHERE account = :account AND type = :type")
EntityFolder getFolderByType(long account, String type);
@Query("SELECT * FROM folder WHERE account IS NULL AND type = '" + EntityFolder.TYPE_DRAFTS + "'")
EntityFolder getLocalDrafts();
@Query("SELECT * FROM folder WHERE type = '" + EntityFolder.TYPE_OUTBOX + "'")
EntityFolder getOutbox();
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE account.`primary` AND type = :type ")
EntityFolder getPrimaryFolder(String type);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insertFolder(EntityFolder folder);


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

@ -61,7 +61,7 @@ public class FragmentAbout extends FragmentEx {
public void run() {
try {
DB db = DB.getInstance(getContext());
EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
EntityFolder drafts = db.folder().getLocalDrafts();
if (drafts != null) {
StringBuilder info = Helper.getDebugInfo();
info.insert(0, getString(R.string.title_debug_info_remark) + "\n\n\n\n");


+ 2
- 3
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -324,16 +324,15 @@ public class FragmentAccount extends FragmentEx {
drafts = true;
}
}
/*
if (!drafts) {
EntityFolder folder = new EntityFolder();
folder.name = getContext().getString(R.string.title_local_drafts);
folder.name = getContext().getString(R.string.title_folder_local_drafts);
folder.type = EntityFolder.TYPE_DRAFTS;
folder.synchronize = false;
folder.after = 0;
folders.add(folder);
}
*/
} finally {
if (istore != null)
istore.close();


+ 15
- 7
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -51,7 +51,6 @@ import java.util.Date;
import java.util.List;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import androidx.annotation.NonNull;
@ -515,9 +514,20 @@ public class FragmentCompose extends FragmentEx {
// Get data
EntityMessage draft = message.getMessage(id);
EntityIdentity ident = identity.getIdentity(args.getLong("iid"));
EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
if (ident == null)
throw new IllegalArgumentException(getContext().getString(R.string.title_from_missing));
EntityFolder drafts = db.folder().getFolderByType(ident.account, EntityFolder.TYPE_DRAFTS);
if (drafts == null)
throw new Throwable(getContext().getString(R.string.title_no_primary_drafts));
drafts = db.folder().getLocalDrafts();
if (drafts == null) {
drafts = new EntityFolder();
drafts.name = getContext().getString(R.string.title_folder_local_drafts);
drafts.type = EntityFolder.TYPE_DRAFTS;
drafts.synchronize = false;
drafts.after = 0;
db.folder().insertFolder(drafts);
}
long rid = args.getLong("rid", -1);
String thread = args.getString("thread");
@ -563,10 +573,8 @@ public class FragmentCompose extends FragmentEx {
db.beginTransaction();
if ("send".equals(action)) {
if (draft.identity == null)
throw new MessagingException(getContext().getString(R.string.title_from_missing));
if (draft.to == null && draft.cc == null && draft.bcc == null)
throw new MessagingException(getContext().getString(R.string.title_to_missing));
throw new IllegalArgumentException(getContext().getString(R.string.title_to_missing));
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE);
@ -583,7 +591,7 @@ public class FragmentCompose extends FragmentEx {
else if ("trash".equals(action)) {
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE);
EntityFolder trash = db.folder().getPrimaryFolder(EntityFolder.TYPE_TRASH);
EntityFolder trash = db.folder().getFolderByType(ident.account, EntityFolder.TYPE_TRASH);
if (trash != null) {
draft.id = null;
draft.folder = trash.id;


+ 0
- 45
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -19,7 +19,6 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
@ -37,9 +36,6 @@ import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.AsyncTaskLoader;
import androidx.loader.content.Loader;
import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -95,7 +91,6 @@ public class FragmentMessages extends FragmentEx {
tvNoEmail.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);
fab.setVisibility(View.GONE);
return view;
}
@ -150,45 +145,5 @@ public class FragmentMessages extends FragmentEx {
}
}
});
LoaderManager.getInstance(this)
.restartLoader(ActivityView.LOADER_MESSAGES_INIT, new Bundle(), initLoaderCallbacks).forceLoad();
}
private static class InitLoader extends AsyncTaskLoader<Bundle> {
InitLoader(@NonNull Context context) {
super(context);
}
@Nullable
@Override
public Bundle loadInBackground() {
Bundle result = new Bundle();
try {
EntityFolder drafts = DB.getInstance(getContext()).folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
result.putBoolean("drafts", drafts != null);
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
result.putBoolean("drafts", false);
}
return result;
}
}
private LoaderManager.LoaderCallbacks initLoaderCallbacks = new LoaderManager.LoaderCallbacks<Bundle>() {
@NonNull
@Override
public Loader<Bundle> onCreateLoader(int id, @Nullable Bundle args) {
return new InitLoader(getContext());
}
@Override
public void onLoadFinished(@NonNull Loader<Bundle> loader, Bundle data) {
fab.setVisibility(data.getBoolean("drafts", false) ? View.VISIBLE : View.GONE);
}
@Override
public void onLoaderReset(@NonNull Loader<Bundle> loader) {
}
};
}

+ 1
- 3
app/src/main/res/values/strings.xml View File

@ -67,7 +67,6 @@
<string name="title_no_user">User name missing</string>
<string name="title_no_password">Password missing</string>
<string name="title_no_idle">IDLE not supported</string>
<string name="title_local_drafts">Local drafts</string>
<string name="title_account_delete">Delete this account permanently?</string>
<string name="title_identity_delete">Delete this identity permanently?</string>
@ -84,6 +83,7 @@
<string name="title_folder_junk">Spam</string>
<string name="title_folder_sent">Sent</string>
<string name="title_folder_user">User</string>
<string name="title_folder_local_drafts">Local drafts</string>
<string name="title_folder_thread">Message thread</string>
<string name="title_no_messages">No messages</string>
@ -118,8 +118,6 @@
<string name="title_save">Save</string>
<string name="title_send">Send</string>
<string name="title_no_primary_drafts">No primary account or no drafts folder</string>
<string name="title_from_missing">Sender missing</string>
<string name="title_to_missing">Recipient missing</string>
<string name="title_draft_trashed">Draft trashed</string>


Loading…
Cancel
Save