feat: 优化代码

pull/103/head
kunfei 5 years ago
parent e2665383d2
commit 77adb5702c
  1. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  2. 6
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  3. 26
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt
  4. 6
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt

@ -95,7 +95,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
}
}
iv_menu_more.onClick {
showMenu(iv_menu_more, getItem(holder.layoutPosition))
showMenu(iv_menu_more, holder.layoutPosition)
}
upShowExplore(iv_explore, item)
} else {
@ -116,8 +116,8 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
}
}
private fun showMenu(view: View, source: BookSource?) {
if (source == null) return
private fun showMenu(view: View, position: Int) {
val source = getItem(position) ?: return
val popupMenu = PopupMenu(context, view)
popupMenu.inflate(R.menu.book_source_item)
val qyMenu = popupMenu.menu.findItem(R.id.menu_enable_explore)

@ -40,7 +40,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
callBack.scrollTo(holder.layoutPosition)
}
ll_title.onLongClick {
showMenu(ll_title, getItem(holder.layoutPosition), holder.layoutPosition)
showMenu(ll_title, holder.layoutPosition)
}
}
if (exIndex == holder.layoutPosition) {
@ -80,8 +80,8 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
}
}
private fun showMenu(view: View, source: BookSource?, position: Int): Boolean {
if (source == null) return true
private fun showMenu(view: View, position: Int): Boolean {
val source = getItem(position) ?: return true
val popupMenu = PopupMenu(context, view)
popupMenu.inflate(R.menu.explore_item)
popupMenu.setOnMenuItemClickListener {

@ -2,6 +2,7 @@ package io.legado.app.ui.replacerule
import android.content.Context
import android.os.Bundle
import android.view.View
import android.widget.PopupMenu
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
@ -81,16 +82,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
callBack.upCountView()
}
iv_menu_more.onClick {
val popupMenu = PopupMenu(context, it)
popupMenu.inflate(R.menu.replace_rule_item)
popupMenu.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.menu_top -> callBack.toTop(item)
R.id.menu_del -> callBack.delete(item)
}
true
}
popupMenu.show()
showMenu(iv_menu_more, holder.layoutPosition)
}
} else {
bundle.keySet().map {
@ -110,6 +102,20 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
}
}
private fun showMenu(view: View, position: Int) {
val item = getItem(position) ?: return
val popupMenu = PopupMenu(context, view)
popupMenu.inflate(R.menu.replace_rule_item)
popupMenu.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.menu_top -> callBack.toTop(item)
R.id.menu_del -> callBack.delete(item)
}
true
}
popupMenu.show()
}
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {
val srcItem = getItem(srcPosition)
val targetItem = getItem(targetPosition)

@ -88,7 +88,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
}
}
iv_menu_more.onClick {
showMenu(iv_menu_more, getItem(holder.layoutPosition))
showMenu(iv_menu_more, holder.layoutPosition)
}
} else {
when (payloads[0]) {
@ -99,8 +99,8 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) :
}
}
private fun showMenu(view: View, source: RssSource?) {
if (source == null) return
private fun showMenu(view: View, position: Int) {
val source = getItem(position) ?: return
val popupMenu = PopupMenu(context, view)
popupMenu.inflate(R.menu.rss_source_item)
popupMenu.setOnMenuItemClickListener { menuItem ->

Loading…
Cancel
Save