mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-22 07:42:52 +00:00
Disable compose on no primary drafts folder
This commit is contained in:
parent
d17ff4f188
commit
3d3bf4b4d3
2 changed files with 40 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<Bundle> {
|
||||
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<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.setEnabled(data.getBoolean("drafts", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(@NonNull Loader<Bundle> loader) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue