From a3f324aa527587004aadccf9f6f3502306d26b52 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 11 Feb 2020 20:08:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/replacerule/ReplaceRuleActivity.kt | 83 ++++++++++++++----- .../app/ui/replacerule/ReplaceRuleAdapter.kt | 4 + .../ui/rss/source/manage/RssSourceActivity.kt | 2 - .../app/ui/widget/prefs/IconListPreference.kt | 8 ++ .../main/res/layout/activity_replace_rule.xml | 1 + app/src/main/res/menu/replace_rule.xml | 43 ---------- app/src/main/res/menu/replace_rule_sel.xml | 20 +++++ 7 files changed, 94 insertions(+), 67 deletions(-) create mode 100644 app/src/main/res/menu/replace_rule_sel.xml 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 51b72cb3c..6ab427d12 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 @@ -7,6 +7,7 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.SubMenu +import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.lifecycle.LiveData import androidx.lifecycle.Observer @@ -21,15 +22,13 @@ import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.ItemTouchCallback import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat -import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.cancelButton -import io.legado.app.lib.dialogs.customView -import io.legado.app.lib.dialogs.okButton +import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.replacerule.edit.ReplaceEditDialog +import io.legado.app.ui.widget.SelectActionBar import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_replace_rule.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* @@ -41,6 +40,7 @@ import java.io.FileNotFoundException class ReplaceRuleActivity : VMBaseActivity(R.layout.activity_replace_rule), SearchView.OnQueryTextListener, + PopupMenu.OnMenuItemClickListener, FileChooserDialog.CallBack, ReplaceRuleAdapter.CallBack { override val viewModel: ReplaceRuleViewModel @@ -56,6 +56,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() initSearchView() + initSelectActionView() observeReplaceRuleData() observeGroupData() } @@ -71,24 +72,6 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi return super.onPrepareOptionsMenu(menu) } - override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.menu_add_replace_rule -> - ReplaceEditDialog().show(supportFragmentManager, "replaceNew") - R.id.menu_group_manage -> - GroupManageDialog().show(supportFragmentManager, "groupManage") - R.id.menu_select_all -> adapter.selectAll() - R.id.menu_revert_selection -> adapter.revertSelection() - R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) - R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) - R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) - R.id.menu_import_source_onLine -> showImportDialog() - R.id.menu_import_source_local -> selectFileSys() - R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) - } - return super.onCompatOptionsItemSelected(item) - } - private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) @@ -109,6 +92,34 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi search_view.setOnQueryTextListener(this) } + private fun initSelectActionView() { + select_action_bar.setMainActionText(R.string.delete) + select_action_bar.inflateMenu(R.menu.replace_rule_sel) + select_action_bar.setOnMenuItemClickListener(this) + select_action_bar.setCallBack(object : SelectActionBar.CallBack { + override fun selectAll(selectAll: Boolean) { + if (selectAll) { + adapter.selectAll() + } else { + adapter.revertSelection() + } + } + + override fun revertSelection() { + adapter.revertSelection() + } + + override fun onClickMainAction() { + this@ReplaceRuleActivity + .alert(titleResource = R.string.sure, messageResource = R.string.sure_del) { + okButton { viewModel.delSelection(adapter.getSelection()) } + noButton { } + } + .show().applyTint() + } + }) + } + private fun observeReplaceRuleData(key: String? = null) { replaceRuleLiveData?.removeObservers(this) dataInit = false @@ -126,6 +137,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi adapter.setItems(it, false) diffResult.dispatchUpdatesTo(adapter) dataInit = true + upCountView() }) } @@ -139,6 +151,29 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi }) } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_add_replace_rule -> + ReplaceEditDialog().show(supportFragmentManager, "replaceNew") + R.id.menu_group_manage -> + GroupManageDialog().show(supportFragmentManager, "groupManage") + + R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) + R.id.menu_import_source_onLine -> showImportDialog() + R.id.menu_import_source_local -> selectFileSys() + } + return super.onCompatOptionsItemSelected(item) + } + + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) + R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) + R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) + } + return false + } + private fun upGroupMenu() { groupMenu?.removeGroup(R.id.source_group) groups.map { @@ -259,6 +294,10 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi } } + override fun upCountView() { + select_action_bar.upCountView(adapter.getSelection().size, adapter.getActualItemCount()) + } + override fun update(vararg rule: ReplaceRule) { viewModel.update(*rule) } 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 62b70de40..5368569d3 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 @@ -27,6 +27,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : selected.add(it) } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) + callBack.upCountView() } fun revertSelection() { @@ -38,6 +39,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) + callBack.upCountView() } fun getSelection(): LinkedHashSet { @@ -76,6 +78,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } else { selected.remove(item) } + callBack.upCountView() } iv_menu_more.onClick { val popupMenu = PopupMenu(context, it) @@ -141,5 +144,6 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : fun edit(rule: ReplaceRule) fun toTop(rule: ReplaceRule) fun upOrder() + fun upCountView() } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index d28ef6cef..8759ef1de 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -91,8 +91,6 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { - R.id.menu_select_all -> adapter.selectAll() - R.id.menu_revert_selection -> adapter.revertSelection() R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt index 14b1abb5e..d56790533 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -4,6 +4,7 @@ import android.content.Context import android.graphics.drawable.Drawable import android.util.AttributeSet import android.widget.ImageView +import androidx.fragment.app.DialogFragment import androidx.preference.ListPreference import androidx.preference.PreferenceViewHolder import io.legado.app.R @@ -43,5 +44,12 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference } } + override fun onClick() { + + } + + inner class IconDialog : DialogFragment() { + + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_replace_rule.xml b/app/src/main/res/layout/activity_replace_rule.xml index 32c44cc24..dbcc248a5 100644 --- a/app/src/main/res/layout/activity_replace_rule.xml +++ b/app/src/main/res/layout/activity_replace_rule.xml @@ -11,6 +11,7 @@ android:id="@+id/title_bar" android:layout_width="match_parent" android:layout_height="wrap_content" + app:contentLayout="@layout/view_search" app:title="@string/replace_purify" /> - - - - - - - - - - - - - - - - - - - - + + + + + + + + +