Skip to content

Commit

Permalink
Merge pull request #249 from lucasnlm/build-9
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
lucasnlm authored Mar 5, 2021
2 parents e5315d7 + d949553 commit 369bc17
Show file tree
Hide file tree
Showing 22 changed files with 132 additions and 84 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 901001
versionName '9.1.0'
versionCode 901011
versionName '9.1.1'
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled true
Expand Down
33 changes: 26 additions & 7 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ import dev.lucasnlm.antimine.tutorial.view.TutorialCompleteDialogFragment
import dev.lucasnlm.antimine.tutorial.view.TutorialLevelFragment
import dev.lucasnlm.antimine.ui.ThematicActivity
import dev.lucasnlm.antimine.ui.ext.toAndroidColor
import dev.lucasnlm.external.IAdsManager
import dev.lucasnlm.external.IAnalyticsManager
import dev.lucasnlm.external.IFeatureFlagManager
import dev.lucasnlm.external.IInstantAppManager
import dev.lucasnlm.external.IPlayGamesManager
import dev.lucasnlm.external.ReviewWrapper
import kotlinx.android.synthetic.main.activity_game.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand All @@ -60,6 +62,9 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
private val savesRepository: ISavesRepository by inject()
private val shareViewModel: ShareManager by inject()
private val playGamesManager: IPlayGamesManager by inject()
private val adsManager: IAdsManager by inject()
private val reviewWrapper: ReviewWrapper by inject()
private val featureFlagManager: IFeatureFlagManager by inject()

private val gameViewModel by viewModel<GameViewModel>()

Expand All @@ -79,6 +84,10 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
super.onCreate(savedInstanceState)
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)

if (!preferencesRepository.isPremiumEnabled()) {
adsManager.start(this)
}

bindViewModel()
bindToolbar()
bindSwitchControlButton()
Expand Down Expand Up @@ -351,6 +360,16 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}
}

private fun startNewGameWithAds() {
if (!preferencesRepository.isPremiumEnabled() && featureFlagManager.isAdsOnNewGameEnabled) {
adsManager.showRewardedAd(this) {
gameViewModel.startNewGame()
}
} else {
gameViewModel.startNewGame()
}
}

private fun refreshRetryShortcut() {
shortcutIcon.apply {
TooltipCompat.setTooltipText(this, getString(R.string.new_game))
Expand All @@ -363,14 +382,10 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O

if (confirmResign) {
newGameConfirmation {
GlobalScope.launch {
gameViewModel.startNewGame()
}
startNewGameWithAds()
}
} else {
GlobalScope.launch {
gameViewModel.startNewGame()
}
startNewGameWithAds()
}
}
}
Expand All @@ -397,6 +412,10 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
savesRepository.setLimit(1)
} else {
preferencesRepository.incrementUseCount()

if (preferencesRepository.getUseCount() > featureFlagManager.minUsageToReview) {
reviewWrapper.startInAppReview(this)
}
}
}

Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import dev.lucasnlm.antimine.tutorial.view.TutorialCompleteDialogFragment
import dev.lucasnlm.antimine.tutorial.view.TutorialLevelFragment
import dev.lucasnlm.antimine.ui.ThematicActivity
import dev.lucasnlm.external.IAnalyticsManager
import dev.lucasnlm.external.IFeatureFlagManager
import dev.lucasnlm.external.IInstantAppManager
import dev.lucasnlm.external.ReviewWrapper
import kotlinx.android.synthetic.main.activity_game.*
Expand All @@ -42,14 +43,11 @@ import org.koin.androidx.viewmodel.ext.android.viewModel

