antoniolg / Kotlin-for-Android-Developers

Companion App for the book

Home Page:http://antonioleiva.com/kotlin-android-developers/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zip code vs city id in chapter-19 branch

bartonstanley opened this issue · comments

In the chapter-19 branch there is a mix-up between zip code and city id. The code compiles and runs because the database is not used. Nonetheless I believe there is an error. Here is what I think needs to change:

In ForecastDataMapper.convertFromDataModel the first parameter in the ForecastList constructor should be "city.id" instead of "zipCode". Additionally, the "zipCode" parameter should be removed from convertFromDataModel so that it takes only a ForecastResult.

Once this change is made the overridden function in RequestForecastCommand must be changed so the "zipCode" parameter is removed from the parameters passed to convertFromDataModel.

This will fix the issue, but I would also recommend changing the name of the "id" parameter on the ForecastList constructor to "cityId" to make it clearer what id this is.

Yeah, I see... It's just the code what it's wrong, not the text in the book 🤔

I'll fix it immediately, thanks!

Ah no, I've been reviewing it, but the code is OK. The zipCode is used as the city id. That's because the zipCode (and not the city id) is the value we have from the App, and it's used to check if the info was cached in the database.

Look the database request in ForecastDb:

        val city = select(CityForecastTable.NAME)
                .whereSimple("${CityForecastTable.ID} = ?", zipCode.toString())
                .parseOpt { CityForecast(HashMap(it), dailyForecast) }

Closing this. It's working as expected and haven't received any updates from the author.