From 3d3bf4b4d3f53d35336853094cf5c72365325165 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 3 Aug 2018 08:42:56 +0000 Subject: [PATCH] Disable compose on no primary drafts folder --- .../java/eu/faircode/email/ActivityView.java | 1 + .../eu/faircode/email/FragmentMessages.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 8750b8b4..12bd5db6 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -64,6 +64,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack static final int LOADER_ACCOUNT_PUT = 1; static final int LOADER_IDENTITY_PUT = 2; static final int LOADER_FOLDER_PUT = 3; + static final int LOADER_MESSAGES_INIT = 4; static final int REQUEST_VIEW = 1; diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index e1db6561..f88e19a2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -21,6 +21,7 @@ package eu.faircode.email; import android.arch.lifecycle.LiveData; import android.arch.lifecycle.Observer; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; @@ -28,6 +29,9 @@ import android.support.annotation.Nullable; import android.support.constraint.Group; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; +import android.support.v4.app.LoaderManager; +import android.support.v4.content.AsyncTaskLoader; +import android.support.v4.content.Loader; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -88,6 +92,7 @@ public class FragmentMessages extends Fragment { tvNoEmail.setVisibility(View.GONE); grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); + fab.setEnabled(false); DB db = DB.getInstance(getContext()); @@ -104,6 +109,8 @@ public class FragmentMessages extends Fragment { db.message().liveThread(thread).observe(this, messagesObserver); } + getLoaderManager().restartLoader(ActivityView.LOADER_MESSAGES_INIT, new Bundle(), initLoaderCallbacks).forceLoad(); + return view; } @@ -149,4 +156,36 @@ public class FragmentMessages extends Fragment { } } }; + + private static class InitLoader extends AsyncTaskLoader { + public InitLoader(@NonNull Context context) { + super(context); + } + + @Nullable + @Override + public Bundle loadInBackground() { + Bundle result = new Bundle(); + EntityFolder drafts = DB.getInstance(getContext()).folder().getPrimaryDraftFolder(); + result.putBoolean("drafts", drafts != null); + return result; + } + } + + private LoaderManager.LoaderCallbacks initLoaderCallbacks = new LoaderManager.LoaderCallbacks() { + @NonNull + @Override + public Loader onCreateLoader(int id, @Nullable Bundle args) { + return new InitLoader(getContext()); + } + + @Override + public void onLoadFinished(@NonNull Loader loader, Bundle data) { + fab.setEnabled(data.getBoolean("drafts", false)); + } + + @Override + public void onLoaderReset(@NonNull Loader loader) { + } + }; }