Clear selection tracker

This commit is contained in:
M66B 2022-04-14 20:10:38 +02:00
parent f9392d05e7
commit 07cacc259e
2 changed files with 18 additions and 6 deletions

View File

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

View File

@ -3503,6 +3503,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
private long[] getSelection() {
if (selectionTracker == null)
return new long[0];
Selection<Long> 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<Void>() {
@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<Void>() {
@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<Void>() {
@Override