|
@@ -2,11 +2,34 @@ package su.ktk.proekt2608
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
import android.os.Bundle
|
|
|
+import retrofit2.Call
|
|
|
+import retrofit2.Callback
|
|
|
+import retrofit2.Response
|
|
|
+import retrofit2.Retrofit
|
|
|
+import retrofit2.converter.gson.GsonConverterFactory
|
|
|
|
|
|
-class kyrs : AppCompatActivity() {
|
|
|
+class kyrs: AppCompatActivity() {
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setContentView(R.layout.activity_kyrs)
|
|
|
+ val retrofit=Retrofit.Builder()
|
|
|
+ .baseUrl("http://www.cbr-xml-daily.ru/")
|
|
|
+ .addConverterFactory(GsonConverterFactory.create())
|
|
|
+ .build()
|
|
|
+ val jsonPlaceHolderApi=retrofit.create(JsonPlaceHolderApi::class.java)
|
|
|
+ val call:Call<List<Valuta>> = jsonPlaceHolderApi.course
|
|
|
+ call.enqueue(object:Callback<List<Valuta>>{
|
|
|
+ override fun onResponce(p0:Call<List<Valuta>>,p1:Response<List<Valuta>>){
|
|
|
+ if(!p1.isSuccessful()){
|
|
|
+ data.setText(p1.code())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ val course:List<Valuta>?=p1.body()
|
|
|
+ if (course!=null)
|
|
|
+ data.append(course.[0].Name)
|
|
|
+ }
|
|
|
+ override fun onFallure(p0:Call<List<Valuta>>)
|
|
|
+ }
|
|
|
}
|
|
|
}
|