Merge "Add clear all button to Recents Go" into ub-launcher3-master

This commit is contained in:
TreeHugger Robot 2019-03-21 22:36:23 +00:00 committed by Android (Google) Code Review
commit 1bfb0c1c51
7 changed files with 93 additions and 10 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/clear_all_button_bg"/>
<corners android:radius="4dp"/>
</shape>

View File

@ -19,13 +19,31 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recent_task_recycler_view"
<LinearLayout
android:id="@+id/recent_task_content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:visibility="gone"/>
android:orientation="vertical"
android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recent_task_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none"/>
<Button
android:id="@+id/clear_all_button"
android:layout_width="@dimen/clear_all_button_width"
android:layout_height="@dimen/clear_all_button_height"
android:layout_gravity="center_horizontal"
android:layout_marginVertical="@dimen/task_item_half_vert_margin"
android:background="@drawable/clear_all_button"
android:gravity="center"
android:text="@string/recents_clear_all"
android:textAllCaps="false"
android:textColor="@color/clear_all_button_text"
android:textSize="14sp"/>
</LinearLayout>
<TextView
android:id="@+id/recent_task_empty_view"
android:layout_width="match_parent"

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<color name="clear_all_button_bg">#FFDADCE0</color>
<color name="clear_all_button_text">#FF5F6368</color>
</resources>

View File

@ -20,4 +20,7 @@
<dimen name="task_thumbnail_height">60dp</dimen>
<dimen name="task_thumbnail_width">36dp</dimen>
<dimen name="task_icon_size">36dp</dimen>
<dimen name="clear_all_button_width">106dp</dimen>
<dimen name="clear_all_button_height">36dp</dimen>
</resources>

View File

@ -61,6 +61,14 @@ public final class TaskInputController {
mAdapter.notifyItemRemoved(position);
}
// TODO: Implement "Clear all" and notify adapter that data has updated
/**
* Logic that occurs when clear all is triggered.
*/
public void onClearAllClicked(View view) {
// TODO: Play an animation so transition is more natural.
int count = mAdapter.getItemCount();
ActivityManagerWrapper.getInstance().removeAllRecentTasks();
mLoader.clearAllTasks();
mAdapter.notifyItemRangeRemoved(0 /* positionStart */, count);
}
}

View File

@ -92,6 +92,13 @@ public final class TaskListLoader {
mTaskList.remove(task);
}
/**
* Clears the current task list.
*/
void clearAllTasks() {
mTaskList.clear();
}
/**
* Loads task content for a list of tasks, including the label, icon, and thumbnail. For content
* that isn't cached, load the content asynchronously in the background.

View File

@ -79,6 +79,7 @@ public final class IconRecentsView extends FrameLayout {
private RecentsToActivityHelper mActivityHelper;
private RecyclerView mTaskRecyclerView;
private View mEmptyView;
private View mContentView;
public IconRecentsView(Context context, AttributeSet attrs) {
super(context, attrs);
@ -102,6 +103,7 @@ public final class IconRecentsView extends FrameLayout {
helper.attachToRecyclerView(mTaskRecyclerView);
mEmptyView = findViewById(R.id.recent_task_empty_view);
mContentView = findViewById(R.id.recent_task_content_view);
mTaskAdapter.registerAdapterDataObserver(new AdapterDataObserver() {
@Override
public void onChanged() {
@ -113,6 +115,9 @@ public final class IconRecentsView extends FrameLayout {
updateContentViewVisibility();
}
});
View clearAllView = findViewById(R.id.clear_all_button);
clearAllView.setOnClickListener(mTaskInputController::onClearAllClicked);
}
}
@ -162,11 +167,11 @@ public final class IconRecentsView extends FrameLayout {
private void updateContentViewVisibility() {
int taskListSize = mTaskLoader.getCurrentTaskList().size();
if (mEmptyView.getVisibility() != VISIBLE && taskListSize == 0) {
crossfadeViews(mEmptyView, mTaskRecyclerView);
crossfadeViews(mEmptyView, mContentView);
mActivityHelper.leaveRecents();
}
if (mTaskRecyclerView.getVisibility() != VISIBLE && taskListSize > 0) {
crossfadeViews(mTaskRecyclerView, mEmptyView);
if (mContentView.getVisibility() != VISIBLE && taskListSize > 0) {
crossfadeViews(mContentView, mEmptyView);
}
}