Permalink
Browse files

Merge branch 'feature/reifiedFunctions' into develop

  • Loading branch information...
gonzapico committed Apr 22, 2017
2 parents 7c3b53b + 49c83fa commit 88b0e115b49704650df73a544f9def667193b716
@@ -1,9 +1,13 @@
package xyz.gonzapico.myfirstkotlinapp
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.support.annotation.IdRes
import android.support.annotation.LayoutRes
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Toast
@@ -22,4 +26,17 @@ fun ViewGroup.inflate(@LayoutRes layoutToInflate: Int,
attachToRoot: Boolean = false) = LayoutInflater.from(context).inflate(
layoutToInflate, this, attachToRoot)
fun ImageView.loadUrl(urlToLoad: String) = Picasso.with(context).load(urlToLoad).into(this)
fun ImageView.loadUrl(urlToLoad: String) = Picasso.with(context).load(urlToLoad).into(this)
/***
* To what activity we want to navigate
*/
inline fun <reified T : Activity> Context.startActivity() {
startActivity(Intent(this, T::class.java))
}
inline fun <reified V : View> View.find(@IdRes resId: Int): V = findViewById(resId) as V
inline fun <reified V : View> Activity.find(@IdRes resId: Int): V = findViewById(resId) as V
inline fun <reified V : View> RecyclerView.ViewHolder.find(@IdRes resId: Int): V = itemView.find<V>(resId)
@@ -11,7 +11,7 @@ class HomeActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
val recyclerView = findViewById(R.id.recycler) as RecyclerView
val recyclerView = find<RecyclerView>(R.id.recycler)
recyclerView.adapter = MediaAdapter(fetchMedia())
}
@@ -6,6 +6,7 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import org.w3c.dom.Text
/**
* Created by gfernandez on 22/04/17.
@@ -25,8 +26,8 @@ class MediaAdapter(
mediaItemList.size
class MediaViewHolder(mediaView: View) : RecyclerView.ViewHolder(mediaView) {
val title = mediaView.findViewById(R.id.media_title) as TextView
val thumb = mediaView.findViewById(R.id.media_thumb) as ImageView
val title = find<TextView>(R.id.media_title)
val thumb = find<ImageView>(R.id.media_thumb)
fun bind(item: MediaItem) {
title.text = item.title

0 comments on commit 88b0e11

Please sign in to comment.