|
@@ -10,6 +10,11 @@ import androidx.appcompat.app.AlertDialog
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
import androidx.fragment.app.DialogFragment
|
|
|
import kotlinx.android.synthetic.main.activity_main.*
|
|
|
+import retrofit2.Call
|
|
|
+import retrofit2.Callback
|
|
|
+import retrofit2.Response
|
|
|
+import retrofit2.Retrofit
|
|
|
+import retrofit2.converter.gson.GsonConverterFactory
|
|
|
import java.text.SimpleDateFormat
|
|
|
import java.util.*
|
|
|
|
|
@@ -20,8 +25,29 @@ class MainActivity : AppCompatActivity() {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setContentView(R.layout.activity_main)
|
|
|
dateNow.text=getCurrentDate()
|
|
|
+//add Retrofit for get JSON
|
|
|
+ val retrofit=Retrofit.Builder()
|
|
|
+ .baseUrl("https://www.cbr-xml-daily.ru")
|
|
|
+ .addConverterFactory(GsonConverterFactory.create())
|
|
|
+ .build()
|
|
|
+ val jsonPlaceHolderAPI=retrofit.create(JsonPlaceHolderAPI::class.java)
|
|
|
+ val call:Call<Valuta> = jsonPlaceHolderAPI.course
|
|
|
+ call.enqueue(object :Callback<Valuta>{
|
|
|
+ override fun onResponse(p0: Call<Valuta>, p1: Response<Valuta>) {
|
|
|
+ val course:Valuta=p1.body()
|
|
|
+ if (course!=null){
|
|
|
+ USD_value.text= String.format("%.2f",course.Valute.USD.Value.toDouble())
|
|
|
+ EUR_value.text=String.format("%.2f",course.Valute.EUR.Value.toDouble())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(p0: Call<Valuta>?, p1: Throwable?) {
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// Function for get date
|
|
|
fun getCurrentDate(): String {
|
|
|
//val currentDate=Calendar.getInstance().time
|