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.database.DataSetObserver 19 20 /** A suggestion cursor that delegates all methods to another SuggestionCursor. */ 21 open class SuggestionCursorWrapper(userQuery: String?, private val mCursor: SuggestionCursor?) : 22 AbstractSuggestionCursorWrapper(userQuery!!) { closenull23 override fun close() { 24 if (mCursor != null) { 25 mCursor.close() 26 } 27 } 28 29 override val count: Int 30 get() = if (mCursor == null) 0 else mCursor.count 31 override val position: Int 32 get() = if (mCursor == null) 0 else mCursor.position 33 moveTonull34 override fun moveTo(pos: Int) { 35 if (mCursor != null) { 36 mCursor.moveTo(pos) 37 } 38 } 39 moveToNextnull40 override fun moveToNext(): Boolean { 41 return mCursor?.moveToNext() ?: false 42 } 43 registerDataSetObservernull44 override fun registerDataSetObserver(observer: DataSetObserver?) { 45 if (mCursor != null) { 46 mCursor.registerDataSetObserver(observer) 47 } 48 } 49 unregisterDataSetObservernull50 override fun unregisterDataSetObserver(observer: DataSetObserver?) { 51 if (mCursor != null) { 52 mCursor.unregisterDataSetObserver(observer) 53 } 54 } 55 56 @Override currentnull57 override fun current(): SuggestionCursor { 58 return mCursor!! 59 } 60 61 override val extraColumns: Collection<String>? 62 get() = mCursor?.extraColumns 63 } 64