Untitled

mail@pastecode.io avatar
unknown
kotlin
3 years ago
1.8 kB
0
Indexable
Never
package com.ryudith.tipsandtricksretrofit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
import com.ryudith.tipsandtricksretrofit.custom.DataItemss
import com.ryudith.tipsandtricksretrofit.custom.Movie
import com.ryudith.tipsandtricksretrofit.custom.ResponseDashboard
import com.ryudith.tipsandtricksretrofit.databinding.ActivityMainBinding
import com.ryudith.tipsandtricksretrofit.util.RetrofitHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.Call
import retrofit2.Response
import java.net.SocketTimeoutException
import javax.security.auth.callback.Callback

private const val TAG = "DEBUG_DATA"
class MainActivity : AppCompatActivity() {
    private lateinit var activityRef : AppCompatActivity
    private lateinit var binding : ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        activityRef = this
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        
        getData()
    }
    fun getData(){
        RetrofitHelper.getRetrofitRef().getPost().enqueue(object : retrofit2.Callback<ResponseDashboard>{
            override fun onResponse(
                call: Call<ResponseDashboard>,
                response: Response<ResponseDashboard>
            ) {
                Log.d(TAG,"list data : ${response.body() as List<DataItemss>}")
            }

            override fun onFailure(call: Call<ResponseDashboard>, t: Throwable) {
                Log.d(TAG, "General exception : ${t.message}")
            }

        })
    }
}