diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index f2d02d2afe..a833a40927 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -60,6 +60,7 @@ import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceManager; +import androidx.recyclerview.selection.SelectionTracker; import androidx.recyclerview.widget.RecyclerView; import java.io.File; @@ -811,6 +812,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc Class type = field.getType(); if (View.class.isAssignableFrom(type) || Animator.class.isAssignableFrom(type) || + SelectionTracker.class.isAssignableFrom(type) || + SelectionTracker.SelectionPredicate.class.isAssignableFrom(type) || RecyclerView.Adapter.class.isAssignableFrom(type)) { Log.i("Clearing " + f.getClass().getSimpleName() + ":" + field.getName()); field.setAccessible(true); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 85ecefad27..bf8ed663c0 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -3503,6 +3503,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private long[] getSelection() { + if (selectionTracker == null) + return new long[0]; + Selection selection = selectionTracker.getSelection(); long[] ids = new long[selection.size()]; @@ -3609,7 +3612,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. args.putLongArray("ids", getSelection()); args.putBoolean("hide", hide); - selectionTracker.clearSelection(); + if (selectionTracker != null) + selectionTracker.clearSelection(); new SimpleTask() { @Override @@ -3658,7 +3662,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. args.putBoolean("threading", threading && (id == null || viewType != AdapterMessage.ViewType.THREAD)); - //selectionTracker.clearSelection(); + //if (selectionTracker != null) + // selectionTracker.clearSelection(); new SimpleTask() { @Override @@ -3774,7 +3779,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. args.putLongArray("ids", getSelection()); args.putBoolean("threads", false); - selectionTracker.clearSelection(); + if (selectionTracker != null) + selectionTracker.clearSelection(); FragmentDialogForwardRaw ask = new FragmentDialogForwardRaw(); ask.setArguments(args); @@ -3859,7 +3865,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private void onActionJunkSelection() { Bundle aargs = new Bundle(); - aargs.putInt("count", selectionTracker.getSelection().size()); + aargs.putInt("count", getSelection().length); FragmentDialogAskSpam ask = new FragmentDialogAskSpam(); ask.setArguments(aargs); @@ -5330,6 +5336,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. view.post(new Runnable() { @Override public void run() { + if (selectionTracker == null) + return; selectionTracker.clearSelection(); for (long id : ids) selectionTracker.select(id); @@ -5632,7 +5640,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. fabMore.show(); Context context = tvSelectedCount.getContext(); - int count = selectionTracker.getSelection().size(); + int count = getSelection().length; tvSelectedCount.setText(NF.format(count)); if (count > (BuildConfig.DEBUG ? 10 : MAX_MORE)) { int ts = Math.round(tvSelectedCount.getTextSize()); @@ -8753,7 +8761,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. args.putLong("wakeup", duration == 0 ? -1 : time); args.putLongArray("ids", getSelection()); - selectionTracker.clearSelection(); + if (selectionTracker != null) + selectionTracker.clearSelection(); new SimpleTask() { @Override