Giter VIP home page Giter VIP logo

android-basics-kotlin-lunch-tray-app's Introduction

Lunch Tray - Starter Code

Starter code for the third independent project for Android Basics in Kotlin

Introduction

This is the starter code for the Lunch Tray app project. This project is an opportunity for you to demonstrate the concepts you learned in Unit 3 of Android Basics in Kotlin.

Pre-requisites

  • Complete Unit 3 of Android Basics in Kotlin

Getting Started

  1. Download the starter code
  2. Open the project in Android Studio
  3. Complete the project in accordance with the app requirements

Tips

  • Use the provided tests to ensure your app is running as expected
  • DO NOT ALTER THE PROVIDED TESTS

android-basics-kotlin-lunch-tray-app's People

Contributors

android-dev-lxl avatar jkcoolmom avatar kkuan2011 avatar osuleymanova avatar owenlarosa avatar owenscott-gds avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

android-basics-kotlin-lunch-tray-app's Issues

Please, help me for this. Don't skip if you could help me, please.

I'm seaching solution for this since the last week. I'm one of GADS 2021 scholars and have Google Android Developer Certification exam in few days, this month. I'm working on a small project that includes Room Database with four tables and there're two tables Student and Course with N to N relationship. My goal is to to search a student by his name and display all the courses taken by this one in a recycler view using ListAdapter or Paging library but with my code, it doesn't work and I don't know the reason. So I'm looking for a way to do that.I posted it on StackOverflow twice but I didn't get satisfied. I know if I find a solution for this, I can use it for other parts of the project because there are other parts which has the same issue. I really need help for this. I want to use it in an other app I want to publish on PlayStore, that app will be my first app. Here is what I did in the project I'm working on:

MY TWO TABLES OR ENTITIES:

@Entity(tableName = "course_table")
data class Course(
    @PrimaryKey(autoGenerate = false)
    val courseName : String,

    @ColumnInfo(name = "course_duration")
    val courseDuration : String
)
@Entity(tableName = "student_table")
data class Student(
    @PrimaryKey(autoGenerate = false)
    val studentName : String,

    val semester : Int,

    val schoolName : String
)

RELATIONS BETWEEN TABLES

@Entity(primaryKeys = ["studentName", "courseName"])
data class StudentAndCourseTogether(
    val studentName : String,
    val courseName : String
)
data class CourseAndStudent(
    @Embedded
    val course : Course,

    @Relation(
        parentColumn = "courseName",
        entityColumn = "studentName",
        associateBy = Junction(StudentAndCourseTogether::class)
    )

    val students : List<Student>
)
data class StudentAndCourse(
    @Embedded
    val student : Student,

    @Relation(parentColumn = "studentName", entityColumn = "courseName", associateBy = Junction(StudentAndCourseTogether::class))
    val courses : List<Course>
)

MY QUERY TO GET ALL COURSES TAKEN BY A STUDENT

@Transaction
    @Query("SELECT * FROM student_table WHERE studentName = :studentName")
    fun getAllCoursesByStudentName(studentName: String) : Flow<List<StudentAndCourse>>

MY REPOSITORY CODE

val allCourseByStudentName = allItemsByNameDao.getAllCoursesByStudentName(studentName = "Esperant")

MY VIEWMODEL CODE

val coursesByStudentName : LiveData<List<StudentAndCourse>> = allItemsByNameRepository.allCourseByStudentName.asLiveData()

MY ADAPTER CODE

