feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 4e5f16dae5
commit 6dbd3e70f4
  1. 29
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt
  3. 8
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt
  4. 4
      app/src/main/res/menu/book_source_item.xml

@ -11,7 +11,6 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookSource
import io.legado.app.help.ItemTouchCallback.OnItemTouchCallbackListener
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 org.jetbrains.anko.sdk27.listeners.onClick
@ -82,20 +81,31 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
iv_menu_more.onClick {
val popupMenu = PopupMenu(context, it)
popupMenu.inflate(R.menu.book_source_item)
val qyMenu = popupMenu.menu.findItem(R.id.menu_enable_explore)
if (item.exploreUrl.isNullOrEmpty()) {
qyMenu.isVisible = false
} else {
if (item.enabledExplore) {
qyMenu.setTitle(R.string.disable_explore)
} else {
qyMenu.setTitle(R.string.enable_explore)
}
}
popupMenu.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.menu_top -> callBack.toTop(item)
R.id.menu_del -> callBack.del(item)
R.id.menu_enable_explore -> {
item.enabledExplore = !item.enabledExplore
callBack.update(item)
iv_explore.visible(item.showExplore())
}
}
true
}
popupMenu.show()
}
if (item.showExplore()) {
iv_explore.visible()
} else {
iv_explore.invisible()
}
iv_explore.visible(item.showExplore())
} else {
payload.keySet().map {
when (it) {
@ -107,16 +117,11 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup)
}
"enabled" -> swt_enabled.isChecked = payload.getBoolean(it)
"showExplore" -> if (payload.getBoolean(it)) {
iv_explore.visible()
} else {
iv_explore.invisible()
}
"showExplore" -> iv_explore.visible(payload.getBoolean(it))
}
}
}
}
}
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {

@ -32,6 +32,9 @@ class DiffCallBack(
return false
if (oldItem.enabled != newItem.enabled)
return false
if (oldItem.showExplore() != newItem.showExplore()) {
return false
}
return true
}

@ -49,6 +49,14 @@ fun View.visible() {
visibility = VISIBLE
}
fun View.visible(visible: Boolean) {
visibility = if (visible) {
VISIBLE
} else {
INVISIBLE
}
}
fun View.screenshot(): Bitmap? {
return runCatching {
val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)

@ -9,4 +9,8 @@
android:id="@+id/menu_del"
android:title="@string/delete" />
<item
android:id="@+id/menu_enable_explore"
android:title="@string/enable_explore" />
</menu>
Loading…
Cancel
Save