Add instant app install button

This commit is contained in:
Lucas Lima 2020-03-08 17:48:44 -03:00
parent 7fbf425ddf
commit ea1514ea41
No known key found for this signature in database
GPG key ID: C828A958035D9C34
8 changed files with 49 additions and 4 deletions

View file

@ -15,6 +15,7 @@ android {
versionCode 45
versionName '6.1.0'
vectorDrawables.useSupportLibrary true
resConfigs 'en', 'pt', 'es', 'zh'
}

View file

@ -22,6 +22,7 @@ import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.preference.PreferenceManager
import com.google.android.gms.instantapps.InstantApps
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.UpdateAvailability
@ -85,7 +86,11 @@ class GameActivity : DaggerAppCompatActivity() {
checkUpdate()
}
checkUseCount()
if (InstantApps.getPackageManagerCompat(this).isInstantApp) {
bindInstantApp()
} else {
checkUseCount()
}
}
private fun bindViewModel() = viewModel.apply {
@ -486,6 +491,15 @@ class GameActivity : DaggerAppCompatActivity() {
}
}
private fun bindInstantApp() {
findViewById<View>(R.id.install).apply {
visibility = View.VISIBLE
setOnClickListener {
InstantApps.showInstallPrompt(this@GameActivity, null, IA_REQUEST_CODE, IA_REFERRER)
}
}
}
private fun openRateUsLink(from: String) {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName")))
@ -503,9 +517,12 @@ class GameActivity : DaggerAppCompatActivity() {
}
companion object {
const val TAG = "GameActivity"
val TAG = GameActivity::class.simpleName
const val PREFERENCE_FIRST_USE = "preference_first_use"
const val PREFERENCE_USE_COUNT = "preference_use_count"
const val PREFERENCE_REQUEST_RATING = "preference_request_rating"
const val IA_REFERRER = "InstallApiActivity"
const val IA_REQUEST_CODE = 5
}
}

View file

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
</vector>

View file

@ -58,7 +58,8 @@
android:textStyle="bold"
android:text="@string/default_time_value"
tools:visibility="visible"
tools:text="10:00" />
tools:text="10:00"
tools:targetApi="m" />
<TextView
android:id="@+id/minesCount"
@ -77,7 +78,8 @@
android:textStyle="bold"
android:visibility="gone"
tools:visibility="visible"
tools:text="99" />
tools:text="99"
tools:targetApi="m" />
</LinearLayout>
@ -87,6 +89,22 @@
android:layout_height="match_parent"
android:layout_below="@+id/toolbar" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/install"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/install"
android:layout_margin="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="gone"
app:backgroundTint="@color/accent"
app:pressedTranslationZ="6dp"
app:elevation="10dp"
app:srcCompat="@drawable/install"
tools:visibility="visible"/>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -3,6 +3,7 @@
<string name="app_name">Anti-Mine</string>
<string name="app_description">Deshabilitar las minas ocultas del campo de minas.</string>
<string name="remaining_mines">Minas Restantes</string>
<string name="install">Instalar</string>
<string name="levelSetup">Dificultad</string>
<string name="standard">Estándar</string>
<string name="beginner">Principiante</string>

View file

@ -3,6 +3,7 @@
<string name="app_name">Anti-Mine</string>
<string name="app_description">Encontre todas as minas escondidas no campo minado.</string>
<string name="remaining_mines">Minas Restantes</string>
<string name="install">Instalar</string>
<string name="levelSetup">Dificuldade</string>
<string name="standard">Padrão</string>
<string name="beginner">Iniciante</string>

View file

@ -3,6 +3,7 @@
<string name="app_name">反雷 - 扫雷</string>
<string name="app_description">你需要清除一个隐藏着地雷的矩形面板,不能使任何地雷爆炸。</string>
<string name="remaining_mines">剩余地雷</string>
<string name="install">安装</string>
<string name="levelSetup">难度</string>
<string name="standard">标准</string>
<string name="beginner">初级</string>

View file

@ -3,6 +3,7 @@
<string name="app_name">Anti-Mine</string>
<string name="app_description">You have to clear a rectangular board containing hidden "mines" without detonating any of them.</string>
<string name="remaining_mines">Remaining mines</string>
<string name="install">Install</string>
<string name="levelSetup">Difficulty</string>
<string name="standard">Standard</string>
<string name="beginner">Beginner</string>