class CourseByStudentNameAdapter :
    ListAdapter<Course,
            CourseByStudentNameAdapter.CourseByStudentNameViewHolder>(DiffCallback) {


    class CourseByStudentNameViewHolder(private val binding: CourseByStudentNameItemBinding) :
        RecyclerView.ViewHolder(binding.root){

        fun bind(course: Course){
            binding.courseName.text = course.courseName
            binding.courseDuration.text = course.courseDuration
        }

    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int,
    ): CourseByStudentNameViewHolder {
        val inflatedLayout = CourseByStudentNameItemBinding.inflate(LayoutInflater.from(
            parent.context), parent, false)

        return CourseByStudentNameViewHolder(inflatedLayout)
    }


    override fun onBindViewHolder(holder: CourseByStudentNameViewHolder, position: Int) {
        val currentCourse = getItem(position)
        if (currentCourse != null) {
            holder.bind(currentCourse)
        }
    }



    companion object DiffCallback : DiffUtil.ItemCallback<Course>(){
        override fun areItemsTheSame(
            oldItem: Course,
            newItem: Course
        ): Boolean = oldItem.courseName == newItem.courseName

        override fun areContentsTheSame(
            oldItem: Course,
            newItem: Course
        ): Boolean = oldItem == newItem

    }
}

MY ASSOCIETED FRAGMENT CODE

@AndroidEntryPoint
class AllCourseByStudentNameFragment : Fragment() {

    private var _binding : FragmentAllCourseByStudentNameBinding? = null
    private val binding get() = _binding!!

    private val viewModel : AllItemsByNameViewModel by activityViewModels()

    private lateinit var adapter : CourseByStudentNameAdapter


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

        setHasOptionsMenu(true)
    }


    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View {
        // Inflate the layout for this fragment
        _binding = FragmentAllCourseByStudentNameBinding.inflate(inflater)
        return binding.root
    }

    @SuppressLint("LongLogTag")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        adapter = CourseByStudentNameAdapter()
        binding.apply {
            recyclerView.adapter = adapter
            recyclerView.layoutManager = LinearLayoutManager(requireContext())
            recyclerView.setHasFixedSize(true)
        }

        viewModel.setName(enteredName = "Esperant")

        viewModel.coursesByStudentName.observe(viewLifecycleOwner){
            for (course in it){
                adapter.submitList(course.courses)
            }
            Log.d(TAG, "The returned list size is ${it.size}")
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()

        _binding = null
    }
}

MY XML CODE

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <androidx.appcompat.widget.LinearLayoutCompat
        android:id="@+id/linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_marginTop="4dp"
        style="@style/itemListTextStyle"
        android:background="@drawable/item_layout_background"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <TextView
            android:id="@+id/course_name"
            android:layout_width="match_parent"
            tools:text="Computer"
            android:gravity="center"
            android:layout_height="wrap_content"/>

        <TextView
            android:id="@+id/course_duration"
            android:layout_width="match_parent"
            tools:text="15 hours"
            android:gravity="center"
            android:layout_height="wrap_content"/>

    </androidx.appcompat.widget.LinearLayoutCompat>

</androidx.constraintlayout.widget.ConstraintLayout>

The project repository link

https://github.com/esperantgada/Room_With_Multiple_Tables

Post on StackOverflow

https://stackoverflow.com/questions/71585416/how-to-display-items-from-two-room-database-tables-with-n-to-n-relationship-in-a

I'll be very glad to hear from you, it's very important for me. Thanks in advance

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
Test Your App

Describe the problem
When attempting to run the app a NullPointerException results in app crashing:

Caused by: java.lang.NullPointerException: null cannot be cast to non-null type androidx.navigation.fragment.NavHostFragment
        at com.example.lunchtray.MainActivity.onCreate(MainActivity.kt:32)

Steps to reproduce?

  1. Implement MainActivity.kt to match the MainActivity.kt implementation in the prior Cupcake codelab and documentation that describes initializing a navHostFragment:
class MainActivity : AppCompatActivity() {

    private lateinit var navController: NavController

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

        val navHostFragment = supportFragmentManager // NULL CANNOT BE CAST TO NON NULL TYPE 
            .findFragmentById(R.id.nav_host_fragment) as NavHostFragment
        navController = navHostFragment.navController

