Merge pull request #143 from lucasnlm/small-improvements

Add Area size option on preferences
This commit is contained in:
Lucas Nunes 2020-08-07 02:58:14 +00:00 committed by GitHub
commit 146d223b68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 87 additions and 45 deletions

View file

@ -9,8 +9,8 @@ android {
defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 703021
versionName '7.3.2'
versionCode 703031
versionName '7.3.3'
minSdkVersion 16
targetSdkVersion 30
multiDexEnabled true

View file

@ -69,7 +69,7 @@ class GameActivity : AppCompatActivity(R.layout.activity_game), DialogInterface.
private val shareViewModel: ShareViewModel by viewModels()
private var status: Status = Status.PreGame
private val usingLargeArea by lazy { preferencesRepository.useLargeAreas() }
private val areaSizeMultiplier by lazy { preferencesRepository.areaSizeMultiplier() }
private var totalMines: Int = 0
private var totalArea: Int = 0
private var rightMines: Int = 0
@ -568,7 +568,7 @@ class GameActivity : AppCompatActivity(R.layout.activity_game), DialogInterface.
* apply these changes.
*/
private fun restartIfNeed(): Boolean {
return (usingLargeArea != preferencesRepository.useLargeAreas()).also {
return (areaSizeMultiplier != preferencesRepository.areaSizeMultiplier()).also {
if (it) {
recreate()
}

View file

@ -10,6 +10,8 @@ class FixedDimensionRepository : IDimensionRepository {
return areaSize() + 2 * areaSeparator()
}
override fun defaultAreaSize(): Float = 50.0f
override fun areaSeparator(): Float = 1.0f
override fun displaySize(): Size = Size(50 * 15, 50 * 30)

View file

@ -9,8 +9,8 @@ android {
defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 703021
versionName '7.3.2'
versionCode 703031
versionName '7.3.3'
minSdkVersion 16
targetSdkVersion 30
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

View file

@ -21,7 +21,7 @@ class AreaScreenshot {
private lateinit var context: Context
private fun saveImage(area: Area, fileName: String, ambientMode: Boolean): File {
val paintSettings = AreaAdapter.createAreaPaintSettings(context, false)
val paintSettings = AreaAdapter.createAreaPaintSettings(context, 128.0f)
val size = paintSettings.rectF.width().toInt()
val testPadding = 4
val bitmap = Bitmap.createBitmap(size + testPadding, size + testPadding, Bitmap.Config.ARGB_8888)

View file

@ -9,6 +9,7 @@ import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
interface IDimensionRepository {
fun areaSize(): Float
fun areaSizeWithPadding(): Float
fun defaultAreaSize(): Float
fun areaSeparator(): Float
fun displaySize(): Size
fun actionBarSize(): Int
@ -25,10 +26,10 @@ class DimensionRepository(
private val preferencesRepository: IPreferencesRepository
) : IDimensionRepository {
override fun areaSize(): Float = if (preferencesRepository.useLargeAreas()) {
context.resources.getDimension(R.dimen.accessible_field_size)
} else {
context.resources.getDimension(R.dimen.field_size)
override fun areaSize(): Float {
val multiplier = preferencesRepository.areaSizeMultiplier() / 100.0f
val maxArea = context.resources.getDimension(R.dimen.field_size)
return maxArea * multiplier
}
override fun areaSeparator(): Float {
@ -39,6 +40,12 @@ class DimensionRepository(
return areaSize() + 2 * areaSeparator()
}
override fun defaultAreaSize(): Float {
val multiplier = 0.5f
val maxArea = context.resources.getDimension(R.dimen.field_size)
return maxArea * multiplier
}
override fun displaySize(): Size = with(Resources.getSystem().displayMetrics) {
return Size(this.widthPixels, this.heightPixels)
}

View file

@ -34,7 +34,7 @@ class MinefieldRepository : IMinefieldRepository {
private fun calculateStandardMode(
dimensionRepository: IDimensionRepository
): Minefield {
val fieldSize = dimensionRepository.areaSize()
val fieldSize = dimensionRepository.defaultAreaSize()
val verticalGap = if (dimensionRepository.navigationBarHeight() > 0)
VERTICAL_STANDARD_GAP else VERTICAL_STANDARD_GAP_WITHOUT_BOTTOM

View file

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
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.repository.IDimensionRepository
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.core.control.ControlStyle
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
@ -24,7 +25,8 @@ import kotlinx.coroutines.launch
class AreaAdapter(
context: Context,
private val viewModel: GameViewModel,
private val preferencesRepository: IPreferencesRepository
private val preferencesRepository: IPreferencesRepository,
dimensionRepository: IDimensionRepository
) : RecyclerView.Adapter<AreaViewHolder>() {
private var field = listOf<Area>()
@ -37,7 +39,7 @@ class AreaAdapter(
init {
setHasStableIds(true)
paintSettings = createAreaPaintSettings(context.applicationContext, viewModel.useAccessibilityMode())
paintSettings = createAreaPaintSettings(context.applicationContext, dimensionRepository.areaSize())
}
fun setAmbientMode(isAmbientMode: Boolean, isLowBitAmbient: Boolean) {
@ -174,13 +176,8 @@ class AreaAdapter(
companion object {
val TAG = AreaAdapter::class.simpleName!!
fun createAreaPaintSettings(context: Context, useLargeArea: Boolean): AreaPaintSettings {
fun createAreaPaintSettings(context: Context, size: Float): AreaPaintSettings {
val resources = context.resources
val size = if (useLargeArea) {
resources.getDimension(R.dimen.accessible_field_size)
} else {
resources.getDimension(R.dimen.field_size)
}
return AreaPaintSettings(
Paint().apply {
isAntiAlias = true

View file

@ -22,7 +22,9 @@ abstract class CommonLevelFragment : Fragment() {
lateinit var preferencesRepository: IPreferencesRepository
protected val viewModel: GameViewModel by activityViewModels()
protected val areaAdapter by lazy { AreaAdapter(requireContext(), viewModel, preferencesRepository) }
protected val areaAdapter by lazy {
AreaAdapter(requireContext(), viewModel, preferencesRepository, dimensionRepository)
}
protected lateinit var recyclerGrid: RecyclerView
abstract val levelFragmentResId: Int

View file

@ -85,7 +85,7 @@ class GameViewModel @ViewModelInject constructor(
Analytics.NewGame(
minefield, newDifficulty,
gameController.seed,
useAccessibilityMode()
getAreaSizeMultiplier()
)
)
@ -140,7 +140,7 @@ class GameViewModel @ViewModelInject constructor(
setup,
currentDifficulty,
gameController.seed,
useAccessibilityMode(),
getAreaSizeMultiplier(),
save.firstOpen.toInt()
)
)
@ -420,7 +420,7 @@ class GameViewModel @ViewModelInject constructor(
}
}
fun useAccessibilityMode() = preferencesRepository.useLargeAreas()
private fun getAreaSizeMultiplier() = preferencesRepository.areaSizeMultiplier()
private fun refreshIndex(targetIndex: Int, multipleChanges: Boolean = false) {
if (!preferencesRepository.useAnimations() || multipleChanges) {

View file

@ -14,7 +14,7 @@ sealed class Analytics(
minefield: Minefield,
difficulty: Difficulty,
seed: Long,
useAccessibilityMode: Boolean
areaSizeMultiplier: Int
) : Analytics(
"New Game",
mapOf(
@ -23,7 +23,7 @@ sealed class Analytics(
"Width" to minefield.width.toString(),
"Height" to minefield.height.toString(),
"Mines" to minefield.mines.toString(),
"Accessibility" to useAccessibilityMode.toString()
"Size Multiplier" to areaSizeMultiplier.toString()
)
)
@ -31,7 +31,7 @@ sealed class Analytics(
minefield: Minefield,
difficulty: Difficulty,
seed: Long,
useAccessibilityMode: Boolean,
areaSizeMultiplier: Int,
firstOpen: Int
) : Analytics(
"Retry Game",
@ -41,7 +41,7 @@ sealed class Analytics(
"Width" to minefield.width.toString(),
"Height" to minefield.height.toString(),
"Mines" to minefield.mines.toString(),
"Accessibility" to useAccessibilityMode.toString(),
"Size Multiplier" to areaSizeMultiplier.toString(),
"First Open" to firstOpen.toString()
)
)

View file

@ -20,7 +20,7 @@ interface IPreferencesRepository {
fun useFlagAssistant(): Boolean
fun useHapticFeedback(): Boolean
fun useLargeAreas(): Boolean
fun areaSizeMultiplier(): Int
fun useAnimations(): Boolean
fun useQuestionMark(): Boolean
fun isSoundEffectsEnabled(): Boolean
@ -65,8 +65,8 @@ class PreferencesRepository(
override fun useHapticFeedback(): Boolean =
getBoolean(PREFERENCE_VIBRATION, true)
override fun useLargeAreas(): Boolean =
getBoolean(PREFERENCE_USE_LARGE_TILE, false)
override fun areaSizeMultiplier(): Int =
getInt(PREFERENCE_AREA_SIZE, 50)
override fun useAnimations(): Boolean =
getBoolean(PREFERENCE_ANIMATION, true)
@ -101,13 +101,18 @@ class PreferencesRepository(
preferencesManager.removeKey(PREFERENCE_OLD_DOUBLE_CLICK)
}
if (preferencesManager.contains(PREFERENCE_OLD_LARGE_AREA)) {
preferencesManager.putInt(PREFERENCE_AREA_SIZE, 63)
preferencesManager.removeKey(PREFERENCE_OLD_LARGE_AREA)
}
}
private companion object {
private const val PREFERENCE_VIBRATION = "preference_vibration"
private const val PREFERENCE_ASSISTANT = "preference_assistant"
private const val PREFERENCE_ANIMATION = "preference_animation"
private const val PREFERENCE_USE_LARGE_TILE = "preference_large_area"
private const val PREFERENCE_AREA_SIZE = "preference_area_size"
private const val PREFERENCE_QUESTION_MARK = "preference_use_question_mark"
private const val PREFERENCE_CONTROL_STYLE = "preference_control_style"
private const val PREFERENCE_OLD_DOUBLE_CLICK = "preference_double_click_open"
@ -116,5 +121,6 @@ class PreferencesRepository(
private const val PREFERENCE_CUSTOM_GAME_MINES = "preference_custom_game_mines"
private const val PREFERENCE_SOUND_EFFECTS = "preference_sound"
private const val PREFERENCE_STATS_BASE = "preference_stats_base"
private const val PREFERENCE_OLD_LARGE_AREA = "preference_large_area"
}
}

View file

@ -2,8 +2,7 @@
<dimen name="app_bar_height">180dp</dimen>
<dimen name="toolbar_elevation">6dp</dimen>
<dimen name="field_size">38dp</dimen>
<dimen name="accessible_field_size">48dp</dimen>
<dimen name="field_size">76dp</dimen>
<dimen name="field_radius">2dp</dimen>
<dimen name="field_padding">1dp</dimen>
<dimen name="highlight_stroke">2dp</dimen>

View file

@ -30,6 +30,7 @@
<string name="settings_gameplay">Gameplay</string>
<string name="settings_accessibility">Accessibility</string>
<string name="settings_large_areas">Use Large Areas</string>
<string name="size">Size</string>
<string name="rating">Feedback</string>
<string name="rating_message">If you like this game, please give us a feedback. It will help us a lot.</string>
<string name="used_software_text">This game uses the following third parties software:</string>

View file

@ -53,11 +53,16 @@
android:title="@string/settings_accessibility"
app:iconSpaceReserved="false">
<SwitchPreferenceCompat
android:checked="false"
android:defaultValue="false"
android:key="preference_large_area"
android:title="@string/settings_large_areas"
<SeekBarPreference
android:key="preference_area_size"
android:max="80"
android:min="40"
android:defaultValue="50"
android:title="@string/size"
app:adjustable="true"
app:min="40"
app:seekBarIncrement="5"
app:showSeekBarValue="true"
app:iconSpaceReserved="false" />
</PreferenceCategory>

View file

@ -10,6 +10,8 @@ class FixedDimensionRepository : IDimensionRepository {
return areaSize() + 2 * areaSeparator()
}
override fun defaultAreaSize(): Float = 50.0f
override fun areaSeparator(): Float = 1.0f
override fun displaySize(): Size = Size(50 * 15, 50 * 30)

View file

@ -58,4 +58,25 @@ class PreferencesRepositoryTest {
assertTrue(preferenceManager.values["preference_double_click_open"] == null)
assertFalse(preferencesRepository.getBoolean("preference_double_click_open", false))
}
@Test
fun testMigrationLargeArea() {
val preferenceManager = TestPreferenceManager()
preferenceManager.putBoolean("preference_large_area", true)
assertTrue(preferenceManager.values["preference_large_area"] as Boolean)
val preferencesRepository = PreferencesRepository(preferenceManager)
assertTrue(preferenceManager.values["preference_large_area"] == null)
assertEquals(63, preferencesRepository.getInt("preference_area_size", -1))
}
@Test
fun testMigrationLargeAreaOff() {
val preferenceManager = TestPreferenceManager()
val preferencesRepository = PreferencesRepository(preferenceManager)
assertTrue(preferenceManager.values["preference_large_area"] == null)
assertEquals(50, preferencesRepository.getInt("preference_area_size", 50))
}
}

View file

@ -6,8 +6,8 @@ android {
compileSdkVersion 30
defaultConfig {
versionCode 703021 // MMmmPPv
versionName '7.3.2'
versionCode 703031 // MMmmPPv
versionName '7.3.3'
minSdkVersion 16
targetSdkVersion 30
}

View file

@ -6,8 +6,8 @@ android {
compileSdkVersion 30
defaultConfig {
versionCode 703021 // MMmmPPv
versionName '7.3.2'
versionCode 703031 // MMmmPPv
versionName '7.3.3'
minSdkVersion 16
targetSdkVersion 30
}

View file

@ -9,8 +9,8 @@ android {
defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 703021
versionName '7.3.2'
versionCode 703031
versionName '7.3.3'
applicationId 'dev.lucasnlm.antimine'
minSdkVersion 23
targetSdkVersion 30