Provide haptic feedback when a game is picked.

This commit is contained in:
codokie 2024-08-08 14:43:49 +03:00
parent 12e6034ef1
commit e4abd73151
2 changed files with 21 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import org.dolphinemu.dolphinemu.databinding.CardGameBinding
import org.dolphinemu.dolphinemu.dialogs.GamePropertiesDialog
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting
import org.dolphinemu.dolphinemu.utils.CoilUtils
import org.dolphinemu.dolphinemu.utils.HapticListener
import java.util.ArrayList
class GameAdapter : RecyclerView.Adapter<GameViewHolder>(),
@ -39,7 +40,7 @@ class GameAdapter : RecyclerView.Adapter<GameViewHolder>(),
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameViewHolder {
val binding = CardGameBinding.inflate(LayoutInflater.from(parent.context))
binding.root.apply {
setOnClickListener(this@GameAdapter)
setOnClickListener(HapticListener.wrapOnClickListener(this@GameAdapter))
setOnLongClickListener(this@GameAdapter)
}

View File

@ -1,5 +1,6 @@
package org.dolphinemu.dolphinemu.utils
import android.view.View
import android.widget.CompoundButton
import androidx.core.view.HapticFeedbackConstantsCompat
import androidx.core.view.ViewCompat
@ -10,6 +11,24 @@ import com.google.android.material.slider.Slider
*/
object HapticListener {
/**
* Wraps a [View.OnClickListener] with haptic feedback.
*
* @param listener The [View.OnClickListener] to be wrapped. Can be null.
* @param feedbackConstant The haptic feedback constant to be used for haptic feedback.
* Defaults to [HapticFeedbackConstantsCompat.CONTEXT_CLICK] if not specified.
* @return A new listener which wraps [listener] with haptic feedback.
*/
fun wrapOnClickListener(
listener: View.OnClickListener?,
feedbackConstant: Int = HapticFeedbackConstantsCompat.CONTEXT_CLICK
): View.OnClickListener {
return View.OnClickListener { view: View ->
listener?.onClick(view)
ViewCompat.performHapticFeedback(view, feedbackConstant)
}
}
/**
* Wraps a [Slider.OnChangeListener] with haptic feedback.
*