Fixed swipe refresh enabled state

pull/152/head
M66B 6 years ago
parent 9786067060
commit 46966c5311

@ -134,6 +134,7 @@ public class FragmentMessages extends FragmentBase {
private boolean outbox = false; private boolean outbox = false;
private boolean connected; private boolean connected;
private boolean searching = false; private boolean searching = false;
private boolean refresh = false;
private boolean manual = false; private boolean manual = false;
private AdapterMessage adapter; private AdapterMessage adapter;
@ -246,6 +247,7 @@ public class FragmentMessages extends FragmentBase {
int colorPrimary = Helper.resolveColor(getContext(), R.attr.colorPrimary); int colorPrimary = Helper.resolveColor(getContext(), R.attr.colorPrimary);
swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE); swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
swipeRefresh.setProgressBackgroundColorSchemeColor(colorPrimary); swipeRefresh.setProgressBackgroundColorSchemeColor(colorPrimary);
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
@ -385,7 +387,7 @@ public class FragmentMessages extends FragmentBase {
((ActivityBase) getActivity()).addBackPressedListener(onBackPressedListener); ((ActivityBase) getActivity()).addBackPressedListener(onBackPressedListener);
// Initialize // Initialize
swipeRefresh.setEnabled(pull); swipeRefresh.setEnabled(false);
tvNoEmail.setVisibility(View.GONE); tvNoEmail.setVisibility(View.GONE);
seekBar.setEnabled(false); seekBar.setEnabled(false);
seekBar.setVisibility(View.GONE); seekBar.setVisibility(View.GONE);
@ -470,7 +472,7 @@ public class FragmentMessages extends FragmentBase {
fabMore.show(); fabMore.show();
} else { } else {
fabMore.hide(); fabMore.hide();
swipeRefresh.setEnabled(pull); swipeRefresh.setEnabled(pull && refresh);
} }
} }
}); });
@ -488,32 +490,34 @@ public class FragmentMessages extends FragmentBase {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("folder", folder); args.putLong("folder", folder);
new SimpleTask<Boolean>() { new SimpleTask<Void>() {
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
manual = true; manual = true;
} }
@Override @Override
protected Boolean onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
long fid = args.getLong("folder"); long fid = args.getLong("folder");
if (!Helper.suitableNetwork(context, false)) if (!Helper.suitableNetwork(context, false))
throw new IllegalArgumentException(context.getString(R.string.title_no_internet)); throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
if (fid < 0) { List<EntityFolder> folders = new ArrayList<>();
List<EntityFolder> folders = db.folder().getFoldersSynchronizingUnified(); if (fid < 0)
for (EntityFolder folder : folders) folders.addAll(db.folder().getFoldersSynchronizingUnified());
EntityOperation.sync(context, folder.id, true); else {
} else {
EntityFolder folder = db.folder().getFolder(fid); EntityFolder folder = db.folder().getFolder(fid);
if (folder != null) if (folder != null)
EntityOperation.sync(context, folder.id, true); folders.add(folder);
} }
for (EntityFolder folder : folders)
EntityOperation.sync(context, folder.id, true);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -745,7 +749,7 @@ public class FragmentMessages extends FragmentBase {
@Override @Override
public void onSelectedChanged(@Nullable RecyclerView.ViewHolder viewHolder, int actionState) { public void onSelectedChanged(@Nullable RecyclerView.ViewHolder viewHolder, int actionState) {
super.onSelectedChanged(viewHolder, actionState); super.onSelectedChanged(viewHolder, actionState);
swipeRefresh.setEnabled(pull && actionState != ItemTouchHelper.ACTION_STATE_SWIPE); swipeRefresh.setEnabled(pull && refresh && actionState != ItemTouchHelper.ACTION_STATE_SWIPE);
} }
@Override @Override
@ -1518,9 +1522,12 @@ public class FragmentMessages extends FragmentBase {
Log.i("Folder state updated count=" + folders.size()); Log.i("Folder state updated count=" + folders.size());
int unseen = 0; int unseen = 0;
boolean sync = false;
boolean errors = false; boolean errors = false;
for (TupleFolderEx folder : folders) { for (TupleFolderEx folder : folders) {
unseen += folder.unseen; unseen += folder.unseen;
if (folder.synchronize)
sync = true;
if (folder.error != null || folder.accountError != null) if (folder.error != null || folder.accountError != null)
errors = true; errors = true;
} }
@ -1546,6 +1553,8 @@ public class FragmentMessages extends FragmentBase {
if (errors && !refreshing && swipeRefresh.isRefreshing()) if (errors && !refreshing && swipeRefresh.isRefreshing())
Snackbar.make(view, R.string.title_sync_errors, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, R.string.title_sync_errors, Snackbar.LENGTH_LONG).show();
refresh = sync;
swipeRefresh.setEnabled(pull && refresh);
swipeRefresh.setRefreshing(refreshing); swipeRefresh.setRefreshing(refreshing);
} }
}); });
@ -1585,6 +1594,8 @@ public class FragmentMessages extends FragmentBase {
if (error != null && !refreshing && swipeRefresh.isRefreshing()) if (error != null && !refreshing && swipeRefresh.isRefreshing())
Snackbar.make(view, error, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, error, Snackbar.LENGTH_LONG).show();
refresh = (folder != null);
swipeRefresh.setEnabled(pull && refresh);
swipeRefresh.setRefreshing(refreshing); swipeRefresh.setRefreshing(refreshing);
} }
}); });

Loading…
Cancel
Save