diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 18d9c06f7..aa1d8e93a 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.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(Pair("key", viewModel.bookData.value?.author)) + setResult(RESULT_OK, Intent().putExtra("key", viewModel.bookData.value?.author)) + finish() } tv_name.onClick { - startActivity(Pair("key", viewModel.bookData.value?.name)) + setResult(RESULT_OK, Intent().putExtra("key", viewModel.bookData.value?.name)) + finish() } } 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..7d5ae6a44 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 @@ -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(R.layout.activity_book_se private var menu: Menu? = null private var precisionSearchMenuItem: MenuItem? = null private var groups = linkedSetOf() + private val searchRequestCode = 69 override fun onActivityCreated(savedInstanceState: Bundle?) { ll_history.setBackgroundColor(backgroundColor) @@ -57,7 +60,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se initSearchView() initOtherView() initLiveData() - initIntent() + receiptIntent(intent) } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -195,8 +198,13 @@ class SearchActivity : VMBaseActivity(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(R.layout.activity_book_se override fun showBookInfo(name: String, author: String) { viewModel.getSearchBook(name, author) { searchBook -> searchBook?.let { - startActivity( + startActivityForResult( + searchRequestCode, Pair("name", it.name), Pair("author", it.author) ) @@ -325,7 +334,8 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se * 显示书籍详情 */ override fun showBookInfo(book: Book) { - startActivity( + startActivityForResult( + searchRequestCode, Pair("name", book.name), Pair("author", book.author) ) 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..27b379ece 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 @@ -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>? = 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( + startActivityForResult( + 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(Pair("key", it)) + } + } + override fun isUpdate(bookUrl: String): Boolean { return bookUrl in activityViewModel.updateList }