Browse Source

что-то

user2 4 years ago
parent
commit
03321354d4

+ 9 - 0
app/src/main/java/su/ktk/proekt2608/Coursapp.kt

@@ -0,0 +1,9 @@
+package su.ktk.proekt2608
+
+import retrofit2.Call
+import retrofit2.http.GET
+
+interface JsonPlaceHolderApi{
+    @get:GET("daily_json.js")
+    val course: Call<List<Valuta>>
+}

+ 24 - 1
app/src/main/java/su/ktk/proekt2608/kyrs.kt

@@ -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>>)
+        }
     }
 }

+ 1 - 0
app/src/main/res/layout/activity_proekt2.xml

@@ -6,6 +6,7 @@
     android:layout_height="match_parent"
     tools:context=".bank">
 <TextView
+    android:id="@+id/data"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Курс доллара"