From fe6a90c10e5df88d1cab8cd6755ce1dfdac2ce06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Mon, 12 Oct 2020 12:04:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B9=A6=E7=B1=8D=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=95=8C=E9=9D=A2=E7=82=B9=E5=87=BB=E4=B9=A6=E5=90=8D?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E4=BD=9C=E8=80=85=E6=97=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/info/BookInfoActivity.kt | 7 ++++--- .../app/ui/book/search/SearchActivity.kt | 20 ++++++++++++++----- .../ui/main/bookshelf/books/BooksFragment.kt | 17 ++++++++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) 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 }