Skip to content

Commit

Permalink
Comment ProxyLifecycleProvider to fix Flutter 3.24 kotlin compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
timbotimbo committed Aug 15, 2024
1 parent 93d7a3a commit f51fedc
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* [Android] Fix touch detection when using Unity's New Input System. [#938](https://github.com/juicycleff/flutter-unity-view-widget/pull/938)
* [Android] Workaround for mUnityplayer error in Unity plugins using the AndroidJavaProxy. [#908](https://github.com/juicycleff/flutter-unity-view-widget/pull/908)
* [Android] Add namespace for Android gradle plugin (AGP) 8 compatibility.
* [Android] Fix kotlin compilation error with Flutter 3.24 and newer. [#973](https://github.com/juicycleff/flutter-unity-view-widget/issues/973)

## 2022.2.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,78 +87,80 @@ class FlutterUnityWidgetPlugin : FlutterPlugin, ActivityAware {
}

/**
* [August 2024 UPDATE] This unused class was disabled to fix compilation errors in Flutter 3.24.
*
* This class provides a {@link LifecycleOwner} for the activity driven by {@link
* ActivityLifecycleCallbacks}.
*
* <p>This is used in the case where a direct Lifecycle/Owner is not available.
*/
@SuppressLint("NewApi")
private class ProxyLifecycleProvider(activity: Activity) : Application.ActivityLifecycleCallbacks, LifecycleOwner, LifecycleProvider {
private val lifecycle = LifecycleRegistry(this)
private var registrarActivityHashCode: Int = 0

init {
UnityPlayerUtils.activity = activity
this.registrarActivityHashCode = activity.hashCode()
activity.application.registerActivityLifecycleCallbacks(this)
}

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
UnityPlayerUtils.activity = activity
if (activity.hashCode() != registrarActivityHashCode) {
return
}
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
}

override fun onActivityStarted(activity: Activity) {
UnityPlayerUtils.activity = activity
if (activity.hashCode() != registrarActivityHashCode) {
return
}
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START)
}

override fun onActivityResumed(activity: Activity) {
UnityPlayerUtils.activity = activity
if (activity.hashCode() != registrarActivityHashCode) {
return
}
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
}

override fun onActivityPaused(activity: Activity) {
UnityPlayerUtils.activity = activity
if (activity.hashCode() != registrarActivityHashCode) {
return
}
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
}

override fun onActivityStopped(activity: Activity) {
UnityPlayerUtils.activity = activity
if (activity.hashCode() != registrarActivityHashCode) {
return
}
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
}

override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
UnityPlayerUtils.activity = activity
}

override fun onActivityDestroyed(activity: Activity) {
UnityPlayerUtils.activity = activity
if (activity.hashCode() != registrarActivityHashCode) {
return
}

activity.application.unregisterActivityLifecycleCallbacks(this)
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
}

override fun getLifecycle(): Lifecycle {
return lifecycle
}
}
// @SuppressLint("NewApi")
// private class ProxyLifecycleProvider(activity: Activity) : Application.ActivityLifecycleCallbacks, LifecycleOwner, LifecycleProvider {
// private val lifecycle = LifecycleRegistry(this)
// private var registrarActivityHashCode: Int = 0
//
// init {
// UnityPlayerUtils.activity = activity
// this.registrarActivityHashCode = activity.hashCode()
// activity.application.registerActivityLifecycleCallbacks(this)
// }
//
// override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
// UnityPlayerUtils.activity = activity
// if (activity.hashCode() != registrarActivityHashCode) {
// return
// }
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
// }
//
// override fun onActivityStarted(activity: Activity) {
// UnityPlayerUtils.activity = activity
// if (activity.hashCode() != registrarActivityHashCode) {
// return
// }
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START)
// }
//
// override fun onActivityResumed(activity: Activity) {
// UnityPlayerUtils.activity = activity
// if (activity.hashCode() != registrarActivityHashCode) {
// return
// }
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
// }
//
// override fun onActivityPaused(activity: Activity) {
// UnityPlayerUtils.activity = activity
// if (activity.hashCode() != registrarActivityHashCode) {
// return
// }
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
// }
//
// override fun onActivityStopped(activity: Activity) {
// UnityPlayerUtils.activity = activity
// if (activity.hashCode() != registrarActivityHashCode) {
// return
// }
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
// }
//
// override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
// UnityPlayerUtils.activity = activity
// }
//
// override fun onActivityDestroyed(activity: Activity) {
// UnityPlayerUtils.activity = activity
// if (activity.hashCode() != registrarActivityHashCode) {
// return
// }
//
// activity.application.unregisterActivityLifecycleCallbacks(this)
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
// }
//
// override fun getLifecycle(): Lifecycle {
// return lifecycle
// }
// }
}

0 comments on commit f51fedc

Please sign in to comment.