From 205d6b86d6997f4a7779ec371607ffb3e925ad8e Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 17 Aug 2021 21:21:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/data/entities/rule/LoginRule.kt | 17 +++++-- .../app/ui/book/login/SourceLoginActivity.kt | 2 +- .../app/ui/book/login/SourceLoginDialog.kt | 46 +++++++++++++++++++ app/src/main/res/layout/dialog_login.xml | 17 ++++--- app/src/main/res/menu/source_login.xml | 4 +- 5 files changed, 72 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/rule/LoginRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/LoginRule.kt index 1f8e7a5e4..a14ea5d67 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/LoginRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/LoginRule.kt @@ -5,7 +5,16 @@ import kotlinx.parcelize.Parcelize @Parcelize data class LoginRule( - val ui: HashMap? = null, - val url: String? = null, - val checkJs: String? = null -) : Parcelable \ No newline at end of file + var ui: List? = null, + var url: String? = null, + var checkJs: String? = null +) : Parcelable { + + @Parcelize + data class RowUi( + var name: String, + var type: String, + ) : Parcelable + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/login/SourceLoginActivity.kt b/app/src/main/java/io/legado/app/ui/book/login/SourceLoginActivity.kt index 709f297a1..118467315 100644 --- a/app/src/main/java/io/legado/app/ui/book/login/SourceLoginActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/login/SourceLoginActivity.kt @@ -74,7 +74,7 @@ class SourceLoginActivity : BaseActivity() { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_success -> { + R.id.menu_ok -> { if (!checking) { checking = true binding.titleBar.snackbar(R.string.check_host_cookie) diff --git a/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt b/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt index 8af31811a..69b92403c 100644 --- a/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt @@ -1,14 +1,25 @@ package io.legado.app.ui.book.login import android.os.Bundle +import android.text.InputType import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.data.entities.rule.LoginRule +import io.legado.app.databinding.DialogLoginBinding +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.applyTint +import io.legado.app.utils.viewbindingdelegate.viewBinding class SourceLoginDialog : BaseDialogFragment() { + private val binding by viewBinding(DialogLoginBinding::bind) + + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -18,7 +29,42 @@ class SourceLoginDialog : BaseDialogFragment() { } override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + binding.toolBar.setBackgroundColor(primaryColor) + val loginRule = arguments?.getParcelable("loginRule") + loginRule?.ui?.forEachIndexed { index, rowUi -> + when (rowUi.type) { + "text" -> layoutInflater.inflate(R.layout.item_source_edit, binding.root) + .apply { + id = index + } + "password" -> layoutInflater.inflate(R.layout.item_source_edit, binding.root) + .apply { + id = index + findViewById(R.id.editText)?.inputType = + InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT + } + } + } + binding.toolBar.inflateMenu(R.menu.source_login) + binding.toolBar.menu.applyTint(requireContext()) + binding.toolBar.setOnMenuItemClickListener { + when (it.itemId) { + R.id.menu_ok -> { + val loginData = hashMapOf() + loginRule?.ui?.forEachIndexed { index, rowUi -> + when (rowUi.type) { + "text", "password" -> { + val value = binding.root.findViewById(index) + .findViewById(R.id.editText).text?.toString() + loginData[rowUi.name] = value + } + } + } + } + } + return@setOnMenuItemClickListener true + } } diff --git a/app/src/main/res/layout/dialog_login.xml b/app/src/main/res/layout/dialog_login.xml index d28eb9303..cbb5f1d42 100644 --- a/app/src/main/res/layout/dialog_login.xml +++ b/app/src/main/res/layout/dialog_login.xml @@ -1,20 +1,23 @@ - + android:background="@color/background_menu" + android:elevation="5dp" + android:theme="?attr/actionBarStyle" + app:displayHomeAsUp="false" + app:fitStatusBar="false" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:titleTextAppearance="@style/ToolbarTitle" /> \ No newline at end of file diff --git a/app/src/main/res/menu/source_login.xml b/app/src/main/res/menu/source_login.xml index c58ada14b..735b6b8fa 100644 --- a/app/src/main/res/menu/source_login.xml +++ b/app/src/main/res/menu/source_login.xml @@ -3,9 +3,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> \ No newline at end of file