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

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

@ -1,5 +1,6 @@
package io.legado.app.ui.book.search
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
@ -209,11 +210,12 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
}
private fun receiptIntent(intent: Intent? = null) {
intent?.getStringExtra("key")?.let {
searchView.setQuery(it, true)
} ?: let {
val key = intent?.getStringExtra("key")
if (key.isNullOrBlank()) {
searchView.findViewById<TextView>(androidx.appcompat.R.id.search_src_text)
.requestFocus()
} else {
searchView.setQuery(key, true)
}
}
@ -370,4 +372,14 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
override fun deleteHistory(searchKeyword: 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.utils.getPrefInt
import io.legado.app.utils.putPrefInt
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -88,9 +87,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
}
override fun onQueryTextSubmit(query: String?): Boolean {
startActivity<SearchActivity> {
putExtra("key", query)
}
SearchActivity.start(requireContext(), query)
return false
}

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

Loading…
Cancel
Save