pull/32/head
kunfei 5 years ago
parent 58f664f3f4
commit aa4d7616ed
  1. 1
      app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt
  2. 1
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  3. 17
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditDialog.kt
  4. 6
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditViewModel.kt
  5. 4
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  6. 35
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt
  7. 3
      app/src/main/res/layout/activity_replace_rule.xml
  8. 86
      app/src/main/res/layout/item_relace_rule.xml
  9. 34
      app/src/main/res/layout/item_replace_rule.xml

@ -11,7 +11,6 @@ import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ATH
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {

@ -14,7 +14,6 @@ import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick

@ -18,6 +18,20 @@ import kotlinx.android.synthetic.main.dialog_replace_edit.*
class ReplaceEditDialog : DialogFragment(),
Toolbar.OnMenuItemClickListener {
companion object {
fun newInstance(id: Long? = null): ReplaceEditDialog {
val dialog = ReplaceEditDialog()
id?.let {
val bundle = Bundle()
bundle.putLong("data", id)
dialog.arguments = bundle
}
return dialog
}
}
private lateinit var viewModel: ReplaceEditViewModel
override fun onStart() {
@ -44,6 +58,9 @@ class ReplaceEditDialog : DialogFragment(),
viewModel.replaceRuleData.observe(this, Observer {
upReplaceView(it)
})
arguments?.let {
viewModel.initData(it)
}
}
override fun onMenuItemClick(item: MenuItem?): Boolean {

@ -1,7 +1,7 @@
package io.legado.app.ui.replacerule
import android.app.Application
import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel
@ -11,10 +11,10 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application
val replaceRuleData = MutableLiveData<ReplaceRule>()
fun initData(intent: Intent) {
fun initData(bundle: Bundle) {
execute {
replaceRuleData.value ?: let {
val id = intent.getLongExtra("data", -1)
val id = bundle.getLong("data")
if (id > 0) {
App.db.replaceRuleDao().findById(id)?.let {
replaceRuleData.postValue(it)

@ -91,6 +91,8 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
}
override fun edit(rule: ReplaceRule) {
ReplaceEditDialog
.newInstance(rule.id)
.show(supportFragmentManager, "editReplace")
}
}

@ -2,16 +2,17 @@ package io.legado.app.ui.replacerule
import android.content.Context
import android.view.LayoutInflater
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import android.widget.PopupMenu
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.ItemTouchCallback
import kotlinx.android.synthetic.main.item_relace_rule.view.*
import kotlinx.android.synthetic.main.item_replace_rule.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
@ -45,7 +46,13 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_relace_rule, parent, false))
return MyViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.item_replace_rule,
parent,
false
)
)
}
override fun onBindViewHolder(holder: MyViewHolder, pos: Int) {
@ -53,14 +60,26 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
}
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(rule: ReplaceRule, listener: CallBack?) = with(itemView) {
tv_name.text = rule.name
fun bind(rule: ReplaceRule, callBack: CallBack) = with(itemView) {
cb_name.text = rule.name
swt_enabled.isChecked = rule.isEnabled
iv_delete.isGone = true
iv_edit.isGone = true
swt_enabled.onClick {
rule.isEnabled = swt_enabled.isChecked
listener?.update(rule)
callBack.update(rule)
}
iv_menu_more.onClick {
val popupMenu = PopupMenu(context, it)
popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit)
popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete)
popupMenu.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.menu_edit -> callBack.edit(rule)
R.id.menu_del -> callBack.delete(rule)
}
true
}
popupMenu.show()
}
}
}

@ -17,9 +17,6 @@
android:id="@+id/rv_replace_rule"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar"

@ -1,86 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/edit"
android:src="@drawable/ic_edit"
android:visibility="gone"
app:tint="@color/tv_text_default"
app:layout_constraintEnd_toStartOf="@id/iv_delete"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/delete"
android:src="@drawable/ic_clear_all"
android:visibility="gone"
app:tint="@color/tv_text_default"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatCheckBox
android:id="@+id/cb_selected"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_name"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textSize="16sp"
android:text="Item Name"
android:textColor="@color/tv_text_default"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/cb_selected"
app:layout_constraintEnd_toStartOf="@id/swt_enabled" />
<Switch
android:id="@+id/swt_enabled"
android:name="@string/enable"
android:text=""
android:paddingStart="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_name"
app:layout_constraintHorizontal_bias="1" />
<!--
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/divider"
app:layout_constraintBottom_toBottomOf="parent"/>
-->
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:padding="8dp">
<androidx.appcompat.widget.AppCompatCheckBox
android:id="@+id/cb_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:ignore="RtlSymmetry" />
<Switch
android:id="@+id/swt_enabled"
android:name="@string/enable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
tools:ignore="RtlSymmetry" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_menu_more"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_margin="6dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_more_vert"
tools:ignore="RtlHardcoded" />
</LinearLayout>
Loading…
Cancel
Save