Created
May 15, 2018 20:33
-
-
Save adrianhall/32dd620fc0cb056a78dcfb6bb4cf2500 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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