1 /*
2  * Copyright (C) 2022 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.quicksearchbox.ui
18 
19 import android.view.View.OnFocusChangeListener
20 import android.widget.ExpandableListAdapter
21 import android.widget.ListAdapter
22 import com.android.quicksearchbox.SuggestionPosition
23 import com.android.quicksearchbox.Suggestions
24 
25 /**
26  * Interface for suggestions adapters.
27  *
28  * @param <A> the adapter class used by the UI, probably either [ListAdapter] or
29  * [ExpandableListAdapter].
30  */
31 interface SuggestionsAdapter<A> {
32   /** Sets the listener to be notified of clicks on suggestions. */
setSuggestionClickListenernull33   fun setSuggestionClickListener(listener: SuggestionClickListener?)
34 
35   /** Sets the listener to be notified of focus change events on suggestion views. */
36   fun setOnFocusChangeListener(l: OnFocusChangeListener?)
37 
38   /** Indicates if there's any suggestions in this adapter. */
39   val isEmpty: Boolean
40   /** Gets the current suggestions. */
41   /** Sets the current suggestions. */
42   var suggestions: Suggestions?
43 
44   /**
45    * Gets the cursor and position corresponding to the given suggestion ID.
46    * @param suggestionId Suggestion ID.
47    */
48   fun getSuggestion(suggestionId: Long): SuggestionPosition?
49 
50   /**
51    * Handles a regular click on a suggestion.
52    *
53    * @param suggestionId The ID of the suggestion clicked. If the suggestion list is flat, this will
54    * be the position within the list.
55    */
56   fun onSuggestionClicked(suggestionId: Long)
57 
58   /**
59    * Handles a click on the query refinement button.
60    *
61    * @param suggestionId The ID of the suggestion clicked. If the suggestion list is flat, this will
62    * be the position within the list.
63    */
64   fun onSuggestionQueryRefineClicked(suggestionId: Long)
65 
66   /** Gets the adapter to be used by the UI view. */
67   val listAdapter: A
68 }
69