Skip to content

Commit

Permalink
Merge pull request #164 from lucasnlm/update-instant-app
Browse files Browse the repository at this point in the history
Update instant app
  • Loading branch information
lucasnlm authored Sep 1, 2020
2 parents 31b3828 + 388409a commit c6555a7
Show file tree
Hide file tree
Showing 76 changed files with 439 additions and 678 deletions.
14 changes: 10 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 800061
versionName '8.0.6'
versionCode 800081
versionName '8.0.8'
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled true
Expand Down Expand Up @@ -76,6 +76,11 @@ android {
applicationId 'dev.lucasnlm.antimine'
}

googleInstant {
dimension 'version'
applicationId 'dev.lucasnlm.antimine'
}

foss {
dimension 'version'
// There's a typo on F-Droid release :(
Expand All @@ -96,6 +101,7 @@ dependencies {
implementation project(':common')

googleImplementation project(':proprietary')
googleInstantImplementation project(':proprietary')
fossImplementation project(':foss')

// AndroidX
Expand All @@ -115,7 +121,7 @@ dependencies {
implementation 'androidx.room:room-ktx:2.2.5'

// Constraint
implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'

// Google
implementation 'com.google.android.material:material:1.2.0'
Expand All @@ -142,7 +148,7 @@ dependencies {
testImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
testImplementation 'androidx.fragment:fragment-testing:1.2.5'
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation 'androidx.test.ext:junit:1.1.1'
testImplementation 'androidx.test.ext:junit:1.1.2'
testImplementation 'io.mockk:mockk:1.10.0'

// Core library
Expand Down
15 changes: 0 additions & 15 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,6 @@
</intent-filter>
</activity>

<activity
android:name="dev.lucasnlm.antimine.TvGameActivity"
android:configChanges="screenSize|orientation"
android:theme="@style/AppTheme.NoActionBar">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN"/>-->
<!-- <category android:name="android.intent.category.LAUNCHER"/>-->
<!-- </intent-filter>-->

<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LEANBACK_LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>

<activity
android:name="dev.lucasnlm.antimine.text.TextActivity"
android:theme="@style/AppTheme">
Expand Down
125 changes: 59 additions & 66 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
drawer.closeDrawer(GravityCompat.START)
gameViewModel.resumeGame()
}
status == Status.Running && instantAppManager.isEnabled(applicationContext) -> showQuitConfirmation {
super.onBackPressed()
}
else -> super.onBackPressed()
}
}
Expand Down Expand Up @@ -234,35 +231,51 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
)
}

