Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57974335 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Catalyst] Provide lifecycleScope for PreferenceLifecycleContext" into main

parents 471e6c9e 70e5bd79
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.LifecycleCoroutineScope
import kotlinx.coroutines.CoroutineScope

/**
 * Interface to provide dynamic preference title.
@@ -138,6 +140,13 @@ interface PreferenceLifecycleProvider {
 */
abstract class PreferenceLifecycleContext(context: Context) : ContextWrapper(context) {

    /**
     * [CoroutineScope] tied to the lifecycle, which is cancelled when the lifecycle is destroyed.
     *
     * @see [androidx.lifecycle.lifecycleScope]
     */
    abstract val lifecycleScope: LifecycleCoroutineScope

    /** Returns the preference widget object associated with given key. */
    abstract fun <T> findPreference(key: String): T?

+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.settingslib.preference
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceDataStore
import androidx.preference.PreferenceGroup
@@ -57,6 +59,9 @@ class PreferenceScreenBindingHelper(

    private val preferenceLifecycleContext =
        object : PreferenceLifecycleContext(context) {
            override val lifecycleScope: LifecycleCoroutineScope
                get() = fragment.lifecycleScope

            override fun <T> findPreference(key: String) =
                preferenceScreen.findPreference(key) as T?