feat: 优化代码

pull/103/head
kunfei 5 years ago
parent ee4f7e638e
commit 0fb66e8ce2
  1. 4
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 12
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt
  4. 35
      app/src/main/res/layout/item_book_source.xml

@ -182,6 +182,10 @@ data class BookSource(
return exploreKinds return exploreKinds
} }
fun showExplore(): Boolean {
return enabledExplore && !exploreUrl.isNullOrEmpty()
}
/** /**
* 执行JS * 执行JS
*/ */

@ -11,6 +11,8 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.ItemTouchCallback.OnItemTouchCallbackListener import io.legado.app.help.ItemTouchCallback.OnItemTouchCallbackListener
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.utils.invisible
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_book_source.view.* import kotlinx.android.synthetic.main.item_book_source.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.* import java.util.*
@ -89,6 +91,11 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} }
popupMenu.show() popupMenu.show()
} }
if (item.showExplore()) {
iv_explore.visible()
} else {
iv_explore.invisible()
}
} else { } else {
payload.keySet().map { payload.keySet().map {
when (it) { when (it) {
@ -100,6 +107,11 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup) String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup)
} }
"enabled" -> swt_enabled.isChecked = payload.getBoolean(it) "enabled" -> swt_enabled.isChecked = payload.getBoolean(it)
"showExplore" -> if (payload.getBoolean(it)) {
iv_explore.visible()
} else {
iv_explore.invisible()
}
} }
} }
} }

@ -48,6 +48,9 @@ class DiffCallBack(
if (oldItem.enabled != newItem.enabled) { if (oldItem.enabled != newItem.enabled) {
payload.putBoolean("enabled", newItem.enabled) payload.putBoolean("enabled", newItem.enabled)
} }
if (oldItem.showExplore() != newItem.showExplore()) {
payload.putBoolean("showExplore", newItem.enabledExplore)
}
if (payload.isEmpty) { if (payload.isEmpty) {
return null return null
} }

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="16dp"> android:padding="16dp">
<io.legado.app.lib.theme.view.ATECheckBox <io.legado.app.lib.theme.view.ATECheckBox
@ -13,9 +12,12 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_weight="1"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/tv_text_default" /> android:textColor="@color/tv_text_default"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/swt_enabled"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<io.legado.app.lib.theme.view.ATESwitch <io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/swt_enabled" android:id="@+id/swt_enabled"
@ -24,7 +26,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="6dp" android:layout_marginLeft="6dp"
android:layout_marginRight="6dp" android:layout_marginRight="6dp"
tools:ignore="RtlSymmetry" /> tools:ignore="RtlSymmetry"
app:layout_constraintRight_toLeftOf="@id/iv_edit"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit" android:id="@+id/iv_edit"
@ -35,7 +40,10 @@
android:contentDescription="@string/edit" android:contentDescription="@string/edit"
android:padding="6dp" android:padding="6dp"
android:src="@drawable/ic_edit" android:src="@drawable/ic_edit"
android:tint="@color/tv_text_default" /> android:tint="@color/tv_text_default"
app:layout_constraintRight_toLeftOf="@id/iv_menu_more"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_menu_more" android:id="@+id/iv_menu_more"
@ -45,6 +53,17 @@
android:padding="6dp" android:padding="6dp"
android:src="@drawable/ic_more_vert" android:src="@drawable/ic_more_vert"
android:tint="@color/tv_text_default" android:tint="@color/tv_text_default"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="RtlHardcoded" /> tools:ignore="RtlHardcoded" />
</LinearLayout> <io.legado.app.ui.widget.image.CircleImageView
android:id="@+id/iv_explore"
android:layout_width="8dp"
android:layout_height="8dp"
android:src="@color/md_green_600"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save