private fun refreshNewGameButton() {
newGame.apply {
TooltipCompat.setTooltipText(this, getString(R.string.new_game))
setColorFilter(minesCount.currentTextColor)
setOnClickListener {
lifecycleScope.launch {
val confirmResign = status == Status.Running
analyticsManager.sentEvent(Analytics.TapGameReset(confirmResign))

if (confirmResign) {
newGameConfirmation {
private fun refreshShortcutIcon(isEndGame: Boolean = false) {
if (isEndGame || instantAppManager.isEnabled(this)) {
shortcutIcon.apply {
TooltipCompat.setTooltipText(this, getString(R.string.new_game))
setImageResource(R.drawable.retry)
setColorFilter(minesCount.currentTextColor)
setOnClickListener {
lifecycleScope.launch {
val confirmResign = status == Status.Running
analyticsManager.sentEvent(Analytics.TapGameReset(confirmResign))

if (confirmResign) {
newGameConfirmation {
GlobalScope.launch {
gameViewModel.startNewGame()
}
}
} else {
GlobalScope.launch {
gameViewModel.startNewGame()
}
}
} else {
GlobalScope.launch {
gameViewModel.startNewGame()
}
}
}
}
} else {
shortcutIcon.apply {
TooltipCompat.setTooltipText(this, getString(R.string.share))
setImageResource(R.drawable.share)
setColorFilter(minesCount.currentTextColor)
setOnClickListener {
shareCurrentGame()
}
}
}

visibility = when (status) {
shortcutIcon.apply {
when (status) {
is Status.Over, is Status.Running -> {
View.VISIBLE
isClickable = true
animate().alpha(1.0f).start()
}
else -> {
View.GONE
isClickable = false
animate().alpha(0.3f).start()
}
}
}
Expand Down Expand Up @@ -332,7 +345,6 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
R.id.share_now -> shareCurrentGame()
R.id.previous_games -> openSaveHistory()
R.id.stats -> openStats()
R.id.install_new -> installFromInstantApp()
R.id.play_games -> googlePlay()
else -> handled = false
}
Expand All @@ -354,7 +366,6 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
private fun onOpenAppActions() {
if (instantAppManager.isEnabled(applicationContext)) {
// Instant App does nothing.
bindInstantApp()
savesRepository.setLimit(1)
} else {
val current = preferencesRepository.getUseCount()
Expand Down Expand Up @@ -418,15 +429,6 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}
}

private fun showQuitConfirmation(action: () -> Unit) {
AlertDialog.Builder(this)
.setTitle(R.string.are_you_sure)
.setMessage(R.string.quit_confirm)
.setPositiveButton(R.string.quit) { _, _ -> action() }
.setNeutralButton(R.string.install) { _, _ -> installFromInstantApp() }
.show()
}

private fun showCustomLevelDialog() {
if (supportFragmentManager.findFragmentByTag(CustomLevelDialogFragment.TAG) == null) {
CustomLevelDialogFragment().apply {
Expand Down Expand Up @@ -528,19 +530,20 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
when (event) {
Event.ResumeGame -> {
status = Status.Running
refreshNewGameButton()
refreshShortcutIcon()
}
Event.StartNewGame -> {
status = Status.PreGame
refreshNewGameButton()
refreshShortcutIcon()
}
Event.Resume, Event.Running -> {
status = Status.Running
gameViewModel.runClock()
refreshNewGameButton()
refreshShortcutIcon()
keepScreenOn(true)
}
Event.Victory -> {
val isResuming = (status == Status.PreGame)
val score = Score(
rightMines,
totalMines,
Expand All @@ -550,12 +553,15 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
gameViewModel.stopClock()
gameViewModel.revealAllEmptyAreas()
gameViewModel.victory()
refreshNewGameButton()
refreshShortcutIcon(true)
keepScreenOn(false)
waitAndShowEndGameDialog(
victory = true,
await = false
)

if (!isResuming) {
waitAndShowEndGameDialog(
victory = true,
await = false
)
}
}
Event.GameOver -> {
val isResuming = (status == Status.PreGame)
Expand All @@ -565,16 +571,18 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
totalArea
)
status = Status.Over(currentTime, score)
refreshNewGameButton()
refreshShortcutIcon(true)
keepScreenOn(false)
gameViewModel.stopClock()

GlobalScope.launch(context = Dispatchers.Main) {
gameViewModel.gameOver(isResuming)
waitAndShowEndGameDialog(
victory = false,
await = true
)
if (!isResuming) {
GlobalScope.launch(context = Dispatchers.Main) {
gameViewModel.gameOver(isResuming)
waitAndShowEndGameDialog(
victory = false,
await = true
)
}
}
}
else -> { }
Expand All @@ -588,7 +596,9 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
private fun restartIfNeed(): Boolean {
return (areaSizeMultiplier != preferencesRepository.areaSizeMultiplier()).also {
if (it) {
recreate()
finish()
startActivity(intent)
overridePendingTransition(0, 0)
}
}
}
Expand All @@ -601,21 +611,6 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}
}

private fun bindInstantApp() {
findViewById<View>(R.id.install).apply {
visibility = View.VISIBLE
setOnClickListener {
installFromInstantApp()
}
}

navigationView.menu.setGroupVisible(R.id.install_group, true)
}

private fun installFromInstantApp() {
instantAppManager.showInstallPrompt(this@GameActivity, null, IA_REQUEST_CODE, IA_REFERRER)
}

private fun openRateUsLink() {
reviewWrapper.startReviewPage(this, BuildConfig.VERSION_NAME)
analyticsManager.sentEvent(Analytics.TapRatingRequest)
Expand Down Expand Up @@ -664,7 +659,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O

private fun showSupportAppDialog() {
if (supportFragmentManager.findFragmentByTag(SupportAppDialogFragment.TAG) == null) {
SupportAppDialogFragment.newInstance(false)
SupportAppDialogFragment.newRequestSupportDialog()
.show(supportFragmentManager, SupportAppDialogFragment.TAG)
}
}
Expand All @@ -679,8 +674,6 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}

companion object {
const val IA_REFERRER = "InstallApiActivity"
const val IA_REQUEST_CODE = 5
const val GOOGLE_PLAY_REQUEST_CODE = 6

const val MIN_USAGES_TO_IAP = 5
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import dev.lucasnlm.antimine.core.analytics.models.Analytics
import dev.lucasnlm.antimine.core.di.CommonModule
import dev.lucasnlm.antimine.di.AppModule
import dev.lucasnlm.antimine.di.ViewModelModule
import dev.lucasnlm.external.IAdsManager
import org.koin.android.ext.android.inject
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin

open class MainApplication : MultiDexApplication() {
private val analyticsManager: IAnalyticsManager by inject()

private val adsManager: IAdsManager by inject()

override fun onCreate() {
super.onCreate()
startKoin {
Expand All @@ -25,5 +28,7 @@ open class MainApplication : MultiDexApplication() {
setup(applicationContext, mapOf())
sentEvent(Analytics.Open)
}

adsManager.start(applicationContext)
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ open class ThematicActivity(@LayoutRes contentLayoutId: Int) : AppCompatActivity
super.onResume()

if (usingTheme.id != currentTheme().id) {
recreate()
finish()
startActivity(intent)
overridePendingTransition(0, 0)
}
}
}
Loading

0 comments on commit c6555a7

Please sign in to comment.