        setupActionBarWithNavController(navController)
    }

    override fun onSupportNavigateUp(): Boolean {
        return navController.navigateUp() || super.onSupportNavigateUp()
    }
}
  1. Attempt to run app, it will crash and output the following error in Logcat:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lunchtray/com.example.lunchtray.MainActivity}: java.lang.NullPointerException: null cannot be cast to non-null type androidx.navigation.fragment.NavHostFragment

Versions
Android Studio version: 2021.1.1 Patch 1
API version of the emulator: 30

Additional information
Include screenshots if they would be useful in clarifying the problem.
image
image

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
In the NavigationTests class

Describe the problem
I think there is an error on the id of the startOrderFragment : R.id.startOrder instead of R.id.startOrderFragment

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.
Capture d’écran 2022-01-03 à 19 24 50

Android Basics: Lunch Tray app

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-5%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray#2

In which task and step of the codelab can this issue be found?

  1. Get Started
    Describe the problem

I think this code must be if not null but you wrote it "If the _subtotal's value is null, subtract the previousEntreePrice from the subtotal."
since if it is null which is false since it initialized already with 0.0 then the condition will never be met!
so it should be if not is null here is an example
if (_subtotal.value != null) {
_subtotal.value = _subtotal.value?.minus(previousEntreePrice)
}
I think you correct that condition in your comment in the Lunch Tray app. in OrderViewModel.kt
because once

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-5%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray

In which task and step of the codelab can this issue be found?
Step 4. Test

Describe the problem
com/example/lunchtray/NavigationTests.kt
lines 83, 126, 163, 200, 218
Unresolved reference: startOrder
should be "R.id.startOrderFragment" instead of "R.id.startOrder"

Steps to reproduce?
Run 'NavigationTests'

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app: Conflicting instructions for calculating subtotal.

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

In which task and step of the codelab can this issue be found?
Project: Lunch Tray app Step 3: § setEntree(), setSide(), and setAccompaniment()

Describe the problem
The instructions on the page conflict with the instructions given in the TODO within the project, one referring to a positive null test and the other to a negative null test.

Within the CodeLab:

If the _subtotal's value is null, subtract the previousEntreePrice from the subtotal.

Within the Project:

// TODO: if _subtotal.value is not null subtract the previous entree price from the current
// subtotal value. This ensures that we only charge for the currently selected entree.

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
Task: Get Started
Step: Initialize the data binding variables in the fragments

Describe the problem
Attempting to initialize the EntreeMenuFragment variable (or any fragment variable declared in the fragment layout xml files) results in the following error: Classifier 'EntreeMenuFragment' does not have a companion object, and thus must be initialized here

Steps to reproduce?

  1. Implement layout xml variables as described in previous code labs:
    Screenshot from 2022-02-11 11-44-42

  2. Attempt to initialize binding variable in the onViewCreated() method in corresponding fragment file:
    Screenshot from 2022-02-11 12-00-17

  3. See error: Classifier 'EntreeMenuFragment' does not have a companion object, and thus must be initialized here

Versions
Android Studio version: Android Studio Bumblebee 2021.1.1 Patch 1

Android Basics: Lunch Tray app (What is the best way to set onCLick for buttons?)

URL of codelab

In which task and step of the codelab can this issue be found?

Describe the problem
Hello!
I have a question about click listener for buttons in layout files. What is the best way to call method in layout?
For example in fragment_entree_menu.xml i want to set onClick listener for setEntree method, but it needs string with name of the entree dish for it.

I've come up only with creating variables in xml with String type and initialize them in EntreeMenuFragment.

Is there a better way to pass string to setEntree?

Screenshots of what i meen:

onClick

Variables

VerInit

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

URL of codelab

In which task and step of the codelab can this issue be found?
Task 4 "Test your app"
Run OrderFunctionalityTests

Describe the problem
The provided code has a test where it clicks on a radio button. The comment says "Select the potato item", but the code below performs a click on "pickles". The price of pickles is different from the price of potatoes, so when it checks the string, it's different throwing an error.

