自动使用登录header

pull/1272/head
gedoor 3 years ago
parent 045dc060cf
commit b80286435d
  1. 2
      app/src/main/AndroidManifest.xml
  2. 11
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  3. 8
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  8. 2
      app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt
  9. 2
      app/src/main/java/io/legado/app/ui/login/SourceLoginActivity.kt
  10. 2
      app/src/main/java/io/legado/app/ui/login/SourceLoginViewModel.kt
  11. 2
      app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt

@ -293,7 +293,7 @@
android:launchMode="singleTop" />
<!-- 书源登录 -->
<activity
android:name="io.legado.app.ui.book.login.SourceLoginActivity"
android:name="io.legado.app.ui.login.SourceLoginActivity"
android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true" />
<!-- 阅读记录 -->

@ -14,6 +14,7 @@ import javax.script.SimpleBindings
/**
* 可在js里调用,source.xxx()
*/
@Suppress("unused")
interface BaseSource : JsExtensions {
fun getStoreUrl(): String
@ -39,7 +40,7 @@ interface BaseSource : JsExtensions {
}
}
if (hasLoginHeader) {
getLoginHeader()?.let {
getLoginHeaderMap()?.let {
putAll(it)
}
}
@ -48,8 +49,12 @@ interface BaseSource : JsExtensions {
/**
* 获取用于登录的头部信息
*/
fun getLoginHeader(): Map<String, String>? {
val cache = CacheManager.get("loginHeader_${getStoreUrl()}") ?: return null
fun getLoginHeader(): String? {
return CacheManager.get("loginHeader_${getStoreUrl()}")
}
fun getLoginHeaderMap(): Map<String, String>? {
val cache = getLoginHeader() ?: return null
return GSON.fromJsonObject(cache)
}

@ -61,18 +61,19 @@ data class BookSource(
if (ruleStr.isNotBlank()) {
kotlin.runCatching {
if (exploreUrl.startsWith("<js>", false)
|| exploreUrl.startsWith("@js", false)
|| exploreUrl.startsWith("@js:", false)
) {
val aCache = ACache.get(appCtx, "explore")
ruleStr = aCache.getAsString(bookSourceUrl) ?: ""
if (ruleStr.isBlank()) {
val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl
bindings["java"] = this
bindings["source"] = this
bindings["baseUrl"] = bookSourceUrl
bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager
val jsStr = if (exploreUrl.startsWith("@")) {
exploreUrl.substring(3)
exploreUrl.substring(4)
} else {
exploreUrl.substring(4, exploreUrl.lastIndexOf("<"))
}
@ -91,6 +92,7 @@ data class BookSource(
}
}
}.onFailure {
it.printStackTrace()
kinds.add(ExploreKind(it.localizedMessage ?: ""))
}
}

@ -32,11 +32,11 @@ import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.group.GroupSelectDialog
import io.legado.app.ui.book.info.edit.BookInfoEditActivity
import io.legado.app.ui.book.login.SourceLoginActivity
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.widget.image.CoverImageView
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding

@ -34,7 +34,6 @@ import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.login.SourceLoginActivity
import io.legado.app.ui.book.read.config.*
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR
@ -48,6 +47,7 @@ import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.BookmarkDialog
import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.dict.DictDialog
import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.replace.ReplaceRuleActivity
import io.legado.app.ui.replace.edit.ReplaceEditActivity
import io.legado.app.ui.widget.dialog.TextDialog

@ -24,10 +24,10 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.book.login.SourceLoginActivity
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog

@ -17,7 +17,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ItemBookSourceBinding
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.model.Debug
import io.legado.app.ui.book.login.SourceLoginActivity
import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback.Callback
import io.legado.app.utils.ColorUtils

@ -1,4 +1,4 @@
package io.legado.app.ui.book.login
package io.legado.app.ui.login
import android.content.DialogInterface
import android.os.Bundle

@ -1,4 +1,4 @@
package io.legado.app.ui.book.login
package io.legado.app.ui.login
import android.os.Bundle
import androidx.activity.viewModels

@ -1,4 +1,4 @@
package io.legado.app.ui.book.login
package io.legado.app.ui.login
import android.app.Application
import io.legado.app.base.BaseViewModel

@ -1,4 +1,4 @@
package io.legado.app.ui.book.login
package io.legado.app.ui.login
import android.annotation.SuppressLint
import android.graphics.Bitmap
Loading…
Cancel
Save