feat: 优化代码

pull/111/head
kunfei 5 years ago
parent e29c9d8ad8
commit 2a87606be5
  1. 13
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 44
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  3. 12
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  4. 12
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  5. 4
      app/src/main/res/layout/popup_action_menu.xml

@ -361,6 +361,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun onCancelSelect() { override fun onCancelSelect() {
cursor_left.invisible() cursor_left.invisible()
cursor_right.invisible() cursor_right.invisible()
textActionMenu?.dismiss()
} }
/** /**
@ -368,9 +369,17 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
*/ */
private fun showTextActionMenu() { private fun showTextActionMenu() {
textActionMenu ?: let { textActionMenu ?: let {
textActionMenu = TextActionMenu(this) textActionMenu = TextActionMenu(this, this)
}
textActionMenu?.let { popup ->
if (!popup.isShowing) {
popup.showAsDropDown(
cursor_left,
cursor_left.width,
-cursor_left.height - ReadBookConfig.durConfig.textSize.dp
)
}
} }
page_view.selectedText
} }
/** /**

@ -5,7 +5,17 @@ import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import kotlinx.android.synthetic.main.item_text.view.*
import kotlinx.android.synthetic.main.popup_action_menu.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class TextActionMenu(context: Context, callBack: CallBack) : class TextActionMenu(context: Context, callBack: CallBack) :
@ -18,8 +28,42 @@ class TextActionMenu(context: Context, callBack: CallBack) :
isTouchable = true isTouchable = true
isOutsideTouchable = false isOutsideTouchable = false
isFocusable = false isFocusable = false
initRecyclerView()
}
private fun initRecyclerView() = with(contentView) {
val adapter = Adapter(context)
recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
recycler_view.adapter = adapter
val menu = MenuBuilder(context)
SupportMenuInflater(context).inflate(R.menu.content_select_action, menu)
adapter.setItems(menu.visibleItems)
}
inner class Adapter(context: Context) :
SimpleRecyclerAdapter<MenuItemImpl>(context, R.layout.item_text) {
override fun convert(
holder: ItemViewHolder,
item: MenuItemImpl,
payloads: MutableList<Any>
) {
with(holder.itemView) {
text_view.text = item.title
}
} }
override fun registerListener(holder: ItemViewHolder) {
holder.itemView.apply {
onClick {
getItem(holder.layoutPosition)?.let {
}
}
}
}
}
interface CallBack { interface CallBack {

@ -353,18 +353,16 @@ class BookSourceEditActivity :
} }
private fun showKeyboardTopPopupWindow() { private fun showKeyboardTopPopupWindow() {
mSoftKeyboardTool?.isShowing?.let { if (it) return } mSoftKeyboardTool?.let {
if (it.isShowing) return
if (!isFinishing) { if (!isFinishing) {
mSoftKeyboardTool?.showAtLocation(ll_content, Gravity.BOTTOM, 0, 0) it.showAtLocation(ll_content, Gravity.BOTTOM, 0, 0)
}
} }
} }
private fun closePopupWindow() { private fun closePopupWindow() {
mSoftKeyboardTool?.let { mSoftKeyboardTool?.dismiss()
if (it.isShowing) {
it.dismiss()
}
}
} }
private inner class KeyboardOnGlobalChangeListener : ViewTreeObserver.OnGlobalLayoutListener { private inner class KeyboardOnGlobalChangeListener : ViewTreeObserver.OnGlobalLayoutListener {

@ -192,18 +192,16 @@ class RssSourceEditActivity :
} }
private fun showKeyboardTopPopupWindow() { private fun showKeyboardTopPopupWindow() {
mSoftKeyboardTool?.isShowing?.let { if (it) return } mSoftKeyboardTool?.let {
if (it.isShowing) return
if (!isFinishing) { if (!isFinishing) {
mSoftKeyboardTool?.showAtLocation(ll_content, Gravity.BOTTOM, 0, 0) it.showAtLocation(ll_content, Gravity.BOTTOM, 0, 0)
}
} }
} }
private fun closePopupWindow() { private fun closePopupWindow() {
mSoftKeyboardTool?.let { mSoftKeyboardTool?.dismiss()
if (it.isShowing) {
it.dismiss()
}
}
} }
private inner class KeyboardOnGlobalChangeListener : ViewTreeObserver.OnGlobalLayoutListener { private inner class KeyboardOnGlobalChangeListener : ViewTreeObserver.OnGlobalLayoutListener {

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@color/background_card" android:background="@drawable/shape_card_view"
android:padding="5dp" /> android:padding="5dp" />

Loading…
Cancel
Save