pull/32/head
kunfei 5 years ago
parent 693522f2df
commit f409d502f7
  1. 9
      app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt
  2. 11
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  3. 4
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  4. 8
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt
  5. 7
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt
  6. 22
      app/src/main/res/layout/item_book_source.xml
  7. 19
      app/src/main/res/layout/item_replace_rule.xml

@ -15,6 +15,9 @@ interface ReplaceRuleDao {
@Query("SELECT id FROM replace_rules ORDER BY sortOrder ASC") @Query("SELECT id FROM replace_rules ORDER BY sortOrder ASC")
fun observeAllIds(): LiveData<List<Long>> fun observeAllIds(): LiveData<List<Long>>
@get:Query("SELECT MIN(sortOrder) FROM replace_rules")
val minOrder: Int
@get:Query("SELECT MAX(sortOrder) FROM replace_rules") @get:Query("SELECT MAX(sortOrder) FROM replace_rules")
val maxOrder: Int val maxOrder: Int
@ -60,15 +63,9 @@ interface ReplaceRuleDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg replaceRule: ReplaceRule): List<Long> fun insert(vararg replaceRule: ReplaceRule): List<Long>
@Update
fun update(replaceRules: ReplaceRule)
@Update @Update
fun update(vararg replaceRules: ReplaceRule) fun update(vararg replaceRules: ReplaceRule)
@Delete
fun delete(replaceRules: ReplaceRule)
@Delete @Delete
fun delete(vararg replaceRules: ReplaceRule) fun delete(vararg replaceRules: ReplaceRule)
} }

@ -6,6 +6,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder import androidx.paging.LivePagedListBuilder
@ -98,11 +99,11 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(recycler_view)
recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.addItemDecoration( recycler_view.addItemDecoration(
DividerItemDecoration( DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply {
this, ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let {
LinearLayoutManager.VERTICAL this.setDrawable(it)
) }
) })
adapter = BookSourceAdapter(this) adapter = BookSourceAdapter(this)
recycler_view.adapter = adapter recycler_view.adapter = adapter
val itemTouchCallback = ItemTouchCallback() val itemTouchCallback = ItemTouchCallback()

@ -94,4 +94,8 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
.newInstance(rule.id) .newInstance(rule.id)
.show(supportFragmentManager, "editReplace") .show(supportFragmentManager, "editReplace")
} }
override fun toTop(rule: ReplaceRule) {
viewModel.toTop(rule)
}
} }

@ -70,13 +70,16 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
rule.isEnabled = swt_enabled.isChecked rule.isEnabled = swt_enabled.isChecked
callBack.update(rule) callBack.update(rule)
} }
iv_edit.onClick {
callBack.edit(rule)
}
iv_menu_more.onClick { iv_menu_more.onClick {
val popupMenu = PopupMenu(context, it) 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_top, Menu.NONE, R.string.to_top)
popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete) popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete)
popupMenu.setOnMenuItemClickListener { item -> popupMenu.setOnMenuItemClickListener { item ->
when (item.itemId) { when (item.itemId) {
R.id.menu_edit -> callBack.edit(rule) R.id.menu_top -> callBack.toTop(rule)
R.id.menu_del -> callBack.delete(rule) R.id.menu_del -> callBack.delete(rule)
} }
true true
@ -90,5 +93,6 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
fun update(rule: ReplaceRule) fun update(rule: ReplaceRule)
fun delete(rule: ReplaceRule) fun delete(rule: ReplaceRule)
fun edit(rule: ReplaceRule) fun edit(rule: ReplaceRule)
fun toTop(rule: ReplaceRule)
} }
} }

@ -22,6 +22,13 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
} }
} }
fun toTop(rule: ReplaceRule) {
execute {
rule.order = App.db.replaceRuleDao().minOrder - 1
App.db.replaceRuleDao().update(rule)
}
}
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.replaceRuleDao().noGroup val sources = App.db.replaceRuleDao().noGroup

@ -20,34 +20,34 @@
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit_source" android:id="@+id/iv_edit_source"
android:layout_width="40dp" android:layout_width="36dp"
android:layout_height="40dp" android:layout_height="36dp"
android:layout_gravity="center" android:layout_gravity="center"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/edit" android:contentDescription="@string/edit"
android:padding="8dp" android:padding="6dp"
android:src="@drawable/ic_edit" android:src="@drawable/ic_edit"
app:tint="@color/tv_text_default" /> app:tint="@color/tv_text_default" />
<ImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_top_source" android:id="@+id/iv_top_source"
android:layout_width="40dp" android:layout_width="36dp"
android:layout_height="40dp" android:layout_height="36dp"
android:layout_gravity="center" android:layout_gravity="center"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/to_top" android:contentDescription="@string/to_top"
android:padding="8dp" android:padding="6dp"
android:src="@drawable/ic_top_source" android:src="@drawable/ic_top_source"
app:tint="@color/tv_text_default" /> app:tint="@color/tv_text_default" />
<ImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_del_source" android:id="@+id/iv_del_source"
android:layout_width="40dp" android:layout_width="36dp"
android:layout_height="40dp" android:layout_height="36dp"
android:layout_gravity="center" android:layout_gravity="center"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/delete" android:contentDescription="@string/delete"
android:padding="8dp" android:padding="6dp"
android:src="@drawable/ic_clear_all" android:src="@drawable/ic_clear_all"
app:tint="@color/tv_text_default" /> app:tint="@color/tv_text_default" />

@ -14,7 +14,7 @@
android:layout_weight="1" android:layout_weight="1"
tools:ignore="RtlSymmetry" /> tools:ignore="RtlSymmetry" />
<Switch <io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/swt_enabled" android:id="@+id/swt_enabled"
android:name="@string/enable" android:name="@string/enable"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -23,11 +23,22 @@
android:layout_marginRight="6dp" android:layout_marginRight="6dp"
tools:ignore="RtlSymmetry" /> tools:ignore="RtlSymmetry" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/edit"
android:padding="6dp"
android:src="@drawable/ic_edit"
android:tint="@color/tv_text_default" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_menu_more" android:id="@+id/iv_menu_more"
android:layout_width="24dp" android:layout_width="36dp"
android:layout_height="24dp" android:layout_height="36dp"
android:layout_margin="6dp" android:padding="6dp"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_more_vert" android:src="@drawable/ic_more_vert"
android:tint="@color/tv_text_default" android:tint="@color/tv_text_default"

Loading…
Cancel
Save