Loading packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/Flows.kt +7 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,13 @@ import kotlinx.coroutines.flow.distinctUntilChangedBy import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map /** * Returns a [Flow] whose values are a list which containing the results of applying the given * [transform] function to each element in the original flow's list. */ inline fun <T, R> Flow<List<T>>.mapItem(crossinline transform: (T) -> R): Flow<List<R>> = map { list -> list.map(transform) } /** * Returns a [Flow] whose values are a list which containing the results of asynchronously applying * the given [transform] function to each element in the original flow's list. Loading packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListModel.kt +3 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,8 @@ interface AppListModel<T : AppRecord> { * * @return the [AppRecord] list which will be displayed. */ fun filter(userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<T>>): Flow<List<T>> fun filter(userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<T>>): Flow<List<T>> = recordListFlow /** * This function is called when the App List's loading is finished and displayed to the user. Loading Loading @@ -67,5 +68,5 @@ interface AppListModel<T : AppRecord> { * @return null if no summary should be displayed. */ @Composable fun getSummary(option: Int, record: T): State<String>? fun getSummary(option: Int, record: T): State<String>? = null } packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListViewModelTest.kt +2 −11 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ import android.content.pm.ApplicationInfo import androidx.compose.runtime.Composable import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.settingslib.spa.framework.compose.stateOf import com.android.settingslib.spa.framework.util.asyncMapItem import com.android.settingslib.spa.framework.util.mapItem import com.android.settingslib.spa.testutils.waitUntil import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi Loading Loading @@ -116,16 +116,7 @@ private class TestAppListModel : AppListModel<TestAppRecord> { var onFirstLoadedCalled = false override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) = appListFlow.asyncMapItem { TestAppRecord(it) } @Composable override fun getSummary(option: Int, record: TestAppRecord) = null override fun filter( userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<TestAppRecord>>, ) = recordListFlow appListFlow.mapItem(::TestAppRecord) override suspend fun onFirstLoaded(recordList: List<TestAppRecord>) { onFirstLoadedCalled = true Loading packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/tests/testutils/TestAppListModel.kt +2 −12 Original line number Diff line number Diff line Loading @@ -17,8 +17,7 @@ package com.android.settingslib.spaprivileged.tests.testutils import android.content.pm.ApplicationInfo import androidx.compose.runtime.Composable import com.android.settingslib.spa.framework.util.asyncMapItem import com.android.settingslib.spa.framework.util.mapItem import com.android.settingslib.spaprivileged.model.app.AppListModel import com.android.settingslib.spaprivileged.model.app.AppRecord import kotlinx.coroutines.flow.Flow Loading @@ -35,16 +34,7 @@ class TestAppListModel( override fun getSpinnerOptions() = options override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) = appListFlow.asyncMapItem { TestAppRecord(it) } @Composable override fun getSummary(option: Int, record: TestAppRecord) = null override fun filter( userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<TestAppRecord>>, ) = recordListFlow appListFlow.mapItem(::TestAppRecord) override fun getGroupTitle(option: Int, record: TestAppRecord) = if (enableGrouping) record.group else null Loading Loading
packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/Flows.kt +7 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,13 @@ import kotlinx.coroutines.flow.distinctUntilChangedBy import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map /** * Returns a [Flow] whose values are a list which containing the results of applying the given * [transform] function to each element in the original flow's list. */ inline fun <T, R> Flow<List<T>>.mapItem(crossinline transform: (T) -> R): Flow<List<R>> = map { list -> list.map(transform) } /** * Returns a [Flow] whose values are a list which containing the results of asynchronously applying * the given [transform] function to each element in the original flow's list. Loading
packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListModel.kt +3 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,8 @@ interface AppListModel<T : AppRecord> { * * @return the [AppRecord] list which will be displayed. */ fun filter(userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<T>>): Flow<List<T>> fun filter(userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<T>>): Flow<List<T>> = recordListFlow /** * This function is called when the App List's loading is finished and displayed to the user. Loading Loading @@ -67,5 +68,5 @@ interface AppListModel<T : AppRecord> { * @return null if no summary should be displayed. */ @Composable fun getSummary(option: Int, record: T): State<String>? fun getSummary(option: Int, record: T): State<String>? = null }
packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListViewModelTest.kt +2 −11 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ import android.content.pm.ApplicationInfo import androidx.compose.runtime.Composable import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.settingslib.spa.framework.compose.stateOf import com.android.settingslib.spa.framework.util.asyncMapItem import com.android.settingslib.spa.framework.util.mapItem import com.android.settingslib.spa.testutils.waitUntil import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi Loading Loading @@ -116,16 +116,7 @@ private class TestAppListModel : AppListModel<TestAppRecord> { var onFirstLoadedCalled = false override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) = appListFlow.asyncMapItem { TestAppRecord(it) } @Composable override fun getSummary(option: Int, record: TestAppRecord) = null override fun filter( userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<TestAppRecord>>, ) = recordListFlow appListFlow.mapItem(::TestAppRecord) override suspend fun onFirstLoaded(recordList: List<TestAppRecord>) { onFirstLoadedCalled = true Loading
packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/tests/testutils/TestAppListModel.kt +2 −12 Original line number Diff line number Diff line Loading @@ -17,8 +17,7 @@ package com.android.settingslib.spaprivileged.tests.testutils import android.content.pm.ApplicationInfo import androidx.compose.runtime.Composable import com.android.settingslib.spa.framework.util.asyncMapItem import com.android.settingslib.spa.framework.util.mapItem import com.android.settingslib.spaprivileged.model.app.AppListModel import com.android.settingslib.spaprivileged.model.app.AppRecord import kotlinx.coroutines.flow.Flow Loading @@ -35,16 +34,7 @@ class TestAppListModel( override fun getSpinnerOptions() = options override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) = appListFlow.asyncMapItem { TestAppRecord(it) } @Composable override fun getSummary(option: Int, record: TestAppRecord) = null override fun filter( userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<TestAppRecord>>, ) = recordListFlow appListFlow.mapItem(::TestAppRecord) override fun getGroupTitle(option: Int, record: TestAppRecord) = if (enableGrouping) record.group else null Loading