Search history and suggestion
This commit is contained in:
@@ -41,6 +41,9 @@
|
||||
|
||||
<service android:name=".ui.download.DownloadService" />
|
||||
|
||||
<provider
|
||||
android:name=".domain.search.MangaSuggestionsProvider"
|
||||
android:authorities="${applicationId}.MangaSuggestionsProvider" />
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.files"
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.koitharu.kotatsu.domain.search
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SearchRecentSuggestionsProvider
|
||||
import android.provider.SearchRecentSuggestions
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
|
||||
class MangaSuggestionsProvider : SearchRecentSuggestionsProvider() {
|
||||
|
||||
init {
|
||||
setupSuggestions(AUTHORITY, MODE)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun saveQuery(context: Context, query: String) {
|
||||
SearchRecentSuggestions(context, AUTHORITY, MODE)
|
||||
.saveRecentQuery(query, null)
|
||||
}
|
||||
|
||||
fun clearHistory(context: Context) {
|
||||
SearchRecentSuggestions(context, AUTHORITY, MODE)
|
||||
.clearHistory()
|
||||
}
|
||||
|
||||
private const val AUTHORITY = "${BuildConfig.APPLICATION_ID}.MangaSuggestionsProvider"
|
||||
private const val MODE = DATABASE_MODE_QUERIES
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.app.SearchManager
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.domain.search.MangaSuggestionsProvider
|
||||
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||
|
||||
class SearchActivity : BaseActivity() {
|
||||
@@ -20,6 +21,7 @@ class SearchActivity : BaseActivity() {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
MangaSuggestionsProvider.saveQuery(this, query)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
title = query
|
||||
supportActionBar?.setSubtitle(R.string.search_results)
|
||||
|
||||
@@ -4,5 +4,7 @@
|
||||
android:hint="@string/search_manga"
|
||||
android:inputType="textPersonName"
|
||||
android:label="@string/app_name"
|
||||
android:searchSuggestAuthority="org.koitharu.kotatsu.MangaSuggestionsProvider"
|
||||
android:searchSuggestSelection=" ?"
|
||||
android:voiceLanguageModel="web_search"
|
||||
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" />
|
||||
|
||||
Reference in New Issue
Block a user