pull/737/head
Robot 4 years ago
commit 1beb5121ff
  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. 8
      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. 25
      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.github.gedoor:rhino-android:1.4'
// //
implementation 'com.ljx.rxhttp:rxhttp:2.4.4'
implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1' implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
kapt 'com.ljx.rxhttp:rxhttp-compiler:2.4.4'
//Glide //Glide
implementation 'com.github.bumptech.glide:glide:4.11.0' implementation 'com.github.bumptech.glide:glide:4.11.0'

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

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

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

@ -26,7 +26,7 @@ object BookWebDav {
private val bookProgressUrl = "${rootWebDavUrl}bookProgress/" private val bookProgressUrl = "${rootWebDavUrl}bookProgress/"
private val zipFilePath = "${FileUtils.getCachePath()}${File.separator}backup.zip" private val zipFilePath = "${FileUtils.getCachePath()}${File.separator}backup.zip"
val rootWebDavUrl: String private val rootWebDavUrl: String
get() { get() {
var url = App.INSTANCE.getPrefString(PreferKey.webDavUrl) var url = App.INSTANCE.getPrefString(PreferKey.webDavUrl)
if (url.isNullOrEmpty()) { if (url.isNullOrEmpty()) {
@ -155,7 +155,7 @@ object BookWebDav {
durChapterTitle = book.durChapterTitle durChapterTitle = book.durChapterTitle
) )
val json = GSON.toJson(bookProgress) val json = GSON.toJson(bookProgress)
val url = getUrl(book) val url = geProtresstUrl(book)
if (initWebDav()) { if (initWebDav()) {
WebDav(url).upload(json.toByteArray()) WebDav(url).upload(json.toByteArray())
} }
@ -164,7 +164,7 @@ object BookWebDav {
fun getBookProgress(book: Book): BookProgress? { fun getBookProgress(book: Book): BookProgress? {
if (initWebDav()) { if (initWebDav()) {
val url = getUrl(book) val url = geProtresstUrl(book)
WebDav(url).download()?.let { byteArray -> WebDav(url).download()?.let { byteArray ->
val json = String(byteArray) val json = String(byteArray)
GSON.fromJsonObject<BookProgress>(json)?.let { GSON.fromJsonObject<BookProgress>(json)?.let {
@ -175,7 +175,7 @@ object BookWebDav {
return null return null
} }
private fun getUrl(book: Book): String { private fun geProtresstUrl(book: Book): String {
return bookProgressUrl + book.name + "_" + book.author + ".json" return bookProgressUrl + book.name + "_" + book.author + ".json"
} }
} }

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

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

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

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

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

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

Loading…
Cancel
Save