Show the Compose implementation of PeopleSpace when Compose is available
Bug: 238993727 Test: Manual Change-Id: I41a6bae879e5a1f4e12f9ff998fb7f5d1320e135
This commit is contained in:
@@ -64,6 +64,7 @@ systemui_compose_java_defaults {
|
||||
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.material3_material3",
|
||||
"androidx.activity_activity-compose",
|
||||
],
|
||||
|
||||
// By default, Compose is disabled and we compile the ComposeFacade
|
||||
|
||||
@@ -17,10 +17,21 @@
|
||||
|
||||
package com.android.systemui.compose
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import com.android.systemui.people.ui.viewmodel.PeopleViewModel
|
||||
|
||||
/** The Compose facade, when Compose is *not* available. */
|
||||
object ComposeFacade : BaseComposeFacade {
|
||||
override fun isComposeAvailable(): Boolean = false
|
||||
|
||||
override fun setPeopleSpaceActivityContent(
|
||||
activity: ComponentActivity,
|
||||
viewModel: PeopleViewModel,
|
||||
onResult: (PeopleViewModel.Result) -> Unit,
|
||||
) {
|
||||
throwComposeUnavailableError()
|
||||
}
|
||||
|
||||
private fun throwComposeUnavailableError() {
|
||||
error(
|
||||
"Compose is not available. Make sure to check isComposeAvailable() before calling any" +
|
||||
|
||||
@@ -16,7 +16,21 @@
|
||||
|
||||
package com.android.systemui.compose
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import com.android.systemui.compose.theme.SystemUITheme
|
||||
import com.android.systemui.people.ui.compose.PeopleScreen
|
||||
import com.android.systemui.people.ui.viewmodel.PeopleViewModel
|
||||
|
||||
/** The Compose facade, when Compose is available. */
|
||||
object ComposeFacade : BaseComposeFacade {
|
||||
override fun isComposeAvailable(): Boolean = true
|
||||
|
||||
override fun setPeopleSpaceActivityContent(
|
||||
activity: ComponentActivity,
|
||||
viewModel: PeopleViewModel,
|
||||
onResult: (PeopleViewModel.Result) -> Unit,
|
||||
) {
|
||||
activity.setContent { SystemUITheme { PeopleScreen(viewModel, onResult) } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ android_library {
|
||||
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.material3_material3",
|
||||
"androidx.activity_activity-compose",
|
||||
],
|
||||
|
||||
kotlincflags: ["-Xjvm-default=all"],
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.android.systemui.compose
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import com.android.systemui.people.ui.viewmodel.PeopleViewModel
|
||||
|
||||
/**
|
||||
* A facade to interact with Compose, when it is available.
|
||||
*
|
||||
@@ -31,4 +34,11 @@ interface BaseComposeFacade {
|
||||
* This value will never change at runtime.
|
||||
*/
|
||||
fun isComposeAvailable(): Boolean
|
||||
|
||||
/** Bind the content of [activity] to [viewModel]. */
|
||||
fun setPeopleSpaceActivityContent(
|
||||
activity: ComponentActivity,
|
||||
viewModel: PeopleViewModel,
|
||||
onResult: (PeopleViewModel.Result) -> Unit,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -27,11 +27,15 @@ import android.view.ViewGroup;
|
||||
import androidx.activity.ComponentActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.android.systemui.compose.ComposeFacade;
|
||||
import com.android.systemui.people.ui.view.PeopleViewBinder;
|
||||
import com.android.systemui.people.ui.viewmodel.PeopleViewModel;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
|
||||
/** People Tile Widget configuration activity that shows the user their conversation tiles. */
|
||||
public class PeopleSpaceActivity extends ComponentActivity {
|
||||
|
||||
@@ -58,13 +62,18 @@ public class PeopleSpaceActivity extends ComponentActivity {
|
||||
int widgetId = getIntent().getIntExtra(EXTRA_APPWIDGET_ID, INVALID_APPWIDGET_ID);
|
||||
viewModel.onWidgetIdChanged(widgetId);
|
||||
|
||||
ViewGroup view = PeopleViewBinder.create(this);
|
||||
PeopleViewBinder.bind(view, viewModel, /* lifecycleOwner= */ this,
|
||||
(result) -> {
|
||||
finishActivity(result);
|
||||
return null;
|
||||
});
|
||||
setContentView(view);
|
||||
Function1<PeopleViewModel.Result, Unit> onResult = (result) -> {
|
||||
finishActivity(result);
|
||||
return null;
|
||||
};
|
||||
|
||||
if (ComposeFacade.INSTANCE.isComposeAvailable()) {
|
||||
ComposeFacade.INSTANCE.setPeopleSpaceActivityContent(this, viewModel, onResult);
|
||||
} else {
|
||||
ViewGroup view = PeopleViewBinder.create(this);
|
||||
PeopleViewBinder.bind(view, viewModel, /* lifecycleOwner= */ this, onResult);
|
||||
setContentView(view);
|
||||
}
|
||||
}
|
||||
|
||||
private void finishActivity(PeopleViewModel.Result result) {
|
||||
|
||||
Reference in New Issue
Block a user