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 package com.android.quicksearchbox
17 
18 import android.content.ComponentName
19 import android.database.Cursor
20 import com.android.quicksearchbox.google.GoogleSource
21 import kotlin.collections.Collection
22 
23 class CursorBackedSourceResult(
24   override val suggestionSource: GoogleSource?,
25   userQuery: String?,
26   cursor: Cursor?
27 ) : CursorBackedSuggestionCursor(userQuery, cursor), SourceResult {
28 
29   constructor(source: GoogleSource?, userQuery: String?) : this(source, userQuery, null)
30 
31   override val source: Source?
32     get() = suggestionSource
33 
34   @get:Override
35   override val suggestionIntentComponent: ComponentName?
36     get() = suggestionSource?.intentComponent
37 
38   override val isSuggestionShortcut: Boolean
39     get() = false
40 
41   override val isHistorySuggestion: Boolean
42     get() = false
43 
44   @Override
toStringnull45   override fun toString(): String {
46     return suggestionSource.toString() + "[" + userQuery + "]"
47   }
48 
49   @get:Override
50   override val extras: SuggestionExtras?
51     get() =
52       if (mCursor == null) null
53       else CursorBackedSuggestionExtras.createExtrasIfNecessary(mCursor, position)!!
54 
55   override val extraColumns: Collection<String>?
56     get() = if (mCursor == null) null else CursorBackedSuggestionExtras.getExtraColumns(mCursor)!!
57 }
58