1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-23 11:56:09 -06:00

Remove deprecated usage of LifecycleObserver (#1641)

This commit is contained in:
Rafał Borcz 2021-11-16 00:38:52 +01:00 committed by GitHub
parent 68fdb167c2
commit 8a181c747c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 15 deletions

View File

@ -185,7 +185,7 @@ dependencies {
implementation 'androidx.core:core-splashscreen:1.0.0-alpha02'
implementation "androidx.activity:activity-ktx:1.4.0"
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.preference:preference-ktx:1.1.1"

View File

@ -6,7 +6,6 @@ import android.util.Log.DEBUG
import android.util.Log.INFO
import android.util.Log.VERBOSE
import android.webkit.WebView
import androidx.fragment.app.FragmentManager
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.yariksoffice.lingver.Lingver
@ -44,7 +43,6 @@ class WulkanowyApp : Application(), Configuration.Provider {
@SuppressLint("UnsafeOptInUsageWarning")
override fun onCreate() {
super.onCreate()
FragmentManager.enableNewStateManager(false)
initializeAppLanguage()
themeManager.applyDefaultTheme()
initLogging()

View File

@ -4,13 +4,12 @@ import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import kotlin.properties.ReadWriteProperty
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
@ -23,15 +22,15 @@ class LifecycleAwareVariable<T : Any> : ReadWriteProperty<Fragment, T>, Lifecycl
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")
@Suppress("unused")
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroyView() {
override fun onDestroy(owner: LifecycleOwner) {
Handler(Looper.getMainLooper()).post {
_value = null
}
}
}
class LifecycleAwareVariableActivity<T : Any> : ReadWriteProperty<AppCompatActivity, T>,
LifecycleObserver {
DefaultLifecycleObserver {
private var _value: T? = null
@ -44,9 +43,7 @@ class LifecycleAwareVariableActivity<T : Any> : ReadWriteProperty<AppCompatActiv
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")
@Suppress("unused")
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroyView() {
override fun onDestroy(owner: LifecycleOwner) {
Handler(Looper.getMainLooper()).post {
_value = null
}