feat: 优化代码

pull/111/head
kunfei 5 years ago
parent d291540513
commit 4c0deef70c
  1. 6
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  4. 4
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  5. 4
      app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt
  6. 2
      app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt
  7. 15
      app/src/main/res/layout/item_fillet_text.xml
  8. 3
      app/src/main/res/layout/item_text.xml
  9. 11
      app/src/main/res/menu/content_select_action.xml

@ -8,12 +8,13 @@ import android.widget.PopupWindow
import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl import androidx.appcompat.view.menu.MenuItemImpl
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView 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.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import kotlinx.android.synthetic.main.item_text.view.* import kotlinx.android.synthetic.main.item_fillet_text.view.*
import kotlinx.android.synthetic.main.popup_action_menu.view.* import kotlinx.android.synthetic.main.popup_action_menu.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
@ -35,6 +36,9 @@ class TextActionMenu(context: Context, callBack: CallBack) :
private fun initRecyclerView() = with(contentView) { private fun initRecyclerView() = with(contentView) {
val adapter = Adapter(context) val adapter = Adapter(context)
recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
recycler_view.addItemDecoration(
DividerItemDecoration(context, DividerItemDecoration.HORIZONTAL)
)
recycler_view.adapter = adapter recycler_view.adapter = adapter
val menu = MenuBuilder(context) val menu = MenuBuilder(context)
SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) SupportMenuInflater(context).inflate(R.menu.content_select_action, menu)

@ -5,11 +5,11 @@ import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import kotlinx.android.synthetic.main.item_text.view.* import kotlinx.android.synthetic.main.item_fillet_text.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class BookAdapter(context: Context, val callBack: CallBack) : class BookAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<Book>(context, R.layout.item_text) { SimpleRecyclerAdapter<Book>(context, R.layout.item_fillet_text) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) {
with(holder.itemView) { with(holder.itemView) {

@ -6,7 +6,7 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchKeyword import io.legado.app.data.entities.SearchKeyword
import io.legado.app.ui.widget.anima.explosion_field.ExplosionField import io.legado.app.ui.widget.anima.explosion_field.ExplosionField
import kotlinx.android.synthetic.main.item_text.view.* import kotlinx.android.synthetic.main.item_fillet_text.view.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -15,7 +15,7 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick
class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
SimpleRecyclerAdapter<SearchKeyword>(activity, R.layout.item_text) { SimpleRecyclerAdapter<SearchKeyword>(activity, R.layout.item_fillet_text) {
private val explosionField = ExplosionField.attach2Window(activity) private val explosionField = ExplosionField.attach2Window(activity)

@ -14,8 +14,8 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.ACache import io.legado.app.utils.ACache
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_fillet_text.view.*
import kotlinx.android.synthetic.main.item_find_book.view.* import kotlinx.android.synthetic.main.item_find_book.view.*
import kotlinx.android.synthetic.main.item_text.view.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
@ -46,7 +46,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
gl_child.removeAllViews() gl_child.removeAllViews()
kindList.map { kind -> kindList.map { kind ->
val tv = LayoutInflater.from(context) val tv = LayoutInflater.from(context)
.inflate(R.layout.item_text, gl_child, false) .inflate(R.layout.item_fillet_text, gl_child, false)
gl_child.addView(tv) gl_child.addView(tv)
tv.text_view.text = kind.title tv.text_view.text = kind.title
tv.text_view.onClick { tv.text_view.onClick {

@ -10,7 +10,7 @@ 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.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import kotlinx.android.synthetic.main.item_text.view.* import kotlinx.android.synthetic.main.item_fillet_text.view.*
import kotlinx.android.synthetic.main.popup_keyboard_tool.view.* import kotlinx.android.synthetic.main.popup_keyboard_tool.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
@ -40,7 +40,7 @@ class KeyboardToolPop(
} }
inner class Adapter(context: Context) : inner class Adapter(context: Context) :
SimpleRecyclerAdapter<String>(context, R.layout.item_text) { SimpleRecyclerAdapter<String>(context, R.layout.item_fillet_text) {
override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) {
with(holder.itemView) { with(holder.itemView) {

@ -11,7 +11,7 @@ import io.legado.app.R
class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) {
init { init {
widgetLayoutResource = R.layout.item_text widgetLayoutResource = R.layout.item_fillet_text
} }
override fun onBindViewHolder(holder: PreferenceViewHolder?) { override fun onBindViewHolder(holder: PreferenceViewHolder?) {

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="@drawable/selector_fillet_btn_bg"
android:ellipsize="end"
android:gravity="center"
android:padding="5dp"
android:maxLines="1"
android:textColor="@color/tv_text_default"
android:textSize="14sp"
tools:ignore="UnusedAttribute" />

@ -4,8 +4,7 @@
android:id="@+id/text_view" android:id="@+id/text_view"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="3dp" android:background="?attr/selectableItemBackground"
android:background="@drawable/selector_fillet_btn_bg"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center" android:gravity="center"
android:padding="5dp" android:padding="5dp"

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto" <menu xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android">
<item <item
android:id="@+id/menu_replace" android:id="@+id/menu_replace"
android:title="@string/replace" android:title="@string/replace" />
app:showAsAction="always" />
<item
android:id="@+id/menu_copy"
android:title="@android:string/copy" />
</menu> </menu>
Loading…
Cancel
Save