Open menu with table of contents Android Assignment 02
Logo of Stuttgart Media University for light theme Logo of Stuttgart Media University for dark theme
Android Development

Android Assignment 02

Introduction to LazyColumn

Stuttgart Media University

Please conduct the following tasks alone. For implementation details you can refer to the lecture slides or the Android developer website. Please do not hesitate to ask me or the tutor if you have any questions.

1 Tasks

  • Create a new Android Project in Android Studio and use your "assignment2" git folder as the project root folder.
    • Template: "Empty Activity"
    • Name: "MovieTracker"
    • Package name: "de.hdmstuttgart.movietracker"
    • Save location: Path to your assignment2 folder
    • Build configuration language: Kotlin DSL [Recommended]
    • Minimum SDK: API 26
  • Add LazyColumn to your MainActivity displaying items according to the row data below
  • Create @Composable for a movie item as described
  • When user clicks on an item, remove the item
  • Run espresso test to validate your implementation

2 Item Views

Use a data model which represents the movie items:

data class Movie (
    val title: String,
    val year: String,
    val actor: String
)

Example Layout:

center

3 Row Data

Use this data to fill out your rows:

title year actor
Dr. No 1962 Sean Connery
From Russia with Love 1963 Sean Connery
Goldfinger 1964 Sean Connery
Thunderball 1965 Sean Connery
You Only Live Twice 1967 Sean Connery

4 Espresso Test

package de.hdmstuttgart.movietracker

import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.performClick
import org.junit.Rule
import org.junit.Test

class Assignment2Test {

    @get:Rule
    val composeTestRule = createAndroidComposeRule<MainActivity>()

    @Test
    fun myTest() {
        composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("Dr. No")
        composeTestRule.onAllNodesWithTag("movieItem")[1].assertTextContains("From Russia with Love")
        composeTestRule.onAllNodesWithTag("movieItem")[2].assertTextContains("Goldfinger")
        composeTestRule.onAllNodesWithTag("movieItem")[3].assertTextContains("Thunderball")
        composeTestRule.onAllNodesWithTag("movieItem")[4].assertTextContains("You Only Live Twice")
        composeTestRule.onAllNodesWithTag("movieItem")[0].performClick()
        composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("From Russia with Love")
        composeTestRule.onAllNodesWithTag("movieItem")[0].performClick()
        composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("Goldfinger")
    }
}

5 Gradle Dependencies

Module build.gradle.kts:

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.ui)
    implementation(libs.androidx.ui.graphics)
    implementation(libs.androidx.ui.tooling.preview)
    implementation(libs.androidx.material3)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
    androidTestImplementation(platform(libs.androidx.compose.bom))
    androidTestImplementation(libs.androidx.ui.test.junit4)
    debugImplementation(libs.androidx.ui.tooling)
    debugImplementation(libs.androidx.ui.test.manifest)
}