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

Android Assignment 05

Introduction to API Calls and Image Loading

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

  • Reuse your assignment4 code and copy it to assignment5 folder.
  • Create a new OMDb API Key here http://www.omdbapi.com/apikey.aspx
  • Replace your static Movie Data source with REST API Calls to OpenMovieDB.
  • Use this get call for your search http://www.omdbapi.com/?apikey=YOURKEY&s=Matrix where you replace "YOURKEY" with your own key and "Matrix" with the search string input from the "textField".
  • Add a poster image to your search result list and saved movies list.
  • Implement Coil to load the poster in your movie item

2 Views

Search Screen:

Home Screen:

3 Espresso Test

Hint: The test is expecting a empty app state. If you have saved movies on app start, the test will fail.

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.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import org.junit.Rule
import org.junit.Test

class Assignment5Test {

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

    @Test
    fun test1() {
        composeTestRule.onNodeWithTag("openSearchButton").performClick()
        composeTestRule.onNodeWithTag("textField").performTextInput("Matrix")
        composeTestRule.onNodeWithTag("searchButton").performClick()
        Thread.sleep(1000)
        composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("The Matrix")
        composeTestRule.onAllNodesWithTag("movieItem")[0].performClick()
        composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("The Matrix")
    }

    @Test
    fun test2() {
        composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("The Matrix")
        composeTestRule.onNodeWithTag("openSearchButton").performClick()
        composeTestRule.onNodeWithTag("textField").performTextInput("her")
        composeTestRule.onNodeWithTag("searchButton").performClick()
        Thread.sleep(1000)
        composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("Her")
        composeTestRule.onAllNodesWithTag("movieItem")[0].performClick()
    }

    @Test
    fun test3() {
        composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("The Matrix")
        composeTestRule.onAllNodesWithTag("movieItem")[1].assertTextContains("Her")
    }
}

4 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)
    implementation(libs.androidx.navigation.compose)
    implementation(libs.androidx.room.gradle.plugin)
    implementation(libs.androidx.room.runtime)
    annotationProcessor(libs.androidx.room.compiler)
    ksp(libs.androidx.room.compiler)
    implementation(libs.androidx.room.ktx)
    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)
    implementation(libs.coil.compose)
    ksp(libs.compiler)
    implementation(libs.converter.gson)
    implementation(libs.retrofit)
}