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.fragment:fragment-ktx:1.3.5"
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.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'

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

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

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

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

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

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

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

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