Convert SuggestionHolder to view binding
This commit is contained in:
1 parent
2ce55b4aef
commit
2ed516cf85
2 files changed
+33
-39
No files matched your search
@@ -97,8 +97,6 @@ import com.hippo.ehviewer.ui.tools.DialogState
|
||||
import com.hippo.ehviewer.util.getParcelableCompat
|
||||
import com.hippo.ehviewer.yorozuya.AnimationUtils
|
||||
import com.hippo.ehviewer.yorozuya.SimpleAnimatorListener
|
||||
import com.hippo.ehviewer.yorozuya.StringUtils
|
||||
import com.hippo.ehviewer.yorozuya.ViewUtils
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
@@ -124,11 +122,10 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
private lateinit var mUrlBuilder: ListUrlBuilder
|
||||
private var _binding: SceneGalleryListBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private var mSearchFab: View? = null
|
||||
private val mSearchFabAnimatorListener: Animator.AnimatorListener =
|
||||
object : SimpleAnimatorListener() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
mSearchFab?.visibility = View.INVISIBLE
|
||||
mSearchFab.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
private val mActionFabAnimatorListener: Animator.AnimatorListener =
|
||||
@@ -345,13 +342,12 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
requireActivity().onBackPressedDispatcher.addCallback(mCallback)
|
||||
mHideActionFabSlop = ViewConfiguration.get(requireContext()).scaledTouchSlop
|
||||
mShowActionFab = true
|
||||
mSearchFab = ViewUtils.`$$`(container, R.id.search_fab)
|
||||
ViewCompat.setWindowInsetsAnimationCallback(
|
||||
binding.root,
|
||||
WindowInsetsAnimationHelper(
|
||||
WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP,
|
||||
binding.fabLayout,
|
||||
mSearchFab!!.parent as View,
|
||||
mSearchFab.parent as View,
|
||||
),
|
||||
)
|
||||
(binding.fabLayout.parent as ViewGroup).removeView(binding.fabLayout)
|
||||
@@ -401,7 +397,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
mActionFabDrawable =
|
||||
AddDeleteDrawable(context, colorID)
|
||||
binding.fabLayout.primaryFab!!.setImageDrawable(mActionFabDrawable)
|
||||
mSearchFab!!.setOnClickListener { onApplySearch() }
|
||||
mSearchFab.setOnClickListener { onApplySearch() }
|
||||
|
||||
// Update list url builder
|
||||
onUpdateUrlBuilder()
|
||||
@@ -752,9 +748,6 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
|
||||
private fun selectSearchFab(animation: Boolean) {
|
||||
_binding ?: return
|
||||
if (null == mSearchFab) {
|
||||
return
|
||||
}
|
||||
mShowActionFab = false
|
||||
if (animation) {
|
||||
val fab: View? = binding.fabLayout.primaryFab
|
||||
@@ -768,9 +761,9 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
.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)
|
||||
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 {
|
||||
@@ -779,25 +772,22 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
fab!!.visibility = View.INVISIBLE
|
||||
fab.scaleX = 0.0f
|
||||
fab.scaleY = 0.0f
|
||||
mSearchFab!!.visibility = View.VISIBLE
|
||||
mSearchFab!!.scaleX = 1.0f
|
||||
mSearchFab!!.scaleY = 1.0f
|
||||
mSearchFab.visibility = View.VISIBLE
|
||||
mSearchFab.scaleX = 1.0f
|
||||
mSearchFab.scaleY = 1.0f
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectActionFab(animation: Boolean) {
|
||||
_binding ?: return
|
||||
if (null == mSearchFab) {
|
||||
return
|
||||
}
|
||||
mShowActionFab = true
|
||||
if (animation) {
|
||||
val delay: Long
|
||||
if (View.INVISIBLE == mSearchFab!!.visibility) {
|
||||
if (View.INVISIBLE == mSearchFab.visibility) {
|
||||
delay = 0L
|
||||
} else {
|
||||
delay = ANIMATE_TIME
|
||||
mSearchFab!!.animate().scaleX(0.0f).scaleY(0.0f)
|
||||
mSearchFab.animate().scaleX(0.0f).scaleY(0.0f)
|
||||
.setListener(mSearchFabAnimatorListener)
|
||||
.setDuration(ANIMATE_TIME).setStartDelay(0L)
|
||||
.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR).start()
|
||||
@@ -814,9 +804,9 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
fab!!.visibility = View.VISIBLE
|
||||
fab.scaleX = 1.0f
|
||||
fab.scaleY = 1.0f
|
||||
mSearchFab!!.visibility = View.INVISIBLE
|
||||
mSearchFab!!.scaleX = 0.0f
|
||||
mSearchFab!!.scaleY = 0.0f
|
||||
mSearchFab.visibility = View.INVISIBLE
|
||||
mSearchFab.scaleX = 0.0f
|
||||
mSearchFab.scaleY = 0.0f
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1155,7 +1145,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
|
||||
runSuspendCatching {
|
||||
if (ListUrlBuilder.MODE_IMAGE_SEARCH == mUrlBuilder.mode) {
|
||||
EhEngine.imageSearch(
|
||||
File(StringUtils.avoidNull(mUrlBuilder.imagePath)),
|
||||
File(mUrlBuilder.imagePath!!),
|
||||
mUrlBuilder.isUseSimilarityScan,
|
||||
mUrlBuilder.isOnlySearchCovers,
|
||||
)
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhTagDatabase
|
||||
import com.hippo.ehviewer.dao.SearchDatabase
|
||||
import com.hippo.ehviewer.databinding.ItemSimpleList2Binding
|
||||
import com.hippo.ehviewer.databinding.SceneSearchbarBinding
|
||||
import com.hippo.ehviewer.ui.legacy.BaseDialogBuilder
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
@@ -40,6 +41,7 @@ abstract class SearchBarScene : BaseScene(), ToolBarScene {
|
||||
private var mAllowEmptySearch = true
|
||||
private val mSearchDatabase = searchDatabase.searchDao()
|
||||
private var onApplySearch: (String) -> Unit = {}
|
||||
protected val mSearchFab get() = binding.searchFab
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@@ -184,30 +186,32 @@ abstract class SearchBarScene : BaseScene(), ToolBarScene {
|
||||
}
|
||||
}
|
||||
|
||||
private class SuggestionHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val text1 = itemView.findViewById(android.R.id.text1) as TextView
|
||||
val text2 = itemView.findViewById(android.R.id.text2) as TextView
|
||||
private class SuggestionHolder(private val binding: ItemSimpleList2Binding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(suggestion: Suggestion?) {
|
||||
val text1 = suggestion?.getText(binding.text1)
|
||||
val text2 = suggestion?.getText(binding.text2)
|
||||
binding.text1.text = text1
|
||||
if (text2 == null) {
|
||||
binding.text2.visibility = View.GONE
|
||||
binding.text2.text = ""
|
||||
} else {
|
||||
binding.text2.visibility = View.VISIBLE
|
||||
binding.text2.text = text2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inner class SuggestionAdapter constructor(private val mInflater: LayoutInflater) :
|
||||
RecyclerView.Adapter<SuggestionHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionHolder {
|
||||
return SuggestionHolder(mInflater.inflate(R.layout.item_simple_list_2, parent, false))
|
||||
return SuggestionHolder(ItemSimpleList2Binding.inflate(mInflater, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SuggestionHolder, position: Int) {
|
||||
val suggestion = mSuggestionList?.get(position)
|
||||
val text1 = suggestion?.getText(holder.text1)
|
||||
val text2 = suggestion?.getText(holder.text2)
|
||||
holder.text1.text = text1
|
||||
if (text2 == null) {
|
||||
holder.text2.visibility = View.GONE
|
||||
holder.text2.text = ""
|
||||
} else {
|
||||
holder.text2.visibility = View.VISIBLE
|
||||
holder.text2.text = text2
|
||||
}
|
||||
holder.bind(suggestion)
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
mSuggestionList?.run {
|
||||
|
||||
Reference in new issue
Block a user