pull/1114/head^2
gedoor 3 years ago
parent ff2c80d045
commit 3278f829ae
  1. 21
      app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  3. 18
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  4. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt
  5. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt

@ -23,22 +23,14 @@ class SharedReceiverActivity : AppCompatActivity() {
when { when {
Intent.ACTION_SEND == intent.action && intent.type == receivingType -> { Intent.ACTION_SEND == intent.action && intent.type == receivingType -> {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
if (openUrl(it)) { dispose(it)
startActivity<SearchActivity> {
putExtra("key", it)
}
}
} }
} }
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& Intent.ACTION_PROCESS_TEXT == intent.action && Intent.ACTION_PROCESS_TEXT == intent.action
&& intent.type == receivingType -> { && intent.type == receivingType -> {
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let { intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let {
if (openUrl(it)) { dispose(it)
startActivity<SearchActivity> {
putExtra("key", it)
}
}
} }
} }
intent.getStringExtra("action") == "readAloud" -> { intent.getStringExtra("action") == "readAloud" -> {
@ -47,9 +39,9 @@ class SharedReceiverActivity : AppCompatActivity() {
} }
} }
private fun openUrl(text: String): Boolean { private fun dispose(text: String) {
if (text.isBlank()) { if (text.isBlank()) {
return false return
} }
val urls = text.split("\\s".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() val urls = text.split("\\s".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val result = StringBuilder() val result = StringBuilder()
@ -57,11 +49,10 @@ class SharedReceiverActivity : AppCompatActivity() {
if (url.matches("http.+".toRegex())) if (url.matches("http.+".toRegex()))
result.append("\n").append(url.trim { it <= ' ' }) result.append("\n").append(url.trim { it <= ' ' })
} }
return if (result.length > 1) { if (result.length > 1) {
startActivity<MainActivity>() startActivity<MainActivity>()
false
} else { } else {
true SearchActivity.start(this, text)
} }
} }
} }

@ -120,9 +120,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
appDb.bookDao.findByName(item.bookName).firstOrNull() appDb.bookDao.findByName(item.bookName).firstOrNull()
} }
if (book == null) { if (book == null) {
startActivity<SearchActivity> { SearchActivity.start(this@ReadRecordActivity, item.bookName)
putExtra("key", item.bookName)
}
} else { } else {
startActivity<ReadBookActivity> { startActivity<ReadBookActivity> {
putExtra("bookUrl", book.bookUrl) putExtra("bookUrl", book.bookUrl)

@ -1,5 +1,6 @@
package io.legado.app.ui.book.search package io.legado.app.ui.book.search
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
@ -209,11 +210,12 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
} }
private fun receiptIntent(intent: Intent? = null) { private fun receiptIntent(intent: Intent? = null) {
intent?.getStringExtra("key")?.let { val key = intent?.getStringExtra("key")
searchView.setQuery(it, true) if (key.isNullOrBlank()) {
} ?: let {
searchView.findViewById<TextView>(androidx.appcompat.R.id.search_src_text) searchView.findViewById<TextView>(androidx.appcompat.R.id.search_src_text)
.requestFocus() .requestFocus()
} else {
searchView.setQuery(key, true)
} }
} }
@ -370,4 +372,14 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
override fun deleteHistory(searchKeyword: SearchKeyword) { override fun deleteHistory(searchKeyword: SearchKeyword) {
viewModel.deleteHistory(searchKeyword) viewModel.deleteHistory(searchKeyword)
} }
companion object {
fun start(context: Context, key: String?) {
context.startActivity<SearchActivity> {
putExtra("key", key)
}
}
}
} }

@ -26,7 +26,6 @@ import io.legado.app.ui.main.bookshelf.BaseBookshelfFragment
import io.legado.app.ui.main.bookshelf.style1.books.BooksFragment import io.legado.app.ui.main.bookshelf.style1.books.BooksFragment
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.putPrefInt import io.legado.app.utils.putPrefInt
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -88,9 +87,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
} }
override fun onQueryTextSubmit(query: String?): Boolean { override fun onQueryTextSubmit(query: String?): Boolean {
startActivity<SearchActivity> { SearchActivity.start(requireContext(), query)
putExtra("key", query)
}
return false return false
} }

@ -76,7 +76,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
} }
override fun onQueryTextChange(newText: String?): Boolean { override fun onQueryTextChange(newText: String?): Boolean {
SearchActivity.start(requireContext(), newText)
return false return false
} }
}) })
@ -160,9 +160,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
} }
override fun onQueryTextSubmit(query: String?): Boolean { override fun onQueryTextSubmit(query: String?): Boolean {
startActivity<SearchActivity> { SearchActivity.start(requireContext(), query)
putExtra("key", query)
}
return false return false
} }

Loading…
Cancel
Save