Steps to reproduce?

  1. A completed lunch tray app.
  2. Run the test "OrderFunctionalityTests"
  3. Function radio_buttons_update_accompaniment_menu_subtotal will throw an error.
  4. // Select the potato item
     onView(withId(R.id.pickles)).perform(click())
     onView(withId(R.id.subtotal))
         .check(matches(withText(containsString("Subtotal: $0.50"))))
    
  5. Get's this error:

androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: a string containing "Subtotal: $0.50"' doesn't match the selected view.
Expected: with text: a string containing "Subtotal: $0.50"
Got: "TextView{id=2131231151, res-name=subtotal, visibility=VISIBLE, width=342, height=67, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@eea6adc, tag=null, root-is-layout-requested=false, has-input-connection=false, x=694.0, y=813.0, text=Subtotal: $0.00, input-type=0, ime-target=false, has-links=false}"

at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1724)
at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:16)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:36)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:103)
at androidx.test.espresso.ViewInteraction.check(ViewInteraction.java:31)
at com.example.lunchtray.OrderFunctionalityTests.radio_buttons_update_accompaniment_menu_subtotal(OrderFunctionalityTests.kt:120)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:154)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
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:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2248)
Caused by: junit.framework.AssertionFailedError: 'with text: a string containing "Subtotal: $0.50"' doesn't match the selected view.
Expected: with text: a string containing "Subtotal: $0.50"
Got: "TextView{id=2131231151, res-name=subtotal, visibility=VISIBLE, width=342, height=67, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@eea6adc, tag=null, root-is-layout-requested=false, has-input-connection=false, x=694.0, y=813.0, text=Subtotal: $0.00, input-type=0, ime-target=false, has-links=false}"

at androidx.test.espresso.matcher.ViewMatchers.assertThat(ViewMatchers.java:17)
at androidx.test.espresso.assertion.ViewAssertions$MatchesViewAssertion.check(ViewAssertions.java:15)
at androidx.test.espresso.ViewInteraction$SingleExecutionViewAssertion.check(ViewInteraction.java:10)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:11)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:2)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Versions
Android Studio version: Android Studio Bumblebee | 2021.1.1 Patch 2
Build #AI-211.7628.21.2111.8193401, built on February 17, 2022
Runtime version: 11.0.11+0-b60-7772763 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.3
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin (211-1.6.10-release-923-AS7442.40), org.intellij.plugins.markdown (211.7142.37)
API version of the emulator:
31

Additional information
New to this, sorry If I'm wrong. Or did something wrong.

Android Basics: Lunch Tray app

URL of codelab

https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tra

In which task and step of the codelab can this issue be found?

  1. Test your app!

Describe the problem

When I started testing, the error: "Unresolved reference: startOrder" occurred
The error pops up throughout NavigationTests.
When I refactored "R.id.startOrder" to "R.id.startOrderFragment" everything worked perfectly.

Errors occur in com.example.lunchtray.NavigationTests on lines: 83, 126, 163, 200, 218

Steps to reproduce?
Just clone the project, build it and run the tests.
There is no id "startOrder", so it should fail

image

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
testing

Describe the problem

In the NavigationTests file several tests refer destination with R.id.startOrder which does not exist. I believe it should be R.id.startOrderFragment. Everything seems to function fine after this small change.

Steps to reproduce?

  1. Go to... NavigationTests
  2. Click on...
  3. See error... all the functions clicking the cancel button

Versions
Android Studio version: 2020.3.1
API version of the emulator: 30

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?authuser=1&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-4%3Fauthuser%3D1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray#3

In which task and step of the codelab can this issue be found?

Task 5 :Project: Lunch Tray app Step 4: Test you app
The Problem is in the downloaded project!

Describe the problem

