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 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=95=8C=E9=9D=A2=E7=82=B9=E5=87=BB=E4=B9=A6?= =?UTF-8?q?=E5=90=8D=E4=BB=A5=E5=8F=8A=E4=BD=9C=E8=80=85=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E6=B3=95=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 } From b19a905047b4d9e942a5ca00525b73193504f53e 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:56:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= 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 | 22 ++++++++----------- .../ui/main/bookshelf/books/BooksFragment.kt | 13 +---------- 3 files changed, 13 insertions(+), 29 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 aa1d8e93a..18d9c06f7 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,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.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.* @@ -238,12 +239,10 @@ class BookInfoActivity : } } tv_author.onClick { - setResult(RESULT_OK, Intent().putExtra("key", viewModel.bookData.value?.author)) - finish() + startActivity(Pair("key", viewModel.bookData.value?.author)) } tv_name.onClick { - setResult(RESULT_OK, Intent().putExtra("key", viewModel.bookData.value?.name)) - finish() + startActivity(Pair("key", viewModel.bookData.value?.name)) } } 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 7d5ae6a44..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 @@ -31,7 +31,6 @@ 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 @@ -52,7 +51,6 @@ 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) @@ -63,6 +61,11 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se receiptIntent(intent) } + override fun onNewIntent(data: Intent?) { + super.onNewIntent(data) + receiptIntent(data) + } + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.book_search, menu) precisionSearchMenuItem = menu.findItem(R.id.menu_precision_search) @@ -198,13 +201,8 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se }) } - 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 { + private fun receiptIntent(intent: Intent? = null) { + intent?.getStringExtra("key")?.let { search_view.setQuery(it, true) } ?: let { search_view.requestFocus() @@ -321,8 +319,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se override fun showBookInfo(name: String, author: String) { viewModel.getSearchBook(name, author) { searchBook -> searchBook?.let { - startActivityForResult( - searchRequestCode, + startActivity( Pair("name", it.name), Pair("author", it.author) ) @@ -334,8 +331,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se * 显示书籍详情 */ override fun showBookInfo(book: Book) { - startActivityForResult( - searchRequestCode, + startActivity( 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 27b379ece..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 @@ -1,6 +1,5 @@ package io.legado.app.ui.main.bookshelf.books -import android.content.Intent import android.os.Bundle import android.view.View 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.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.* import kotlinx.android.synthetic.main.fragment_books.* @@ -51,7 +49,6 @@ 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 { @@ -143,20 +140,12 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), } override fun openBookInfo(book: Book) { - startActivityForResult( - searchRequestCode, + startActivity( 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 }