From ea2c5036f2ad102c181433a5cf68aaff00ce0204 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Tue, 30 Jun 2020 11:39:48 -0300 Subject: [PATCH] Fix double click bug --- .../antimine/common/level/view/AreaAdapter.kt | 30 ++++++++++++++----- .../common/level/view/CommonLevelFragment.kt | 5 +++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt index fafcf794..7c3a9230 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt @@ -14,10 +14,13 @@ import dev.lucasnlm.antimine.common.R import dev.lucasnlm.antimine.common.level.models.Area import dev.lucasnlm.antimine.common.level.models.AreaPaintSettings import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel +import dev.lucasnlm.antimine.core.control.ControlStyle +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository class AreaAdapter( context: Context, - private val viewModel: GameViewModel + private val viewModel: GameViewModel, + private val preferencesRepository: IPreferencesRepository ) : RecyclerView.Adapter() { private var field = listOf() @@ -74,7 +77,18 @@ class AreaAdapter( } } - override fun onSingleTapConfirmed(e: MotionEvent?): Boolean = false + override fun onSingleTapConfirmed(e: MotionEvent?): Boolean { + if (preferencesRepository.controlStyle() == ControlStyle.DoubleClick) { + val position = adapterPosition + if (position == RecyclerView.NO_POSITION) { + Log.d(TAG, "Item no longer exists.") + } else if (clickEnabled) { + viewModel.onSingleClick(position) + return true + } + } + return false + } }) itemView.setOnLongClickListener { target -> @@ -91,11 +105,13 @@ class AreaAdapter( } itemView.setOnClickListener { - val position = adapterPosition - if (position == RecyclerView.NO_POSITION) { - Log.d(TAG, "Item no longer exists.") - } else if (clickEnabled) { - viewModel.onSingleClick(position) + if (preferencesRepository.controlStyle() != ControlStyle.DoubleClick) { + val position = adapterPosition + if (position == RecyclerView.NO_POSITION) { + Log.d(TAG, "Item no longer exists.") + } else if (clickEnabled) { + viewModel.onSingleClick(position) + } } } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/CommonLevelFragment.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/CommonLevelFragment.kt index 67712634..59d90b8b 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/CommonLevelFragment.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/CommonLevelFragment.kt @@ -13,14 +13,17 @@ import androidx.recyclerview.widget.RecyclerView import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel import dev.lucasnlm.antimine.common.level.widget.FixedGridLayoutManager +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository import javax.inject.Inject abstract class CommonLevelFragment : Fragment() { @Inject lateinit var dimensionRepository: IDimensionRepository + @Inject + lateinit var preferencesRepository: IPreferencesRepository protected val viewModel: GameViewModel by activityViewModels() - protected val areaAdapter by lazy { AreaAdapter(requireContext(), viewModel) } + protected val areaAdapter by lazy { AreaAdapter(requireContext(), viewModel, preferencesRepository) } protected lateinit var recyclerGrid: RecyclerView abstract val levelFragmentResId: Int