1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.launcher3.taskbar.allapps
18 
19 import android.content.Context
20 import android.view.View
21 import com.android.launcher3.R
22 import com.android.launcher3.allapps.AllAppsTransitionListener
23 import com.android.launcher3.anim.PendingAnimation
24 import com.android.launcher3.config.FeatureFlags
25 import com.android.launcher3.dragndrop.DragOptions.PreDragCondition
26 import com.android.launcher3.model.data.ItemInfo
27 import com.android.launcher3.util.ResourceBasedOverride
28 import com.android.launcher3.util.ResourceBasedOverride.Overrides
29 
30 /** Stub for managing the Taskbar search session. */
31 open class TaskbarSearchSessionController : ResourceBasedOverride, AllAppsTransitionListener {
32 
33     /** Start the search session lifecycle. */
startLifecyclenull34     open fun startLifecycle() = Unit
35 
36     /** Destroy the search session. */
37     open fun onDestroy() = Unit
38 
39     /** Updates the predicted items shown in the zero-state. */
40     open fun setZeroStatePredictedItems(items: List<ItemInfo>) = Unit
41 
42     /** Updates the search suggestions shown in the zero-state. */
43     open fun setZeroStateSearchSuggestions(items: List<ItemInfo>) = Unit
44 
45     override fun onAllAppsTransitionStart(toAllApps: Boolean) = Unit
46 
47     override fun onAllAppsTransitionEnd(toAllApps: Boolean) = Unit
48 
49     /** Creates a [PreDragCondition] for [view], if it is a search result that requires one. */
50     open fun createPreDragConditionForSearch(view: View): PreDragCondition? = null
51 
52     open fun canHandleBackInvoked(): Boolean = false
53 
54     open fun handleBackInvoked(): Boolean = false
55 
56     open fun onAllAppsAnimationPending(
57         animation: PendingAnimation,
58         toAllApps: Boolean,
59         showKeyboard: Boolean,
60     ) = Unit
61 
62     companion object {
63         @JvmStatic
64         fun newInstance(context: Context): TaskbarSearchSessionController {
65             if (!FeatureFlags.ENABLE_ALL_APPS_SEARCH_IN_TASKBAR.get()) {
66                 return TaskbarSearchSessionController()
67             }
68 
69             return Overrides.getObject(
70                 TaskbarSearchSessionController::class.java,
71                 context,
72                 R.string.taskbar_search_session_controller_class,
73             )
74         }
75     }
76 }
77