Search history and suggestion
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user