Arxcis / prog2007-gruppearbeid

Prosjekt inkluderer obligatorisk gruppearbeid til faget PROG-2007 - Mobile Programming.
The Unlicense
0 stars 0 forks source link

Navigate the Star wars web #9

Closed Arxcis closed 2 years ago

Arxcis commented 2 years ago

ER diagram

Demo - Navigation

naviage-the-web

Bibli2311 commented 2 years ago

It works on my phone and I have looked through the code: But I have one question: In PlanetActivity (not PlanetS) we have this code:

if (planet != null) {
            Network.getPeopleByURL(planet.residents, residents, residentsAdapter){ error ->
                Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
            }

The variable "planets.residents" contains a list of URLs of the different residents. Where in the code is this URL list filled?

Arxcis commented 2 years ago

It works on my phone and I have looked through the code: But I have one question: In PlanetActivity (not PlanetS) we have this code:

if (planet != null) {
            Network.getPeopleByURL(planet.residents, residents, residentsAdapter){ error ->
                Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
            }

The variable "planets.residents" contains a list of URLs of the different residents. Where in the code is this URL list filled?

You are correct. From Planet.kt we can see that planet.residents is an array of strings, each string being an URL:

data class Planet(
    /** "name": "Tatooine" */
    val name: String,

    /** "residents": ["https://swapi.dev/api/people/1/", ...] */
    val residents: ArrayList<String>,

    /** "films": ["https://swapi.dev/api/films/1/", ...] */
    val films: ArrayList<String>,
) : Serializable

If we look at the network request again.

Network.getPeopleByURL(planet.residents, residents, residentsAdapter){ error ->
    Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
}

Network.getPeopleByURL() goes through all planet.residents URLs and does a network-request for each. The result from the network-requests is put into the residents-variable - the second argument. When all network-requets have been completed, the residentsAdapter is notified to do a re-render:

residentsAdapter.notifyDataSetChanged()

I think this happens a bit hidden, and it could have been improved and be more visible if we had a success -> -handler, like we have an -> error-handler, but I digress.