Support search in DownloadsScene

This commit is contained in:
FooIbar committed 2023-08-15 23:03:52 +08:00
1 parent 4594ac592c
commit 01e03ec0f0
16 files changed
+111 -79

No files matched your search

@@ -503,7 +503,7 @@ object DownloadManager : OnSpiderListener {
ensureDownload()
}
fun moveDownload(fromPosition: Int, toPosition: Int): List<DownloadInfo> {
private fun moveDownload(fromPosition: Int, toPosition: Int): List<DownloadInfo> {
val info = allInfoList.removeAt(fromPosition)
allInfoList.add(toPosition, info)
val range = if (fromPosition < toPosition) fromPosition..toPosition else toPosition..fromPosition
@@ -515,12 +515,11 @@ object DownloadManager : OnSpiderListener {
return list
}
fun moveDownload(label: String?, fromPosition: Int, toPosition: Int) =
getInfoListForLabel(label)!!.let {
val absFromPosition = allInfoList.indexOf(it[fromPosition])
val absToPosition = allInfoList.indexOf(it[toPosition])
moveDownload(absFromPosition, absToPosition)
}
fun moveDownload(fromItem: DownloadInfo, toItem: DownloadInfo): List<DownloadInfo> {
val fromPosition = allInfoList.indexOf(fromItem)
val toPosition = allInfoList.indexOf(toItem)
return moveDownload(fromPosition, toPosition)
}
suspend fun resetAllReadingProgress() = coroutineScope {
allInfoList.forEach { info ->
@@ -102,6 +102,7 @@ import com.hippo.ehviewer.ui.tools.CropDefaults
import com.hippo.ehviewer.ui.tools.DialogState
import com.hippo.ehviewer.util.FileUtils
import com.hippo.ehviewer.util.LongList
import com.hippo.ehviewer.util.containsIgnoreCase
import com.hippo.ehviewer.util.sendTo
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.util.lang.launchIO
@@ -116,12 +117,13 @@ import com.hippo.ehviewer.download.DownloadManager as downloadManager
@SuppressLint("RtlHardcoded")
class DownloadsScene :
BaseToolbarScene(),
SearchBarScene(),
DownloadInfoListener,
OnClickFabListener {
/*---------------
Whole life cycle
---------------*/
private var mKeyword: String? = null
private var mLabel: String? = null
private var mList: List<DownloadInfo>? = null
@@ -141,13 +143,16 @@ class DownloadsScene :
private val dialogState = DialogState()
override val fabLayout get() = binding.fabLayout
private fun initLabels() {
context ?: return
val listLabel = downloadManager.labelList
mLabels = ArrayList(listLabel.size + LABEL_OFFSET)
// Add "All" and "Default" label names
mLabels.add(getString(R.string.download_all))
mLabels.add(getString(R.string.default_download_label_name))
mLabels = arrayListOf(
getString(R.string.download_all),
getString(R.string.default_download_label_name),
)
listLabel.forEach {
mLabels.add(it.label)
}
@@ -207,10 +212,14 @@ class DownloadsScene :
else -> DownloadManager.getLabelDownloadInfoList(mLabel)
?: DownloadManager.allInfoList.also { mLabel = null }
}
mList = if (mType != -1) {
list.filter { it.state == mType }
} else {
list
mList = list.filter {
(mType == -1 || it.state == mType) &&
mKeyword?.let { keyword ->
it.galleryInfo.run {
title.containsIgnoreCase(keyword) || titleJpn.containsIgnoreCase(keyword) ||
uploader.containsIgnoreCase(keyword)
}
} ?: true
}
if (mAdapter != null) {
mAdapter!!.notifyDataSetChanged()
@@ -219,12 +228,9 @@ class DownloadsScene :
}
private fun updateTitle() {
setTitle(
getString(
R.string.scene_download_title,
if (mLabel != null) mLabel else getString(R.string.download_all),
),
)
val title = getString(R.string.scene_download_title, mLabel ?: getString(R.string.download_all))
setSearchBarHint(title)
setEditTextHint(getString(R.string.search_bar_hint, title))
}
private fun onInit() {
@@ -325,10 +331,11 @@ class DownloadsScene :
if (fromPosition == toPosition) {
return false
}
val list = when (mLabel) {
null -> DownloadManager.moveDownload(fromPosition, toPosition)
getString(R.string.default_download_label_name) -> DownloadManager.moveDownload(null, fromPosition, toPosition)
else -> DownloadManager.moveDownload(mLabel, fromPosition, toPosition)
val fromItem = mList!![fromPosition]
val toItem = mList!![toPosition]
val list = DownloadManager.moveDownload(fromItem, toItem)
if (mType != -1 || mKeyword != null) {
mList = mList!!.sortedByDescending { it.position }
}
mAdapter!!.notifyItemMoved(fromPosition, toPosition)
lifecycleScope.launchIO {
@@ -360,13 +367,28 @@ class DownloadsScene :
addAboveSnackView(fabLayout)
updateView()
}
setOnApplySearch {
mKeyword = it.takeUnless { it.isEmpty() }
updateForLabel()
updateView()
}
return binding.root
}
override fun onSearchViewExpanded() {
super.onSearchViewExpanded()
if (tracker.isInCustomChoice) tracker.clearSelection()
showSearchFab(true)
}
override fun onSearchViewHidden() {
super.onSearchViewHidden()
hideSearchFab(true)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
updateTitle()
setNavigationIcon(R.drawable.ic_baseline_menu_24)
}
override fun onDestroyView() {
@@ -203,7 +203,7 @@ class FavoritesScene : SearchBarScene() {
} else {
setSearchBarHint(getString(R.string.favorites_title_2, favCatName, keyword))
}
setEditTextHint(getString(R.string.favorites_search_bar_hint, favCatName))
setEditTextHint(getString(R.string.search_bar_hint, favCatName))
Settings.recentFavCat = urlBuilder.favCat
}
@@ -422,7 +422,6 @@ class FavoritesScene : SearchBarScene() {
}
})
itemTouchHelper.attachToRecyclerView(binding.recyclerView)
allowEmptySearch = false
return binding.root
}
@@ -164,52 +164,68 @@ abstract class SearchBarScene : BaseScene(), ToolBarScene {
privLockModeStart = null
}
fun selectSearchFab(animation: Boolean) {
_binding ?: return
mShowActionFab = false
fun showSearchFab(animation: Boolean, delay: Long = 0) {
if (animation) {
val fab: View? = fabLayout.primaryFab
val delay: Long
if (View.INVISIBLE == fab!!.visibility) {
delay = 0L
} else {
delay = ANIMATE_TIME
fabLayout.setExpanded(expanded = false, animation = true)
fab.animate().scaleX(0.0f).scaleY(0.0f).setListener(mActionFabAnimatorListener)
.setDuration(ANIMATE_TIME).setStartDelay(0L)
.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR).start()
}
mSearchFab.visibility = View.VISIBLE
mSearchFab.rotation = -45.0f
mSearchFab.animate().scaleX(1.0f).scaleY(1.0f).rotation(0.0f).setListener(null)
.setDuration(ANIMATE_TIME).setStartDelay(delay)
.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR).start()
} else {
fabLayout.setExpanded(expanded = false, animation = false)
val fab = fabLayout.primaryFab!!
fab.visibility = View.INVISIBLE
fab.scaleX = 0.0f
fab.scaleY = 0.0f
mSearchFab.visibility = View.VISIBLE
mSearchFab.scaleX = 1.0f
mSearchFab.scaleY = 1.0f
}
}
fun selectActionFab(animation: Boolean) {
_binding ?: return
mShowActionFab = true
if (animation) {
val delay: Long
if (View.INVISIBLE == mSearchFab.visibility) {
delay = 0L
} else {
delay = ANIMATE_TIME
fun hideSearchFab(animation: Boolean): Long {
return if (View.INVISIBLE == mSearchFab.visibility) {
0L
} else {
if (animation) {
mSearchFab.animate().scaleX(0.0f).scaleY(0.0f)
.setListener(mSearchFabAnimatorListener)
.setDuration(ANIMATE_TIME).setStartDelay(0L)
.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR).start()
} else {
mSearchFab.visibility = View.INVISIBLE
mSearchFab.scaleX = 0.0f
mSearchFab.scaleY = 0.0f
}
ANIMATE_TIME
}
}
fun selectSearchFab(animation: Boolean) {
_binding ?: return
mShowActionFab = false
val delay = if (animation) {
val fab = fabLayout.primaryFab!!
if (View.INVISIBLE == fab.visibility) {
0L
} else {
fabLayout.setExpanded(expanded = false, animation = true)
fab.animate().scaleX(0.0f).scaleY(0.0f).setListener(mActionFabAnimatorListener)
.setDuration(ANIMATE_TIME).setStartDelay(0L)
.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR).start()
ANIMATE_TIME
}
} else {
fabLayout.setExpanded(expanded = false, animation = false)
val fab = fabLayout.primaryFab!!
fab.visibility = View.INVISIBLE
fab.scaleX = 0.0f
fab.scaleY = 0.0f
0L
}
showSearchFab(animation, delay)
}
fun selectActionFab(animation: Boolean) {
_binding ?: return
mShowActionFab = true
val delay = hideSearchFab(animation)
if (animation) {
val fab = fabLayout.primaryFab!!
fab.visibility = View.VISIBLE
fab.rotation = -45.0f
@@ -222,9 +238,6 @@ abstract class SearchBarScene : BaseScene(), ToolBarScene {
fab.visibility = View.VISIBLE
fab.scaleX = 1.0f
fab.scaleY = 1.0f
mSearchFab.visibility = View.INVISIBLE
mSearchFab.scaleX = 0.0f
mSearchFab.scaleY = 0.0f
}
}
@@ -21,3 +21,5 @@ fun String.toLongOrDefault(defaultValue: Long): Long {
fun String.toFloatOrDefault(defaultValue: Float): Float {
return toFloatOrNull() ?: defaultValue
}
fun String?.containsIgnoreCase(other: String) = this?.contains(other, true) ?: false
+7 -10
View File
@@ -17,29 +17,26 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_filter"
android:icon="@drawable/v_filter_dark_x24"
android:title="@string/download_filter"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_open_side_sheet"
android:icon="@drawable/ic_outline_label_24"
android:title="@string/download_labels"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_filter"
android:title="@string/download_filter"
app:showAsAction="never" />
<item
android:id="@+id/action_start_all"
android:icon="@drawable/v_play_x24"
android:title="@string/download_start_all"
app:showAsAction="ifRoom" />
app:showAsAction="never" />
<item
android:id="@+id/action_stop_all"
android:icon="@drawable/v_pause_x24"
android:title="@string/download_stop_all"
app:showAsAction="ifRoom" />
app:showAsAction="never" />
<item
android:id="@+id/action_reset_reading_progress"
+1 -1
View File
@@ -294,7 +294,7 @@
<string name="settings_advanced_dump_logcat_to">Protokolldatei wurde auf %s gespeichert.</string>
<string name="cloud_favorites">Cloud-Favoriten</string>
<string name="local_favorites">Lokale Favoriten</string>
<string name="favorites_search_bar_hint">%s durchsuchen</string>
<string name="search_bar_hint">%s durchsuchen</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">Aus Favoriten löschen</string>
+1 -1
View File
@@ -354,7 +354,7 @@
<!-- Favorites -->
<string name="cloud_favorites">Favoritos en la nube</string>
<string name="local_favorites">Favoritos locales</string>
<string name="favorites_search_bar_hint">Buscar %s</string>
<string name="search_bar_hint">Buscar %s</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">Eliminar de favoritos</string>
+1 -1
View File
@@ -393,7 +393,7 @@
<!-- Favorites -->
<string name="cloud_favorites">Favoris de cloud</string>
<string name="local_favorites">Favoris locales</string>
<string name="favorites_search_bar_hint">Chercher dans %s</string>
<string name="search_bar_hint">Chercher dans %s</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">Effacer de favoris</string>
+1 -1
View File
@@ -390,7 +390,7 @@
<!-- Favorites -->
<string name="cloud_favorites">Cloudのお気に入り</string>
<string name="local_favorites">ローカルのお気に入り</string>
<string name="favorites_search_bar_hint">%sを検索</string>
<string name="search_bar_hint">%sを検索</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">お気に入りから削除</string>
+1 -1
View File
@@ -364,7 +364,7 @@
<!-- Favorites -->
<string name="cloud_favorites">클라우드 즐겨찾기</string>
<string name="local_favorites">로컬 즐겨찾기</string>
<string name="favorites_search_bar_hint">%s 검색</string>
<string name="search_bar_hint">%s 검색</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">즐겨찾기에서 삭제</string>
+1 -1
View File
@@ -379,7 +379,7 @@
<!-- Favorites -->
<string name="cloud_favorites">รายการโปรดบนเว็บ</string>
<string name="local_favorites">รายการโปรดบนเครื่อง</string>
<string name="favorites_search_bar_hint">ค้นหา %s</string>
<string name="search_bar_hint">ค้นหา %s</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">ลบออกจากรายการโปรด</string>
+1 -1
View File
@@ -409,7 +409,7 @@
<!-- Favorites -->
<string name="cloud_favorites">云端收藏</string>
<string name="local_favorites">本地收藏</string>
<string name="favorites_search_bar_hint">搜索 %s</string>
<string name="search_bar_hint">搜索 %s</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">删除收藏</string>
+1 -1
View File
@@ -419,7 +419,7 @@
<!-- Favorites -->
<string name="cloud_favorites">雲端收藏</string>
<string name="local_favorites">本地收藏</string>
<string name="favorites_search_bar_hint">搜索 %s</string>
<string name="search_bar_hint">搜索 %s</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">刪除收藏</string>
+1 -1
View File
@@ -400,7 +400,7 @@
<!-- Favorites -->
<string name="cloud_favorites">雲端收藏</string>
<string name="local_favorites">本機收藏</string>
<string name="favorites_search_bar_hint">搜尋 %s</string>
<string name="search_bar_hint">搜尋 %s</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">移除收藏</string>
+1 -1
View File
@@ -467,7 +467,7 @@
<!-- Favorites -->
<string name="cloud_favorites">Cloud Favorites</string>
<string name="local_favorites">Local Favorites</string>
<string name="favorites_search_bar_hint">Search %s</string>
<string name="search_bar_hint">Search %s</string>
<string name="favorites_title">%s</string>
<string name="favorites_title_2">%1$s - %2$s</string>
<string name="delete_favorites_dialog_title">Delete from favorites</string>