Another attempt to workaround AndroidX bug

https://issuetracker.google.com/issues/78495471
This commit is contained in:
M66B 2019-02-05 16:17:37 +00:00
parent e83acece19
commit 60d040eff0
1 changed files with 17 additions and 8 deletions

View File

@ -659,6 +659,16 @@ public class FragmentMessages extends FragmentBase {
};
private ItemTouchHelper.Callback touchHelper = new ItemTouchHelper.Callback() {
private Handler handler = new Handler();
private Runnable enableSelection = new Runnable() {
@Override
public void run() {
if (selectionPredicate != null)
selectionPredicate.setEnabled(true);
}
};
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
TupleMessageEx message = getMessage(viewHolder);
@ -693,8 +703,13 @@ public class FragmentMessages extends FragmentBase {
AdapterMessage.ViewHolder holder = ((AdapterMessage.ViewHolder) viewHolder);
holder.setDisplacement(dX);
if (selectionPredicate != null)
selectionPredicate.setEnabled(!isCurrentlyActive);
if (selectionPredicate != null) {
handler.removeCallbacks(enableSelection);
if (isCurrentlyActive)
selectionPredicate.setEnabled(false);
else
handler.postDelayed(enableSelection, 1000);
}
TupleMessageEx message = getMessage(viewHolder);
if (message == null)
@ -743,9 +758,6 @@ public class FragmentMessages extends FragmentBase {
Log.i("Swiped dir=" + direction + " message=" + message.id);
if (selectionPredicate != null)
selectionPredicate.setEnabled(false);
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD);
@ -1955,9 +1967,6 @@ public class FragmentMessages extends FragmentBase {
return;
}
if (selectionPredicate != null)
selectionPredicate.setEnabled(true);
if (viewType == AdapterMessage.ViewType.THREAD) {
// Mark duplicates
Map<String, List<TupleMessageEx>> duplicates = new HashMap<>();