Merge remote-tracking branch 'origin/master' into master

pull/1114/head
bushixuanqi 3 years ago
commit 7bb6a63571
  1. 1
      app/build.gradle
  2. 2
      app/src/main/java/io/legado/app/help/LifecycleHelp.kt
  3. 6
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt
  4. 6
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt
  5. 21
      app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt
  6. 8
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  7. 4
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  8. 2
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  9. 18
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  10. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt
  11. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt

@ -133,7 +133,6 @@ dependencies {
implementation "androidx.activity:activity-ktx:1.2.3" implementation "androidx.activity:activity-ktx:1.2.3"
implementation "androidx.fragment:fragment-ktx:1.3.5" implementation "androidx.fragment:fragment-ktx:1.3.5"
implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.preference:preference-ktx:1.1.1'
implementation "androidx.collection:collection-ktx:1.1.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'androidx.viewpager2:viewpager2:1.0.0'

@ -4,7 +4,6 @@ import android.app.Activity
import android.app.Application import android.app.Application
import android.os.Bundle import android.os.Bundle
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.LanguageUtils import io.legado.app.utils.LanguageUtils
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import java.util.* import java.util.*
@ -111,7 +110,6 @@ object LifecycleHelp : Application.ActivityLifecycleCallbacks {
} }
private fun onFinished() { private fun onFinished() {
Coroutine.cancel()
finishedListener?.invoke() finishedListener?.invoke()
} }
} }

@ -14,7 +14,7 @@ class Coroutine<T>(
companion object { companion object {
val DEFAULT = MainScope() private val DEFAULT = MainScope()
fun <T> async( fun <T> async(
scope: CoroutineScope = DEFAULT, scope: CoroutineScope = DEFAULT,
@ -24,10 +24,6 @@ class Coroutine<T>(
return Coroutine(scope, context, block) return Coroutine(scope, context, block)
} }
fun cancel() {
DEFAULT.cancel()
}
} }
private val job: Job private val job: Job

@ -75,7 +75,7 @@ class WebBook(val bookSource: BookSource) {
} }
suspend fun exploreBookAwait( suspend fun exploreBookAwait(
scope: CoroutineScope = Coroutine.DEFAULT, scope: CoroutineScope,
url: String, url: String,
page: Int? = 1, page: Int? = 1,
): ArrayList<SearchBook> { ): ArrayList<SearchBook> {
@ -114,7 +114,7 @@ class WebBook(val bookSource: BookSource) {
} }
suspend fun getBookInfoAwait( suspend fun getBookInfoAwait(
scope: CoroutineScope = Coroutine.DEFAULT, scope: CoroutineScope,
book: Book, book: Book,
canReName: Boolean = true, canReName: Boolean = true,
): Book { ): Book {
@ -164,7 +164,7 @@ class WebBook(val bookSource: BookSource) {
} }
suspend fun getChapterListAwait( suspend fun getChapterListAwait(
scope: CoroutineScope = Coroutine.DEFAULT, scope: CoroutineScope,
book: Book, book: Book,
): List<BookChapter> { ): List<BookChapter> {
book.type = bookSource.bookSourceType book.type = bookSource.bookSourceType

@ -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)
} }
} }
} }

@ -16,6 +16,7 @@ import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.msg import io.legado.app.utils.msg
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import splitties.init.appCtx import splitties.init.appCtx
import kotlin.math.max import kotlin.math.max
@ -270,7 +271,7 @@ object ReadBook {
success?.invoke() success?.invoke()
} }
removeLoading(chapter.index) removeLoading(chapter.index)
} ?: download(chapter, resetPageOffset = resetPageOffset) } ?: download(this, chapter, resetPageOffset = resetPageOffset)
} ?: removeLoading(index) } ?: removeLoading(index)
}.onError { }.onError {
removeLoading(index) removeLoading(index)
@ -288,7 +289,7 @@ object ReadBook {
if (BookHelp.hasContent(book, chapter)) { if (BookHelp.hasContent(book, chapter)) {
removeLoading(chapter.index) removeLoading(chapter.index)
} else { } else {
download(chapter, false) download(this, chapter, false)
} }
} ?: removeLoading(index) } ?: removeLoading(index)
}.onError { }.onError {
@ -299,6 +300,7 @@ object ReadBook {
} }
private fun download( private fun download(
scope: CoroutineScope,
chapter: BookChapter, chapter: BookChapter,
resetPageOffset: Boolean, resetPageOffset: Boolean,
success: (() -> Unit)? = null success: (() -> Unit)? = null
@ -306,7 +308,7 @@ object ReadBook {
val book = book val book = book
val webBook = webBook val webBook = webBook
if (book != null && webBook != null) { if (book != null && webBook != null) {
CacheBook.download(Coroutine.DEFAULT, webBook, book, chapter) CacheBook.download(scope, webBook, book, chapter)
} else if (book != null) { } else if (book != null) {
contentLoadFinish( contentLoadFinish(
book, chapter, "没有书源", resetPageOffset = resetPageOffset book, chapter, "没有书源", resetPageOffset = resetPageOffset

@ -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)

@ -418,7 +418,7 @@ object ChapterProvider {
* 超出边界处理 * 超出边界处理
*/ */
private fun exceed(textLine: TextLine, words: Array<String>) { private fun exceed(textLine: TextLine, words: Array<String>) {
val endX = textLine.textChars.last().end val endX = textLine.textChars.lastOrNull()?.end ?: return
if (endX > visibleRight) { if (endX > visibleRight) {
val cc = (endX - visibleRight) / words.size val cc = (endX - visibleRight) / words.size
for (i in 0..words.lastIndex) { for (i in 0..words.lastIndex) {

@ -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