Rename task input controller.
The TaskInputController class doesn't need to be tightly coupled with the actual input method, so we should rename it and the methods to correspond to the actual logic. For example, both tapping a task and pressing the overview button on recents should launch a task and should both use this logic. Bug: 114136250 Test: Launch tasks, clear tasks, clear all Change-Id: If4f7f1d6ee9b05ffaf65cb13df633679cc8efcbe
This commit is contained in:
parent
1bfb0c1c51
commit
969e7a6c57
|
@ -23,24 +23,25 @@ import com.android.systemui.shared.recents.model.Task;
|
|||
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
||||
|
||||
/**
|
||||
* Controller responsible for task logic that occurs on various input to the recents view.
|
||||
* Controller that provides logic for task-related commands on recents and updating the model/view
|
||||
* as appropriate.
|
||||
*/
|
||||
public final class TaskInputController {
|
||||
public final class TaskActionController {
|
||||
|
||||
private final TaskListLoader mLoader;
|
||||
private final TaskAdapter mAdapter;
|
||||
|
||||
public TaskInputController(TaskListLoader loader,TaskAdapter adapter) {
|
||||
public TaskActionController(TaskListLoader loader, TaskAdapter adapter) {
|
||||
mLoader = loader;
|
||||
mAdapter = adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic that occurs when a task view is tapped. Launches the respective task.
|
||||
* Launch the task associated with the task holder, animating into the app.
|
||||
*
|
||||
* @param viewHolder the task view holder that has been tapped
|
||||
* @param viewHolder the task view holder to launch
|
||||
*/
|
||||
public void onTaskClicked(TaskHolder viewHolder) {
|
||||
public void launchTask(TaskHolder viewHolder) {
|
||||
TaskItemView itemView = (TaskItemView) (viewHolder.itemView);
|
||||
View v = itemView.getThumbnailView();
|
||||
int left = 0;
|
||||
|
@ -53,7 +54,12 @@ public final class TaskInputController {
|
|||
opts, null /* resultCallback */, null /* resultCallbackHandler */);
|
||||
}
|
||||
|
||||
public void onTaskSwiped(TaskHolder viewHolder) {
|
||||
/**
|
||||
* Removes the task holder and the task, updating the model and the view.
|
||||
*
|
||||
* @param viewHolder the task view holder to remove
|
||||
*/
|
||||
public void removeTask(TaskHolder viewHolder) {
|
||||
int position = viewHolder.getAdapterPosition();
|
||||
Task task = viewHolder.getTask();
|
||||
ActivityManagerWrapper.getInstance().removeTask(task.key.id);
|
||||
|
@ -62,9 +68,9 @@ public final class TaskInputController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Logic that occurs when clear all is triggered.
|
||||
* Clears all tasks and updates the model and view.
|
||||
*/
|
||||
public void onClearAllClicked(View view) {
|
||||
public void clearAllTasks() {
|
||||
// TODO: Play an animation so transition is more natural.
|
||||
int count = mAdapter.getItemCount();
|
||||
ActivityManagerWrapper.getInstance().removeAllRecentTasks();
|
|
@ -39,14 +39,14 @@ public final class TaskAdapter extends Adapter<TaskHolder> {
|
|||
private static final String TAG = "TaskAdapter";
|
||||
private final TaskListLoader mLoader;
|
||||
private final ArrayMap<Integer, TaskItemView> mTaskIdToViewMap = new ArrayMap<>();
|
||||
private TaskInputController mInputController;
|
||||
private TaskActionController mTaskActionController;
|
||||
|
||||
public TaskAdapter(@NonNull TaskListLoader loader) {
|
||||
mLoader = loader;
|
||||
}
|
||||
|
||||
public void setInputController(TaskInputController inputController) {
|
||||
mInputController = inputController;
|
||||
public void setActionController(TaskActionController taskActionController) {
|
||||
mTaskActionController = taskActionController;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,7 @@ public final class TaskAdapter extends Adapter<TaskHolder> {
|
|||
TaskItemView itemView = (TaskItemView) LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.task_item_view, parent, false);
|
||||
TaskHolder holder = new TaskHolder(itemView);
|
||||
itemView.setOnClickListener(view -> mInputController.onTaskClicked(holder));
|
||||
itemView.setOnClickListener(view -> mTaskActionController.launchTask(holder));
|
||||
return holder;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
|||
*/
|
||||
public final class TaskSwipeCallback extends ItemTouchHelper.SimpleCallback {
|
||||
|
||||
private final TaskInputController mTaskInputController;
|
||||
private final TaskActionController mTaskActionController;
|
||||
|
||||
public TaskSwipeCallback(TaskInputController inputController) {
|
||||
public TaskSwipeCallback(TaskActionController taskActionController) {
|
||||
super(0 /* dragDirs */, RIGHT);
|
||||
mTaskInputController = inputController;
|
||||
mTaskActionController = taskActionController;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,7 +42,7 @@ public final class TaskSwipeCallback extends ItemTouchHelper.SimpleCallback {
|
|||
@Override
|
||||
public void onSwiped(ViewHolder viewHolder, int direction) {
|
||||
if (direction == RIGHT) {
|
||||
mTaskInputController.onTaskSwiped((TaskHolder) viewHolder);
|
||||
mTaskActionController.removeTask((TaskHolder) viewHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
|
|||
import com.android.launcher3.R;
|
||||
import com.android.quickstep.RecentsToActivityHelper;
|
||||
import com.android.quickstep.TaskAdapter;
|
||||
import com.android.quickstep.TaskInputController;
|
||||
import com.android.quickstep.TaskActionController;
|
||||
import com.android.quickstep.TaskListLoader;
|
||||
import com.android.quickstep.TaskSwipeCallback;
|
||||
|
||||
|
@ -74,7 +74,7 @@ public final class IconRecentsView extends FrameLayout {
|
|||
private final Context mContext;
|
||||
private final TaskListLoader mTaskLoader;
|
||||
private final TaskAdapter mTaskAdapter;
|
||||
private final TaskInputController mTaskInputController;
|
||||
private final TaskActionController mTaskActionController;
|
||||
|
||||
private RecentsToActivityHelper mActivityHelper;
|
||||
private RecyclerView mTaskRecyclerView;
|
||||
|
@ -86,8 +86,8 @@ public final class IconRecentsView extends FrameLayout {
|
|||
mContext = context;
|
||||
mTaskLoader = new TaskListLoader(mContext);
|
||||
mTaskAdapter = new TaskAdapter(mTaskLoader);
|
||||
mTaskInputController = new TaskInputController(mTaskLoader, mTaskAdapter);
|
||||
mTaskAdapter.setInputController(mTaskInputController);
|
||||
mTaskActionController = new TaskActionController(mTaskLoader, mTaskAdapter);
|
||||
mTaskAdapter.setActionController(mTaskActionController);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,7 +99,7 @@ public final class IconRecentsView extends FrameLayout {
|
|||
mTaskRecyclerView.setLayoutManager(
|
||||
new LinearLayoutManager(mContext, VERTICAL, true /* reverseLayout */));
|
||||
ItemTouchHelper helper = new ItemTouchHelper(
|
||||
new TaskSwipeCallback(mTaskInputController));
|
||||
new TaskSwipeCallback(mTaskActionController));
|
||||
helper.attachToRecyclerView(mTaskRecyclerView);
|
||||
|
||||
mEmptyView = findViewById(R.id.recent_task_empty_view);
|
||||
|
@ -117,7 +117,7 @@ public final class IconRecentsView extends FrameLayout {
|
|||
});
|
||||
|
||||
View clearAllView = findViewById(R.id.clear_all_button);
|
||||
clearAllView.setOnClickListener(mTaskInputController::onClearAllClicked);
|
||||
clearAllView.setOnClickListener(v -> mTaskActionController.clearAllTasks());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue