pull/737/head 3.20.121112
gedoor 4 years ago
parent 76d04dab9c
commit ba6fc2e5d1
  1. 2
      app/build.gradle
  2. 3
      app/src/main/assets/updateLog.md
  3. 6
      app/src/main/java/io/legado/app/App.kt
  4. 24
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  5. 6
      app/src/main/java/io/legado/app/help/storage/BookWebDav.kt
  6. 7
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  7. 2
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt
  8. 4
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt
  9. 21
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt
  11. 2
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt

@ -172,8 +172,10 @@ dependencies {
implementation 'com.github.gedoor:rhino-android:1.4'
//
implementation 'com.ljx.rxhttp:rxhttp:2.4.4'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
kapt 'com.ljx.rxhttp:rxhttp-compiler:2.4.4'
//Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'

@ -3,6 +3,9 @@
* 关注合作公众号 **[小说拾遗]** 获取好看的小说。
* 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2020/12/11**
* 修复因修改进度同步导致的bug
**2020/12/09**
* 修复bug
* 优化中文排序

@ -15,9 +15,11 @@ import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.constant.EventBus
import io.legado.app.data.AppDatabase
import io.legado.app.help.*
import io.legado.app.help.http.HttpHelper
import io.legado.app.utils.LanguageUtils
import io.legado.app.utils.postEvent
import org.jetbrains.anko.defaultSharedPreferences
import rxhttp.wrapper.param.RxHttp
@Suppress("DEPRECATION")
class App : MultiDexApplication() {
@ -44,14 +46,14 @@ class App : MultiDexApplication() {
CrashHandler(this)
LanguageUtils.setConfiguration(this)
db = AppDatabase.createDatabase(INSTANCE)
RxHttp.init(HttpHelper.client, BuildConfig.DEBUG)
packageManager.getPackageInfo(packageName, 0)?.let {
versionCode = it.versionCode
versionName = it.versionName
}
createNotificationChannels()
applyDayNight()
LiveEventBus
.config()
LiveEventBus.config()
.supportBroadcast(this)
.lifecycleObserverAlwaysActive(true)
.autoClear(false)

@ -7,6 +7,8 @@ import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.*
import retrofit2.Retrofit
import rxhttp.toStr
import rxhttp.wrapper.param.RxHttp
import java.net.InetSocketAddress
import java.net.Proxy
import java.util.concurrent.TimeUnit
@ -39,23 +41,11 @@ object HttpHelper {
builder.build()
}
fun simpleGet(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode)
.get(url, mapOf(Pair(AppConst.UA_NAME, AppConfig.userAgent)))
.execute()
return response.body()
}
return null
}
suspend fun simpleGetAsync(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode)
.getAsync(url, mapOf(Pair(AppConst.UA_NAME, AppConfig.userAgent)))
return response.body()
}
return null
suspend fun simpleGetAsync(url: String): String {
val str = RxHttp.get(url)
.addHeader(AppConst.UA_NAME, AppConfig.userAgent)
.toStr()
return str.await()
}
suspend fun simpleGetBytesAsync(url: String): ByteArray? {

@ -155,7 +155,7 @@ object BookWebDav {
durChapterTitle = book.durChapterTitle
)
val json = GSON.toJson(bookProgress)
val url = getUrl(book)
val url = geProtresstUrl(book)
if (initWebDav()) {
WebDav(url).upload(json.toByteArray())
}
@ -164,7 +164,7 @@ object BookWebDav {
fun getBookProgress(book: Book): BookProgress? {
if (initWebDav()) {
val url = getUrl(book)
val url = geProtresstUrl(book)
WebDav(url).download()?.let { byteArray ->
val json = String(byteArray)
GSON.fromJsonObject<BookProgress>(json)?.let {
@ -175,7 +175,7 @@ object BookWebDav {
return null
}
private fun getUrl(book: Book): String {
private fun geProtresstUrl(book: Book): String {
return bookProgressUrl + book.name + "_" + book.author + ".json"
}
}

@ -118,11 +118,8 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
}
}
private fun importSourceUrl(url: String) {
HttpHelper.simpleGet(url, "UTF-8").let { body ->
if (body == null) {
throw Exception(context.getString(R.string.error_get_data))
}
private suspend fun importSourceUrl(url: String) {
HttpHelper.simpleGetAsync(url).let { body ->
val items: List<Map<String, Any>> = Restore.jsonPath.parse(body).read("$")
for (item in items) {
val jsonItem = Restore.jsonPath.parse(item)

@ -48,7 +48,7 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) {
fun import(text: String) {
execute {
if (text.isAbsUrl()) {
HttpHelper.simpleGet(text)?.let {
HttpHelper.simpleGetAsync(text).let {
val rules = OldReplace.jsonToReplaceRules(it)
allRules.addAll(rules)
}

@ -113,8 +113,8 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
}
}
private fun importSourceUrl(url: String) {
HttpHelper.simpleGet(url, "UTF-8")?.let { body ->
private suspend fun importSourceUrl(url: String) {
HttpHelper.simpleGetAsync(url).let { body ->
val items: List<Map<String, Any>> = Restore.jsonPath.parse(body).read("$")
for (item in items) {
val jsonItem = Restore.jsonPath.parse(item)

@ -47,7 +47,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
private fun initBook(book: Book) {
if (ReadBook.book?.bookUrl != book.bookUrl) {
downloadProgress(book)
ReadBook.resetData(book)
isInitFinish = true
if (!book.isLocalBook() && ReadBook.webBook == null) {
@ -67,6 +66,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
ReadBook.loadContent(resetPageOffset = true)
}
syncBookProgress(book)
} else {
ReadBook.book = book
if (ReadBook.durChapterIndex != book.durChapterIndex) {
@ -100,15 +100,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
private fun downloadProgress(book: Book) {
BookWebDav.getBookProgress(book)?.let {
book.durChapterIndex = it.durChapterIndex
book.durChapterPos = it.durChapterPos
book.durChapterTime = it.durChapterTime
book.durChapterTitle = it.durChapterTitle
}
}
private fun loadBookInfo(
book: Book,
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null,
@ -168,14 +159,16 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun syncBookProgress(book: Book) {
execute {
downloadProgress(book)
ReadBook.durChapterIndex = book.durChapterIndex
ReadBook.durChapterPos = book.durChapterPos
ReadBook.prevTextChapter = null
BookWebDav.getBookProgress(book)?.let {
book.durChapterIndex = it.durChapterIndex
book.durChapterPos = it.durChapterPos
book.durChapterTime = it.durChapterTime
book.durChapterTitle = it.durChapterTitle
ReadBook.clearTextChapter()
ReadBook.loadContent(resetPageOffset = true)
}
}
}
fun changeTo(newBook: Book) {
execute {

@ -21,7 +21,7 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application
fun importOnLine(url: String, finally: (msg: String) -> Unit) {
execute {
HttpHelper.simpleGetAsync(url)?.let { json ->
HttpHelper.simpleGetAsync(url).let { json ->
GSON.fromJsonArray<HttpTTS>(json)?.let {
App.db.httpTTSDao.insert(*it.toTypedArray())
}

@ -28,7 +28,7 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) {
fun importOnLine(url: String, finally: (msg: String) -> Unit) {
execute {
HttpHelper.simpleGetAsync(url)?.let { json ->
HttpHelper.simpleGetAsync(url).let { json ->
GSON.fromJsonArray<TxtTocRule>(json)?.let {
App.db.txtTocRule.insert(*it.toTypedArray())
}

Loading…
Cancel
Save