commit
ee2b6b7920
@ -0,0 +1,71 @@ |
||||
package io.legado.app.ui.config |
||||
|
||||
import android.os.Bundle |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import io.legado.app.R |
||||
import io.legado.app.base.BaseDialogFragment |
||||
import io.legado.app.databinding.DialogCheckSourceConfigBinding |
||||
import io.legado.app.model.CheckSource |
||||
import io.legado.app.lib.theme.primaryColor |
||||
import io.legado.app.utils.setLayout |
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding |
||||
import io.legado.app.utils.toastOnUi |
||||
import splitties.views.onClick |
||||
|
||||
class CheckSourceConfig : BaseDialogFragment(R.layout.dialog_check_source_config) { |
||||
|
||||
private val binding by viewBinding(DialogCheckSourceConfigBinding::bind) |
||||
//允许的最小超时时间,秒 |
||||
private val minTimeout = 60L |
||||
|
||||
override fun onStart() { |
||||
super.onStart() |
||||
setLayout( |
||||
0.9f, |
||||
ViewGroup.LayoutParams.WRAP_CONTENT |
||||
) |
||||
} |
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
||||
binding.toolBar.setBackgroundColor(primaryColor) |
||||
CheckSource.run { |
||||
binding.checkSourceTimeout.setText((timeout / 1000).toString()) |
||||
binding.checkSearch?.isChecked = checkSearch |
||||
binding.checkDiscovery?.isChecked = checkDiscovery |
||||
binding.checkInfo?.isChecked = checkInfo |
||||
binding.checkCategory?.isChecked = checkCategory |
||||
binding.checkContent?.isChecked = checkContent |
||||
binding.tvCancel.onClick { |
||||
dismiss() |
||||
} |
||||
binding.tvOk.onClick { |
||||
val text = binding.checkSourceTimeout.text.toString() |
||||
when { |
||||
text.isBlank() -> { |
||||
toastOnUi("${getString(R.string.timeout)}${getString(R.string.cannot_empty)}") |
||||
return@onClick |
||||
} |
||||
text.toLong() < minTimeout -> { |
||||
toastOnUi("${getString(R.string.timeout)}${getString(R.string.less_than)}${minTimeout}${getString(R.string.seconds)}") |
||||
return@onClick |
||||
} |
||||
else -> timeout = text.toLong() * 1000 |
||||
} |
||||
val _checkSearch = binding.checkSearch?.isChecked |
||||
val _checkDiscovery = binding.checkDiscovery?.isChecked |
||||
if (!_checkSearch && !_checkDiscovery) { |
||||
toastOnUi(getString(R.string.error_check_source_config)) |
||||
return@onClick |
||||
} |
||||
checkSearch = _checkSearch |
||||
checkDiscovery = _checkDiscovery |
||||
checkInfo = binding.checkInfo?.isChecked |
||||
checkCategory = binding.checkCategory?.isChecked |
||||
checkContent = binding.checkContent?.isChecked |
||||
putConfig() |
||||
dismiss() |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,94 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
||||
|
||||
<androidx.appcompat.widget.Toolbar |
||||
android:id="@+id/tool_bar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:theme="?attr/actionBarStyle" |
||||
app:title="@string/check_source_config" |
||||
app:popupTheme="@style/AppTheme.PopupOverlay" |
||||
app:titleTextAppearance="@style/ToolbarTitle" /> |
||||
|
||||
<io.legado.app.ui.widget.text.TextInputLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingTop="3dp"> |
||||
|
||||
<io.legado.app.lib.theme.view.ThemeEditText |
||||
android:id="@+id/check_source_timeout" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:hint="@string/check_source_timeout" |
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" /> |
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout> |
||||
|
||||
<com.google.android.flexbox.FlexboxLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="12dp" |
||||
android:paddingRight="12dp" |
||||
app:flexWrap="wrap" |
||||
app:justifyContent="space_between"> |
||||
|
||||
<io.legado.app.lib.theme.view.ThemeCheckBox |
||||
android:id="@+id/check_search" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/check_search" /> |
||||
<io.legado.app.lib.theme.view.ThemeCheckBox |
||||
android:id="@+id/check_discovery" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/check_discovery" /> |
||||
<io.legado.app.lib.theme.view.ThemeCheckBox |
||||
android:id="@+id/check_info" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
app:layout_wrapBefore="true" |
||||
android:text="@string/check_info" /> |
||||
<io.legado.app.lib.theme.view.ThemeCheckBox |
||||
android:id="@+id/check_category" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/check_category" /> |
||||
<io.legado.app.lib.theme.view.ThemeCheckBox |
||||
android:id="@+id/check_content" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/check_content" /> |
||||
|
||||
</com.google.android.flexbox.FlexboxLayout> |
||||
|
||||
<com.google.android.flexbox.FlexboxLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="12dp" |
||||
android:paddingRight="12dp" |
||||
app:flexWrap="wrap" |
||||
app:justifyContent="flex_end"> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/tv_cancel" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:padding="12dp" |
||||
android:text="@string/cancel" |
||||
tools:ignore="RtlHardcoded" /> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/tv_ok" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:padding="12dp" |
||||
android:text="@string/ok" |
||||
tools:ignore="RtlHardcoded" /> |
||||
|
||||
</com.google.android.flexbox.FlexboxLayout> |
||||
</LinearLayout> |
Loading…
Reference in new issue