|
|
|
@ -2,28 +2,30 @@ package io.legado.app.ui.book.login |
|
|
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.text.InputType |
|
|
|
|
import android.util.Base64 |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
|
import io.legado.app.data.entities.rule.LoginRule |
|
|
|
|
import io.legado.app.data.appDb |
|
|
|
|
import io.legado.app.databinding.DialogLoginBinding |
|
|
|
|
import io.legado.app.help.CacheManager |
|
|
|
|
import io.legado.app.lib.theme.primaryColor |
|
|
|
|
import io.legado.app.ui.widget.text.EditText |
|
|
|
|
import io.legado.app.ui.widget.text.TextInputLayout |
|
|
|
|
import io.legado.app.utils.EncoderUtils |
|
|
|
|
import io.legado.app.utils.GSON |
|
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
|
|
|
|
|
class SourceLoginDialog : BaseDialogFragment() { |
|
|
|
|
|
|
|
|
|
private val binding by viewBinding(DialogLoginBinding::bind) |
|
|
|
|
companion object { |
|
|
|
|
fun start(fragmentManager: FragmentManager, sourceUrl: String) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private val binding by viewBinding(DialogLoginBinding::bind) |
|
|
|
|
|
|
|
|
|
override fun onCreateView( |
|
|
|
|
inflater: LayoutInflater, |
|
|
|
@ -35,19 +37,27 @@ class SourceLoginDialog : BaseDialogFragment() { |
|
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
binding.toolBar.setBackgroundColor(primaryColor) |
|
|
|
|
val sourceUrl = arguments?.getString("sourceUrl") |
|
|
|
|
val loginRule = arguments?.getParcelable<LoginRule>("loginRule") |
|
|
|
|
val sourceUrl = arguments?.getString("sourceUrl") ?: return |
|
|
|
|
val bookSource = appDb.bookSourceDao.getBookSource(sourceUrl) ?: return |
|
|
|
|
val loginHeader = bookSource.getLoginHeader() |
|
|
|
|
val loginRule = bookSource.loginUrl |
|
|
|
|
loginRule?.ui?.forEachIndexed { index, rowUi -> |
|
|
|
|
when (rowUi.type) { |
|
|
|
|
"text" -> layoutInflater.inflate(R.layout.item_source_edit, binding.root) |
|
|
|
|
.apply { |
|
|
|
|
id = index |
|
|
|
|
findViewById<EditText>(R.id.editText).apply { |
|
|
|
|
setText(loginHeader?.get(rowUi.name)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
"password" -> layoutInflater.inflate(R.layout.item_source_edit, binding.root) |
|
|
|
|
.apply { |
|
|
|
|
id = index |
|
|
|
|
findViewById<EditText>(R.id.editText)?.inputType = |
|
|
|
|
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT |
|
|
|
|
findViewById<EditText>(R.id.editText).apply { |
|
|
|
|
inputType = |
|
|
|
|
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT |
|
|
|
|
setText(loginHeader?.get(rowUi.name)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -66,14 +76,7 @@ class SourceLoginDialog : BaseDialogFragment() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
val data = Base64.encodeToString( |
|
|
|
|
EncoderUtils.decryptAES( |
|
|
|
|
GSON.toJson(loginData).toByteArray(), |
|
|
|
|
AppConst.androidId.toByteArray() |
|
|
|
|
), |
|
|
|
|
Base64.DEFAULT |
|
|
|
|
) |
|
|
|
|
CacheManager.put("login_$sourceUrl", data) |
|
|
|
|
bookSource.putLoginHeader(GSON.toJson(loginData)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return@setOnMenuItemClickListener true |
|
|
|
|