From 8aafe711670bd5ef7284c0634ccf7caa3dddb843 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 12 Jun 2019 15:28:07 -0500 Subject: [PATCH] Restore selected state in TaskListFragment --- .../astrid/activity/TaskListFragment.java | 11 +++++++-- .../tasklist/TaskListRecyclerAdapter.java | 23 +------------------ 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index cd75fb463..55822c6d1 100644 --- a/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -36,6 +36,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import com.google.android.material.snackbar.Snackbar; +import com.google.common.primitives.Longs; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.QueryTemplate; @@ -100,6 +101,7 @@ public final class TaskListFragment extends InjectingFragment public static final String ACTION_RELOAD = "action_reload"; public static final String ACTION_DELETED = "action_deleted"; public static final int REQUEST_MOVE_TASKS = 10103; + private static final String EXTRA_SELECTED_TASK_IDS = "extra_selected_task_ids"; private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234; private static final String EXTRA_FILTER = "extra_filter"; private static final String FRAG_TAG_SORT_DIALOG = "frag_tag_sort_dialog"; @@ -197,7 +199,11 @@ public final class TaskListFragment extends InjectingFragment super.onViewStateRestored(savedInstanceState); if (savedInstanceState != null) { - recyclerAdapter.restoreSaveState(savedInstanceState); + long[] longArray = savedInstanceState.getLongArray(EXTRA_SELECTED_TASK_IDS); + if (longArray != null && longArray.length > 0) { + taskAdapter.setSelected(longArray); + recyclerAdapter.startActionMode(); + } } } @@ -217,7 +223,8 @@ public final class TaskListFragment extends InjectingFragment public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); - outState.putAll(recyclerAdapter.getSaveState()); + List selectedTaskIds = taskAdapter.getSelected(); + outState.putLongArray(EXTRA_SELECTED_TASK_IDS, Longs.toArray(selectedTaskIds)); } @Override diff --git a/app/src/main/java/org/tasks/tasklist/TaskListRecyclerAdapter.java b/app/src/main/java/org/tasks/tasklist/TaskListRecyclerAdapter.java index 1cb5c5580..bb4f96d2a 100644 --- a/app/src/main/java/org/tasks/tasklist/TaskListRecyclerAdapter.java +++ b/app/src/main/java/org/tasks/tasklist/TaskListRecyclerAdapter.java @@ -1,6 +1,5 @@ package org.tasks.tasklist; -import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; @@ -10,7 +9,6 @@ import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.ListUpdateCallback; import androidx.recyclerview.widget.RecyclerView; -import com.google.common.primitives.Longs; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.adapter.TaskAdapter; import com.todoroo.astrid.api.Filter; @@ -24,8 +22,6 @@ import org.tasks.intents.TaskIntents; public abstract class TaskListRecyclerAdapter extends RecyclerView.Adapter implements ViewHolder.ViewHolderCallbacks, ListUpdateCallback { - private static final String EXTRA_SELECTED_TASK_IDS = "extra_selected_task_ids"; - protected final TaskAdapter adapter; final TaskListFragment taskList; private final RecyclerView recyclerView; @@ -48,23 +44,6 @@ public abstract class TaskListRecyclerAdapter extends RecyclerView.Adapter selectedTaskIds = adapter.getSelected(); - information.putLongArray(EXTRA_SELECTED_TASK_IDS, Longs.toArray(selectedTaskIds)); - return information; - } - - public void restoreSaveState(Bundle savedState) { - long[] longArray = savedState.getLongArray(EXTRA_SELECTED_TASK_IDS); - if (longArray != null && longArray.length > 0) { - mode = actionModeProvider.startActionMode(adapter, taskList, this); - adapter.setSelected(longArray); - - updateModeTitle(); - } - } - @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -120,7 +99,7 @@ public abstract class TaskListRecyclerAdapter extends RecyclerView.Adapter