Last active
January 17, 2021 18:40
-
-
Save kyodgorbek/57a4c038f0404b60d64f3716e52379de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CurrenciesAdapter(private val context: Context, private var list: MutableList<CurrencyResponse>) : RecyclerView.Adapter<CurrenciesAdapter.MyViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { | |
val inflater = LayoutInflater.from(context) | |
val view: View = inflater.inflate(R.layout.currency_layout,parent,false) | |
return MyViewHolder(view) | |
} | |
override fun getItemCount(): Int { | |
return list.size | |
} | |
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { | |
val user = list.get(position) | |
holder.name?.text = user.quotes.USDAOA.toString() | |
holder.info1?.text = user?.quotes.USDALL.toString() | |
holder.info2?.text = user?.quotes.USDAED.toString() | |
val addressObj = user.quotes.USDAOA.toString() | |
holder.address?.text = user.quotes.USDAFN.toString() | |
} | |
class MyViewHolder(var view: View) : RecyclerView.ViewHolder(view){ | |
var name: TextView? = null | |
var info1: TextView? = null | |
var info2: TextView? = null | |
var address: TextView? = null | |
init { | |
name = view.findViewById(R.id.txt_user_name) | |
info1 = view.findViewById(R.id.txt_user_info1) | |
info2 = view.findViewById(R.id.txt_user_info2) | |
address = view.findViewById(R.id.txt_user_address) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
private var adapter: CurrenciesAdapter? = null | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
recycler_main.layoutManager = LinearLayoutManager(this@MainActivity) | |
adapter = CurrenciesAdapter(this) | |
recycler_main.adapter = adapter | |
if (isInternetAvailable()) { | |
getUsersData() | |
} | |
} | |
private fun getUsersData() { | |
showProgressBar() | |
var apiInterface: CurrenciesResponse = CurrencyClient().getApiClient()!!.create( | |
CurrenciesResponse::class.java | |
) | |
apiInterface.getCurrencies().enqueue(object : Callback<List<CurrencyResponse>> { | |
override fun onResponse( | |
call: Call<List<CurrencyResponse>>, | |
response: Response<List<CurrencyResponse>>) | |
{ | |
hideProgressBar() | |
val currencyResponse = response.body() | |
adapter?.list = currencyResponse | |
} | |
override fun onFailure(call: Call<List<CurrencyResponse>>, t: Throwable) { | |
hideProgressBar() | |
Log.e("error", t.localizedMessage) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment