Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion .idea/copyright/Google.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.catalog.app.multiple

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.google.android.catalog.framework.annotations.Sample

@Sample(name = "Same file sample 1", "Show how a file can contain multiple samples")
@Composable
fun SameFileSample1() {
Box(Modifier.fillMaxSize()) {
Text(text = "Hi, I am same file sample 1")
}
}

@Sample(name = "Same file sample 2", "Show how a file can contain multiple samples")
@Composable
fun SameFileSample2() {
Box(Modifier.fillMaxSize()) {
Text(text = "Hi, I am same file sample 2")
}
}
7 changes: 5 additions & 2 deletions framework/base/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
package com.google.android.catalog.framework.base {

public final class CatalogSample {
ctor public CatalogSample(String name, String description, java.util.List<java.lang.String> tags, String documentation, String sourcePath, String path, java.util.List<java.lang.String> owners, com.google.android.catalog.framework.base.CatalogTarget target, optional int minSDK);
ctor public CatalogSample(String name, String description, java.util.List<java.lang.String> tags, String documentation, String sourcePath, String path, java.util.List<java.lang.String> owners, com.google.android.catalog.framework.base.CatalogTarget target, optional int minSDK, String route);
method public String component1();
method public String component10();
method public String component2();
method public java.util.List<java.lang.String> component3();
method public String component4();
Expand All @@ -12,13 +13,14 @@ package com.google.android.catalog.framework.base {
method public java.util.List<java.lang.String> component7();
method public com.google.android.catalog.framework.base.CatalogTarget component8();
method public int component9();
method public com.google.android.catalog.framework.base.CatalogSample copy(String name, String description, java.util.List<java.lang.String> tags, String documentation, String sourcePath, String path, java.util.List<java.lang.String> owners, com.google.android.catalog.framework.base.CatalogTarget target, int minSDK);
method public com.google.android.catalog.framework.base.CatalogSample copy(String name, String description, java.util.List<java.lang.String> tags, String documentation, String sourcePath, String path, java.util.List<java.lang.String> owners, com.google.android.catalog.framework.base.CatalogTarget target, int minSDK, String route);
method public String getDescription();
method public String getDocumentation();
method public int getMinSDK();
method public String getName();
method public java.util.List<java.lang.String> getOwners();
method public String getPath();
method public String getRoute();
method public String getSourcePath();
method public java.util.List<java.lang.String> getTags();
method public com.google.android.catalog.framework.base.CatalogTarget getTarget();
Expand All @@ -28,6 +30,7 @@ package com.google.android.catalog.framework.base {
property public final String name;
property public final java.util.List<java.lang.String> owners;
property public final String path;
property public final String route;
property public final String sourcePath;
property public final java.util.List<java.lang.String> tags;
property public final com.google.android.catalog.framework.base.CatalogTarget target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ data class CatalogSample(
val owners: List<String>,
val target: CatalogTarget,
val minSDK: Int = 0,
val route: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class SampleProcessor(
val packageName = functionSample.packageName.asString()
val sampleFile = functionSample.simpleName.asString()
val sample = functionSample.getAnnotationsByType(Sample::class).first()
val sampleSource = sample.sourcePath.ifBlank { filePath }
val minSDK = functionSample.getAnnotationsByType(RequiresApi::class).minOfOrNull {
it.value
} ?: 0
Expand All @@ -133,11 +134,12 @@ class SampleProcessor(
sampleDescription = sample.description,
sampleTags = sample.tags,
sampleDocs = sample.documentation,
sampleSource = sample.sourcePath.ifBlank { filePath },
sampleSource = sampleSource,
samplePath = filePath.substringBefore("/src"),
sampleOwners = sample.owners,
sampleTarget = target,
sampleMinSdk = minSDK,
sampleRoute = "$sampleSource#$sampleFile",
).toByteArray()
)
}
Expand All @@ -164,6 +166,7 @@ private fun sampleTemplate(
sampleOwners: Array<String>,
sampleTarget: String,
sampleMinSdk: Int,
sampleRoute: String,
) = """
package $samplePackage

Expand Down Expand Up @@ -192,6 +195,7 @@ class ${sampleFile}Module {
listOf(${sampleOwners.joinToString(",") { "\"$it\"" }}),
$sampleTarget,
$sampleMinSdk,
"$sampleRoute",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fun CatalogNavigation(
// Add the home destination
composable(CATALOG_DESTINATION) {
CatalogScreen(samples.toList()) {
navController.navigate(it.name)
navController.navigate(it.route)
}
}

Expand All @@ -72,15 +72,15 @@ private fun NavGraphBuilder.addTargets(
) {
when (val target = sample.target) {
is CatalogTarget.TargetComposable -> {
composable(sample.name) {
composable(sample.route) {
SampleScaffold(sample = sample, onBackClick = onBackClick) {
target.composable()
}
}
}

is CatalogTarget.TargetFragment -> {
composable(sample.name) {
composable(sample.route) {
SampleScaffold(sample = sample, onBackClick = onBackClick) {
FragmentContainer(
modifier = Modifier.fillMaxSize(),
Expand All @@ -94,7 +94,7 @@ private fun NavGraphBuilder.addTargets(
}

is CatalogTarget.TargetActivity -> {
activity(sample.name) {
activity(sample.route) {
label = sample.name
activityClass = target.targetClass
}
Expand Down
2 changes: 1 addition & 1 deletion spotless/copyright.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright $YEAR Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down