pull/1303/head
gedoor 3 years ago
parent cc4c429957
commit cc16a8e2d2
  1. 25
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt
  4. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  5. 17
      app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt
  6. 18
      app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt
  7. 11
      app/src/main/java/io/legado/app/utils/EncoderUtils.kt
  8. 5
      app/src/main/res/menu/audio_play.xml

@ -84,11 +84,12 @@ interface BaseSource : JsExtensions {
*/ */
fun getLoginInfo(): String? { fun getLoginInfo(): String? {
try { try {
val key = AppConst.androidId.encodeToByteArray(0, 8)
val cache = CacheManager.get("userInfo_${getStoreUrl()}") ?: return null val cache = CacheManager.get("userInfo_${getStoreUrl()}") ?: return null
val byteArrayB = Base64.decode(cache, Base64.DEFAULT) val encodeBytes = Base64.decode(cache, Base64.DEFAULT)
val byteArrayA = EncoderUtils.decryptAES(byteArrayB, AppConst.androidId.toByteArray()) val decodeBytes = EncoderUtils.decryptAES(encodeBytes, key)
?: return null ?: return null
return String(byteArrayA) return String(decodeBytes)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
return null return null
@ -102,18 +103,16 @@ interface BaseSource : JsExtensions {
/** /**
* 保存用户信息,aes加密 * 保存用户信息,aes加密
*/ */
fun putLoginInfo(info: String) { fun putLoginInfo(info: String): Boolean {
try { return try {
val data = Base64.encodeToString( val key = (AppConst.androidId).encodeToByteArray(0, 8)
EncoderUtils.decryptAES( val encodeBytes = EncoderUtils.encryptAES(info.toByteArray(), key)
info.toByteArray(), val encodeStr = Base64.encodeToString(encodeBytes, Base64.DEFAULT)
AppConst.androidId.toByteArray() CacheManager.put("userInfo_${getStoreUrl()}", encodeStr)
), true
Base64.DEFAULT
)
CacheManager.put("userInfo_${getStoreUrl()}", data)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
false
} }
} }

@ -25,6 +25,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.model.AudioPlay import io.legado.app.model.AudioPlay
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
import io.legado.app.ui.book.changesource.ChangeSourceDialog import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.image.CoverImageView
@ -59,6 +60,13 @@ class AudioPlayActivity :
} }
} }
} }
private val sourceEditResult =
registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) {
it ?: return@registerForActivityResult
if (it.resultCode == RESULT_OK) {
viewModel.upSource()
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.transparent() binding.titleBar.transparent()
@ -94,6 +102,11 @@ class AudioPlayActivity :
} }
} }
R.id.menu_copy_audio_url -> sendToClip(AudioPlayService.url) R.id.menu_copy_audio_url -> sendToClip(AudioPlayService.url)
R.id.menu_edit_source -> AudioPlay.bookSource?.let {
sourceEditResult.launch {
putExtra("data", it.bookSourceUrl)
}
}
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }

@ -82,6 +82,14 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun upSource() {
execute {
AudioPlay.book?.let { book ->
AudioPlay.bookSource = appDb.bookSourceDao.getBookSource(book.origin)
}
}
}
fun changeTo(book1: Book) { fun changeTo(book1: Book) {
execute { execute {
var oldTocSize: Int = book1.totalChapterNum var oldTocSize: Int = book1.totalChapterNum

@ -74,7 +74,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
} }
private val sourceEditActivity = private val sourceEditActivity =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
if (it.resultCode == RESULT_OK) { if (it.resultCode == RESULT_OK) {
viewModel.upBookSource { viewModel.upBookSource {
@ -732,9 +732,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun openSourceEditActivity() { override fun openSourceEditActivity() {
ReadBook.bookSource?.let { ReadBook.bookSource?.let {
sourceEditActivity.launch(Intent(this, BookSourceEditActivity::class.java).apply { sourceEditActivity.launch {
putExtra("data", it.bookSourceUrl) putExtra("data", it.bookSourceUrl)
}) }
} }
} }

@ -105,14 +105,15 @@ class RuleUiLoginDialog : BaseDialogFragment() {
bookSource.removeLoginInfo() bookSource.removeLoginInfo()
return@setOnMenuItemClickListener true return@setOnMenuItemClickListener true
} }
bookSource.putLoginInfo(GSON.toJson(loginData)) if (bookSource.putLoginInfo(GSON.toJson(loginData))) {
bookSource.getLoginJs()?.let { bookSource.getLoginJs()?.let {
try { try {
bookSource.evalJS(it) bookSource.evalJS(it)
toastOnUi(R.string.success) toastOnUi(R.string.success)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
toastOnUi(e.localizedMessage ?: "ERROR") toastOnUi(e.localizedMessage ?: "ERROR")
}
} }
} }
} }

@ -4,6 +4,7 @@ import android.app.Activity.RESULT_OK
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContract import androidx.activity.result.contract.ActivityResultContract
class SelectImageContract : ActivityResultContract<Int, Pair<Int?, Uri?>?>() { class SelectImageContract : ActivityResultContract<Int, Pair<Int?, Uri?>?>() {
@ -24,4 +25,21 @@ class SelectImageContract : ActivityResultContract<Int, Pair<Int?, Uri?>?>() {
return null return null
} }
}
class StartActivityForResult(private val cls: Class<*>) :
ActivityResultContract<Intent.() -> Unit, ActivityResult>() {
override fun createIntent(context: Context, input: Intent.() -> Unit): Intent {
val intent = Intent(context, cls)
intent.apply(input)
return intent
}
override fun parseResult(
resultCode: Int, intent: Intent?
): ActivityResult {
return ActivityResult(resultCode, intent)
}
} }

@ -120,7 +120,7 @@ object EncoderUtils {
fun decryptAES( fun decryptAES(
data: ByteArray?, data: ByteArray?,
key: ByteArray?, key: ByteArray?,
transformation: String = "AES/ECB/PKCS5Padding", transformation: String = "DES/ECB/PKCS5Padding",
iv: ByteArray? = null iv: ByteArray? = null
): ByteArray? { ): ByteArray? {
return symmetricTemplate(data, key, "AES", transformation, iv, false) return symmetricTemplate(data, key, "AES", transformation, iv, false)
@ -154,15 +154,12 @@ object EncoderUtils {
else { else {
val keySpec = SecretKeySpec(key, algorithm) val keySpec = SecretKeySpec(key, algorithm)
val cipher = Cipher.getInstance(transformation) val cipher = Cipher.getInstance(transformation)
val mode = if (isEncrypt) Cipher.ENCRYPT_MODE else Cipher.DECRYPT_MODE
if (iv == null || iv.isEmpty()) { if (iv == null || iv.isEmpty()) {
cipher.init(if (isEncrypt) Cipher.ENCRYPT_MODE else Cipher.DECRYPT_MODE, keySpec) cipher.init(mode, keySpec)
} else { } else {
val params: AlgorithmParameterSpec = IvParameterSpec(iv) val params: AlgorithmParameterSpec = IvParameterSpec(iv)
cipher.init( cipher.init(mode, keySpec, params)
if (isEncrypt) Cipher.ENCRYPT_MODE else Cipher.DECRYPT_MODE,
keySpec,
params
)
} }
cipher.doFinal(data) cipher.doFinal(data)
} }

@ -20,4 +20,9 @@
android:title="@string/copy_play_url" android:title="@string/copy_play_url"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_edit_source"
android:title="@string/edit_book_source"
app:showAsAction="never" />
</menu> </menu>
Loading…
Cancel
Save