Skip to content

Instantly share code, notes, and snippets.

@adamsp
Last active October 10, 2017 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsp/43c15744f6e8bba6202308c51bc10ecf to your computer and use it in GitHub Desktop.
Save adamsp/43c15744f6e8bba6202308c51bc10ecf to your computer and use it in GitHub Desktop.
Paging Lib Blog MainActivity.kt
var screenshotLoader: ScreenshotLoader? = null
var adapter: ScreenshotPickerAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
screenshotLoader = SAFScreenshotLoader(contentResolver, diskExecutor)
adapter = ScreenshotPickerAdapter(this)
val recycler = findViewById(R.id.main_recycler) as RecyclerView?
recycler?.layoutManager = GridLayoutManager(this, 2)
recycler?.adapter = adapter
loadScreenshots()
}
private fun loadScreenshots() {
screenshotLoader?.allScreenshots({
if (!isDestroyed()) {
runOnUiThread {
if (!isDestroyed()) {
adapter?.setList(it)
}
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment