Skip to content

Commit

Permalink
Merge pull request #1810 from google/ben/m3
Browse files Browse the repository at this point in the history
Convert samples to M3 and edge to edge
  • Loading branch information
mlykotom authored Dec 11, 2024
2 parents a03d4df + 167b8a7 commit 60d967c
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 312 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ buildscript {

plugins {
id "com.diffplug.spotless" version "6.5.2"
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.android.kotlin) apply false
alias(libs.plugins.jetbrains.dokka)
Expand Down
19 changes: 3 additions & 16 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
*/
@file:Suppress("UnstableApiUsage")

import org.jetbrains.kotlin.gradle.dsl.JvmTarget


plugins {
id(libs.plugins.android.application.get().pluginId)
id(libs.plugins.android.kotlin.get().pluginId)
alias(libs.plugins.android.application)
alias(libs.plugins.android.kotlin)
alias(libs.plugins.compose.plugin)
}

Expand Down Expand Up @@ -69,25 +66,15 @@ dependencies {
implementation(project(":drawablepainter"))
implementation(project(":permissions"))

implementation(libs.androidx.appcompat)
implementation(libs.mdc)

implementation(libs.coil.compose)
implementation(libs.coil.gif)

implementation(libs.compose.material.material)
implementation(libs.compose.material.iconsext)
implementation(libs.compose.material3.material3)
implementation(libs.compose.foundation.layout)
debugImplementation(libs.compose.ui.tooling)
implementation(libs.compose.ui.tooling.preview)
implementation(libs.compose.ui.util)

implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.activity.compose)

implementation(libs.androidx.core)
implementation(libs.androidx.fragment)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.runtime)

implementation(libs.kotlin.stdlib)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable

/**
* A list which automatically populates the list of sample activities in this app
Expand All @@ -40,7 +35,7 @@ class MainActivity : ComponentActivity() {
val data = getData(intent.getStringExtra(EXTRA_PATH))

setContent {
AccompanistM3SampleTheme {
AccompanistSampleTheme {
MainScreen(
listData = data,
onItemClick = { startActivity(it) }
Expand Down Expand Up @@ -123,17 +118,3 @@ class MainActivity : ComponentActivity() {
}

private const val EXTRA_PATH = "com.example.android.apis.Path"

/**
* TODO Migrate whole sample app to m3 and move to Theme.kt
*/
@Composable
fun AccompanistM3SampleTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
MaterialTheme(
colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme(),
content = content
)
}
35 changes: 31 additions & 4 deletions sample/src/main/java/com/google/accompanist/sample/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,45 @@
package com.google.accompanist.sample

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun AccompanistSample(
contentPadding: PaddingValues = PaddingValues(16.dp),
content: @Composable () -> Unit
) {
AccompanistSampleTheme {
Surface(
modifier = Modifier.fillMaxSize()
) {
Box(
modifier = Modifier.padding(contentPadding).safeDrawingPadding(),
propagateMinConstraints = true
) {
content()
}
}
}
}