As I was testing the app with the provided test that came with to project, I was keep getting errors during NavigationTests like : Unresolved reference: startOrder , and it seems the problem was on the NavigationTests class.
I edited from startOrder to startOrderFragment and all tests work perfectly fine now.

Steps to reproduce?

  1. Go to - com.example.lunchtray (androidTest)
  2. Click on - run NavigationsTests
  3. See error - Unresolved reference: startOrder

Versions
_Android Studio version: Android Studio Bumblebee / 2021.1.1
_API version of the emulator: 31.2.6

Additional information
Include screenshots if they would be useful in clarifying the problem.

error

Android Basics: Lunch Tray app: issue in code comment

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray

In which task and step of the codelab can this issue be found?
Get started

Describe the problem
The code comment in the class com.example.lunchtray.model.OrderViewModel in line 102 of the code in branch main is wrong:

        // TODO: if _accompaniment.value is not null subtract the previous accompaniment price from
        //  the current subtotal value. This ensures that we only charge for the currently selected
        //  accompaniment.

It has to be:

        // TODO: if _subtotal.value is not null subtract the previous accompaniment price from
        //  the current subtotal value. This ensures that we only charge for the currently selected
        //  accompaniment.

Android Basics: Lunch Tray app

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-5%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray#2

In which task and step of the codelab can this issue be found?
Navigation

Describe the problem
Direction classes aren't generated as the dependency for safergs was omitted - is this intentional?

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Lunch Tray app - Hardcoded strings in the test for the european formatting

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-5%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray#3

In which task and step of the codelab can this issue be found?
4. Testing

Describe the problem
All tests comparing strings that relate to payments fail on european format (€), because the tests have hardcoded american system ($)

Android Basics: Lunch Tray app

URL of codelab

In which task and step of the codelab can this issue be found?

Describe the problem

HI! Question......In Main Activity, NavHostFragment is red for me and navController in parentheses has a red underline.
EX: navController = navHostFragment.navController.
setupActionBarWithNavController(navController)

This is literally the ONLY error I have. The project is done, I just need help fixing this.

How do I fix this?

please help.

screen shot at bottom...

Screen Shot 2022-03-03 at 6 33 41 AM

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

URL of codelab

https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-5%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray#3
In which task and step of the codelab can this issue be found?
4. Test your app

Describe the problem
The NavigationTests.kt provided has 5 lines as assertEquals(navController.currentDestination?.id, R.id.startOrder) , which should be assertEquals(navController.currentDestination?.id, R.id.startOrderFragment)
Otherwise the testcases can not run with the built error.

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?authuser=1&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-4%3Fauthuser%3D1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray#2

In which task and step of the codelab can this issue be found?
I just need help in fragment_entree_menu_xml

Describe the problem

android:checked="@{viewModel.entree.equals(viewModel.menuItems["cauliflower"].name)}"
android:onClick="@{() -> viewModel.setEntree(viewModel.menuItems["cauliflower"].name'

This is how I tried to set checked and onClick attribut for this view but it didn't work. Please, I need help.
Thanks in advance for your helps.

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
Project: Lunch Tray app
3. Get started
setEntree(), setSide(), and setAccompaniment()

Describe the problem
In the given code it says :
// TODO: if _subtotal.value is not null subtract the previous entree price from the current
// subtotal value. This ensures that we only charge for the currently selected entree.

but the tutorial says:
If the _subtotal's value is null, subtract the previousEntreePrice from the subtotal.

They tutorial is correct while the TODO note is wrong

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
Step 3 "Get Started"

Describe the problem
There is a typo in:

  1. If the _subtotal's value is null(is null, really?), subtract the previousEntreePrice from the subtotal.

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-5%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray#3

In which task and step of the codelab can this issue be found?
Step 4: Test your app

Describe the problem
NavigationTests.kt targets a fragment with the id of "startOrder" instead of "startOrderFragment" causing the navigation tests to fail through no fault of the student.

