diff --git a/app/build.gradle b/app/build.gradle index 79c34886..f4de144b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { // versionCode and versionName must be hardcoded to support F-droid - versionCode 702001 - versionName '7.2.0' + versionCode 702011 + versionName '7.2.1' minSdkVersion 16 targetSdkVersion 29 multiDexEnabled true diff --git a/app/src/test/java/dev/lucasnlm/antimine/mocks/FixedDimensionRepository.kt b/app/src/test/java/dev/lucasnlm/antimine/mocks/FixedDimensionRepository.kt index 2d564b17..be6eb11d 100644 --- a/app/src/test/java/dev/lucasnlm/antimine/mocks/FixedDimensionRepository.kt +++ b/app/src/test/java/dev/lucasnlm/antimine/mocks/FixedDimensionRepository.kt @@ -15,4 +15,6 @@ class FixedDimensionRepository : IDimensionRepository { override fun displaySize(): Size = Size(50 * 15, 50 * 30) override fun actionBarSize(): Int = 50 + + override fun navigationBarHeight(): Int = 0 } diff --git a/common/build.gradle b/common/build.gradle index 667046bf..81c45525 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { // versionCode and versionName must be hardcoded to support F-droid - versionCode 702001 - versionName '7.2.0' + versionCode 702011 + versionName '7.2.1' minSdkVersion 16 targetSdkVersion 29 testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DimensionRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DimensionRepository.kt index 4fb7a873..88c874e4 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DimensionRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DimensionRepository.kt @@ -12,6 +12,7 @@ interface IDimensionRepository { fun areaSeparator(): Float fun displaySize(): Size fun actionBarSize(): Int + fun navigationBarHeight(): Int } data class Size( @@ -51,4 +52,17 @@ class DimensionRepository( styledAttributes.recycle() return actionBarSize } + + override fun navigationBarHeight(): Int { + // TODO use official mode if available + val resources = context.resources + val resourceId: Int = resources.getIdentifier(NAVIGATION_BAR_HEIGHT, DEF_TYPE_DIMEN, DEF_PACKAGE) + return if (resourceId > 0) { resources.getDimensionPixelSize(resourceId) } else 0 + } + + companion object { + private const val NAVIGATION_BAR_HEIGHT = "navigation_bar_height" + private const val DEF_TYPE_DIMEN = "dimen" + private const val DEF_PACKAGE = "android" + } } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/MinefieldRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/MinefieldRepository.kt index 73e2939c..188a183a 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/MinefieldRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/MinefieldRepository.kt @@ -35,10 +35,12 @@ class MinefieldRepository : IMinefieldRepository { dimensionRepository: IDimensionRepository ): Minefield { val fieldSize = dimensionRepository.areaSize() + val verticalGap = if (dimensionRepository.navigationBarHeight() > 0) + VERTICAL_STANDARD_GAP else VERTICAL_STANDARD_GAP_WITHOUT_BOTTOM val display = dimensionRepository.displaySize() val calculatedWidth = ((display.width / fieldSize).toInt() - HORIZONTAL_STANDARD_GAP) - val calculatedHeight = ((display.height / fieldSize).toInt() - VERTICAL_STANDARD_GAP) + val calculatedHeight = ((display.height / fieldSize).toInt() - verticalGap) val finalWidth = calculatedWidth.coerceAtLeast(MIN_STANDARD_WIDTH) val finalHeight = calculatedHeight.coerceAtLeast(MIN_STANDARD_HEIGHT) val finalMines = (finalWidth * finalHeight * CUSTOM_LEVEL_RATIO).toInt() @@ -55,6 +57,7 @@ class MinefieldRepository : IMinefieldRepository { private const val CUSTOM_LEVEL_RATIO = 0.2 private const val HORIZONTAL_STANDARD_GAP = 1 + private const val VERTICAL_STANDARD_GAP_WITHOUT_BOTTOM = 4 private const val VERTICAL_STANDARD_GAP = 3 private const val MIN_STANDARD_WIDTH = 6 private const val MIN_STANDARD_HEIGHT = 9 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 0a366f5f..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 @@ -3,7 +3,6 @@ package dev.lucasnlm.antimine.common.level.view import android.content.Context import android.os.Bundle import android.util.DisplayMetrics -import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -14,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 @@ -54,19 +56,9 @@ abstract class CommonLevelFragment : Fragment() { val displayMetrics = DisplayMetrics() windowManager.defaultDisplay.getMetrics(displayMetrics) - val typedValue = TypedValue() - val actionBarHeight = if (context.theme.resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) { - TypedValue.complexToDimensionPixelSize(typedValue.data, resources.displayMetrics) - } else { - 0 - } - - val resourceId: Int = resources.getIdentifier("navigation_bar_height", "dimen", "android") - val bottom = if (resourceId > 0) { resources.getDimensionPixelSize(resourceId) } else 0 - - val height = displayMetrics.heightPixels - actionBarHeight - bottom + val height = recyclerGrid.measuredHeight val recyclerViewHeight = (dimensionRepository.areaSize() * boardHeight) - val separatorsHeight = (dimensionRepository.areaSeparator() * (boardHeight - 1)) + val separatorsHeight = (2 * dimensionRepository.areaSeparator() * (boardHeight - 1)) return ((height - recyclerViewHeight - separatorsHeight) / 2).coerceAtLeast(0.0f).toInt() } diff --git a/common/src/main/res/values-v21/themes.xml b/common/src/main/res/values-v21/themes.xml index ab83d501..95c58477 100644 --- a/common/src/main/res/values-v21/themes.xml +++ b/common/src/main/res/values-v21/themes.xml @@ -4,6 +4,7 @@ @color/primary @color/primary_dark @color/accent + @color/primary true diff --git a/common/src/main/res/values/themes.xml b/common/src/main/res/values/themes.xml index 1c36d49c..bfbeb92a 100644 --- a/common/src/main/res/values/themes.xml +++ b/common/src/main/res/values/themes.xml @@ -4,6 +4,7 @@ @color/primary @color/primary_dark @color/accent + @color/primary