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.content.Context 20 import android.util.AttributeSet 21 import android.view.View 22 import android.widget.ExpandableListAdapter 23 import android.widget.ExpandableListView 24 25 /** Suggestions view that displays suggestions clustered by corpus type. */ 26 class ClusteredSuggestionsView(context: Context?, attrs: AttributeSet?) : 27 ExpandableListView(context, attrs), SuggestionsListView<ExpandableListAdapter?> { 28 29 @JvmField var mSuggestionsAdapter: SuggestionsAdapter<ExpandableListAdapter?>? = null 30 setSuggestionsAdapternull31 override fun setSuggestionsAdapter(adapter: SuggestionsAdapter<ExpandableListAdapter?>?) { 32 mSuggestionsAdapter = adapter 33 super.setAdapter(adapter?.listAdapter) 34 } 35 getSuggestionsAdapternull36 override fun getSuggestionsAdapter(): SuggestionsAdapter<ExpandableListAdapter?>? { 37 return mSuggestionsAdapter 38 } 39 40 // TODO: this function does not appear to be used currently and remains unimplemented getSelectedItemIdnull41 override fun getSelectedItemId(): Long { 42 return 0 43 } 44 45 @Suppress("UNUSED_PARAMETER") setLimitSuggestionsToViewHeightnull46 fun setLimitSuggestionsToViewHeight(limit: Boolean) { 47 // not supported 48 } 49 50 @Override onFinishInflatenull51 override fun onFinishInflate() { 52 super.onFinishInflate() 53 setItemsCanFocus(false) 54 setOnGroupClickListener( 55 object : OnGroupClickListener { 56 override fun onGroupClick( 57 parent: ExpandableListView?, 58 v: View?, 59 groupPosition: Int, 60 id: Long 61 ): Boolean { 62 // disable collapsing / expanding 63 return true 64 } 65 } 66 ) 67 } 68 expandAllnull69 fun expandAll() { 70 if (mSuggestionsAdapter != null) { 71 val adapter: ExpandableListAdapter? = mSuggestionsAdapter?.listAdapter 72 for (i in 0 until adapter!!.getGroupCount()) { 73 expandGroup(i) 74 } 75 } 76 } 77 } 78