Skip to content

Instantly share code, notes, and snippets.

View cdmunoz's full-sized avatar

Carlos Daniel cdmunoz

View GitHub Profile
package co.cdmunoz.cryptocurrencyapp.utils
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
class InfiniteScrollListener(
val func: () -> Unit,
val layoutManager: LinearLayoutManager) : RecyclerView.OnScrollListener() {
class InfiniteScrollListener(
val func: () -> Unit,
val layoutManager: LinearLayoutManager) : RecyclerView.OnScrollListener() {
private var previousTotal = 0
private var loading = true
private var visibleThreshold = 2
private var firstVisibleItem = 0
private var visibleItemCount = 0
private var totalItemCount = 0
class Constants {
companion object {
const val OFFSET = 12
const val LIMIT = 12
const val START_ZERO_VALUE = "0"
const val DATABASE_NAME = "cryptocurrencies_db"
const val LIST_SCROLLING = 12
}
}
class CryptocurrenciesActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(layout.activity_cryptocurrencies)
initializeRecycler()
progressBar.visibility = View.VISIBLE
loadData()
class InfiniteScrollListener(
val func: () -> Unit,
val layoutManager: LinearLayoutManager) : RecyclerView.OnScrollListener() {
private var previousTotal = 0
private var loading = true
private var visibleThreshold = 2
private var firstVisibleItem = 0
private var visibleItemCount = 0
private var totalItemCount = 0
class InfiniteScrollListener(
val func: () -> Unit,
val layoutManager: LinearLayoutManager) : RecyclerView.OnScrollListener() {
private var previousTotal = 0
private var loading = true
private var visibleThreshold = 2
private var firstVisibleItem = 0
private var visibleItemCount = 0
private var totalItemCount = 0
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
tools:context="co.cdmunoz.cryptocurrencyapp.ui.list.CryptocurrenciesActivity"
>
class CryptocurrenciesAdapter(
cryptocurrencies: List<Cryptocurrency>?) : RecyclerView.Adapter<CryptocurrencieViewHolder>() {
private var cryptocurrenciesList = ArrayList<Cryptocurrency>()
init {
this.cryptocurrenciesList = cryptocurrencies as ArrayList<Cryptocurrency>
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): CryptocurrencieViewHolder {
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cryptocurrency_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_4dp"
app:cardElevation="@dimen/cardview_default_elevation"
@Module
class AppModule(val app: Application) {
//...rest of the code
@Provides
@Singleton
fun provideUtils(): Utils = Utils(app)
}