修复书籍信息界面点击书名以及作者时无法搜索的BUG

pull/416/head
口口吕 4 years ago
parent 14de73270d
commit fe6a90c10e
  1. 7
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 20
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  3. 17
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt

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

@ -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
@ -30,6 +31,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import java.text.Collator
@ -50,6 +52,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private var menu: Menu? = null
private var precisionSearchMenuItem: MenuItem? = null
private var groups = linkedSetOf<String>()
private val searchRequestCode = 69
override fun onActivityCreated(savedInstanceState: Bundle?) {
ll_history.setBackgroundColor(backgroundColor)
@ -57,7 +60,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
initSearchView()
initOtherView()
initLiveData()
initIntent()
receiptIntent(intent)
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
@ -195,8 +198,13 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
})
}
private fun initIntent() {
intent.getStringExtra("key")?.let {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
receiptIntent(data)
}
private fun receiptIntent(data: Intent? = null) {
data?.getStringExtra("key")?.let {
search_view.setQuery(it, true)
} ?: let {
search_view.requestFocus()
@ -313,7 +321,8 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
override fun showBookInfo(name: String, author: String) {
viewModel.getSearchBook(name, author) { searchBook ->
searchBook?.let {
startActivity<BookInfoActivity>(
startActivityForResult<BookInfoActivity>(
searchRequestCode,
Pair("name", it.name),
Pair("author", it.author)
)
@ -325,7 +334,8 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
* 显示书籍详情
*/
override fun showBookInfo(book: Book) {
startActivity<BookInfoActivity>(
startActivityForResult<BookInfoActivity>(
searchRequestCode,
Pair("name", book.name),
Pair("author", book.author)
)

@ -1,5 +1,6 @@
package io.legado.app.ui.main.bookshelf.books
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.lifecycle.LiveData
@ -22,10 +23,9 @@ import io.legado.app.lib.theme.accentColor
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.book.search.SearchActivity
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
@ -51,6 +51,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
private var bookshelfLiveData: LiveData<List<Book>>? = null
private var position = 0
private var groupId = -1L
private val searchRequestCode = 68
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
arguments?.let {
@ -142,12 +143,20 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
}
override fun openBookInfo(book: Book) {
context?.startActivity<BookInfoActivity>(
startActivityForResult<BookInfoActivity>(
searchRequestCode,
Pair("name", book.name),
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 {
return bookUrl in activityViewModel.updateList
}

Loading…
Cancel
Save