Steps to reproduce?

  1. Go to... app > src > androidTest > java > com > example > lunchtray > NavigationTests.kt
  2. Click on... Run>NavigationTests
  3. See error... Unsolved Reference: "startOrder"

Versions
Android Studio version: Chipmunk | 2021.2.1 Patch 2
API version of the emulator: 31

Additional information

Students can remedy this problem by refactoring the fragment's id from startOrderFragment into startOrder, but the fixing the test is a better solution to keep with the naming conventions of the other fragments and avoid confusion over errors from otherwise good code.

Include screenshots if they would be useful in clarifying the problem.

Missing information in Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
Get started

Describe the problem
Will report the issue here as I can't find anywhere else to.

There is no mention of the TODO in main_activity.xml in the Codelab.

Because the target audience for this Codelab is beginners and the Codelabs in the Android Basics in Kotlin course have no mention of the built-in TODO feature in Android Studio, beginners will struggle to find out how to resolve the issue of running the program when retrieving the NavController in MainActivity.kt. Note: I am aware that the projects are meant to give the "student" some experience on their own, i.e. not hold their hand, but considering the format of this project and former projects, I don't think not mentioning that TODO as opposed to all other TODOs make any sense.

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
NavigationTests ( https://github.com/google-developer-training/android-basics-kotlin-lunch-tray-app/blob/main/app/src/androidTest/java/com/example/lunchtray/NavigationTests.kt )

Describe the problem
In testing the app navigation, the tests use the wrong id for the start Fragment (R.id.startOrder instead of R.id.startOrderFragment)

Steps to reproduce?

  1. Go to... https://github.com/google-developer-training/android-basics-kotlin-lunch-tray-app/blob/main/app/src/androidTest/java/com/example/lunchtray/NavigationTests.kt
  2. Click on...run tests
  3. See error...startOrder not found

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app | Build Failing

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

In which task and step of the codelab can this issue be found?
Building project with compileSdkVersion & targetSdkVersion 31

Describe the problem
The project build produces errors:

/home/USER/code/AndroidStudioProjects/android-basics-kotlin-lunch-tray-app/app/src/main/AndroidManifest.xml:27:9-33:20 Error:
	android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
/home/USER/code/AndroidStudioProjects/android-basics-kotlin-lunch-tray-app/app/src/main/AndroidManifest.xml:34:9-40:20 Error:
	android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
/home/USER/code/AndroidStudioProjects/android-basics-kotlin-lunch-tray-app/app/src/main/AndroidManifest.xml:41:9-47:20 Error:
	android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

As stated in the error, I set the android:exported value to true, but it still produces the same error.

Steps to reproduce?

  1. Set the targetSdkVersion & compileSdkVersion to 31
  2. Build the project

Versions
Android Studio version: Android Studio Bumblebee | 2021.1.1 Patch 2 Build #AI-211.7628.21.2111.8193401, built on February 17, 2022
API version of the emulator: 30

Android Basics: Lunch Tray app

URL of codelab

In which task and step of the codelab can this issue be found?
Project : Lunch Tray App

Describe the problem
Different instrumentation in web and code(comment)

Says subtotal.value is null in website but not null in comment of the code
Screenshot (54)
Screenshot (55)

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray?authuser=1&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-4%3Fauthuser%3D1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-project-lunch-tray#2

In which task and step of the codelab can this issue be found?
Section:
setEntree(), setSide(), and setAccompaniment()

Describe the problem
Point 2:
2. If the _subtotal's value is not null, subtract the previousEntreePrice from the subtotal.

"not" word missing

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?

Testing

Describe the problem

Order name and other descriptions are not visible in the Check Out page. Only price information is passed correctly.

Prices are set correctly but food info is not visible. I think that I did not manage to pass specific MenuItem data within Datasource class to _entree.

I tried many ways but I could not make it work. Could you please help me?

Thanks in advance. The details are as follows:

I think I am doing something incorrectly in the view model when I try to set _entree.value. I am setting _entree.value in the ViewModel function like that:

fun setEntree(entree: String) {
        // TODO: if _entree.value is not null, set the previous entree price to the current
        //  entree price.

        if (_entree.value != null){

            previousEntreePrice= _entree.value!!.price

            Log.d(TAG,"setEntree if 1 is called")
        }

        // TODO: if _subtotal.value is not null subtract the previous entree price from the current
        //  subtotal value. This ensures that we only charge for the currently selected entree.

        if (_subtotal.value != null){

            _subtotal.value = _subtotal.value!!.minus(previousEntreePrice)

            Log.d(TAG,"setEntree if 2 is called")
        }

        // TODO: set the current entree value to the menu item corresponding to the passed in string

        _entree.value = DataSource.menuItems[entree]

        // TODO: update the subtotal to reflect the price of the selected entree.

        updateSubtotal(_entree.value!!.price)

    }

And this is the part of the layout where I set in the radio button:

...
        <RadioButton
                    android:id="@+id/skillet"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?attr/textAppearanceBody1"
                    android:text='@{viewModel.menuItems["skillet"].name}'
                    android:checked='@{viewModel.entree.name.equals(viewModel.menuItems["skillet"].name)}'
                    android:onClick='@{() -> viewModel.setEntree("skillet")}'
                    tools:text="Entree 4" />
...

Finally this is the part from the order check out layout:

...
            <TextView
                android:id="@+id/entree_selection"
                style="@style/Widget.LunchTray.TextView.CheckoutItem.Info"
                android:text='@{viewModel.entree.name}'
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/order_summary"
                tools:text="Cauliflower" />
...

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version: 2021.1.1.0
API version of the emulator: API 29

Additional information
Include screenshots if they would be useful in clarifying the problem.

You can see the check out page in the emulator like below:

image

As you can see that, prices re summed correctly between each fragment but no any data is visible in the checkout fragment.

Android Basics: Lunch Tray app

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-project-lunch-tray

In which task and step of the codelab can this issue be found?
Step 4: Test your app

Describe the problem
In NavigationTests.kt, several (all?) of the tests attempt to call assertEquals() with an incorrect reference to the resource ID of the StartOrderFragment.

It is misspelled "R.id.startOrder" instead of "R.id.startOrderFragment"

Steps to reproduce?
Attempt to run NavigationTests on the completed project, and it will throw a compile error due to the misspellings.

Additional information
Include screenshots if they would be useful in clarifying the problem.
From GitHub:
image

Android Basics: Lunch Tray app

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

In which task and step of the codelab can this issue be found?
Get started, where you set the text to listen for subtotal.

Describe the problem
The tools:text doesn't match what should actually be the text value as the tools:text is missing a colon after subtotal. This is true in: the entree, side and accompaniment fragments but not in the checkout fragment. This led to confusion for me especially since the output of the failing test doesn't print the subtotal string that is wrong.

Steps to reproduce?

  1. Go to fragment_entree_menu.xml
  2. Lock at the tools:text field.
  3. See that there is no colon after the subtotal.

Android Basics: Lunch Tray app

URL of codelab

In which task and step of the codelab can this issue be found?

The text msg shown in the last app screenshot after clicking submit is a snack bar . But it is mentioned as a toast msg

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Android Basics: Lunch Tray app

URL of codelab

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

In which task and step of the codelab can this issue be found?
3) Get started -> Under title "setEntree(), setSide(), and setAccompaniment()"
Step 2:
If the _subtotal's value is null, subtract the previousEntreePrice from the subtotal. (This explanation corresponds to SetEntree() function)

Describe the problem
I think _subtotal.value is never null because the variable gets initialized as soon as OrderViewModel object is created. Therefore, the variable that should be tested should be _entree.value.

The same goes for setSide and setAccompainment.

I used _entree.value, _side.value and _setAcompainment and all androidTests were passed successfully.

Kind regards,

 Calaudio

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.