From 478a48834855891a2b7537b3a1c4f2cde8e87c0a Mon Sep 17 00:00:00 2001 From: Maksym H Date: Mon, 12 Jun 2023 21:14:29 +0300 Subject: [PATCH] Android: minor update (cherry picked from commit d2408a9324f08fde9cb109490bf8fbf04f748531) --- Android/app/build.gradle | 25 +++++++++++-------- .../game/helpers/UsefulExtensions.kt | 17 ++++++------- .../src/main/res/layout/restart_dialog.xml | 3 ++- Android/app/src/main/res/values/styles.xml | 4 +-- Android/build.gradle | 4 +-- Android/native/build.gradle | 8 +++--- Android/native/jni/Android.mk | 1 - 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Android/app/build.gradle b/Android/app/build.gradle index 1a7ad64e9..c4da0a6d0 100644 --- a/Android/app/build.gradle +++ b/Android/app/build.gradle @@ -47,6 +47,7 @@ android { abi { enable true reset() + //noinspection ChromeOsAbiSupport include 'armeabi-v7a', 'arm64-v8a', 'x86_64' } } @@ -66,7 +67,7 @@ android { import org.apache.tools.ant.taskdefs.condition.Os -task prepareAssetsFiles() { +tasks.register('prepareAssetsFiles') { def assetsFolder = "build/assets/Files" def projRoot = "../.." @@ -94,20 +95,22 @@ task prepareAssetsFiles() { copy { from "${projRoot}/textures" into "${assetsFolder}/textures" exclude '*.txt' } - - task zipAssetsFiles(type: Zip) { - archiveFileName = "Files.zip" - destinationDirectory = file("src/main/assets/data") - - from "${assetsFolder}" - } } -preBuild.dependsOn zipAssetsFiles +tasks.register('zipAssetsFiles', Zip) { + dependsOn prepareAssetsFiles + archiveFileName = 'assets.zip' + destinationDirectory = file('src/main/assets/data') + from('build/assets/Files') +} + +tasks.named("preBuild") { + dependsOn(zipAssetsFiles) +} // Map for the version code that gives each ABI a value. def abiCodes = ['armeabi-v7a': 0, 'arm64-v8a': 1, 'x86_64': 2] -android.applicationVariants.all { variant -> +android.applicationVariants.configureEach { variant -> variant.outputs.each { output -> def abiName = output.filters[0].identifier @@ -124,5 +127,5 @@ dependencies { implementation 'androidx.appcompat:appcompat-resources:1.6.1' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' implementation 'androidx.work:work-runtime-ktx:2.8.1' - implementation 'com.google.android.material:material:1.8.0' + implementation 'com.google.android.material:material:1.9.0' } diff --git a/Android/app/src/main/java/com/multicraft/game/helpers/UsefulExtensions.kt b/Android/app/src/main/java/com/multicraft/game/helpers/UsefulExtensions.kt index 06d5d54d0..966541f2b 100644 --- a/Android/app/src/main/java/com/multicraft/game/helpers/UsefulExtensions.kt +++ b/Android/app/src/main/java/com/multicraft/game/helpers/UsefulExtensions.kt @@ -30,6 +30,7 @@ import android.provider.Settings import android.view.View import android.view.Window import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.view.* import com.multicraft.game.R @@ -41,7 +42,7 @@ import java.io.InputStream import kotlin.system.exitProcess // Activity extensions -fun Activity.getIcon() = try { +fun AppCompatActivity.getIcon() = try { packageManager.getApplicationIcon(packageName) } catch (e: PackageManager.NameNotFoundException) { ContextCompat.getDrawable(this, R.mipmap.ic_launcher) @@ -63,7 +64,7 @@ fun Activity.finishApp(restart: Boolean) { exitProcess(0) } -fun Activity.defaultDialog(title: Int, view: View, style: Int = R.style.CustomDialog): AlertDialog { +fun AppCompatActivity.defaultDialog(title: Int, view: View, style: Int = R.style.CustomDialog): AlertDialog { val builder = AlertDialog.Builder(this, style) .setIcon(getIcon()) .setTitle(title) @@ -72,7 +73,7 @@ fun Activity.defaultDialog(title: Int, view: View, style: Int = R.style.CustomDi return builder.create() } -fun Activity.headlessDialog( +fun AppCompatActivity.headlessDialog( view: View, style: Int = R.style.LightTheme, isCancelable: Boolean = false @@ -83,16 +84,15 @@ fun Activity.headlessDialog( return builder.create() } -fun Activity.show(dialog: AlertDialog) { +fun AppCompatActivity.show(dialog: AlertDialog) { window?.makeFullScreen() if (!isFinishing) dialog.show() } -fun Activity.showConnectionDialog(listener: (() -> Unit)? = null) { +fun AppCompatActivity.showConnectionDialog(listener: (() -> Unit)? = null) { val binding = ConnDialogBinding.inflate(layoutInflater) val dialog = defaultDialog(R.string.conn_title, binding.root) binding.wifi.setOnClickListener { - @Suppress("DEPRECATION") dialog.dismiss() startActivityForResult( Intent(Settings.ACTION_WIFI_SETTINGS), @@ -100,7 +100,6 @@ fun Activity.showConnectionDialog(listener: (() -> Unit)? = null) { ) } binding.mobile.setOnClickListener { - @Suppress("DEPRECATION") dialog.dismiss() startActivityForResult( Intent(Settings.ACTION_WIRELESS_SETTINGS), @@ -114,7 +113,7 @@ fun Activity.showConnectionDialog(listener: (() -> Unit)? = null) { show(dialog) } -fun Activity.showRestartDialog(isRestart: Boolean = true) { +fun AppCompatActivity.showRestartDialog(isRestart: Boolean = true) { val message = if (isRestart) getString(R.string.restart) else getString(R.string.no_space) val binding = RestartDialogBinding.inflate(layoutInflater) @@ -125,7 +124,7 @@ fun Activity.showRestartDialog(isRestart: Boolean = true) { show(dialog) } -fun Activity.isConnected(): Boolean { +fun AppCompatActivity.isConnected(): Boolean { val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager if (ApiLevelHelper.isMarshmallow()) { val activeNetwork = cm.activeNetwork ?: return false diff --git a/Android/app/src/main/res/layout/restart_dialog.xml b/Android/app/src/main/res/layout/restart_dialog.xml index efec7cd59..304f9040e 100644 --- a/Android/app/src/main/res/layout/restart_dialog.xml +++ b/Android/app/src/main/res/layout/restart_dialog.xml @@ -1,5 +1,6 @@ @@ -35,7 +36,7 @@ android:paddingTop="4dp" android:paddingEnd="12dp" android:paddingBottom="4dp" - android:src="@drawable/sad" /> + app:srcCompat="@drawable/sad" /> @drawable/bg_common - @android:color/transparent + @android:color/transparent 0% 0%