From f409d502f77935668df967e3a589848884da4cef Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Sep 2019 23:03:05 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/ReplaceRuleDao.kt | 9 +++----- .../app/ui/booksource/BookSourceActivity.kt | 11 +++++----- .../app/ui/replacerule/ReplaceRuleActivity.kt | 4 ++++ .../app/ui/replacerule/ReplaceRuleAdapter.kt | 8 +++++-- .../ui/replacerule/ReplaceRuleViewModel.kt | 7 ++++++ app/src/main/res/layout/item_book_source.xml | 22 +++++++++---------- app/src/main/res/layout/item_replace_rule.xml | 19 ++++++++++++---- 7 files changed, 52 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt index 6c0031aa4..3b75e9555 100644 --- a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt @@ -15,6 +15,9 @@ interface ReplaceRuleDao { @Query("SELECT id FROM replace_rules ORDER BY sortOrder ASC") fun observeAllIds(): LiveData> + @get:Query("SELECT MIN(sortOrder) FROM replace_rules") + val minOrder: Int + @get:Query("SELECT MAX(sortOrder) FROM replace_rules") val maxOrder: Int @@ -60,15 +63,9 @@ interface ReplaceRuleDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg replaceRule: ReplaceRule): List - @Update - fun update(replaceRules: ReplaceRule) - @Update fun update(vararg replaceRules: ReplaceRule) - @Delete - fun delete(replaceRules: ReplaceRule) - @Delete fun delete(vararg replaceRules: ReplaceRule) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt index 73646f3ff..b98a8bf2f 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt @@ -6,6 +6,7 @@ import android.view.Menu import android.view.MenuItem import android.view.SubMenu import androidx.appcompat.widget.SearchView +import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.paging.LivePagedListBuilder @@ -98,11 +99,11 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.addItemDecoration( - DividerItemDecoration( - this, - LinearLayoutManager.VERTICAL - ) - ) + DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { + ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { + this.setDrawable(it) + } + }) adapter = BookSourceAdapter(this) recycler_view.adapter = adapter val itemTouchCallback = ItemTouchCallback() diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 3242e1e2b..5c0796169 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -94,4 +94,8 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi .newInstance(rule.id) .show(supportFragmentManager, "editReplace") } + + override fun toTop(rule: ReplaceRule) { + viewModel.toTop(rule) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt index 01e14e1a1..55b9d6c3c 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt @@ -70,13 +70,16 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : rule.isEnabled = swt_enabled.isChecked callBack.update(rule) } + iv_edit.onClick { + callBack.edit(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_top, Menu.NONE, R.string.to_top) 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_top -> callBack.toTop(rule) R.id.menu_del -> callBack.delete(rule) } true @@ -90,5 +93,6 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : fun update(rule: ReplaceRule) fun delete(rule: ReplaceRule) fun edit(rule: ReplaceRule) + fun toTop(rule: ReplaceRule) } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index af6648bd5..85f7cf430 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -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) { execute { val sources = App.db.replaceRuleDao().noGroup diff --git a/app/src/main/res/layout/item_book_source.xml b/app/src/main/res/layout/item_book_source.xml index fb6263705..a95216088 100644 --- a/app/src/main/res/layout/item_book_source.xml +++ b/app/src/main/res/layout/item_book_source.xml @@ -20,34 +20,34 @@ - - diff --git a/app/src/main/res/layout/item_replace_rule.xml b/app/src/main/res/layout/item_replace_rule.xml index 7b14d9375..ef3f211c0 100644 --- a/app/src/main/res/layout/item_replace_rule.xml +++ b/app/src/main/res/layout/item_replace_rule.xml @@ -14,7 +14,7 @@ android:layout_weight="1" tools:ignore="RtlSymmetry" /> - + +