Permalink
Browse files

Merge branch 'feature/collections' into develop

  • Loading branch information...
gonzapico committed Apr 22, 2017
2 parents d9437dc + 2ddaa2a commit af988a66715b6c1ecbdba959f3c8ae206009c22a
@@ -3,15 +3,10 @@ package xyz.gonzapico.myfirstkotlinapp
/**
* Created by gfernandez on 22/04/17.
*/
fun fetchMedia(): List<MediaItem> = listOf(
MediaItem("One", "http://lorempixel.com/400/400/sports/1/", MediaItem.TYPE.PHOTO),
MediaItem("Two", "http://lorempixel.com/400/400/sports/2/", MediaItem.TYPE.PHOTO),
MediaItem("Three", "http://lorempixel.com/400/400/sports/3/", MediaItem.TYPE.PHOTO),
MediaItem("Four", "http://lorempixel.com/400/400/sports/4/", MediaItem.TYPE.PHOTO),
MediaItem("Five", "http://lorempixel.com/400/400/sports/5/", MediaItem.TYPE.PHOTO),
MediaItem("Six", "http://lorempixel.com/400/400/sports/6/", MediaItem.TYPE.PHOTO),
MediaItem("Seven", "http://lorempixel.com/400/400/sports/7/", MediaItem.TYPE.PHOTO),
MediaItem("Eigth", "http://lorempixel.com/400/400/sports/8/", MediaItem.TYPE.PHOTO),
MediaItem("Nine", "http://lorempixel.com/400/400/sports/9/", MediaItem.TYPE.PHOTO),
MediaItem("Ten", "http://lorempixel.com/400/400/sports/10/", MediaItem.TYPE.VIDEO)
)
fun fetchMedia(): List<MediaItem> = (0..10).map {
MediaItem(
"Title $it",
"http://lorempixel.com/200/200/sports/$it/",
if (it % 3 == 0) MediaItem.TYPE.VIDEO
else MediaItem.TYPE.PHOTO)
}
@@ -2,22 +2,44 @@ package xyz.gonzapico.myfirstkotlinapp
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_home.*
class HomeActivity : AppCompatActivity() {
var adapter = MediaAdapter() {
// This is valid just if there is one input parameter
showToast(it.title)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
// Call the function find just the first time that the view is inflated. Next, it should be cached
// id = recycler
val adapter = MediaAdapter() {
// This is valid just if there is one input parameter
showToast(it.title)
}
recycler.adapter = adapter
adapter.mediaItemList = fetchMedia()
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.home_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
val media = fetchMedia()
when (item.itemId) {
R.id.filter_all -> {
media
}
R.id.filter_photos -> {
media.filter { it.type == MediaItem.TYPE.PHOTO }
}
R.id.filter_videos -> {
media.filter { it.type == MediaItem.TYPE.VIDEO }
}
else -> media
}
return true
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/filter_all"
android:title="All"/>
<item
android:id="@+id/filter_photos"
android:title="Photos"/>
<item
android:id="@+id/filter_videos"
android:title="Videos"/>
</menu>

0 comments on commit af988a6

Please sign in to comment.