Merge pull request #2135 from 821938089/opt-source-manager

优化书源管理和校验
pull/2143/head
kunfei 2 years ago committed by GitHub
commit 7564e17583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 27
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  3. 5
      app/src/main/res/menu/book_source_sel.xml
  4. 1
      app/src/main/res/values-es-rES/strings.xml
  5. 1
      app/src/main/res/values-ja-rJP/strings.xml
  6. 1
      app/src/main/res/values-pt-rBR/strings.xml
  7. 1
      app/src/main/res/values-zh-rHK/strings.xml
  8. 1
      app/src/main/res/values-zh-rTW/strings.xml
  9. 1
      app/src/main/res/values-zh/strings.xml
  10. 1
      app/src/main/res/values/strings.xml

@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
import android.view.WindowManager
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
@ -363,6 +364,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
R.id.menu_share_source -> viewModel.saveToFile(adapter.selection) { R.id.menu_share_source -> viewModel.saveToFile(adapter.selection) {
share(it) share(it)
} }
R.id.menu_check_selected_interval -> adapter.checkSelectedInterval()
} }
return true return true
} }
@ -376,6 +378,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
customView { alertBinding.root } customView { alertBinding.root }
okButton { okButton {
keepScreenOn(true)
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
CheckSource.keyword = it CheckSource.keyword = it
@ -493,6 +496,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
} }
observeEvent<Int>(EventBus.CHECK_SOURCE_DONE) { observeEvent<Int>(EventBus.CHECK_SOURCE_DONE) {
keepScreenOn(false)
snackBar?.dismiss() snackBar?.dismiss()
snackBar = null snackBar = null
groups.map { group -> groups.map { group ->
@ -524,6 +528,19 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
} }
/**
* 保持亮屏
*/
fun keepScreenOn(on: Boolean) {
val isScreenOn = (window.attributes.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0
if (on == isScreenOn) return
if (on) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
override fun upCountView() { override fun upCountView() {
binding.selectActionBar binding.selectActionBar
.upCountView(adapter.selection.size, adapter.itemCount) .upCountView(adapter.selection.size, adapter.itemCount)

@ -24,6 +24,7 @@ import io.legado.app.utils.ColorUtils
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.visible import io.legado.app.utils.visible
import java.util.*
class BookSourceAdapter(context: Context, val callBack: CallBack) : class BookSourceAdapter(context: Context, val callBack: CallBack) :
@ -31,6 +32,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
ItemTouchCallback.Callback { ItemTouchCallback.Callback {
private val selected = linkedSetOf<BookSource>() private val selected = linkedSetOf<BookSource>()
private val selectedPosition = linkedSetOf<Int>()
val selection: List<BookSource> val selection: List<BookSource>
get() { get() {
@ -141,8 +143,10 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
if (view.isPressed) { if (view.isPressed) {
if (checked) { if (checked) {
selected.add(it) selected.add(it)
selectedPosition.add(holder.layoutPosition)
} else { } else {
selected.remove(it) selected.remove(it)
selectedPosition.remove(holder.layoutPosition)
} }
callBack.upCountView() callBack.upCountView()
} }
@ -215,25 +219,42 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} }
fun selectAll() { fun selectAll() {
getItems().forEach { getItems().forEachIndexed { index, it ->
selected.add(it) selected.add(it)
selectedPosition.add(index)
} }
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView() callBack.upCountView()
} }
fun revertSelection() { fun revertSelection() {
getItems().forEach { getItems().forEachIndexed { index, it ->
if (selected.contains(it)) { if (selected.contains(it)) {
selected.remove(it) selected.remove(it)
selectedPosition.remove(index)
} else { } else {
selected.add(it) selected.add(it)
selectedPosition.add(index)
} }
} }
notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null)))
callBack.upCountView() 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 { override fun swap(srcPosition: Int, targetPosition: Int): Boolean {
val srcItem = getItem(srcPosition) val srcItem = getItem(srcPosition)
val targetItem = getItem(targetPosition) val targetItem = getItem(targetPosition)
@ -275,8 +296,10 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
getItem(position)?.let { getItem(position)?.let {
if (isSelected) { if (isSelected) {
selected.add(it) selected.add(it)
selectedPosition.add(position)
} else { } else {
selected.remove(it) selected.remove(it)
selectedPosition.remove(position)
} }
notifyItemChanged(position, bundleOf(Pair("selected", null))) notifyItemChanged(position, bundleOf(Pair("selected", null)))
callBack.upCountView() callBack.upCountView()

@ -58,4 +58,9 @@
android:title="@string/check_select_source" android:title="@string/check_select_source"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_check_selected_interval"
android:title="@string/check_selected_interval"
app:showAsAction="never" />
</menu> </menu>

@ -1007,4 +1007,5 @@
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string> <string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string> <string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
<string name="example">Ejemplo</string> <string name="example">Ejemplo</string>
<string name="check_selected_interval">选中所选区间</string>
</resources> </resources>

@ -1010,4 +1010,5 @@
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string> <string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string> <string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
<string name="example"></string> <string name="example"></string>
<string name="check_selected_interval">选中所选区间</string>
</resources> </resources>

@ -1010,4 +1010,5 @@
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string> <string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string> <string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
<string name="example">Exemplo</string> <string name="example">Exemplo</string>
<string name="check_selected_interval">选中所选区间</string>
</resources> </resources>

@ -1007,4 +1007,5 @@
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string> <string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string> <string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
<string name="example">示例</string> <string name="example">示例</string>
<string name="check_selected_interval">选中所选区间</string>
</resources> </resources>

@ -1009,4 +1009,5 @@
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string> <string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string> <string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
<string name="example">示例</string> <string name="example">示例</string>
<string name="check_selected_interval">选中所选区间</string>
</resources> </resources>

@ -1009,4 +1009,5 @@
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string> <string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string> <string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
<string name="example">示例</string> <string name="example">示例</string>
<string name="check_selected_interval">选中所选区间</string>
</resources> </resources>

@ -1010,4 +1010,5 @@
<string name="page_touch_slop_title">滑动翻页阈值</string> <string name="page_touch_slop_title">滑动翻页阈值</string>
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string> <string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string> <string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
<string name="check_selected_interval">选中所选区间</string>
</resources> </resources>

Loading…
Cancel
Save