Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Context
- import android.support.v7.widget.CardView
- import android.util.AttributeSet
- import android.view.View
- import android.widget.ImageView
- import android.widget.RelativeLayout
- import android.widget.TextView
- import android.widget.Toast
- import butterknife.bindView
- import com.squareup.picasso.Picasso
- import kotlinx.android.synthetic.url_preview.*
- import org.jetbrains.anko.onClick
- class UrlRenderView : CardView {
- constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
- setupView()
- }
- constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
- constructor(context: Context) : this(context, null)
- private fun setupView() {
- inflate(context, R.layout.url_preview, this)
- tv_preview_title.text = "Yo"
- }
- public fun setupView(preview: UrlPreview) {
- if (preview.title == null) {
- visibility = GONE;
- } else {
- visibility = VISIBLE;
- picasso.load(preview.image).into(imageView) // missing placeholder
- setTitle(preview.title)
- setContent(preview.description)
- setSource(preview.url)
- }
- }
- protected fun setTitle(title: String) {
- titleView.text = title
- }
- protected fun setContent(content: String) {
- contentView.text = content
- }
- protected fun setSource(source: String) {
- sourceView.text = source
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout
- style="@style/Feed.CardView"
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="130dp"
- android:layout_marginBottom="6dp"
- android:layout_marginLeft="6dp"
- android:layout_marginRight="6dp"
- android:layout_marginTop="6dp">
- <ImageView
- android:id="@+id/iv_url_preview"
- android:layout_width="130dp"
- android:layout_height="130dp"
- android:layout_marginRight="12dp"
- android:scaleType="centerCrop"/>
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/iv_url_preview"
- android:layout_marginBottom="12dp"
- android:layout_marginLeft="12dp"
- android:layout_marginTop="12dp"
- android:layout_toRightOf="@+id/iv_url_preview">
- <com.devspark.robototextview.widget.RobotoTextView
- android:id="@+id/tv_preview_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="@color/h19_black_light"
- android:textSize="@dimen/text_size_small"
- app:typeface="roboto_light"
- tools:text="Oppenheim, 35 finally makes Tour dream a reality"/>
- <com.devspark.robototextview.widget.RobotoTextView
- android:id="@+id/tv_preview_body"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_above="@+id/tv_preview_source"
- android:layout_below="@+id/tv_preview_title"
- android:ellipsize="end"
- android:gravity="center_vertical"
- android:maxLines="2"
- android:textColor="@color/h19_black_medium"
- android:textSize="13sp"
- tools:text="As Rob Oppenheim stood behind the scoring area at Sawgrass Golf Club, we could hardly wait."/>
- <com.devspark.robototextview.widget.RobotoTextView
- android:id="@+id/tv_preview_source"
- style="@style/Caption"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- tools:text="golfchannel.com"/>
- </RelativeLayout>
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement