|
@@ -19,6 +19,7 @@ import androidx.lifecycle.LifecycleRegistry
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
|
import androidx.lifecycle.repeatOnLifecycle
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper
|
|
import androidx.recyclerview.widget.ItemTouchHelper
|
|
|
|
|
+import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
import io.legado.app.R
|
|
import io.legado.app.R
|
|
|
import io.legado.app.base.VMBaseActivity
|
|
import io.legado.app.base.VMBaseActivity
|
|
@@ -49,6 +50,7 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
|
|
|
import io.legado.app.ui.widget.recycler.ItemTouchCallback
|
|
import io.legado.app.ui.widget.recycler.ItemTouchCallback
|
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider
|
|
|
import io.legado.app.utils.ACache
|
|
import io.legado.app.utils.ACache
|
|
|
|
|
+import io.legado.app.utils.NetworkUtils
|
|
|
import io.legado.app.utils.applyTint
|
|
import io.legado.app.utils.applyTint
|
|
|
import io.legado.app.utils.cnCompare
|
|
import io.legado.app.utils.cnCompare
|
|
|
import io.legado.app.utils.dpToPx
|
|
import io.legado.app.utils.dpToPx
|
|
@@ -103,6 +105,11 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|
|
override var sortAscending = true
|
|
override var sortAscending = true
|
|
|
private set
|
|
private set
|
|
|
private var snackBar: Snackbar? = null
|
|
private var snackBar: Snackbar? = null
|
|
|
|
|
+ private var showDuplicationSource = false
|
|
|
|
|
+ private val bookSourceDecoration by lazy {
|
|
|
|
|
+ BookSourceDecoration(adapter)
|
|
|
|
|
+ }
|
|
|
|
|
+ private val hostMap = hashMapOf<String, String>()
|
|
|
private val qrResult = registerForActivityResult(QrCodeResult()) {
|
|
private val qrResult = registerForActivityResult(QrCodeResult()) {
|
|
|
it ?: return@registerForActivityResult
|
|
it ?: return@registerForActivityResult
|
|
|
showDialogFragment(ImportBookSourceDialog(it))
|
|
showDialogFragment(ImportBookSourceDialog(it))
|
|
@@ -265,6 +272,11 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|
|
searchView.setQuery(getString(R.string.disabled_explore), true)
|
|
searchView.setQuery(getString(R.string.disabled_explore), true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ R.id.menu_show_same_source -> {
|
|
|
|
|
+ item.isChecked = !item.isChecked
|
|
|
|
|
+ toggleDuplicationSourceView(item.isChecked)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
R.id.menu_help -> showHelp("SourceMBookHelp")
|
|
R.id.menu_help -> showHelp("SourceMBookHelp")
|
|
|
}
|
|
}
|
|
|
if (item.groupId == R.id.source_group) {
|
|
if (item.groupId == R.id.source_group) {
|
|
@@ -335,7 +347,12 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|
|
appDb.bookSourceDao.flowSearch(searchKey)
|
|
appDb.bookSourceDao.flowSearch(searchKey)
|
|
|
}
|
|
}
|
|
|
}.map { data ->
|
|
}.map { data ->
|
|
|
- if (sortAscending) {
|
|
|
|
|
|
|
+ hostMap.clear()
|
|
|
|
|
+ if (showDuplicationSource) {
|
|
|
|
|
+ data.sortedWith(
|
|
|
|
|
+ compareBy<BookSourcePart> { getSourceHost(it.bookSourceUrl) == "#" }
|
|
|
|
|
+ .thenBy { getSourceHost(it.bookSourceUrl) })
|
|
|
|
|
+ } else if (sortAscending) {
|
|
|
when (sort) {
|
|
when (sort) {
|
|
|
BookSourceSort.Weight -> data.sortedBy { it.weight }
|
|
BookSourceSort.Weight -> data.sortedBy { it.weight }
|
|
|
BookSourceSort.Name -> data.sortedWith { o1, o2 ->
|
|
BookSourceSort.Name -> data.sortedWith { o1, o2 ->
|
|
@@ -383,7 +400,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|
|
AppLog.put("书源界面更新书源出错", it)
|
|
AppLog.put("书源界面更新书源出错", it)
|
|
|
}.flowOn(IO).conflate().collect { data ->
|
|
}.flowOn(IO).conflate().collect { data ->
|
|
|
adapter.setItems(data, adapter.diffItemCallback, !Debug.isChecking)
|
|
adapter.setItems(data, adapter.diffItemCallback, !Debug.isChecking)
|
|
|
- itemTouchCallback.isCanDrag = sort == BookSourceSort.Default
|
|
|
|
|
|
|
+ itemTouchCallback.isCanDrag =
|
|
|
|
|
+ sort == BookSourceSort.Default && !showDuplicationSource
|
|
|
delay(500)
|
|
delay(500)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -667,6 +685,21 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private fun toggleDuplicationSourceView(enable: Boolean) {
|
|
|
|
|
+ showDuplicationSource = enable
|
|
|
|
|
+ adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
|
|
|
|
+ override fun onChanged() {
|
|
|
|
|
+ if (enable) {
|
|
|
|
|
+ binding.recyclerView.addItemDecoration(bookSourceDecoration)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ binding.recyclerView.removeItemDecoration(bookSourceDecoration)
|
|
|
|
|
+ }
|
|
|
|
|
+ adapter.unregisterAdapterDataObserver(this)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ upBookSource(searchView.query?.toString())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 保持亮屏
|
|
* 保持亮屏
|
|
|
*/
|
|
*/
|
|
@@ -686,6 +719,12 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|
|
.upCountView(adapter.selection.size, adapter.itemCount)
|
|
.upCountView(adapter.selection.size, adapter.itemCount)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ override fun getSourceHost(origin: String): String {
|
|
|
|
|
+ return hostMap.getOrPut(origin) {
|
|
|
|
|
+ NetworkUtils.getSubDomainOrNull(origin) ?: "#"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
override fun onQueryTextChange(newText: String?): Boolean {
|
|
override fun onQueryTextChange(newText: String?): Boolean {
|
|
|
newText?.let {
|
|
newText?.let {
|
|
|
upBookSource(it)
|
|
upBookSource(it)
|