Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created May 15, 2018 20:33
Show Gist options
  • Save adrianhall/32dd620fc0cb056a78dcfb6bb4cf2500 to your computer and use it in GitHub Desktop.
Save adrianhall/32dd620fc0cb056a78dcfb6bb4cf2500 to your computer and use it in GitHub Desktop.
package com.shellmonger.apps.mynotes.repositories.datasources
import android.arch.paging.DataSource
import android.arch.paging.ItemKeyedDataSource
import android.util.Log
import com.shellmonger.apps.mynotes.models.Note
class MockNotesDataSource : ItemKeyedDataSource<Int, Note>() {
companion object {
private val TAG = this::class.java.simpleName
const val MAX_PAGE_SIZE = 20
}
/**
* The list of items in the data source
*/
private val items: MutableList<Note> = ArrayList()
init {
// Create some fake data
for (i in 0..200) {
items.add(Note().apply { title = "title $i"; content = "content $i" })
}
}
fun inRange(position: Int, start: Int, end: Int): Int {
if (position < start) return start
if (position > end) return end
return position
}
// Other methods here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment