From 3aa2f5ff6a9af023be7f788448ac5a0e5040a1f2 Mon Sep 17 00:00:00 2001 From: Teodor Grigor Date: Tue, 20 Aug 2024 16:58:09 +0300 Subject: [PATCH 1/2] Remove deprecated elements from codebase --- .../teogor/drifter/plugin/UnityBuildTask.kt | 42 ++- .../drifter/plugin/UnityNativeBuildTask.kt | 3 +- gradle/libs.versions.toml | 2 + integration/api/integration.api | 69 ----- .../drifter/integration/core/SharedElement.kt | 43 --- .../drifter/integration/core/Storage.kt | 34 --- .../integration/core/UnityControllerBase.kt | 36 --- .../integration/core/UnityStorageBase.kt | 81 ----- .../drifter/integration/core/Validator.kt | 96 ------ .../drifter/integration/model/Vector2.kt | 1 + .../drifter/integration/model/Vector3.kt | 29 -- .../integration/utilities/UnityVersionInfo.kt | 2 +- .../java/com/unity3d/player/UnityPlayer.java | 12 +- .../player/utils/PhoneStateChangeListener.kt | 3 +- wallpaper/api/wallpaper.api | 3 + wallpaper/build.gradle.kts | 1 + .../wallpaper/LiveWallpaperUnityFacade.kt | 282 +++++++++--------- .../wallpaper/UnityWallpaperService.kt | 10 +- ...eWallpaperCompatibleUnityPlayerActivity.kt | 2 +- 19 files changed, 196 insertions(+), 555 deletions(-) delete mode 100644 integration/src/main/kotlin/dev/teogor/drifter/integration/core/SharedElement.kt delete mode 100644 integration/src/main/kotlin/dev/teogor/drifter/integration/core/Storage.kt delete mode 100644 integration/src/main/kotlin/dev/teogor/drifter/integration/core/UnityControllerBase.kt delete mode 100644 integration/src/main/kotlin/dev/teogor/drifter/integration/core/UnityStorageBase.kt delete mode 100644 integration/src/main/kotlin/dev/teogor/drifter/integration/core/Validator.kt delete mode 100644 integration/src/main/kotlin/dev/teogor/drifter/integration/model/Vector3.kt diff --git a/gradle-plugin/src/main/kotlin/dev/teogor/drifter/plugin/UnityBuildTask.kt b/gradle-plugin/src/main/kotlin/dev/teogor/drifter/plugin/UnityBuildTask.kt index 0c56249..a3a59c0 100644 --- a/gradle-plugin/src/main/kotlin/dev/teogor/drifter/plugin/UnityBuildTask.kt +++ b/gradle-plugin/src/main/kotlin/dev/teogor/drifter/plugin/UnityBuildTask.kt @@ -19,6 +19,7 @@ package dev.teogor.drifter.plugin import com.android.build.api.dsl.CommonExtension import dev.teogor.drifter.plugin.models.UnityOptions import org.gradle.api.Project +import java.util.Locale @OptIn(InternalDrifterApi::class) fun Project.unityBuildTask( @@ -57,14 +58,18 @@ fun Project.unityBuildTask( } afterEvaluate { - if (project(path).tasks.findByName("mergeDebugJniLibFolders") != null) { - project(path).tasks.named("mergeDebugJniLibFolders").get() - .dependsOn(unityNativeBuildTask) - } - if (project(path).tasks.findByName("mergeReleaseJniLibFolders") != null) { - project(path).tasks.named("mergeReleaseJniLibFolders").get() - .dependsOn(unityNativeBuildTask) + val buildTypeTaskNames = commonExtension.buildTypes.map { + val formattedBuildType = it.name.splitCamelCase().toTitleCase() + formattedBuildType } + + buildTypeTaskNames + .mapNotNull { formattedName -> + project(path).tasks.named("merge${formattedName}JniLibFolders").getOrNull() + } + .forEach { task -> + task.dependsOn(unityNativeBuildTask) + } } androidResources { @@ -86,3 +91,26 @@ fun Project.unityBuildTask( } } } + +/** + * Splits a camel case string into separate words. + */ +private fun String.splitCamelCase(): String { + return this.replace(Regex("([a-z])([A-Z])"), "$1 $2") +} + +/** + * Converts a string to title case. + * + * Title case means that the first character of each word is capitalized. + * + * @return The string in title case. + */ +private fun String.toTitleCase(): String { + return this.split(" ").joinToString(" ") { word -> + word.replaceFirstChar { char -> + if (char.isLowerCase()) char.titlecase(Locale.getDefault()) + else char.toString() + } + } +} diff --git a/gradle-plugin/src/main/kotlin/dev/teogor/drifter/plugin/UnityNativeBuildTask.kt b/gradle-plugin/src/main/kotlin/dev/teogor/drifter/plugin/UnityNativeBuildTask.kt index b519678..8a80c12 100644 --- a/gradle-plugin/src/main/kotlin/dev/teogor/drifter/plugin/UnityNativeBuildTask.kt +++ b/gradle-plugin/src/main/kotlin/dev/teogor/drifter/plugin/UnityNativeBuildTask.kt @@ -27,6 +27,7 @@ import org.gradle.api.file.CopySpec import org.gradle.api.file.DeleteSpec import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskExecutionException +import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.register import org.gradle.process.ExecSpec @@ -69,7 +70,7 @@ open class UnityNativeBuildTask : DefaultTask() { val configuration = options.configuration.value val staticLibraries = emptyArray() - val android = project.extensions.getByType(AndroidComponents::class.java) + val android = project.extensions.getByType() val sdkComponents = android.sdkComponents options.platforms.forEach { architecture -> diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 69d6152..d208b39 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,6 +18,7 @@ junit4 = "4.13.2" hilt = "2.51.1" hiltExt = "1.2.0" +preference = "1.2.1" teogor-winds = "1.0.2" teogor-ceres = "1.0.0-alpha04" @@ -86,6 +87,7 @@ ceres-monetisation-admob = { group = "dev.teogor.ceres", name = "monetisation-ad ceres-monetisation-messaging = { group = "dev.teogor.ceres", name = "monetisation-messaging" } buildconfig-plugin = { module = "com.github.gmazzo:gradle-buildconfig-pluginn", version.ref = "buildConfig" } +androidx-preference = { module = "androidx.preference:preference", version.ref = "preference" } androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "annotation" } androidx-startup-runtime = { module = "androidx.startup:startup-runtime", version.ref = "startup-runtime" } core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" } diff --git a/integration/api/integration.api b/integration/api/integration.api index 159441c..95cd236 100644 --- a/integration/api/integration.api +++ b/integration/api/integration.api @@ -69,32 +69,9 @@ public final class dev/teogor/drifter/integration/core/PlayerPrefs$Companion { public final fun getInstance ()Ldev/teogor/drifter/integration/core/PlayerPrefs; } -public class dev/teogor/drifter/integration/core/SharedElement { - public field content Ljava/lang/Object; - protected fun ()V - public fun (Ljava/lang/Object;)V - public final fun getContent ()Ljava/lang/Object; - public final fun getInstance ()Ldev/teogor/drifter/integration/core/SharedElement; - public final fun getObject (Ljava/lang/String;)Ljava/lang/Object; - public final fun setContent (Ljava/lang/Object;)V - public final fun toJson ()Ljava/lang/String; -} - -public class dev/teogor/drifter/integration/core/Storage { - public fun ()V - public final fun getStorageElement (Ljava/lang/String;)Ljava/lang/String; - protected final fun value (Ljava/lang/Object;)Ljava/lang/String; - protected final fun writeElement (Ljava/lang/String;Ljava/lang/String;)V -} - public abstract interface annotation class dev/teogor/drifter/integration/core/UnityCallback : java/lang/annotation/Annotation { } -public class dev/teogor/drifter/integration/core/UnityControllerBase { - public fun (Ljava/lang/String;)V - public final fun invokeAction (Ljava/lang/String;Lorg/json/JSONObject;)V -} - public final class dev/teogor/drifter/integration/core/UnityDispatcher { public fun (Ljava/lang/String;Ljava/lang/String;Ldev/teogor/drifter/integration/core/Message;)V public final fun getFunctionName ()Ljava/lang/String; @@ -102,33 +79,6 @@ public final class dev/teogor/drifter/integration/core/UnityDispatcher { public final fun getGameObject ()Ljava/lang/String; } -public class dev/teogor/drifter/integration/core/UnityStorageBase { - public fun ()V - protected fun getStorageElement (Ljava/lang/String;Ljava/lang/Object;Ldev/teogor/drifter/integration/common/TypeConverter;)Ljava/lang/Object; - public static synthetic fun getStorageElement$default (Ldev/teogor/drifter/integration/core/UnityStorageBase;Ljava/lang/String;Ljava/lang/Object;Ldev/teogor/drifter/integration/common/TypeConverter;ILjava/lang/Object;)Ljava/lang/Object; - protected fun writeElement (Ljava/lang/String;Ljava/lang/Object;Ldev/teogor/drifter/integration/common/TypeConverter;)Ljava/lang/Object; - public static synthetic fun writeElement$default (Ldev/teogor/drifter/integration/core/UnityStorageBase;Ljava/lang/String;Ljava/lang/Object;Ldev/teogor/drifter/integration/common/TypeConverter;ILjava/lang/Object;)Ljava/lang/Object; -} - -public final class dev/teogor/drifter/integration/core/Validator { - public static final field Companion Ldev/teogor/drifter/integration/core/Validator$Companion; - public fun ()V - public final fun dataChangedRead ()V - public final fun getContext ()Landroid/content/Context; - public final fun getStorageElement (Ljava/lang/String;)Ljava/lang/String; - public final fun getStorageElement (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public final fun isDataChanged ()Z - public final fun markAsRead (Ljava/lang/String;)V - public final fun setDataChanged ()V - public final fun toast (Ljava/lang/String;)V - public final fun writeElement (Ljava/lang/String;I)V - public final fun writeElement (Ljava/lang/String;Ljava/lang/String;)V -} - -public final class dev/teogor/drifter/integration/core/Validator$Companion { - public final fun getInstance ()Ldev/teogor/drifter/integration/core/Validator; -} - public final class dev/teogor/drifter/integration/initializer/ActivityContextProvider { public static final field INSTANCE Ldev/teogor/drifter/integration/initializer/ActivityContextProvider; public final fun getApplicationContext ()Landroid/content/Context; @@ -159,25 +109,6 @@ public final class dev/teogor/drifter/integration/model/Vector2$Companion { public final fun asVector (Landroid/view/MotionEvent;)Ldev/teogor/drifter/integration/model/Vector2; } -public final class dev/teogor/drifter/integration/model/Vector3 { - public fun (FFF)V - public final fun asSharedElement ()Ldev/teogor/drifter/integration/core/SharedElement; - public final fun component1 ()F - public final fun component2 ()F - public final fun component3 ()F - public final fun copy (FFF)Ldev/teogor/drifter/integration/model/Vector3; - public static synthetic fun copy$default (Ldev/teogor/drifter/integration/model/Vector3;FFFILjava/lang/Object;)Ldev/teogor/drifter/integration/model/Vector3; - public fun equals (Ljava/lang/Object;)Z - public final fun getX ()F - public final fun getY ()F - public final fun getZ ()F - public fun hashCode ()I - public final fun setX (F)V - public final fun setY (F)V - public final fun setZ (F)V - public fun toString ()Ljava/lang/String; -} - public final class dev/teogor/drifter/integration/player/UnityPlayerHolder { public fun (Ldev/teogor/drifter/integration/player/UnityPlayerPauseResumeManager;)V public final fun isVisible ()Z diff --git a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/SharedElement.kt b/integration/src/main/kotlin/dev/teogor/drifter/integration/core/SharedElement.kt deleted file mode 100644 index f11b12d..0000000 --- a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/SharedElement.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2023 teogor (Teodor Grigor) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.teogor.drifter.integration.core - -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken - -@Deprecated("to be removed later on") -open class SharedElement { - lateinit var content: T - - constructor(content: T) { - this.content = content - } - - protected constructor() - - val instance: SharedElement - get() = SharedElement() - - fun getObject(jsonString: String?): T { - val collectionType = object : TypeToken?>() {}.type - return Gson().fromJson(jsonString, collectionType) - } - - fun toJson(): String { - return Gson().toJson(this) - } -} diff --git a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/Storage.kt b/integration/src/main/kotlin/dev/teogor/drifter/integration/core/Storage.kt deleted file mode 100644 index c0af1b8..0000000 --- a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/Storage.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2023 teogor (Teodor Grigor) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.teogor.drifter.integration.core - -// todo same as UnityStorage -@Deprecated("to be removed later on") -open class Storage { - protected fun value(param: T): String { - return SharedElement(param).toJson() - } - - protected fun writeElement(key: String, content: String?) { - Validator.instance.writeElement(key, content) - Validator.instance.setDataChanged() - } - - fun getStorageElement(element: String): String? { - return Validator.instance.getStorageElement(element) - } -} diff --git a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/UnityControllerBase.kt b/integration/src/main/kotlin/dev/teogor/drifter/integration/core/UnityControllerBase.kt deleted file mode 100644 index a9f3e51..0000000 --- a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/UnityControllerBase.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2023 teogor (Teodor Grigor) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.teogor.drifter.integration.core - -import dev.teogor.drifter.unity.common.LocalUnityEngine -import org.json.JSONObject - -@Deprecated( - message = "This class is deprecated in favor of UnityMessageSender. Please migrate to the newer class for improved access and functionality.", - replaceWith = ReplaceWith( - "UnityMessageSender", - "dev.teogor.drifter.common.UnityMessageSender", - ), -) -open class UnityControllerBase( - private val receiver: String, -) { - - fun invokeAction(methodName: String, data: JSONObject) { - LocalUnityEngine.current.sendMessage(receiver, methodName, data.toString()) - } -} diff --git a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/UnityStorageBase.kt b/integration/src/main/kotlin/dev/teogor/drifter/integration/core/UnityStorageBase.kt deleted file mode 100644 index 7c74402..0000000 --- a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/UnityStorageBase.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2023 teogor (Teodor Grigor) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.teogor.drifter.integration.core - -import dev.teogor.drifter.integration.common.TypeConverter - -@Deprecated( - message = "This class is deprecated in favor of UnityPlayerPrefs. Please migrate to the newer class for improved access and functionality.", - replaceWith = ReplaceWith( - "UnityPlayerPrefs", - "dev.teogor.drifter.common.UnityPlayerPrefs", - ), -) -open class UnityStorageBase { - protected open fun writeElement( - key: String, - content: T, - converter: TypeConverter? = null, - ): T { - when { - converter != null -> PlayerPrefs.instance.setString( - key = key, - value = converter.convertToString(content), - ) - - content is String -> PlayerPrefs.instance.setString( - key = key, - value = content, - ) - - content is Int -> PlayerPrefs.instance.setInt( - key = key, - value = content, - ) - - else -> throw IllegalArgumentException("Invalid type for content") - } - return content - } - - @Suppress("UNCHECKED_CAST") - @UnityCallback - protected open fun getStorageElement( - key: String, - defaultValue: T, - converter: TypeConverter? = null, - ): T { - return when { - converter != null -> PlayerPrefs.instance.getString( - key = key, - defValue = null, - )?.let { converter.convertFromString(it) } ?: defaultValue - - defaultValue is String -> PlayerPrefs.instance.getString( - key = key, - defValue = defaultValue, - ) as? T ?: defaultValue - - defaultValue is Int -> PlayerPrefs.instance.getInt( - key = key, - defValue = defaultValue, - ) as? T ?: defaultValue - - else -> defaultValue - } - } -} diff --git a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/Validator.kt b/integration/src/main/kotlin/dev/teogor/drifter/integration/core/Validator.kt deleted file mode 100644 index a01515d..0000000 --- a/integration/src/main/kotlin/dev/teogor/drifter/integration/core/Validator.kt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2023 teogor (Teodor Grigor) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.teogor.drifter.integration.core - -import android.content.Context -import android.widget.Toast -import dev.teogor.drifter.integration.initializer.ActivityContextProvider.applicationContext - -@Deprecated("to be removed later on") -class Validator { - @get:UnityCallback - var isDataChanged = false - private set - - @UnityCallback - fun dataChangedRead() { - isDataChanged = false - } - - @UnityCallback - fun setDataChanged() { - isDataChanged = true - } - - @get:UnityCallback - val context: Context? - get() = try { - applicationContext - } catch (ignored: Exception) { - null - } - - @UnityCallback - fun markAsRead(element: String) { - writeElement(element, null) - } - - @UnityCallback - fun getStorageElement(key: String): String? { - return PlayerPrefs.instance.getString( - key, - null, - ) - } - - @Suppress("UNCHECKED_CAST") - @UnityCallback - fun getStorageElement( - key: String, - defaultValue: T, - ): T { - return when (defaultValue) { - is Int -> PlayerPrefs.instance.getInt( - key, - defaultValue, - ) as? T ?: defaultValue - else -> throw RuntimeException("Invalid t format") - } - } - - @UnityCallback - fun toast(content: String?) { - Toast.makeText(context, content, Toast.LENGTH_SHORT).show() - } - - fun writeElement(key: String, content: String?) { - PlayerPrefs.instance.setString(key, content) - } - - fun writeElement(key: String, content: Int) { - PlayerPrefs.instance.setInt(key, content) - } - - companion object { - private var validatorInstance: Validator? = null - val instance: Validator by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { - validatorInstance ?: Validator().also { - validatorInstance = it - } - } - } -} diff --git a/integration/src/main/kotlin/dev/teogor/drifter/integration/model/Vector2.kt b/integration/src/main/kotlin/dev/teogor/drifter/integration/model/Vector2.kt index 75f2b07..43508d5 100644 --- a/integration/src/main/kotlin/dev/teogor/drifter/integration/model/Vector2.kt +++ b/integration/src/main/kotlin/dev/teogor/drifter/integration/model/Vector2.kt @@ -19,6 +19,7 @@ package dev.teogor.drifter.integration.model import android.view.MotionEvent import dev.teogor.drifter.integration.core.Message +@Suppress("unused") class Vector2( val x: Float, val y: Float, diff --git a/integration/src/main/kotlin/dev/teogor/drifter/integration/model/Vector3.kt b/integration/src/main/kotlin/dev/teogor/drifter/integration/model/Vector3.kt deleted file mode 100644 index 52faa6e..0000000 --- a/integration/src/main/kotlin/dev/teogor/drifter/integration/model/Vector3.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2023 teogor (Teodor Grigor) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.teogor.drifter.integration.model - -import dev.teogor.drifter.integration.core.SharedElement - -data class Vector3( - var x: Float, - var y: Float, - var z: Float, -) { - fun asSharedElement(): SharedElement { - return SharedElement(this) - } -} diff --git a/integration/src/main/kotlin/dev/teogor/drifter/integration/utilities/UnityVersionInfo.kt b/integration/src/main/kotlin/dev/teogor/drifter/integration/utilities/UnityVersionInfo.kt index 54e6a6a..715c8c8 100644 --- a/integration/src/main/kotlin/dev/teogor/drifter/integration/utilities/UnityVersionInfo.kt +++ b/integration/src/main/kotlin/dev/teogor/drifter/integration/utilities/UnityVersionInfo.kt @@ -79,7 +79,7 @@ class UnityVersionInfo private constructor( ) ) { try { - val unityVersion = applicationInfo.metaData[metaDataName] as String? + val unityVersion = applicationInfo.metaData.getString(metaDataName) instance = UnityVersionInfo(unityVersion) return } catch (th: Throwable) { diff --git a/unity/v2022-3-7f1/src/main/java/com/unity3d/player/UnityPlayer.java b/unity/v2022-3-7f1/src/main/java/com/unity3d/player/UnityPlayer.java index 981a3ba..526090c 100644 --- a/unity/v2022-3-7f1/src/main/java/com/unity3d/player/UnityPlayer.java +++ b/unity/v2022-3-7f1/src/main/java/com/unity3d/player/UnityPlayer.java @@ -26,9 +26,7 @@ import android.os.Looper; import android.os.Message; import android.os.Process; -import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; -import android.util.Log; import android.view.InputEvent; import android.view.KeyEvent; import android.view.MotionEvent; @@ -39,7 +37,6 @@ import android.view.ViewParent; import android.view.Window; import android.view.WindowManager; -import android.widget.FrameLayout; import androidx.annotation.NonNull; @@ -57,8 +54,10 @@ import java.util.concurrent.TimeUnit; import dev.teogor.drifter.unity.common.BaseUnityPlayer; -import dev.teogor.drifter.unity.common.IUnityPlayer; +/** + * @noinspection ALL + */ public class UnityPlayer extends BaseUnityPlayer implements IUnityPlayerLifecycleEvents { public static final int ANR_TIMEOUT_SECONDS = 4; private static final int RUN_STATE_CHANGED_MSG_CODE = 2269; @@ -189,7 +188,6 @@ public UnityPlayer(Context context, IUnityPlayerLifecycleEvents iUnityPlayerLife * @param gameObject The name of the Unity GameObject to receive the message. * @param methodName The name of the method to invoke on the GameObject. * @param funcParam The parameter to pass to the method as a UTF-8 encoded string. - * * @throws UnsupportedOperationException If native libraries are not loaded. */ public static void UnitySendMessage(String gameObject, String methodName, String funcParam) { @@ -205,8 +203,8 @@ public static void UnitySendMessage(String gameObject, String methodName, String * *

This method is native and should be implemented in a platform-specific manner.

* - * @param gameObject The name of the Unity GameObject to receive the message. - * @param methodName The name of the method to invoke on the GameObject. + * @param gameObject The name of the Unity GameObject to receive the message. + * @param methodName The name of the method to invoke on the GameObject. * @param messageData The message data to pass to the method as a byte array. */ private static native void nativeUnitySendMessage(String gameObject, String methodName, byte[] messageData); diff --git a/unity/v2022-3-7f1/src/main/kotlin/com/unity3d/player/utils/PhoneStateChangeListener.kt b/unity/v2022-3-7f1/src/main/kotlin/com/unity3d/player/utils/PhoneStateChangeListener.kt index a9d3ba4..0c2bd83 100644 --- a/unity/v2022-3-7f1/src/main/kotlin/com/unity3d/player/utils/PhoneStateChangeListener.kt +++ b/unity/v2022-3-7f1/src/main/kotlin/com/unity3d/player/utils/PhoneStateChangeListener.kt @@ -14,6 +14,8 @@ * limitations under the License. */ +@file:Suppress("DEPRECATION") + package com.unity3d.player.utils import android.annotation.TargetApi @@ -25,7 +27,6 @@ import android.telephony.TelephonyManager import androidx.annotation.RequiresApi import com.unity3d.player.UnityPlayer -@Suppress("DEPRECATION") class PhoneStateChangeListener( private val context: Context, private val unityPlayer: UnityPlayer, diff --git a/wallpaper/api/wallpaper.api b/wallpaper/api/wallpaper.api index 747ac85..a9c8c26 100644 --- a/wallpaper/api/wallpaper.api +++ b/wallpaper/api/wallpaper.api @@ -41,12 +41,15 @@ public final class dev/teogor/drifter/wallpaper/LiveWallpaperUnityFacade$Prefere public final fun getInt (Ljava/lang/String;I)I public final fun getLong (Ljava/lang/String;J)J public final fun getString (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; + public final fun getStringSet (Ljava/lang/String;Ljava/util/Set;)Ljava/util/Set; + public static synthetic fun getStringSet$default (Ldev/teogor/drifter/wallpaper/LiveWallpaperUnityFacade$PreferenceEditorFacade;Ljava/lang/String;Ljava/util/Set;ILjava/lang/Object;)Ljava/util/Set; public final fun hasKey (Ljava/lang/String;)Z public final fun putBoolean (Ljava/lang/String;Z)Z public final fun putFloat (Ljava/lang/String;F)Z public final fun putInt (Ljava/lang/String;I)Z public final fun putLong (Ljava/lang/String;J)Z public final fun putString (Ljava/lang/String;Ljava/lang/String;)Z + public final fun putStringSet (Ljava/lang/String;Ljava/util/Set;)Z public final fun remove (Ljava/lang/String;)Z public final fun startEditing ()Z } diff --git a/wallpaper/build.gradle.kts b/wallpaper/build.gradle.kts index 26fc145..61f9841 100644 --- a/wallpaper/build.gradle.kts +++ b/wallpaper/build.gradle.kts @@ -48,6 +48,7 @@ dependencies { implementation(libs.appcompat) implementation(libs.androidx.startup.runtime) implementation(libs.gson) + implementation(libs.androidx.preference) } winds { diff --git a/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/LiveWallpaperUnityFacade.kt b/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/LiveWallpaperUnityFacade.kt index db9d730..5a515d0 100644 --- a/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/LiveWallpaperUnityFacade.kt +++ b/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/LiveWallpaperUnityFacade.kt @@ -20,14 +20,21 @@ import android.annotation.SuppressLint import android.content.Context import android.content.SharedPreferences import android.graphics.Point -import android.preference.PreferenceManager +import android.service.wallpaper.WallpaperService +import androidx.preference.PreferenceManager import dev.teogor.drifter.integration.player.UnityPlayerInstanceManager import dev.teogor.drifter.integration.utilities.MultiTapDetector import dev.teogor.drifter.wallpaper.UnityWallpaperService.UnityWallpaperEngine import dev.teogor.drifter.wallpaper.activities.LiveWallpaperCompatibleUnityPlayerActivity /** - * Central class for communicating with Unity C# side. All interactions to and from C# side are done here. + * Central class for interacting with Unity from the wallpaper service. + * + * This class provides access to various functionalities required for communication + * with the Unity C# side of the application, including managing preferences and + * interacting with the wallpaper engine. + * + * @property applicationContext The application context used for various operations. */ class LiveWallpaperUnityFacade private constructor( /** @@ -39,49 +46,41 @@ class LiveWallpaperUnityFacade private constructor( ) { /** + * Provides access to shared preferences for editing and retrieval. + * * Note: Called from C# code. * - * @return Instance of `LiveWallpaperUnityFacade.PreferenceEditorFacade`. + * @return Instance of [PreferenceEditorFacade]. */ - val preferencesEditorFacade: LiveWallpaperUnityFacade.PreferenceEditorFacade + val preferencesEditorFacade: PreferenceEditorFacade = PreferenceEditorFacade() /** + * Provides access to the current wallpaper engine state. + * * Note: Called from C# code. * - * @return Instance of `LiveWallpaperUnityFacade.WallpaperEngineFacade`. + * @return Instance of [WallpaperEngineFacade]. */ - val wallpaperEngineFacade: LiveWallpaperUnityFacade.WallpaperEngineFacade + val wallpaperEngineFacade: WallpaperEngineFacade = WallpaperEngineFacade() /** + * Detects multi-tap gestures within the wallpaper area. + * * Note: Called from C# code. * - * @return Instance of `MultiTapDetector`. + * @return Instance of [MultiTapDetector]. */ val multiTapDetector = MultiTapDetector(Point(0, 0)) - /** - * @return Currently active `UnityWallpaperService.UnityWallpaperEngine`, or null if none is active. - */ - /** - * Sets the currently active `UnityWallpaperService.UnityWallpaperEngine`. - * - * @param activeWallpaperEngine Currently active `UnityWallpaperService.UnityWallpaperEngine`. - */ - /** - * Currently active `UnityWallpaperService.UnityWallpaperEngine`, or null if none is active. - */ - var activeWallpaperEngine: UnityWallpaperEngine? = null /** - * @param context Application Context. + * The currently active wallpaper engine, or `null` if no engine is active. */ - init { - preferencesEditorFacade = PreferenceEditorFacade() - wallpaperEngineFacade = WallpaperEngineFacade() - } + var activeWallpaperEngine: UnityWallpaperEngine? = null /** - * Updates the current Context of the `LiveWallpaperCompatibleUnityPlayerActivity` - * to allow using soft input. + * Updates the context of [LiveWallpaperCompatibleUnityPlayerActivity] to allow + * using soft input. + * * Note: Called from C# code. */ fun updateUnityPlayerActivityContext() { @@ -89,33 +88,40 @@ class LiveWallpaperUnityFacade private constructor( } /** - * Provides safe access to current `WallpaperService.Engine` methods. + * Provides safe access to current [WallpaperService.Engine] methods. */ inner class WallpaperEngineFacade { + /** + * Indicates whether the wallpaper engine is currently visible. + * + * @return `true` if the engine is visible, `false` otherwise. + */ val isVisible: Boolean - get() = if (activeWallpaperEngine == null) false else activeWallpaperEngine!!.isVisible + get() = activeWallpaperEngine?.isVisible ?: false + + /** + * Indicates whether the wallpaper engine is in preview mode. + * + * @return `true` if the engine is in preview mode, `false` otherwise. + */ val isPreview: Boolean - get() = if (activeWallpaperEngine == null) false else activeWallpaperEngine!!.isPreview + get() = activeWallpaperEngine?.isPreview ?: false } /** - * Provides safe access to `SharedPreferences` read/write operations. + * Provides safe access to shared preferences read/write operations. */ inner class PreferenceEditorFacade { - private val mDefaultSharedPreferences: SharedPreferences + private val mDefaultSharedPreferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences( + applicationContext, + ) private var mCurrentPreferencesEditor: SharedPreferences.Editor? = null - init { - mDefaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences( - applicationContext, - ) - } - /** - * Commit your preferences changes back from this Editor to the - * [SharedPreferences] object it is editing. This atomically - * performs the requested modifications, replacing whatever is currently - * in the SharedPreferences. + * Begins editing the shared preferences. Changes are not committed until + * [finishEditing] is called. + * + * @return `true` if editing has started successfully, `false` otherwise. */ @SuppressLint("CommitPrefEdits") fun startEditing(): Boolean { @@ -125,237 +131,229 @@ class LiveWallpaperUnityFacade private constructor( } /** - * Commit your preferences changes back from this Editor to the - * [SharedPreferences] object it is editing. This atomically - * performs the requested modifications, replacing whatever is currently - * in the SharedPreferences. + * Commits changes made during editing to the shared preferences. + * + * @return `true` if changes were committed successfully, `false` otherwise. */ fun finishEditing(): Boolean { if (mCurrentPreferencesEditor == null) return false - mCurrentPreferencesEditor!!.apply() + mCurrentPreferencesEditor?.apply() mCurrentPreferencesEditor = null return true } /** - * Checks whether the preferences contains a preference. + * Checks if the shared preferences contain a specific key. * * @param key The name of the preference to check. - * @return Returns true if the preference exists in the preferences, otherwise false. + * @return `true` if the preference exists, `false` otherwise. */ fun hasKey(key: String?): Boolean { return mDefaultSharedPreferences.contains(key) } /** - * Retrieve a String value from the preferences. + * Retrieves a String value from the shared preferences. * - * @param key The name of the preference to retrieve. - * @param defValue Value to return if this preference does not exist. - * @return Returns the preference value if it exists, or defValue. Throws - * ClassCastException if there is a preference with this name that is not - * a String. - * @throws ClassCastException + * @param key The name of the preference to retrieve. + * @param defValue Value to return if the preference does not exist. + * @return The preference value if it exists, otherwise `defValue`. + * @throws ClassCastException If there is a preference with this name that is not a String. */ fun getString(key: String?, defValue: String?): String? { return mDefaultSharedPreferences.getString(key, defValue) } + /** - * Retrieve a set of String values from the preferences. - * + * Retrieves a set of String values from the shared preferences. * - * Note that you *must not* modify the set instance returned - * by this call. The consistency of the stored data is not guaranteed - * if you do, nor is your ability to modify the instance at all. + * Note that the returned set should not be modified. * * @param key The name of the preference to retrieve. * @param defValues Values to return if this preference does not exist. - * - * @return Returns the preference values if they exist, or defValues. - * Throws ClassCastException if there is a preference with this name - * that is not a Set. - * - * @throws ClassCastException + * @return The set of preference values if they exist, otherwise `defValues`. + * @throws ClassCastException If there is a preference with this name that is not a Set. */ - // @Nullable - // Set getStringSet(String key, @Nullable Set defValues); + fun getStringSet(key: String, defValues: Set? = null): Set? { + return mDefaultSharedPreferences.getStringSet(key, defValues) + } + /** - * Retrieve an int value from the preferences. + * Retrieves an int value from the shared preferences. * - * @param key The name of the preference to retrieve. - * @param defValue Value to return if this preference does not exist. - * @return Returns the preference value if it exists, or defValue. Throws - * ClassCastException if there is a preference with this name that is not - * an int. - * @throws ClassCastException + * @param key The name of the preference to retrieve. + * @param defValue Value to return if the preference does not exist. + * @return The preference value if it exists, otherwise `defValue`. + * @throws ClassCastException If there is a preference with this name that is not an int. */ fun getInt(key: String?, defValue: Int): Int { return mDefaultSharedPreferences.getInt(key, defValue) } /** - * Retrieve a long value from the preferences. + * Retrieves a long value from the shared preferences. * - * @param key The name of the preference to retrieve. - * @param defValue Value to return if this preference does not exist. - * @return Returns the preference value if it exists, or defValue. Throws - * ClassCastException if there is a preference with this name that is not - * a long. - * @throws ClassCastException + * @param key The name of the preference to retrieve. + * @param defValue Value to return if the preference does not exist. + * @return The preference value if it exists, otherwise `defValue`. + * @throws ClassCastException If there is a preference with this name that is not a long. */ fun getLong(key: String?, defValue: Long): Long { return mDefaultSharedPreferences.getLong(key, defValue) } /** - * Retrieve a float value from the preferences. + * Retrieves a float value from the shared preferences. * - * @param key The name of the preference to retrieve. - * @param defValue Value to return if this preference does not exist. - * @return Returns the preference value if it exists, or defValue. Throws - * ClassCastException if there is a preference with this name that is not - * a float. - * @throws ClassCastException + * @param key The name of the preference to retrieve. + * @param defValue Value to return if the preference does not exist. + * @return The preference value if it exists, otherwise `defValue`. + * @throws ClassCastException If there is a preference with this name that is not a float. */ fun getFloat(key: String?, defValue: Float): Float { return mDefaultSharedPreferences.getFloat(key, defValue) } /** - * Retrieve a boolean value from the preferences. + * Retrieves a boolean value from the shared preferences. * - * @param key The name of the preference to retrieve. - * @param defValue Value to return if this preference does not exist. - * @return Returns the preference value if it exists, or defValue. Throws - * ClassCastException if there is a preference with this name that is not - * a boolean. - * @throws ClassCastException + * @param key The name of the preference to retrieve. + * @param defValue Value to return if the preference does not exist. + * @return The preference value if it exists, otherwise `defValue`. + * @throws ClassCastException If there is a preference with this name that is not a boolean. */ fun getBoolean(key: String?, defValue: Boolean): Boolean { return mDefaultSharedPreferences.getBoolean(key, defValue) } /** - * Set a String value in the preferences. + * Sets a String value in the shared preferences. * - * @param key The name of the preference to modify. + * @param key The name of the preference to modify. * @param value The new value for the preference. - * @return true if editing has started and operation succeeded, false otherwise. + * @return `true` if the value was set successfully, `false` otherwise. */ fun putString(key: String?, value: String?): Boolean { if (mCurrentPreferencesEditor == null) return false - mCurrentPreferencesEditor!!.putString(key, value) + mCurrentPreferencesEditor?.putString(key, value) return true } + /** - * Set a set of String values in the preferences. + * Sets a set of String values in the shared preferences. * * @param key The name of the preference to modify. - * @param values The set of new values for the preference. Passing `null` - * for this argument is equivalent to calling [.remove] with - * this key. - * @return true if editing has started and operation succeeded, false otherwise. + * @param values The set of new values for the preference. Passing `null` is equivalent to calling + * [.remove] with this key. + * @return `true` if the values were set successfully, `false` otherwise. */ - // Editor putStringSet(String key, @Nullable Set values); + fun putStringSet(key: String, values: Set?): Boolean { + mCurrentPreferencesEditor?.putStringSet(key, values) + return true + } + /** - * Set an int value in the preferences. + * Sets an int value in the shared preferences. * - * @param key The name of the preference to modify. + * @param key The name of the preference to modify. * @param value The new value for the preference. - * @return true if editing has started and operation succeeded, false otherwise. + * @return `true` if the value was set successfully, `false` otherwise. */ fun putInt(key: String?, value: Int): Boolean { if (mCurrentPreferencesEditor == null) return false - mCurrentPreferencesEditor!!.putInt(key, value) + mCurrentPreferencesEditor?.putInt(key, value) return true } /** - * Set a long value in the preferences + * Sets a long value in the shared preferences. * - * @param key The name of the preference to modify. + * @param key The name of the preference to modify. * @param value The new value for the preference. - * @return true if editing has started and operation succeeded, false otherwise. + * @return `true` if the value was set successfully, `false` otherwise. */ fun putLong(key: String?, value: Long): Boolean { if (mCurrentPreferencesEditor == null) return false - mCurrentPreferencesEditor!!.putLong(key, value) + mCurrentPreferencesEditor?.putLong(key, value) return true } /** - * Set a float value in the preferences. + * Sets a float value in the shared preferences. * - * @param key The name of the preference to modify. + * @param key The name of the preference to modify. * @param value The new value for the preference. - * @return true if editing has started and operation succeeded, false otherwise. + * @return `true` if the value was set successfully, `false` otherwise. */ fun putFloat(key: String?, value: Float): Boolean { if (mCurrentPreferencesEditor == null) return false - mCurrentPreferencesEditor!!.putFloat(key, value) + mCurrentPreferencesEditor?.putFloat(key, value) return true } /** - * Set a boolean value in the preferences. + * Sets a boolean value in the shared preferences. * - * @param key The name of the preference to modify. + * @param key The name of the preference to modify. * @param value The new value for the preference. - * @return true if editing has started and operation succeeded, false otherwise. + * @return `true` if the value was set successfully, `false` otherwise. */ fun putBoolean(key: String?, value: Boolean): Boolean { if (mCurrentPreferencesEditor == null) return false - mCurrentPreferencesEditor!!.putBoolean(key, value) + mCurrentPreferencesEditor?.putBoolean(key, value) return true } /** - * Remove value from the preferences. + * Removes a preference from the shared preferences. * * @param key The name of the preference to remove. - * @return true if editing has started and operation succeeded, false otherwise. + * @return `true` if the value was removed successfully, `false` otherwise. */ fun remove(key: String?): Boolean { if (mCurrentPreferencesEditor == null) return false - mCurrentPreferencesEditor!!.remove(key) + mCurrentPreferencesEditor?.remove(key) return true } /** - * Remove all values from the preferences. + * Clears all preferences from the shared preferences. * - * @return true if editing has started and operation succeeded, false otherwise. + * @return `true` if all values were removed successfully, `false` otherwise. */ fun clear(): Boolean { if (mCurrentPreferencesEditor == null) return false - mCurrentPreferencesEditor!!.clear() + mCurrentPreferencesEditor?.clear() return true } } companion object { /** + * Provides access to Unity events. + * * Note: Called from C# code. * - * @return Instance of `UnityEventsProxy`. + * @return Instance of [UnityEventsProxy]. */ val eventsProxy = UnityEventsProxy() - private var liveWallpaperUnityFacadeInstance: LiveWallpaperUnityFacade? = - null + private var liveWallpaperUnityFacadeInstance: LiveWallpaperUnityFacade? = null - val instance: LiveWallpaperUnityFacade? by lazy( - LazyThreadSafetyMode.SYNCHRONIZED, - ) { - if (liveWallpaperUnityFacadeInstance == null) { - UnityPlayerInstanceManager.instance.unityPlayerWrapperInstance - ?.let { unityPlayerWrapper -> - val applicationContext = unityPlayerWrapper.applicationContext - liveWallpaperUnityFacadeInstance = - LiveWallpaperUnityFacade(applicationContext) - } + /** + * Provides the singleton instance of [LiveWallpaperUnityFacade]. + * + * Initializes the instance if it has not been created yet using + * [UnityPlayerInstanceManager]. + * + * @return Singleton instance of [LiveWallpaperUnityFacade]. + */ + val instance: LiveWallpaperUnityFacade? by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { + liveWallpaperUnityFacadeInstance ?: UnityPlayerInstanceManager.instance.unityPlayerWrapperInstance?.let { unityPlayerWrapper -> + LiveWallpaperUnityFacade(unityPlayerWrapper.applicationContext).also { + liveWallpaperUnityFacadeInstance = it + } } - liveWallpaperUnityFacadeInstance } } } diff --git a/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/UnityWallpaperService.kt b/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/UnityWallpaperService.kt index 3fa50f9..aeebe8b 100644 --- a/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/UnityWallpaperService.kt +++ b/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/UnityWallpaperService.kt @@ -258,8 +258,6 @@ class UnityWallpaperService : WallpaperService() { xPixelOffset: Int, yPixelOffset: Int, ) { - if (mUnityEventsProxy == null) return - // Pass event to C# mUnityEventsProxy.offsetsChanged( xOffset, @@ -272,8 +270,6 @@ class UnityWallpaperService : WallpaperService() { } override fun onDesiredSizeChanged(desiredWidth: Int, desiredHeight: Int) { - if (mUnityEventsProxy == null) return - // Pass event to C# if (mLiveWallpaperUnityFacade == null || mLiveWallpaperUnityFacade?.activeWallpaperEngine === this) { mUnityEventsProxy.desiredSizeChanged(desiredWidth, desiredHeight) @@ -296,7 +292,7 @@ class UnityWallpaperService : WallpaperService() { unityPlayerHolder!!.onVisibilityChanged(true, mCurrentSurfaceHolder) // Send events to C# - mUnityEventsProxy!!.desiredSizeChanged(desiredMinimumWidth, desiredMinimumHeight) + mUnityEventsProxy.desiredSizeChanged(desiredMinimumWidth, desiredMinimumHeight) mUnityEventsProxy.visibilityChanged(true) mUnityEventsProxy.isPreviewChanged(isPreview) } else { @@ -309,7 +305,7 @@ class UnityWallpaperService : WallpaperService() { // Send events to C#. // Do this before Unity was paused to avoid them being received in paused state if (mLiveWallpaperUnityFacade == null || mUnityPlayerInstanceManager!!.activeUnityPlayerHolder == unityPlayerHolder) { - mUnityEventsProxy!!.visibilityChanged(false) + mUnityEventsProxy.visibilityChanged(false) } unityPlayerHolder!!.onVisibilityChanged(false, null) } @@ -348,7 +344,7 @@ class UnityWallpaperService : WallpaperService() { } override fun onMultiTapDetected(finalTapPositionX: Float, finalTapPositionY: Float) { - mUnityEventsProxy!!.multiTapDetected(finalTapPositionX, finalTapPositionY) + mUnityEventsProxy.multiTapDetected(finalTapPositionX, finalTapPositionY) } private fun log(obj: Any?, isVerbose: Boolean = false) { diff --git a/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/activities/LiveWallpaperCompatibleUnityPlayerActivity.kt b/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/activities/LiveWallpaperCompatibleUnityPlayerActivity.kt index b7151a9..39b6ab8 100644 --- a/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/activities/LiveWallpaperCompatibleUnityPlayerActivity.kt +++ b/wallpaper/src/main/kotlin/dev/teogor/drifter/wallpaper/activities/LiveWallpaperCompatibleUnityPlayerActivity.kt @@ -226,7 +226,7 @@ abstract class LiveWallpaperCompatibleUnityPlayerActivity : Activity() { // Force event injection by overriding dispatchKeyEvent(). override fun dispatchKeyEvent(event: KeyEvent): Boolean { // todo KeyEvent.ACTION_MULTIPLE deprecated - return if (mUnityPlayerWrapper == null && event.action == KeyEvent.ACTION_MULTIPLE) { + return if (mUnityPlayerWrapper != null && event.action == KeyEvent.ACTION_MULTIPLE) { mUnityPlayerWrapper!!.injectInputEvent( event, ) From 4afd118a550f46141f6375eef6c7ba211782ce0d Mon Sep 17 00:00:00 2001 From: Teodor Grigor Date: Tue, 20 Aug 2024 22:08:15 +0300 Subject: [PATCH 2/2] Add DrifterConstants object for Unity integration constants --- codegen/api/codegen.api | 9 +++++-- .../Constants.kt => DrifterConstants.kt} | 27 +++++++++++++++---- .../writers/UnityMessageSenderOutputWriter.kt | 4 +-- 3 files changed, 31 insertions(+), 9 deletions(-) rename codegen/src/main/kotlin/dev/teogor/drifter/codegen/{commons/Constants.kt => DrifterConstants.kt} (51%) diff --git a/codegen/api/codegen.api b/codegen/api/codegen.api index f0ecdd0..b188686 100644 --- a/codegen/api/codegen.api +++ b/codegen/api/codegen.api @@ -5,8 +5,13 @@ public final class dev/teogor/drifter/codegen/CodeGenerator : dev/teogor/drifter public fun getCodeOutputStreamMaker ()Ldev/teogor/drifter/codegen/facades/CodeOutputStreamMaker; } -public final class dev/teogor/drifter/codegen/commons/ConstantsKt { - public static final fun getUnityMessageSender ()Lcom/squareup/kotlinpoet/ClassName; +public final class dev/teogor/drifter/codegen/DrifterConstants { + public static final field INSTANCE Ldev/teogor/drifter/codegen/DrifterConstants; +} + +public final class dev/teogor/drifter/codegen/DrifterConstants$UnityIntegration { + public static final field INSTANCE Ldev/teogor/drifter/codegen/DrifterConstants$UnityIntegration; + public final fun getUnityMessageSender ()Lcom/squareup/kotlinpoet/ClassName; } public final class dev/teogor/drifter/codegen/commons/UtilsKt { diff --git a/codegen/src/main/kotlin/dev/teogor/drifter/codegen/commons/Constants.kt b/codegen/src/main/kotlin/dev/teogor/drifter/codegen/DrifterConstants.kt similarity index 51% rename from codegen/src/main/kotlin/dev/teogor/drifter/codegen/commons/Constants.kt rename to codegen/src/main/kotlin/dev/teogor/drifter/codegen/DrifterConstants.kt index 804f79a..30b8dab 100644 --- a/codegen/src/main/kotlin/dev/teogor/drifter/codegen/commons/Constants.kt +++ b/codegen/src/main/kotlin/dev/teogor/drifter/codegen/DrifterConstants.kt @@ -14,11 +14,28 @@ * limitations under the License. */ -package dev.teogor.drifter.codegen.commons +package dev.teogor.drifter.codegen import com.squareup.kotlinpoet.ClassName -val UnityMessageSender = ClassName( - "dev.teogor.drifter.common", - "UnityMessageSender", -) +/** + * Container for constants and utility objects related to the Drifter library. + */ +object DrifterConstants { + + /** + * Contains constants related to Drifter's integration with Unity. + */ + object UnityIntegration { + + /** + * Represents the fully qualified class name of the `UnityMessageSender` class within the Drifter core library. + * + * This class is responsible for sending messages between Unity and the native side of the application. + */ + val UnityMessageSender = ClassName( + "dev.teogor.drifter.core", + "UnityMessageSender", + ) + } +} diff --git a/codegen/src/main/kotlin/dev/teogor/drifter/codegen/writers/UnityMessageSenderOutputWriter.kt b/codegen/src/main/kotlin/dev/teogor/drifter/codegen/writers/UnityMessageSenderOutputWriter.kt index e9b1f3a..f09fb75 100644 --- a/codegen/src/main/kotlin/dev/teogor/drifter/codegen/writers/UnityMessageSenderOutputWriter.kt +++ b/codegen/src/main/kotlin/dev/teogor/drifter/codegen/writers/UnityMessageSenderOutputWriter.kt @@ -22,7 +22,7 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.ParameterSpec import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.TypeSpec -import dev.teogor.drifter.codegen.commons.UnityMessageSender +import dev.teogor.drifter.codegen.DrifterConstants import dev.teogor.drifter.codegen.commons.fileBuilder import dev.teogor.drifter.codegen.commons.safe import dev.teogor.drifter.codegen.commons.toTitleCase @@ -49,7 +49,7 @@ class UnityMessageSenderOutputWriter( ) { addType( TypeSpec.classBuilder(name) - .superclass(UnityMessageSender) + .superclass(DrifterConstants.UnityIntegration.UnityMessageSender) .addSuperclassConstructorParameter( "receiver = %S", actionBridge.receiverGameObject,