pull/1251/head
gedoor 3 years ago
parent 10fb05b0aa
commit 205d6b86d6
  1. 17
      app/src/main/java/io/legado/app/data/entities/rule/LoginRule.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/login/SourceLoginActivity.kt
  3. 46
      app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt
  4. 17
      app/src/main/res/layout/dialog_login.xml
  5. 4
      app/src/main/res/menu/source_login.xml

@ -5,7 +5,16 @@ import kotlinx.parcelize.Parcelize
@Parcelize @Parcelize
data class LoginRule( data class LoginRule(
val ui: HashMap<String, String>? = null, var ui: List<RowUi>? = null,
val url: String? = null, var url: String? = null,
val checkJs: String? = null var checkJs: String? = null
) : Parcelable ) : Parcelable {
@Parcelize
data class RowUi(
var name: String,
var type: String,
) : Parcelable
}

@ -74,7 +74,7 @@ class SourceLoginActivity : BaseActivity<ActivitySourceLoginBinding>() {
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_success -> { R.id.menu_ok -> {
if (!checking) { if (!checking) {
checking = true checking = true
binding.titleBar.snackbar(R.string.check_host_cookie) binding.titleBar.snackbar(R.string.check_host_cookie)

@ -1,14 +1,25 @@
package io.legado.app.ui.book.login package io.legado.app.ui.book.login
import android.os.Bundle import android.os.Bundle
import android.text.InputType
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment 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() { class SourceLoginDialog : BaseDialogFragment() {
private val binding by viewBinding(DialogLoginBinding::bind)
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
@ -18,7 +29,42 @@ class SourceLoginDialog : BaseDialogFragment() {
} }
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor)
val loginRule = arguments?.getParcelable<LoginRule>("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<EditText>(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<String, String?>()
loginRule?.ui?.forEachIndexed { index, rowUi ->
when (rowUi.type) {
"text", "password" -> {
val value = binding.root.findViewById<TextInputLayout>(index)
.findViewById<EditText>(R.id.editText).text?.toString()
loginData[rowUi.name] = value
}
}
}
}
}
return@setOnMenuItemClickListener true
}
} }

@ -1,20 +1,23 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/background" android:background="@color/background"
android:gravity="center" android:gravity="center"
android:padding="20dp"
android:orientation="horizontal"> android:orientation="horizontal">
<io.legado.app.ui.widget.text.AccentTextView <androidx.appcompat.widget.Toolbar
android:id="@+id/title" android:id="@+id/tool_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingBottom="12dp" android:background="@color/background_menu"
android:textSize="16sp" android:elevation="5dp"
android:textStyle="bold" android:theme="?attr/actionBarStyle"
android:text="@string/login" /> app:displayHomeAsUp="false"
app:fitStatusBar="false"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextAppearance="@style/ToolbarTitle" />
</LinearLayout> </LinearLayout>

@ -3,9 +3,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/menu_success" android:id="@+id/menu_ok"
android:icon="@drawable/ic_check" android:icon="@drawable/ic_check"
android:title="@string/success" android:title="@string/ok"
app:showAsAction="always" /> app:showAsAction="always" />
</menu> </menu>
Loading…
Cancel
Save