Skip to content

Commit

Permalink
Convert permissions to m3
Browse files Browse the repository at this point in the history
  • Loading branch information
bentrengrove committed Dec 11, 2024
1 parent a327d83 commit 2e6aee2
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 57 deletions.
1 change: 0 additions & 1 deletion sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ dependencies {
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)
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
)
}
19 changes: 15 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,29 @@
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.fillMaxSize
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

@Composable
fun AccompanistSample(content: @Composable () -> Unit) {
AccompanistSampleTheme {
Surface(Modifier.fillMaxSize().safeDrawingPadding(), content = 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 @@ -32,14 +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.AccompanistM3SampleTheme
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

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

TwoPane(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ 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.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
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.AccompanistM3SampleTheme
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 {
AccompanistM3SampleTheme {
Surface(modifier = Modifier.fillMaxSize()) {
DraggableExample(this@DraggableFoldAwareColumnSample)
}
AccompanistSample {
DraggableExample(this@DraggableFoldAwareColumnSample)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ 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.AccompanistM3SampleTheme
import com.google.accompanist.sample.AccompanistSample

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

TwoPane(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +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.AccompanistM3SampleTheme
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

class NavDrawerFoldAwareColumnSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AccompanistM3SampleTheme {
AccompanistSample {
NavDrawerExample(this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.AccompanistM3SampleTheme
import com.google.accompanist.sample.AccompanistSample

class NavRailFoldAwareColumnSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AccompanistM3SampleTheme {
AccompanistSample {
Row {
NavRail(this@NavRailFoldAwareColumnSample)
Surface(modifier = Modifier.fillMaxSize()) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ 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.AccompanistM3SampleTheme
import com.google.accompanist.sample.AccompanistSample

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

TwoPane(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

class RequestLocationPermissionsSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
AccompanistSampleTheme {
AccompanistSample {
Sample()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,35 @@

package com.google.accompanist.sample.permissions

import android.Manifest
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.MultiplePermissionsState
import com.google.accompanist.permissions.PermissionState
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.AccompanistSample

@OptIn(ExperimentalPermissionsApi::class)
class RequestMultiplePermissionsSample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
AccompanistSampleTheme {
AccompanistSample {
val multiplePermissionsState = rememberMultiplePermissionsState(
listOf(
android.Manifest.permission.RECORD_AUDIO,
android.Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.CAMERA,
)
)
Sample(multiplePermissionsState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material3.Button
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
Expand All @@ -39,7 +41,9 @@ class RequestPermissionSample : ComponentActivity() {

setContent {
AccompanistSampleTheme {
Sample()
Surface(Modifier.fillMaxSize()) {
Sample()
}
}
}
}
Expand Down

0 comments on commit 2e6aee2

Please sign in to comment.