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

Loading…
Cancel
Save