Giter Club home page Giter Club logo

basic-android-kotlin-compose-training-cupcake's Introduction

Cupcake app

This app contains an order flow for cupcakes with options for quantity, flavor, and pickup date. The order details get displayed on an order summary screen and can be shared to another app to send the order.

Pre-requisites

  • Experience with Kotlin syntax.
  • How to create and run a project in Android Studio.
  • How to create composable functions

Getting Started

  1. Install Android Studio, if you don't already have it.
  2. Download the sample.
  3. Import the sample into Android Studio.
  4. Build and run the sample.

basic-android-kotlin-compose-training-cupcake's People

Contributors

johnshea avatar the-scrambler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

basic-android-kotlin-compose-training-cupcake's Issues

Navigate between screens with Compose: Android Basics with Compose

It's not really an error, but it gets in the way. I refer to the videos of each module. It would be very interesting if, when choosing to translate automatically, the chosen language would be saved.

The way it is today, even reloading the screen, you have to go to the video settings and set it again.

Navigate between screens with Compose: Android Basics with Compose

Missed word in the code snippet.
In section 7. Make the AppBar respond to navigation
The text says: 4. Inside CupcakeAppBar, replace the hardcoded app name with the current screen's title by passing in currentScreen.title to the call to getResource() for the title parameter of TopAppBar.
But the following code snippet lacks a call to the currentScreen.title: title = { Text(stringResource(currentScreen.)) },

Navigate between screens with Compose: Android Basics with Compose

The Starter Code for this training exercise does not produce the result offered with the solution code. It's really annoying. The solution code works, but it cannot be achieved using the starter code plus instructions.. During the fifth part of the exercise the error the difference between the instruction and the solution is very obvious, Thands for nothing regarding the coding exercise with no matching solution.

Wrong Method Name shown on "Navigate between screens with Compose" (NavHostController)

Item 1 of this page mentions the following instruction and code:

In the CupcakeApp composable, below the navController variable, create a variable named backStackEntry and call the currentBackStackEntry() method of navController using the by delegate.

@Composable
fun CupcakeApp(modifier: Modifier = Modifier, viewModel: OrderViewModel = viewModel()){

    val navController = rememberNavController()

    val backStackEntry by navController.currentBackStackEntryAsState()

    ...
}

The instruction says that the method from the navController is currentBackStackEntry() when it is actually currentBackStackEntryAsState().

The correct text should be:

In the CupcakeApp composable, below the navController variable, create a variable named backStackEntry and call the currentBackStackEntryAsState() method of navController using the by delegate.

Navigate between screens with Compose: Android Basics with Compose

Unit 4. Pathway 1.
4. Define routes and create a NavHostController
You'll call the composable() function once for each of the four routes.
...
7. The flavor screen gets the list of flavors from the app's string resources. Transform the list...
Please, check brackets after code snippet in this part.

Test the Cupcake app: Android Basics in Compose

The CupcakeOrderScreenTest file, in package androidTest/java, contains a Test function (summaryScreen_verifyContentDisplay) with a minor error. The last call to composeTestRule.onNodeWithText() is missing an Assert statement. Should read:

    composeTestRule.onNodeWithText(
        composeTestRule.activity.getString(
            R.string.subtotal_price,
            fakeOrderUiState.price
        )
    ).assertIsDisplayed()

Could not find androidx.compose.ui:ui-test-junit4:. Required by: project :app

URL of codelab
Basic android-kotlin-compose-training (Test the Cupcake App)

In which task and step of the codelab can this issue be found?
Get the solution code (cupcake)

Describe the problem
After get the solution code and run tests from androidTest>java.com.example.cupcake.test>CupcakeScreenNavigationTest and run tests from class CupcakeScreenNavigationTest { ... } , you will receive the error
Could not find androidx.compose.ui:ui-test-junit4:. Required by: project :app

Steps to reproduce?

  1. Go to androidTest>java.com.example.cupcake.test>CupcakeScreenNavigationTest
    Screenshot from 2023-04-17 02-20-15

  2. Click on Run CupcakeScreenNavigationTest in class CupcakeScreenNavigationTest at line 37.
    Screenshot from 2023-04-17 02-25-52

  3. See error Could not find androidx.compose.ui:ui-test-junit4:. Required by: project :app

Versions
_Android Studio version: Android Studio Eletric Eel | 2022.1.1 Patch 2
_API version of the emulator: 33

