mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
@@ -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<ActivityBookSourceBinding, BookSourceV
|
||||
R.id.menu_share_source -> viewModel.saveToFile(adapter.selection) {
|
||||
share(it)
|
||||
}
|
||||
R.id.menu_check_selected_interval -> adapter.checkSelectedInterval()
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -376,6 +378,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
okButton {
|
||||
keepScreenOn(true)
|
||||
alertBinding.editView.text?.toString()?.let {
|
||||
if (it.isNotEmpty()) {
|
||||
CheckSource.keyword = it
|
||||
@@ -493,6 +496,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
}
|
||||
}
|
||||
observeEvent<Int>(EventBus.CHECK_SOURCE_DONE) {
|
||||
keepScreenOn(false)
|
||||
snackBar?.dismiss()
|
||||
snackBar = null
|
||||
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() {
|
||||
binding.selectActionBar
|
||||
.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.startActivity
|
||||
import io.legado.app.utils.visible
|
||||
import java.util.*
|
||||
|
||||
|
||||
class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
||||
@@ -31,6 +32,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
|
||||
ItemTouchCallback.Callback {
|
||||
|
||||
private val selected = linkedSetOf<BookSource>()
|
||||
private val selectedPosition = linkedSetOf<Int>()
|
||||
|
||||
val selection: List<BookSource>
|
||||
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()
|
||||
|
||||
@@ -58,4 +58,9 @@
|
||||
android:title="@string/check_select_source"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_check_selected_interval"
|
||||
android:title="@string/check_selected_interval"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
|
||||
@@ -1007,4 +1007,5 @@
|
||||
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
|
||||
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
|
||||
<string name="example">Ejemplo</string>
|
||||
<string name="check_selected_interval">选中所选区间</string>
|
||||
</resources>
|
||||
|
||||
@@ -1010,4 +1010,5 @@
|
||||
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
|
||||
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
|
||||
<string name="example">例</string>
|
||||
<string name="check_selected_interval">选中所选区间</string>
|
||||
</resources>
|
||||
|
||||
@@ -1010,4 +1010,5 @@
|
||||
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
|
||||
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
|
||||
<string name="example">Exemplo</string>
|
||||
<string name="check_selected_interval">选中所选区间</string>
|
||||
</resources>
|
||||
|
||||
@@ -1007,4 +1007,5 @@
|
||||
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
|
||||
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
|
||||
<string name="example">示例</string>
|
||||
<string name="check_selected_interval">选中所选区间</string>
|
||||
</resources>
|
||||
|
||||
@@ -1009,4 +1009,5 @@
|
||||
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
|
||||
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
|
||||
<string name="example">示例</string>
|
||||
<string name="check_selected_interval">选中所选区间</string>
|
||||
</resources>
|
||||
|
||||
@@ -1009,4 +1009,5 @@
|
||||
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
|
||||
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
|
||||
<string name="example">示例</string>
|
||||
<string name="check_selected_interval">选中所选区间</string>
|
||||
</resources>
|
||||
|
||||
@@ -1010,4 +1010,5 @@
|
||||
<string name="page_touch_slop_title">滑动翻页阈值</string>
|
||||
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
|
||||
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
|
||||
<string name="check_selected_interval">选中所选区间</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user