Refresh PeopleSpace tiles earlier to avoid recomposition
This CL moves the logic used to refresh the PeopleSpace tiles on RESUME events so that the first time it is triggered happens before our first composition, to avoid composing and redrawing this screen twice, which reduces GPU consumption. See b/276871425 for details. Test: See go/sysui-memory-comparison Bug: 276871425 Change-Id: I0feec96dc526b38f5bec0a7da29bd2fbe4dc2d7e
This commit is contained in:
@@ -42,13 +42,10 @@ import androidx.compose.runtime.key
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.android.compose.theme.LocalAndroidColorScheme
|
||||
import com.android.systemui.R
|
||||
import com.android.systemui.compose.modifiers.sysuiResTag
|
||||
@@ -70,15 +67,6 @@ fun PeopleScreen(
|
||||
val priorityTiles by viewModel.priorityTiles.collectAsState()
|
||||
val recentTiles by viewModel.recentTiles.collectAsState()
|
||||
|
||||
// Make sure to refresh the tiles/conversations when the lifecycle is resumed, so that it
|
||||
// updates them when going back to the Activity after leaving it.
|
||||
val lifecycleOwner = LocalLifecycleOwner.current
|
||||
LaunchedEffect(lifecycleOwner, viewModel) {
|
||||
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
viewModel.onTileRefreshRequested()
|
||||
}
|
||||
}
|
||||
|
||||
// Call [onResult] this activity when the ViewModel tells us so.
|
||||
LaunchedEffect(viewModel.result) {
|
||||
viewModel.result.collect { result ->
|
||||
|
||||
@@ -20,7 +20,10 @@ import android.appwidget.AppWidgetManager
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.android.systemui.compose.ComposeFacade.isComposeAvailable
|
||||
import com.android.systemui.compose.ComposeFacade.setPeopleSpaceActivityContent
|
||||
import com.android.systemui.flags.FeatureFlags
|
||||
@@ -29,6 +32,7 @@ import com.android.systemui.people.ui.view.PeopleViewBinder
|
||||
import com.android.systemui.people.ui.view.PeopleViewBinder.bind
|
||||
import com.android.systemui.people.ui.viewmodel.PeopleViewModel
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/** People Tile Widget configuration activity that shows the user their conversation tiles. */
|
||||
class PeopleSpaceActivity
|
||||
@@ -50,6 +54,16 @@ constructor(
|
||||
)
|
||||
viewModel.onWidgetIdChanged(widgetId)
|
||||
|
||||
// Make sure to refresh the tiles/conversations when the lifecycle is resumed, so that it
|
||||
// updates them when going back to the Activity after leaving it.
|
||||
// Note that we do this here instead of inside an effect in the PeopleScreen() composable
|
||||
// because otherwise onTileRefreshRequested() will be called after the first composition,
|
||||
// which will trigger a new recomposition and redraw, affecting the GPU memory (see
|
||||
// b/276871425).
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) { viewModel.onTileRefreshRequested() }
|
||||
}
|
||||
|
||||
// Set the content of the activity, using either the View or Compose implementation.
|
||||
if (featureFlags.isEnabled(Flags.COMPOSE_PEOPLE_SPACE) && isComposeAvailable()) {
|
||||
Log.d(TAG, "Using the Compose implementation of the PeopleSpaceActivity")
|
||||
|
||||
@@ -109,14 +109,6 @@ object PeopleViewBinder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure to refresh the tiles/conversations when the Activity is resumed, so that it
|
||||
// updates them when going back to the Activity after leaving it.
|
||||
lifecycleOwner.lifecycleScope.launch {
|
||||
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
viewModel.onTileRefreshRequested()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setNoConversationsContent(view: ViewGroup, onGotItClicked: () -> Unit) {
|
||||
|
||||
Reference in New Issue
Block a user