Additional information
In build.gradle, we have already an androidTestImplementation "androidx.compose.ui:ui-test-junit4", as shown below:
Screenshot from 2023-04-17 02-28-41

Wrong text instruction on the "Navigate between screens with Compose" Guide.

There is a small mistake with the text for the callback function being passed to the OrderSummaryScreen Composable.

Here is what the text says, followed by the code example:

2 - Add another parameter of type ( ) -> Unit and name this one onSendButtonClicked.

@Composable
fun OrderSummaryScreen(
    orderUiState: OrderUiState,
    onCancelButtonClicked: () -> Unit,
    onSendButtonClicked: (String, String) -> Unit,
    modifier: Modifier = Modifier
){
    ...
}

The text should say:
2 - Add another parameter of type (String, String) -> Unit and name this one onSendButtonClicked.

Link to the page

Navigate between screens with Compose: Android Basics with Compose

In step 5 "Navigate between routes",
in step 2 of "Add button handlers to OrderSummaryScreen":

The guide says to add:
onSendButtonClicked: (String, String) -> Unit = {},
But if you do this you will get an error; "Expected 2 parameters of types String, String"

In the cupcake repo onSendBUttonClicked is declared without default value which does not give an error.

The guide should be updated accordingly.

Navigate between screens with Compose: Android Basics with Compose

@composable
fun OrderSummaryScreen(
orderUiState: OrderUiState,
onCancelButtonClicked: () -> Unit = {},
onSendButtonClicked: (String, String) -> Unit = {},
modifier: Modifier = Modifier
){
...
}
This code seems a mistake to me:
onSendButtonClicked: (String, String) -> Unit = {}, does not work, because the two parameters are missing from the default value.
Could you help me with this issue?
Thank you!

Navigate between screens with Compose: Android Basics with Compose

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-navigation?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-4-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-navigation#6

In which task and step of the codelab can this issue be found?
One Step 7 | Make the AppBar respond to the navigation

Describe the problem
In the 4th point of this step (4. Inside CupcakeAppBar...), there is a syntax error in the given code block. We are not calling the .title from the currentScreen parameter.

TopAppBar(
   title = { Text(stringResource(currentScreen.)) },
   modifier = modifier,
   navigationIcon = {
       if (canNavigateBack) {
           IconButton(onClick = navigateUp) {
               Icon(
                   imageVector = Icons.Filled.ArrowBack,
                   contentDescription = stringResource(R.string.back_button)
               )
           }
       }
   }
)

It should be :

TopAppBar(
   title = { Text(stringResource(currentScreen.title)) },
   modifier = modifier,
   navigationIcon = {
       if (canNavigateBack) {
           IconButton(onClick = navigateUp) {
               Icon(
                   imageVector = Icons.Filled.ArrowBack,
                   contentDescription = stringResource(R.string.back_button)
               )
           }
       }
   }
)

image

