优化搜索逻辑

pull/416/head
口口吕 4 years ago
parent f594193b15
commit b19a905047
  1. 7
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 22
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  3. 13
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt

@ -32,6 +32,7 @@ import io.legado.app.ui.book.chapterlist.ChapterListActivity
import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.ui.book.group.GroupSelectDialog
import io.legado.app.ui.book.info.edit.BookInfoEditActivity import io.legado.app.ui.book.info.edit.BookInfoEditActivity
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.image.CoverImageView
import io.legado.app.utils.* import io.legado.app.utils.*
@ -238,12 +239,10 @@ class BookInfoActivity :
} }
} }
tv_author.onClick { tv_author.onClick {
setResult(RESULT_OK, Intent().putExtra("key", viewModel.bookData.value?.author)) startActivity<SearchActivity>(Pair("key", viewModel.bookData.value?.author))
finish()
} }
tv_name.onClick { tv_name.onClick {
setResult(RESULT_OK, Intent().putExtra("key", viewModel.bookData.value?.name)) startActivity<SearchActivity>(Pair("key", viewModel.bookData.value?.name))
finish()
} }
} }

@ -31,7 +31,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import java.text.Collator import java.text.Collator
@ -52,7 +51,6 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private var menu: Menu? = null private var menu: Menu? = null
private var precisionSearchMenuItem: MenuItem? = null private var precisionSearchMenuItem: MenuItem? = null
private var groups = linkedSetOf<String>() private var groups = linkedSetOf<String>()
private val searchRequestCode = 69
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
ll_history.setBackgroundColor(backgroundColor) ll_history.setBackgroundColor(backgroundColor)
@ -63,6 +61,11 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
receiptIntent(intent) receiptIntent(intent)
} }
override fun onNewIntent(data: Intent?) {
super.onNewIntent(data)
receiptIntent(data)
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.book_search, menu) menuInflater.inflate(R.menu.book_search, menu)
precisionSearchMenuItem = menu.findItem(R.id.menu_precision_search) precisionSearchMenuItem = menu.findItem(R.id.menu_precision_search)
@ -198,13 +201,8 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
}) })
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { private fun receiptIntent(intent: Intent? = null) {
super.onActivityResult(requestCode, resultCode, data) intent?.getStringExtra("key")?.let {
receiptIntent(data)
}
private fun receiptIntent(data: Intent? = null) {
data?.getStringExtra("key")?.let {
search_view.setQuery(it, true) search_view.setQuery(it, true)
} ?: let { } ?: let {
search_view.requestFocus() search_view.requestFocus()
@ -321,8 +319,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
override fun showBookInfo(name: String, author: String) { override fun showBookInfo(name: String, author: String) {
viewModel.getSearchBook(name, author) { searchBook -> viewModel.getSearchBook(name, author) { searchBook ->
searchBook?.let { searchBook?.let {
startActivityForResult<BookInfoActivity>( startActivity<BookInfoActivity>(
searchRequestCode,
Pair("name", it.name), Pair("name", it.name),
Pair("author", it.author) Pair("author", it.author)
) )
@ -334,8 +331,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
* 显示书籍详情 * 显示书籍详情
*/ */
override fun showBookInfo(book: Book) { override fun showBookInfo(book: Book) {
startActivityForResult<BookInfoActivity>( startActivity<BookInfoActivity>(
searchRequestCode,
Pair("name", book.name), Pair("name", book.name),
Pair("author", book.author) Pair("author", book.author)
) )

@ -1,6 +1,5 @@
package io.legado.app.ui.main.bookshelf.books package io.legado.app.ui.main.bookshelf.books
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
@ -23,7 +22,6 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.ui.audio.AudioPlayActivity
import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.main.MainViewModel import io.legado.app.ui.main.MainViewModel
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.fragment_books.* import kotlinx.android.synthetic.main.fragment_books.*
@ -51,7 +49,6 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
private var bookshelfLiveData: LiveData<List<Book>>? = null private var bookshelfLiveData: LiveData<List<Book>>? = null
private var position = 0 private var position = 0
private var groupId = -1L private var groupId = -1L
private val searchRequestCode = 68
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
arguments?.let { arguments?.let {
@ -143,20 +140,12 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
} }
override fun openBookInfo(book: Book) { override fun openBookInfo(book: Book) {
startActivityForResult<BookInfoActivity>( startActivity<BookInfoActivity>(
searchRequestCode,
Pair("name", book.name), Pair("name", book.name),
Pair("author", book.author) Pair("author", book.author)
) )
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
data?.getStringExtra("key")?.let {
startActivity<SearchActivity>(Pair("key", it))
}
}
override fun isUpdate(bookUrl: String): Boolean { override fun isUpdate(bookUrl: String): Boolean {
return bookUrl in activityViewModel.updateList return bookUrl in activityViewModel.updateList
} }

Loading…
Cancel
Save