class TvGameActivity : ThematicActivity(R.layout.activity_game_tv), DialogInterface.OnDismissListener {
private val preferencesRepository: IPreferencesRepository by inject()

private val analyticsManager: IAnalyticsManager by inject()

private val instantAppManager: IInstantAppManager by inject()

private val savesRepository: ISavesRepository by inject()

private val reviewWrapper: ReviewWrapper by inject()
private val featureFlagManager: IFeatureFlagManager by inject()

val gameViewModel by viewModel<GameViewModel>()

Expand Down Expand Up @@ -204,8 +202,11 @@ class TvGameActivity : ThematicActivity(R.layout.activity_game_tv), DialogInterf
// Instant App does nothing.
savesRepository.setLimit(1)
} else {
reviewWrapper.startInAppReview(this)
preferencesRepository.incrementUseCount()

if (preferencesRepository.getUseCount() > featureFlagManager.minUsageToReview) {
reviewWrapper.startInAppReview(this)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ class GameOverDialogFragment : AppCompatDialogFragment() {
analyticsManager.sentEvent(Analytics.CloseEndGameScreen)
activity?.let {
if (!it.isFinishing) {
gameViewModel.viewModelScope.launch {
lifecycleScope.launch {
gameViewModel.revealMines()
}
}
}

dismissAllowingStateLoss()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.lucasnlm.antimine.gameover

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
Expand Down Expand Up @@ -32,8 +31,6 @@ import dev.lucasnlm.external.IAnalyticsManager
import dev.lucasnlm.external.IBillingManager
import dev.lucasnlm.external.IFeatureFlagManager
import dev.lucasnlm.external.IInstantAppManager
import dev.lucasnlm.external.ReviewWrapper
import kotlinx.android.synthetic.main.view_play_games_button.view.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
Expand All @@ -49,7 +46,6 @@ class WinGameDialogFragment : AppCompatDialogFragment() {
private val preferencesRepository: IPreferencesRepository by inject()
private val billingManager: IBillingManager by inject()
private val featureFlagManager: IFeatureFlagManager by inject()
private val reviewWrapper: ReviewWrapper by inject()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -74,16 +70,6 @@ class WinGameDialogFragment : AppCompatDialogFragment() {
}
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)

activity?.let {
if (!it.isFinishing) {
reviewWrapper.startInAppReview(it)
}
}
}

fun showAllowingStateLoss(manager: FragmentManager, tag: String?) {
val fragmentTransaction = manager.beginTransaction()
fragmentTransaction.add(this, tag)
Expand Down
58 changes: 30 additions & 28 deletions app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,41 @@ open class LevelFragment : CommonLevelFragment(R.layout.fragment_level) {

private fun centerMinefield(minefield: Minefield) = with(recyclerGrid) {
post {
val singleAreaSize = dimensionRepository.areaSizeWithPadding()
val actionBarSize = dimensionRepository.actionBarSize()
val displayMetrics = DisplayMetrics()
requireActivity().windowManager.defaultDisplay.getRealMetrics(displayMetrics)
val screenHeight = if (context.isAndroidTv()) {
displayMetrics.heightPixels
} else {
displayMetrics.heightPixels - actionBarSize
}
activity?.let {
val singleAreaSize = dimensionRepository.areaSizeWithPadding()
val actionBarSize = dimensionRepository.actionBarSize()
val displayMetrics = DisplayMetrics()
it.windowManager.defaultDisplay.getRealMetrics(displayMetrics)
val screenHeight = if (context.isAndroidTv()) {
displayMetrics.heightPixels
} else {
displayMetrics.heightPixels - actionBarSize
}

val screenWidth = displayMetrics.widthPixels
val boardWidth = singleAreaSize * minefield.width
val boardHeight = singleAreaSize * minefield.height
val screenWidth = displayMetrics.widthPixels
val boardWidth = singleAreaSize * minefield.width
val boardHeight = singleAreaSize * minefield.height

val multiplierY = if (boardHeight > screenHeight) {
(boardHeight / screenHeight - 1) * 0.5
} else {
0.0
}
val multiplierY = if (boardHeight > screenHeight) {
(boardHeight / screenHeight - 1) * 0.5
} else {
0.0
}

val multiplierX = if (boardWidth > screenWidth) {
(boardWidth / screenWidth - 1) * 0.5
} else {
0.0
}
val multiplierX = if (boardWidth > screenWidth) {
(boardWidth / screenWidth - 1) * 0.5
} else {
0.0
}

val dx = (boardWidth - screenWidth).coerceAtLeast(0.0f) * multiplierX
val dy = (boardHeight - screenHeight).coerceAtLeast(0.0f) * multiplierY
val dx = (boardWidth - screenWidth).coerceAtLeast(0.0f) * multiplierX
val dy = (boardHeight - screenHeight).coerceAtLeast(0.0f) * multiplierY

smoothScrollBy(dx.toInt(), dy.toInt(), null, 300)
post {
requestLayout()
focusOnCenterIfNeeded()
smoothScrollBy(dx.toInt(), dy.toInt(), null, 300)
post {
requestLayout()
focusOnCenterIfNeeded()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class AreaAdapter(
MotionEvent.ACTION_DOWN -> {
view.isPressed = true
velocityTracker?.clear()
velocityTracker?.recycle()
velocityTracker = velocityTracker ?: VelocityTracker.obtain()
velocityTracker?.addMovement(motionEvent)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.lucasnlm.antimine.common.level.view

import android.content.Context
import android.util.AttributeSet
import androidx.recyclerview.widget.RecyclerView

class CustomRecyclerView : RecyclerView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

override fun fling(velocityX: Int, velocityY: Int): Boolean {
// Disable fling due to internal runtime issues with Instant App
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -412,23 +412,25 @@ open class GameViewModel(
}

suspend fun revealMines() {
val explosionTime = (explosionDelay() / gameController.getMinesCount().coerceAtLeast(10))
val delayMillis = explosionTime.coerceAtMost(25L)
if (initialized) {
val explosionTime = (explosionDelay() / gameController.getMinesCount().coerceAtLeast(10))
val delayMillis = explosionTime.coerceAtMost(25L)

gameController.run {
showWrongFlags()
refreshField()
gameController.run {
showWrongFlags()
refreshField()

findExplodedMine()?.let { exploded ->
takeExplosionRadius(exploded).take(20).forEach {
revealArea(it.id)
refreshField()
delay(delayMillis)
findExplodedMine()?.let { exploded ->
takeExplosionRadius(exploded).take(20).forEach {
revealArea(it.id)
refreshField()
delay(delayMillis)
}
}
}

showAllMines()
refreshField()
showAllMines()
refreshField()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/main/res/layout-watch/fragment_level.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
<dev.lucasnlm.antimine.common.level.view.CustomRecyclerView
android:id="@+id/recyclerGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/res/layout/fragment_level.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
<dev.lucasnlm.antimine.common.level.view.CustomRecyclerView
android:id="@+id/recyclerGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -18,5 +18,5 @@
android:scrollbars="vertical|horizontal">

<requestFocus />
</androidx.recyclerview.widget.RecyclerView>
</dev.lucasnlm.antimine.common.level.view.CustomRecyclerView>
</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract class IFeatureFlagManager {
abstract val isRecyclerScrollEnabled: Boolean
abstract val isFoos: Boolean
abstract val isThemeTastingEnabled: Boolean
abstract val minUsageToReview: Int

abstract suspend fun refresh()
}
6 changes: 1 addition & 5 deletions foss/src/main/java/dev/lucasnlm/external/BillingManager.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package dev.lucasnlm.external

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import dev.lucasnlm.external.model.PurchaseInfo
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf

class BillingManager(
private val context: Context,
) : IBillingManager {

class BillingManager : IBillingManager {
override fun start() {
// Empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FeatureFlagManager : IFeatureFlagManager() {
override val isRecyclerScrollEnabled: Boolean = true
override val isFoos: Boolean = true
override val isThemeTastingEnabled: Boolean = true
override val minUsageToReview: Int = Int.MAX_VALUE

override suspend fun refresh() {
// No Feature Flags on FOSS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.koin.dsl.module
val ExternalModule = module {
single { InstantAppManager() } bind IInstantAppManager::class

single { BillingManager(get()) } bind IBillingManager::class
single { BillingManager() } bind IBillingManager::class

single { PlayGamesManager(get()) } bind IPlayGamesManager::class

Expand Down
Loading

0 comments on commit 369bc17

Please sign in to comment.