Android Kotlin: Forecast App 02 - Retrofit + Coroutines + Gson Fetch API Data - MVVM Tutorial Course

preview_player
Показать описание
📗 Get the code from this tutorial 👇👇

In the previous part we created blank fragments. We can navigate between them using the navigation architecture component library. In this tutorial, we will add some actual functionality to this Forecast MVVM app, namely the ability to fetch weather from an API.

This means that in this part you are going to learn how to use Retrofit together with Gson to fetch and parse JSON data from an API. The API we are going to use is Apixu which is a weather API offering a generous free plan. You can apply what you learn here to any other API you desire so should there be any problems with Apixu in the future, you will be able to switch to a different API very easily.

Go to my website for more information, code examples and articles:

Follow me on social media:
Рекомендации по теме
Комментарии
Автор

Ill say it again.
THIS is the most powerful tutorial series of 2019.
These cover it all, everything I use in a professional environment and most of the concepts needed for the foundation of a good application.
Thank you!
I Also have a TON of love amd respect for Florian and Mitch. They know who they are and I know Florian is working on a phenomenal series on Kotlin !

matt-g-recovers
Автор

Wow that json to kotlin class plugin is really really helpful. Thank you very much.

agung_laksana
Автор

I am still going through this tutorial. This is definitely the best android tutorial on Youtube. You are a hero.

waichee
Автор

This video saved my semester!, I couldn´t understand how to use Retrofit till I found this one.
Thank you so much for the great quality content. I will surely do the whole tutorial in the future :)

zapphiere
Автор

The url for fetching weather has changed

As cheryl posted :
For new API:



@GET("current")
fun getCurrentWeather(
@Query("query") location: String,
@Query("lang") languageCode: String = "en"


companion object{
operator fun
val requestInterceptor = Interceptor { chain->
val url = chain.request()
.url()
.newBuilder()
.addQueryParameter("access_key", API_KEY)
.build()
val request = chain.request()
.newBuilder()
.url(url)
.build()
}

val okHttpClient = OkHttpClient.Builder()

.build()

return Retrofit.Builder()
.client(okHttpClient)


.build()


}


Plus Android 8 does not allows url with only "http"
Solution :
Step 1- add this entry in manifest
<application
...>


Step 2 - and:
create

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>

It worked for me..!! Cheers

nehankpoilkar
Автор

Hi Reso Coder, Thank you for this tutorial. The is Deprecated. will this tutorial be updated to make use of kotlin coroutines, suspend?

kaletsugas
Автор

If people are still having issues getting a null error from the response, do the following:

1. In ApixuWeatherApiService.kt, remove @Query("language") languageCode: String = "en". The current version of WeatherStack does not support foreign languages on the free plan, and English uses no language code (unset)

2. Follow the instructions given by nehank poilkar to ensure you do not have issues related to the new parameter nomenclature and due to the fact that Android Studio by default does not allow access to the internet or non-HTTPS resources

marshallborsos
Автор

I just found how to fix this, and you don't need to reply my question, you tutorials are helpful for us

developertriplogic
Автор

Thank you very much! I usually do this in Java and am new to kotlin. Thank you for teaching me how to use retrofit with coroutines.
You've gained a new sub !

thelumiereguy
Автор

Getting an ERROR :
Attempt to invoke virtual method 'java.lang.String on a null object reference


My URL made by companion object in ApiService looks like this for some reason :


Can not figure out why the key is at the end of the url and how to put it where it belongs
Any ideas?

orlov_alex
Автор

Really thanks. You saved my life and time…

roothresh
Автор

Brilliant! Is there a Patreon so we can donate to keep the tutorials coming?

stcojo
Автор

Wow! That really interesting and simple guide about Retro + Weather + Kotlin + VM.

alextroy
Автор

Thanks for explanation in the ApiService!

fahrican
Автор

Very good tutorial! It turns out I was doing alot of things the wrong way. Looking forward to future tutorials!

Monarch_
Автор

for what annotation used for in android??is this doing anything in the code flow or just a metadata

thomasj.
Автор

Awesome Tutorial Reso Coder.. keep it up

AshishGautam-syvm
Автор

This tutorial is the best gift for Christmas! Thanks!

Kekszmester
Автор

Thank you very much for your fabulous videos! I wanted to ask you which theme is the one that you have in Android Studio??
Thanks

Regards from Argentina!

LeaCuvelo
Автор

Love your tutorials! I am developing my own forecat app but with custom api and less functionalities. But I have some issue, maybe you will be able to help me.
How can I get the api error request caught? (basically havig the same service a you)

justynakozik
welcome to shbcf.ru