mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 11:46:03 -06:00
Remove deprecated usage of LifecycleObserver (#1641)
This commit is contained in:
parent
68fdb167c2
commit
8a181c747c
@ -185,7 +185,7 @@ dependencies {
|
|||||||
implementation 'androidx.core:core-splashscreen:1.0.0-alpha02'
|
implementation 'androidx.core:core-splashscreen:1.0.0-alpha02'
|
||||||
implementation "androidx.activity:activity-ktx:1.4.0"
|
implementation "androidx.activity:activity-ktx:1.4.0"
|
||||||
implementation "androidx.appcompat:appcompat:1.4.0-rc01"
|
implementation "androidx.appcompat:appcompat:1.4.0-rc01"
|
||||||
implementation "androidx.fragment:fragment-ktx:1.3.6"
|
implementation "androidx.fragment:fragment-ktx:1.4.0-rc01"
|
||||||
implementation "androidx.annotation:annotation:1.3.0"
|
implementation "androidx.annotation:annotation:1.3.0"
|
||||||
|
|
||||||
implementation "androidx.preference:preference-ktx:1.1.1"
|
implementation "androidx.preference:preference-ktx:1.1.1"
|
||||||
|
@ -6,7 +6,6 @@ import android.util.Log.DEBUG
|
|||||||
import android.util.Log.INFO
|
import android.util.Log.INFO
|
||||||
import android.util.Log.VERBOSE
|
import android.util.Log.VERBOSE
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
import androidx.hilt.work.HiltWorkerFactory
|
import androidx.hilt.work.HiltWorkerFactory
|
||||||
import androidx.work.Configuration
|
import androidx.work.Configuration
|
||||||
import com.yariksoffice.lingver.Lingver
|
import com.yariksoffice.lingver.Lingver
|
||||||
@ -44,7 +43,6 @@ class WulkanowyApp : Application(), Configuration.Provider {
|
|||||||
@SuppressLint("UnsafeOptInUsageWarning")
|
@SuppressLint("UnsafeOptInUsageWarning")
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
FragmentManager.enableNewStateManager(false)
|
|
||||||
initializeAppLanguage()
|
initializeAppLanguage()
|
||||||
themeManager.applyDefaultTheme()
|
themeManager.applyDefaultTheme()
|
||||||
initLogging()
|
initLogging()
|
||||||
|
@ -4,13 +4,12 @@ import android.os.Handler
|
|||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.LifecycleObserver
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.OnLifecycleEvent
|
|
||||||
import kotlin.properties.ReadWriteProperty
|
import kotlin.properties.ReadWriteProperty
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class LifecycleAwareVariable<T : Any> : ReadWriteProperty<Fragment, T>, LifecycleObserver {
|
class LifecycleAwareVariable<T : Any> : ReadWriteProperty<Fragment, T>, DefaultLifecycleObserver {
|
||||||
|
|
||||||
private var _value: T? = null
|
private var _value: T? = null
|
||||||
|
|
||||||
@ -23,15 +22,15 @@ class LifecycleAwareVariable<T : Any> : ReadWriteProperty<Fragment, T>, Lifecycl
|
|||||||
override fun getValue(thisRef: Fragment, property: KProperty<*>) = _value
|
override fun getValue(thisRef: Fragment, property: KProperty<*>) = _value
|
||||||
?: throw IllegalStateException("Trying to call an lifecycle-aware value outside of the view lifecycle, or the value has not been initialized")
|
?: throw IllegalStateException("Trying to call an lifecycle-aware value outside of the view lifecycle, or the value has not been initialized")
|
||||||
|
|
||||||
@Suppress("unused")
|
override fun onDestroy(owner: LifecycleOwner) {
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
Handler(Looper.getMainLooper()).post {
|
||||||
fun onDestroyView() {
|
_value = null
|
||||||
_value = null
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LifecycleAwareVariableActivity<T : Any> : ReadWriteProperty<AppCompatActivity, T>,
|
class LifecycleAwareVariableActivity<T : Any> : ReadWriteProperty<AppCompatActivity, T>,
|
||||||
LifecycleObserver {
|
DefaultLifecycleObserver {
|
||||||
|
|
||||||
private var _value: T? = null
|
private var _value: T? = null
|
||||||
|
|
||||||
@ -44,9 +43,7 @@ class LifecycleAwareVariableActivity<T : Any> : ReadWriteProperty<AppCompatActiv
|
|||||||
override fun getValue(thisRef: AppCompatActivity, property: KProperty<*>) = _value
|
override fun getValue(thisRef: AppCompatActivity, property: KProperty<*>) = _value
|
||||||
?: throw IllegalStateException("Trying to call an lifecycle-aware value outside of the view lifecycle, or the value has not been initialized")
|
?: throw IllegalStateException("Trying to call an lifecycle-aware value outside of the view lifecycle, or the value has not been initialized")
|
||||||
|
|
||||||
@Suppress("unused")
|
override fun onDestroy(owner: LifecycleOwner) {
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
||||||
fun onDestroyView() {
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
Handler(Looper.getMainLooper()).post {
|
||||||
_value = null
|
_value = null
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user