From c14008543770a3bf56a7995f1d54e6353936f51f Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Sat, 6 Aug 2022 12:59:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceActivity.kt | 17 ++++++++++++ .../book/source/manage/BookSourceAdapter.kt | 27 +++++++++++++++++-- app/src/main/res/menu/book_source_sel.xml | 5 ++++ app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 54 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index bd9cd1cf9..37aa77e84 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.SubMenu +import android.view.WindowManager import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.PopupMenu @@ -363,6 +364,7 @@ class BookSourceActivity : VMBaseActivity viewModel.saveToFile(adapter.selection) { share(it) } + R.id.menu_check_selected_interval -> adapter.checkSelectedInterval() } return true } @@ -376,6 +378,7 @@ class BookSourceActivity : VMBaseActivity(EventBus.CHECK_SOURCE_DONE) { + keepScreenOn(false) snackBar?.dismiss() snackBar = null groups.map { group -> @@ -524,6 +528,19 @@ class BookSourceActivity : VMBaseActivity() + private val selectedPosition = linkedSetOf() val selection: List get() { @@ -141,8 +143,10 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : if (view.isPressed) { if (checked) { selected.add(it) + selectedPosition.add(holder.layoutPosition) } else { selected.remove(it) + selectedPosition.remove(holder.layoutPosition) } callBack.upCountView() } @@ -215,25 +219,42 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } fun selectAll() { - getItems().forEach { + getItems().forEachIndexed { index, it -> selected.add(it) + selectedPosition.add(index) } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) callBack.upCountView() } fun revertSelection() { - getItems().forEach { + getItems().forEachIndexed { index, it -> if (selected.contains(it)) { selected.remove(it) + selectedPosition.remove(index) } else { selected.add(it) + selectedPosition.add(index) } } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) callBack.upCountView() } + fun checkSelectedInterval() { + val minPosition = Collections.min(selectedPosition) + val maxPosition = Collections.max(selectedPosition) + val itemCount = maxPosition - minPosition + 1 + for (i in minPosition..maxPosition) { + getItem(i)?.let { + selected.add(it) + selectedPosition.add(i) + } + } + notifyItemRangeChanged(minPosition, itemCount, bundleOf(Pair("selected", null))) + callBack.upCountView() + } + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) @@ -275,8 +296,10 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : getItem(position)?.let { if (isSelected) { selected.add(it) + selectedPosition.add(position) } else { selected.remove(it) + selectedPosition.remove(position) } notifyItemChanged(position, bundleOf(Pair("selected", null))) callBack.upCountView() diff --git a/app/src/main/res/menu/book_source_sel.xml b/app/src/main/res/menu/book_source_sel.xml index f73160d90..3fd99868c 100644 --- a/app/src/main/res/menu/book_source_sel.xml +++ b/app/src/main/res/menu/book_source_sel.xml @@ -58,4 +58,9 @@ android:title="@string/check_select_source" app:showAsAction="never" /> + + diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 1b8b20c70..2a7ff5263 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1007,4 +1007,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) Ejemplo + 选中所选区间 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 3ab62635c..67ffe8fd9 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1010,4 +1010,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) + 选中所选区间 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 7c11db47e..60d2886bd 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1010,4 +1010,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) Exemplo + 选中所选区间 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 99a15125e..34ba2a46a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1007,4 +1007,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) 示例 + 选中所选区间 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 928a00828..7b8de3a1b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1009,4 +1009,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) 示例 + 选中所选区间 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index e395e543c..de1f51ece 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1009,4 +1009,5 @@ 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) 示例 + 选中所选区间 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3b1824116..18656565b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1010,4 +1010,5 @@ 滑动翻页阈值 滑动翻页阈值(0 = 系统默认值) 滑动多长距离才会触发滑动翻页(系统默认值 %s px) + 选中所选区间