Test the Cupcake app: Android Basics with Compose (Test the CupcakeApp #5)

URL of codelab
https://developer.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-test-cupcake#4

In which task and step of the codelab can this issue be found?
Test the Cupcake App - Step 5 Write navigation tests

Describe the problem
Since this is the first time an "empty file" is being created, the extension of the file should be mentioned. Also helps to be consistent with a later step that mentions the file extension ComposeRuleExtensions.kt.

IS:
Create an empty Kotlin file in the test directory called ScreenAssertions.

SHOULD BE:
Create an empty Kotlin file in the test directory called ScreenAssertions.kt.

Steps to reproduce?
N/A

Versions
N/A

Test the Cupcake app: Android Basics in Compose

import org.junit.Assert.assertEquals
...

@Test
fun cupcakeNavHost_verifyStartDestination() {assertEquals(Cupcake.Start.name, currentBackStackEntry?.destination?.route)
}

This snipet of code is not working properly. So, they should be changed to as below.

@Test
    fun cupcakeNavHost_verifyStartDestination() {
        assertEquals(CupcakeScreen.Start.name, navController.currentBackStackEntry?.destination?.route)
    }

Navigate between screens with Compose: Missing currentScreen parameter

The instructions are lacking description of adding the currentScreen parameter below.
Also the title parameter of the CupCakeScreen enum is missing.

@Composable
fun CupcakeAppBar(
    currentScreen: CupcakeScreen,
    canNavigateBack: Boolean,
    navigateUp: () -> Unit,
    modifier: Modifier = Modifier
) {
    TopAppBar(
        title = { Text(stringResource(currentScreen.title)) },
        
       

Navigate between screens with Compose: Android Basics with Compose

Step 5 (Navigate between routes) -> Add button handlers to SummaryScreen -> Sub-step 2

The text should read:
Add another parameter of type (String, String) -> Unit and name this one onSendButtonClicked.

Instead of:
Add another parameter of type () -> Unit and name this one onSendButtonClicked.

Navigate between screens with Compose: Android Basics with Compose

n the CupcakeAppBar, pass in backStackEntry?.destination?.route for the currentScreen parameter. Because this is nullable, use the elvis operator (?:) to specify CupcakeScreen.Start.name as the default.

currentScreen = backStackEntry?.destination?.route ?: CupcakeScreen.Start.name,

sample code shows this should be located as a val here:
// Get the name of the current screen
val currentScreen = CupcakeScreen.valueOf(
backStackEntry?.destination?.route ?: CupcakeScreen.Start.name
)

Navigate between screens with Compose: Android Basics with Compose title property is missing

At the step 7. Make the AppBar respond to navigation in code snippet of sub-step 4 the currentScreen object is passed to stringResource function, but should be passed title property of the object instead

TopAppBar(
   - title = { Text(stringResource(currentScreen.)) },
   + title = { Text(stringResource(currentScreen.title)) },
   modifier = modifier,
   navigationIcon = {
       if (canNavigateBack) {
           IconButton(onClick = navigateUp) {
               Icon(
                   imageVector = Icons.Filled.ArrowBack,
                   contentDescription = stringResource(R.string.back_button)
               )
           }
       }
   }

Test the Cupcake app: Android Basics in Compose

Issue 1

The third snippet is kinda misleading

@Test
fun cupcakeNavHost_verifyStartDestination() {assertEquals(Cupcake.Start.name, currentBackStackEntry?.destination?.route)
}

Cupcake.Start.name should be CupcakeScreen.Start.name. Additionally currentBackStackEntry cannot be resolved - it should read navController.currentBackStackEntry?.destination?.route.

To sum it up:

@Test
fun cupcakeNavHost_verifyStartDestination() {
    assertEquals(CupcakeScreen.Start.name, navController.currentBackStackEntry?.destination?.route)
}

Issue 2

Following the Verify navigation to the Flavor screen section the code snippet reads

@Test
fun cupcakeNavHost_clickOneCupcake_navigatesToSelectFlavorScreen() {
   composeTestRule.onNodeWithStringId(R.string.one_cupcake)
       .performClick()
}

However there is no #onNodeWithStringId in androidx.compose.ui.test - see docs
By looking at the solution it becomes clear that this is an extension method that was added however it is not mentioned on the Codelab.

Navigate between screens with Compose: Android Basics with Compose

There's a small mistake in the docs, in this code, the title property stringResource id should be currentScreen.title

TopAppBar(
   title = { Text(stringResource(currentScreen.)) },
   modifier = modifier,
   navigationIcon = {
       if (canNavigateBack) {
           IconButton(onClick = navigateUp) {
               Icon(
                   imageVector = Icons.Filled.ArrowBack,
                   contentDescription = stringResource(R.string.back_button)
               )
           }
       }
   }
)

This code is missing the 'title' property at the end of the stringResource(currentScreen).
It should be:

TopAppBar(
   title = { Text(stringResource(currentScreen.title)) },
   modifier = modifier,
   navigationIcon = {
       if (canNavigateBack) {
           IconButton(onClick = navigateUp) {
               Icon(
                   imageVector = Icons.Filled.ArrowBack,
                   contentDescription = stringResource(R.string.back_button)
               )
           }
       }
   }
)

Navigate between screens with Compose: Android Basics with Compose

I have a Problem as "Interface NavHost does not have constructors" even when i have given constructors

Code is following:
`/*

  • Copyright (C) 2023 The Android Open Source Project
  • 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.example.cupcake

import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHost
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.cupcake.ui.OrderViewModel

enum class CupcakeScreen {
Start,
Flavour,
Pickup,
Summary
}

/**

  • Composable that displays the topBar and displays back button if back navigation is possible.
    */
    @composable
    fun CupcakeAppBar(
    canNavigateBack: Boolean,
    navigateUp: () -> Unit,
    modifier: Modifier = Modifier
    ) {
    TopAppBar(
    title = { Text(stringResource(id = R.string.app_name)) },
    colors = TopAppBarDefaults.mediumTopAppBarColors(
    containerColor = MaterialTheme.colorScheme.primaryContainer
    ),
    modifier = modifier,
    navigationIcon = {
    if (canNavigateBack) {
    IconButton(onClick = navigateUp) {
    Icon(
    imageVector = Icons.Filled.ArrowBack,
    contentDescription = stringResource(R.string.back_button)
    )
    }
    }
    }
    )
    }

@Preview(showBackground = true)
@composable
fun CupcakeApp(
viewModel: OrderViewModel = viewModel(),
navController: NavHostController = rememberNavController()
) {

Scaffold(
    topBar = {
        CupcakeAppBar(
            canNavigateBack = false,
            navigateUp = { /* TODO: implement back navigation */ }
        )
    }
) { innerPadding ->
    val uiState by viewModel.uiState.collectAsState()
    Text("Hi", modifier = Modifier.padding(innerPadding))
    NavHost(
        navController = navController,
        startDestination = CupcakeScreen.Start.name,
        modifier = Modifier.padding(innerPadding),
    ) {}
}

}
`

Navigate between screens with Compose: Android Basics with Compose

In starter code of the Cupcake app, there is no "currentScreen" parameter in "@composable
fun CupcakeAppBar" in java/com/example/cupcake/CupcakeScreen.kt
The text value of the TopAppBar title is hardcoded.
Therefore, it's hard to understand the step "7" in the pathway, because according to the tutorial, the existence of "currentScreen" parameter is expected. Also the text of the tutorial is a bit ambiguous. You don't know whether is CupcakeAppBar composable or CupcakeAppBar call in CupcakeApp composable meant.
image

Test the Cupcake app: Android Basics in Compose

The starter code (on "navigation" branch) does not include the ComposeRuleExtensions.kt file. This file contains the extension function onNodeWithStringId(...) which is needed for part 5 of this codelab.

Navigate between screens with Compose: Android Basics with Compose

Step 7 should use context instead of stringResource() to retrieve the string resource in order to be consistent.

Step 7 instructs to use stringResouce(). However, step 6 sets up to use context, and step 8 shows that context was indeed used, not stringResource(). So, step 7 should be fixed to:

  1. The flavor screen gets the list of flavors from the app's string resources. Create a list of strings from the flavors list in the view model. You can transform the list of resource IDs into a list of strings using the map() function and calling context.resources.getString(id).
composable(route = CupcakeScreen.Flavor.name) {
    val context = LocalContext.current
    SelectOptionScreen(
        subtotal = uiState.price,
        options = flavors.map { id -> context.resources.getString(id) }
    )
}

Navigate between screens with Compose: Android Basics with Compose

Inside the

Add button handlers to SelectOptionScreen

I am facing an issue on Point Number 3 and 4

OutlinedButton(modifier = Modifier.weight(1f), onClick = onCancelButtonClicked) {
Text(stringResource(R.string.cancel))
}

above this code snippet onClick has some problem and that should be onClick = onCancelButtonClicked() with opening and closing parenthesis ()

point 4

also for the onClick = onNextButtonClicked( )

without the parenthesis, it's not working...

Test the Cupcake app: Android Basics in Compose

When checking out main and running all the tests from CupcakeScreenNavigationtest I get the following exception for every test:

12-25 15:39:20.491 24678 24705 E TestRunner: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.cupcake.test/androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared ?

Does anybody have the same problem? I just checked it out and didn't change anything.

Navigate between screens with Compose: Android Basics with Compose

Note: The quantityOptions property comes from calling collectAsState() in the line before the NavHost. Other properties from the view model will be accessed the same way.

It looks like it does not
It comes from DataSource.kt
quantityOptions has nothing to do with the viewmodel

Navigate between screens with Compose: Android Basics with Compose

In the following code snippet (which is found in task 4. Define routes and create a NavHostController),
the line 8 should not have curly braces:

import com.example.cupcake.ui.SelectOptionScreen

composable(route = CupcakeScreen.Flavor.name) {
    val context = LocalContext.current
    SelectOptionScreen(
        subtotal = uiState.price,
        options = DataSource.flavors.map { id -> context.resources.getString(id) }
        }
    )
}

Instead, it should look like this:

import com.example.cupcake.ui.SelectOptionScreen

composable(route = CupcakeScreen.Flavor.name) {
    val context = LocalContext.current
    SelectOptionScreen(
        subtotal = uiState.price,
        options = DataSource.flavors.map { id -> context.resources.getString(id) }
    )
}

Navigate between screens with Compose: Android Basics with Compose

In the "Handle routes in your NavHost" section, there is a note that states:

Note: The quantityOptions property comes from calling collectAsState() in the line before the NavHost. Other properties from the view model will be accessed the same way.

This statement is incorrect as quantityOptions property does not come from calling collectAsState() but rather comes from data.DataSource. Therefore, the note above should read:

Note: The quantityOptions property comes from the DataSource object inside the data package.

Navigate between screens with Compose: Android Basics with Compose

Within the trailing lambda, get a reference to LocalContext.current and store it in a variable named context. You can use this variable to get the strings from the list of resource IDs in the view model to display the list of flavors.

composable(route = CupcakeScreen.Flavor.name) {
val context = LocalContext.current

}

this val context = LocalContext.current will never be used in the whole app
and again the list of flavors has nothing to do with the viewmodel, it is in DataSource.kt

Navigate between screens with Compose: Android Basics with Compose

I was reading the tutorial on developping mobile application and I think some examples are missing here (french version) :

Spécifiez le type de données supplémentaires envoyées avec l'intent. Vous pouvez utiliser "text/plain" pour un texte simple, mais d'autres types, tels que , sont également disponibles.

This is located in Navigate between screens with Compose: Android Basics with Compose -> Navigate to another app.

I checked the english version and it seems to be fine so I don't know if french is the only language affected by this issue.

Run Test Errors

Please help me. Thanks! =))

image

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/ui/text/input/TextInputForTests;
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.withTextInputService(ComposeUiTest.android.kt:393)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.access$withTextInputService(ComposeUiTest.android.kt:234)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$runTest$1$1$1$1$1$1.invoke(ComposeUiTest.android.kt:329)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.withComposeIdlingResource(ComposeUiTest.android.kt:383)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.access$withComposeIdlingResource(ComposeUiTest.android.kt:234)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$runTest$1$1$1$1$1.invoke(ComposeUiTest.android.kt:328)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.withWindowRecomposer(ComposeUiTest.android.kt:357)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.access$withWindowRecomposer(ComposeUiTest.android.kt:234)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$runTest$1$1$1$1.invoke(ComposeUiTest.android.kt:327)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.withTestCoroutines(ComposeUiTest.android.kt:370)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.access$withTestCoroutines(ComposeUiTest.android.kt:234)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$runTest$1$1$1.invoke(ComposeUiTest.android.kt:326)
at androidx.compose.ui.test.junit4.EspressoLink.withStrategy(EspressoLink.android.kt:66)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$runTest$1$1.invoke(ComposeUiTest.android.kt:325)
at androidx.compose.ui.test.junit4.IdlingResourceRegistry.withRegistry(IdlingResourceRegistry.jvm.kt:157)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$runTest$1.invoke(ComposeUiTest.android.kt:324)
at androidx.compose.ui.test.junit4.ComposeRootRegistry.withRegistry(ComposeRootRegistry.android.kt:146)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.runTest(ComposeUiTest.android.kt:323)
at androidx.compose.ui.test.junit4.AndroidComposeTestRule$apply$1.evaluate(AndroidComposeTestRule.android.kt:271)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:67)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:446)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2248)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.compose.ui.text.input.TextInputForTests" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/android.test.base.jar", zip file "/data/app/~~XbZTGxgD6oNfodUjARGmIQ==/com.example.cupcake.test-O2ey1wPFXJ567UEJ7LQl_w==/base.apk", zip file "/data/app/~~m08M6kj6RlnbNKNTaMDwAA==/com.example.cupcake-aQ7Ef34hQHHD2vudOtdmwg==/base.apk"],nativeLibraryDirectories=[/data/app/~~XbZTGxgD6oNfodUjARGmIQ==/com.example.cupcake.test-O2ey1wPFXJ567UEJ7LQl_w==/lib/arm64, /data/app/~~m08M6kj6RlnbNKNTaMDwAA==/com.example.cupcake-aQ7Ef34hQHHD2vudOtdmwg==/lib/arm64, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

Navigate between screens with Compose: Android Basics with Compose

in Add button handlers to OrderSummaryScreen
in 2.Add another parameter of type (String, String) -> Unit with a default value of {} and name this one onSendButtonClicked.

fun OrderSummaryScreen(
    orderUiState: OrderUiState,
    onCancelButtonClicked: () -> Unit = {},
    onSendButtonClicked: (String, String) -> Unit = {},
    modifier: Modifier = Modifier
){
    ...
}

change signature of lambda expression
onSendButtonClicked: (String, String) -> Unit = {}
to
onSendButtonClicked: (String, String) -> Unit = { s: String, s1: String -> }

Navigate between screens with Compose: Android Basics with Compose

In part 6 (Navigate to Another App), there seems to be a typo in the process for setting up a basic intent. In step 2 of this process, it states

For a simple piece of text, you can use "text/plain", though other types, such as <insert examples>, are available.

It seems like the "<insert examples>" text was a reminder to the author(s) of this document to add some examples of other additional data types to be sent with an intent, but it was never replaced.

Navigate between screens with Compose: Android Basics with Compose Step 5

On Step 5
image

I cannot go furhter then Flavor.
The "onNextButtonClicked from Flavor to Pickup is not working.

I already copied the whole NavHost from the solution and the issue is still the same.
I cannot find the fault.

image

Ich already tried to figure out, what happens on the Event with Log.d
On SelectedOptionScreen the onNextButtonClicked is received, but in the Flavor Screen, nothing happens...??? And the Log.d is not carried out at all.

I can not go to the PickupScreen. I am really confused and dont know, where to look after the Problem anymore...

Since nobody else seems to have this problem....it is probably my own fault (or nobody had tried the navigation at this time of the codlab??)...but I dont know where I coud have made it...

And funny thing is, that i can got to Pickup directly from Start...... Where is the fault here?

image

AND...the "Cancel" Button is not working either...

Navigate between screens with Compose: Android Basics with Compose

At the end of "Add button handlers to OrderSummaryScreen" step, it's missing adding lambdas to OrderSummaryPreview

@Preview
@Composable
fun OrderSummaryPreview(){
    OrderSummaryScreen(
        orderUiState = OrderUiState(0, "Test", "Test", "$300.00"),
        onSendButtonClicked = { subject: String, summary: String -> }, //*** HERE
        onCancelButtonClicked = {} //*** HERE
    )
}

And OrderSummaryScreen the lambdas shouldn't have { }.

@Composable
fun OrderSummaryScreen(
    orderUiState: OrderUiState,
    onCancelButtonClicked: () -> Unit, //*** HERE
    onSendButtonClicked: (String, String) -> Unit, //*** HERE
    modifier: Modifier = Modifier
){

The solution ZIP file at the end of the tutorial has this code, but the tutorial does not.

Navigate between screens with Compose: Android Basics with Compose

Following along, half way through adding button handlers to the OrderSummaryScreen, it states:

"Add another parameter of type (String, String) -> Unit with a default value of {} and name this one onSendButtonClicked."
and shows:

@composable
fun OrderSummaryScreen(
orderUiState: OrderUiState,
onCancelButtonClicked: () -> Unit = {},
onSendButtonClicked: (String, String) -> Unit = {},
modifier: Modifier = Modifier
){
...
}

But that onSendButtonClicked wont compile correctly in the end. Besides it breaks the former @Preview, which is also nowhere mentioned in the Tutorial. You should fix that.

Navigate between screens with Compose: Android Basics with Compose

Hello!

In the OrderSummaryScreen function, the following starting value can't be added to the parameter onSendButtonClicked:
onSendButtonClicked: (String, String) -> Unit = {},
This is because {} does not take the two String parameters. I might have missed something, but I got an error message when building.
I solved the problem by replacing {} with {first, second -> Unit}.
I hope this message is helpful, and it's not just that I am too clumsy. :D

David

PS: Thank you for providing such a great material!

Navigation in Jetpack Compose - Test the Cupcake app - java.util.Calendar vs. android.icu.util.Calendar

https://developer.android.com/codelabs/basic-android-kotlin-compose-test-cupcake?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-4-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-test-cupcake#4

In which task and step of the codelab can this issue be found?
Task 5: Write navigation tests (target of link)
Section: Write more helper methods
after step 3: First helper method right below the green note

Describe the problem
The usage of two different calendar implementations confuses me.

1. Different calendar for instantiation and creation of argument

Sample code provided in the course (see above) and in the solution code:

import android.icu.util.Calendar
...
private fun getFormattedDate(): String {
    val calendar = Calendar.getInstance()
    calendar.add(java.util.Calendar.DATE, 1)
    ...
}

Why are two different calendar implementations used at this point?

2. Inconsistent usage of calendar classes

For the same use case two different calendar classes are used.
OrderViewModel.pickupOptions() => java.util.Calendar
CupcakeScreenNavigationTest.getFormattedDate() => android.icu.util.Calendar

Can you please use one calendar implementation consistently and briefly explain why this implementation is the right one to use?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.