@Composable
fun AccompanistSampleTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
MaterialTheme(
colors = if (darkTheme) darkColors() else lightColors(),
colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme(),
content = content
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
Expand All @@ -32,13 +32,13 @@ import com.google.accompanist.adaptive.TwoPane
import com.google.accompanist.adaptive.TwoPaneStrategy
import com.google.accompanist.adaptive.VerticalTwoPaneStrategy
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

class BasicTwoPaneSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AccompanistSampleTheme {
AccompanistSample {
val displayFeatures = calculateDisplayFeatures(this)

TwoPane(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.FavoriteBorder
import androidx.compose.material3.Surface
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -47,18 +45,16 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import com.google.accompanist.adaptive.FoldAwareColumn
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample
import com.google.accompanist.sample.R
import kotlin.math.roundToInt

class DraggableFoldAwareColumnSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AccompanistSampleTheme {
Surface(modifier = Modifier.fillMaxSize()) {
DraggableExample(this@DraggableFoldAwareColumnSample)
}
AccompanistSample {
DraggableExample(this@DraggableFoldAwareColumnSample)
}
}
}
Expand All @@ -77,13 +73,13 @@ fun DraggableExample(activity: Activity) {
}
}
.width(400.dp)
.border(5.dp, MaterialTheme.colors.secondary),
.border(5.dp, MaterialTheme.colorScheme.secondary),
displayFeatures = calculateDisplayFeatures(activity),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Icon(
modifier = Modifier
.border(2.dp, MaterialTheme.colors.primary)
.border(2.dp, MaterialTheme.colorScheme.primary)
.padding(20.dp)
.align(Alignment.Start),
imageVector = Icons.Default.FavoriteBorder,
Expand All @@ -92,14 +88,14 @@ fun DraggableExample(activity: Activity) {
Text(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.border(2.dp, MaterialTheme.colors.primary),
.border(2.dp, MaterialTheme.colorScheme.primary),
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
)
Image(
modifier = Modifier
.ignoreFold()
.align(Alignment.End)
.border(2.dp, MaterialTheme.colors.primary),
.border(2.dp, MaterialTheme.colorScheme.primary),
painter = painterResource(id = R.drawable.placeholder),
contentDescription = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.accompanist.adaptive.FoldAwareConfiguration
import com.google.accompanist.adaptive.HorizontalTwoPaneStrategy
import com.google.accompanist.adaptive.TwoPane
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

class HorizontalTwoPaneSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AccompanistSampleTheme {
AccompanistSample {
val displayFeatures = calculateDisplayFeatures(this)

TwoPane(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Face
Expand All @@ -38,9 +34,13 @@ import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.ThumbUp
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -50,13 +50,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.accompanist.adaptive.FoldAwareColumn
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

class NavDrawerFoldAwareColumnSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AccompanistSampleTheme {
AccompanistSample(contentPadding = PaddingValues(all = 0.dp)) {
NavDrawerExample(this)
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ fun NavDrawerExample(activity: Activity) {
NavigationDrawerItem(
modifier = Modifier
.padding(5.dp)
.border(2.dp, MaterialTheme.colors.primary, CircleShape),
.border(2.dp, MaterialTheme.colorScheme.primary, CircleShape),
icon = { Icon(imageVector = it, contentDescription = it.name) },
label = { Text(it.name.substringAfter('.')) },
selected = it == selectedIcon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.NavigationRail
import androidx.compose.material.NavigationRailItem
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Face
Expand All @@ -38,6 +32,12 @@ import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.ThumbUp
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationRail
import androidx.compose.material3.NavigationRailItem
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -47,13 +47,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.accompanist.adaptive.FoldAwareColumn
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

class NavRailFoldAwareColumnSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AccompanistSampleTheme {
AccompanistSample {
Row {
NavRail(this@NavRailFoldAwareColumnSample)
Surface(modifier = Modifier.fillMaxSize()) {}
Expand Down Expand Up @@ -83,7 +83,7 @@ fun NavRail(activity: Activity) {
NavigationRailItem(
modifier = Modifier
.padding(5.dp)
.border(2.dp, MaterialTheme.colors.primary),
.border(2.dp, MaterialTheme.colorScheme.primary),
selected = it == selectedIcon,
onClick = { selectedIcon = it },
icon = { Icon(imageVector = it, contentDescription = it.name) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.accompanist.adaptive.FoldAwareConfiguration
import com.google.accompanist.adaptive.TwoPane
import com.google.accompanist.adaptive.VerticalTwoPaneStrategy
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

class VerticalTwoPaneSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AccompanistSampleTheme {
AccompanistSample {
val displayFeatures = calculateDisplayFeatures(this)

TwoPane(
Expand Down
Loading

0 comments on commit 60d967c

Please sign in to comment.