Browse Source

Disable compose on no primary drafts folder

main
M66B 6 years ago
parent
commit
3d3bf4b4d3
2 changed files with 40 additions and 0 deletions
  1. +1
    -0
      app/src/main/java/eu/faircode/email/ActivityView.java
  2. +39
    -0
      app/src/main/java/eu/faircode/email/FragmentMessages.java

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

@ -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;


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

@ -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…
Cancel
Save