mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Use action mode to copy/global search/local search manga title or author
Also fixes to local searching title/tag/author from recents controller on fresh app start
This commit is contained in:
parent
f490eee34e
commit
df168e7154
7 changed files with 104 additions and 19 deletions
|
@ -129,7 +129,7 @@ class LibraryCategoryAdapter(val controller: LibraryController?) :
|
|||
}
|
||||
}
|
||||
|
||||
fun performFilter() {
|
||||
private fun performFilter() {
|
||||
val s = getFilter(String::class.java)
|
||||
if (s.isNullOrBlank()) {
|
||||
if (mangas.firstOrNull()?.filter?.isNotBlank() == true) {
|
||||
|
|
|
@ -1277,6 +1277,7 @@ class LibraryController(
|
|||
adapter.removeAllScrollableHeaders()
|
||||
}
|
||||
adapter.setFilter(query)
|
||||
if (adapter.itemCount == 0) return true
|
||||
viewScope.launchUI {
|
||||
adapter.performFilterAsync()
|
||||
}
|
||||
|
|
|
@ -131,8 +131,9 @@ class MangaDetailsAdapter(
|
|||
fun startDownloadRange(position: Int)
|
||||
fun readNextChapter(readingButton: View)
|
||||
fun topCoverHeight(): Int
|
||||
fun tagClicked(text: String)
|
||||
fun localSearch(text: String)
|
||||
fun globalSearch(text: String)
|
||||
fun showFloatingActionMode(view: View, content: String, label: Int)
|
||||
fun showChapterFilter()
|
||||
fun favoriteManga(longPress: Boolean)
|
||||
fun copyToClipboard(content: String, label: Int, useToast: Boolean = false)
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.view.LayoutInflater
|
|||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
|
@ -196,6 +197,7 @@ class MangaDetailsController :
|
|||
private var headerHeight = 0
|
||||
private var fullCoverActive = false
|
||||
var returningFromReader = false
|
||||
private var floatingActionMode: android.view.ActionMode? = null
|
||||
|
||||
override fun getTitle(): String? {
|
||||
return manga?.title
|
||||
|
@ -367,6 +369,7 @@ class MangaDetailsController :
|
|||
override fun onDestroyView(view: View) {
|
||||
snack?.dismiss()
|
||||
adapter = null
|
||||
finishFloatingActionMode()
|
||||
trackingBottomSheet = null
|
||||
super.onDestroyView(view)
|
||||
}
|
||||
|
@ -425,6 +428,19 @@ class MangaDetailsController :
|
|||
}
|
||||
},
|
||||
)
|
||||
|
||||
binding.touchView.setOnTouchListener { _, event ->
|
||||
if (event.action == MotionEvent.ACTION_DOWN) {
|
||||
finishFloatingActionMode()
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun finishFloatingActionMode() {
|
||||
floatingActionMode ?: return
|
||||
floatingActionMode?.finish()
|
||||
floatingActionMode = null
|
||||
}
|
||||
|
||||
private fun setInsets(insets: WindowInsetsCompat, appbarHeight: Int, offset: Int) {
|
||||
|
@ -1345,7 +1361,7 @@ class MangaDetailsController :
|
|||
}
|
||||
}
|
||||
|
||||
override fun tagClicked(text: String) {
|
||||
override fun localSearch(text: String) {
|
||||
if (router.backstackSize < 2) {
|
||||
return
|
||||
}
|
||||
|
@ -1377,6 +1393,15 @@ class MangaDetailsController :
|
|||
router.pushController(GlobalSearchController(text).withFadeTransaction())
|
||||
}
|
||||
|
||||
override fun showFloatingActionMode(view: View, content: String, label: Int) {
|
||||
if (content.isBlank()) return
|
||||
finishFloatingActionMode()
|
||||
floatingActionMode = view.startActionMode(
|
||||
FloatingMangaDetailsActionModeCallback(content, label),
|
||||
android.view.ActionMode.TYPE_FLOATING,
|
||||
)
|
||||
}
|
||||
|
||||
override fun showChapterFilter() {
|
||||
ChaptersSortBottomSheet(this).show()
|
||||
}
|
||||
|
@ -1654,4 +1679,45 @@ class MangaDetailsController :
|
|||
Unread
|
||||
}
|
||||
}
|
||||
|
||||
inner class FloatingMangaDetailsActionModeCallback(
|
||||
val text: String,
|
||||
val label: Int,
|
||||
) : android.view.ActionMode.Callback {
|
||||
override fun onCreateActionMode(mode: android.view.ActionMode?, menu: Menu?): Boolean {
|
||||
mode?.menuInflater?.inflate(R.menu.manga_details_title, menu)
|
||||
val context = view?.context ?: return false
|
||||
val prevController = router.backstack.getOrNull(router.backstackSize - 2)?.controller
|
||||
val localItem = menu?.findItem(R.id.action_local_search) ?: return true
|
||||
localItem.isVisible = when (prevController) {
|
||||
is LibraryController, is BrowseController, is RecentsController -> true
|
||||
else -> false
|
||||
}
|
||||
val library = context.getString(R.string.library).lowercase(Locale.getDefault())
|
||||
localItem.title = context.getString(R.string.search_, library)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: android.view.ActionMode?, menu: Menu?): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onActionItemClicked(
|
||||
mode: android.view.ActionMode?,
|
||||
item: MenuItem?,
|
||||
): Boolean {
|
||||
mode?.finish()
|
||||
val context = view?.context ?: return true
|
||||
when (item?.itemId) {
|
||||
R.id.action_copy -> copyToClipboard(text, context.getString(label))
|
||||
R.id.action_global_search -> globalSearch(text)
|
||||
R.id.action_local_search -> localSearch(text)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: android.view.ActionMode?) {
|
||||
floatingActionMode = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,22 +127,15 @@ class MangaHeaderHolder(
|
|||
favoriteButton.setOnClickListener {
|
||||
adapter.delegate.favoriteManga(false)
|
||||
}
|
||||
title.setOnClickListener {
|
||||
title.text?.let { adapter.delegate.globalSearch(it.toString().toNormalized()) }
|
||||
title.setOnClickListener { view ->
|
||||
title.text?.toString()?.toNormalized()?.let {
|
||||
adapter.delegate.showFloatingActionMode(view, it, R.string.title)
|
||||
}
|
||||
}
|
||||
title.setOnLongClickListener {
|
||||
adapter.delegate.copyToClipboard(title.text.toString(), R.string.title)
|
||||
true
|
||||
}
|
||||
mangaAuthor.setOnClickListener {
|
||||
mangaAuthor.text?.let { adapter.delegate.globalSearch(it.toString()) }
|
||||
}
|
||||
mangaAuthor.setOnLongClickListener {
|
||||
adapter.delegate.copyToClipboard(
|
||||
mangaAuthor.text.toString(),
|
||||
R.string.author,
|
||||
)
|
||||
true
|
||||
mangaAuthor.setOnClickListener { view ->
|
||||
mangaAuthor.text?.toString()?.let {
|
||||
adapter.delegate.showFloatingActionMode(view, it, R.string.title)
|
||||
}
|
||||
}
|
||||
applyBlur()
|
||||
mangaCover.setOnClickListener { adapter.delegate.zoomImageFromThumb(coverCard) }
|
||||
|
@ -489,7 +482,7 @@ class MangaHeaderHolder(
|
|||
chip.setTextColor(textColor)
|
||||
chip.text = genreText
|
||||
chip.setOnClickListener {
|
||||
adapter.delegate.tagClicked(genreText)
|
||||
adapter.delegate.localSearch(genreText)
|
||||
}
|
||||
chip.setOnLongClickListener {
|
||||
adapter.delegate.copyToClipboard(genreText, genreText)
|
||||
|
|
|
@ -73,6 +73,11 @@
|
|||
android:layout_height="match_parent"
|
||||
app:fastScrollerBubbleEnabled="true" />
|
||||
|
||||
<View
|
||||
android:id="@+id/touch_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/manga_cover_full"
|
||||
android:layout_width="match_parent"
|
||||
|
|
19
app/src/main/res/menu/manga_details_title.xml
Normal file
19
app/src/main/res/menu/manga_details_title.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_copy"
|
||||
android:icon="@drawable/ic_done_all_24dp"
|
||||
android:title="@string/copy_value"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_global_search"
|
||||
android:icon="@drawable/ic_search_24dp"
|
||||
android:title="@string/label_global_search"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_local_search"
|
||||
android:icon="@drawable/ic_search_24dp"
|
||||
android:title="@string/search"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
Loading…
Add table
Add a link
Reference in a new issue