diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 2870818c2..5eb4e564d 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.search +import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -57,7 +58,12 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se initSearchView() initOtherView() initLiveData() - initIntent() + receiptIntent(intent) + } + + override fun onNewIntent(data: Intent?) { + super.onNewIntent(data) + receiptIntent(data) } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -195,8 +201,8 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se }) } - private fun initIntent() { - intent.getStringExtra("key")?.let { + private fun receiptIntent(intent: Intent? = null) { + intent?.getStringExtra("key")?.let { search_view.setQuery(it, true) } ?: let { search_view.requestFocus() diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 644f7683d..c0004de15 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -23,9 +23,7 @@ import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainViewModel -import io.legado.app.utils.getPrefInt -import io.legado.app.utils.getViewModelOfActivity -import io.legado.app.utils.observeEvent +import io.legado.app.utils.* import kotlinx.android.synthetic.main.fragment_books.* import org.jetbrains.anko.startActivity import kotlin.math.max @@ -142,7 +140,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), } override fun openBookInfo(book: Book) { - context?.startActivity( + startActivity( Pair("name", book.name), Pair("author", book.author) )