Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies {

implementation(libs.glance.appwidget)
implementation(libs.glance.material)
implementation(libs.androidx.xr.material3)

testImplementation(libs.junit)
androidTestImplementation(libs.truth)
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@
core-performance-play-services dependency requires minSdk 24. We fall back to using
DefaultDevicePerformance from the core-performance dependency (minSdk 19) if the SDK level
is <24.

XR features are only used on SDK level >= 34 (UPSIDE_DOWN_CAKE),
so it's safe to override their declared minSdk as well.
-->
<uses-sdk tools:overrideLibrary="androidx.core.performance.play.services" />
<uses-sdk tools:overrideLibrary="androidx.core.performance.play.services,
com.google.ar.imp.apibindings, androidx.xr.scenecore, androidx.xr.arcore,
androidx.xr.compose, androidx.xr.compose.material3,
androidx.xr.runtime.openxr, androidx.xr.runtime" />

<application
android:name=".SocialApp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ import androidx.activity.enableEdgeToEdge
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.glance.appwidget.updateAll
import androidx.lifecycle.lifecycleScope
import androidx.xr.compose.material3.EnableXrComponentOverrides
import androidx.xr.compose.material3.ExperimentalMaterial3XrApi
import com.google.android.samples.socialite.ui.Main
import com.google.android.samples.socialite.widget.SociaLiteAppWidget
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3XrApi::class)
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -49,9 +52,17 @@ class MainActivity : ComponentActivity() {
lifecycleScope.launch { SociaLiteAppWidget().updateAll(this@MainActivity) }
}
setContent {
Main(
appArgs = extractAppArgs(intent),
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
EnableXrComponentOverrides {
Main(
appArgs = extractAppArgs(intent),
)
}
} else {
Main(
appArgs = extractAppArgs(intent),
)
}
Comment on lines +55 to +65

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Main(appArgs = extractAppArgs(intent)) call is duplicated in both branches of the if/else statement. To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, could we refactor this block to define the Main composable invocation once and then use it within the conditional EnableXrComponentOverrides wrapper and the else block?

This would make the code slightly cleaner and easier to modify if the arguments or structure of the Main call changes in the future.

            val mainUi = @Composable {
                Main(
                    appArgs = extractAppArgs(intent),
                )
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
                EnableXrComponentOverrides {
                    mainUi()
                }
            } else {
                mainUi()
            }

}
}

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ generativeai = "0.9.0"
datastore = "1.1.4"
lifecycleViewmodel = "1.0.0-SNAPSHOT"
navigation3 = "0.1.0-SNAPSHOT"
xrMaterial3Version = "1.0.0-alpha07"


[libraries]
Expand Down Expand Up @@ -127,6 +128,7 @@ androidx-lifecycle-viewmodel-navigation3 = { module = "androidx.lifecycle:lifecy
androidx-lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodel" }
androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "navigation3" }
androidx-navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "navigation3" }
androidx-xr-material3 = { group = "androidx.xr.compose.material3", name = "material3", version.ref = "xrMaterial3Version" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
Expand Down
Loading