Advertisement
Guest User

anko

a guest
Nov 9th, 2015
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. import android.content.Context
  2. import android.support.v7.widget.CardView
  3. import android.util.AttributeSet
  4. import android.view.View
  5. import android.widget.ImageView
  6. import android.widget.RelativeLayout
  7. import android.widget.TextView
  8. import android.widget.Toast
  9. import butterknife.bindView
  10. import com.squareup.picasso.Picasso
  11. import kotlinx.android.synthetic.url_preview.*
  12. import org.jetbrains.anko.onClick
  13.  
  14. class UrlRenderView : CardView {
  15. constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
  16. setupView()
  17. }
  18.  
  19. constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
  20.  
  21. constructor(context: Context) : this(context, null)
  22.  
  23. private fun setupView() {
  24. inflate(context, R.layout.url_preview, this)
  25. tv_preview_title.text = "Yo"
  26. }
  27.  
  28. public fun setupView(preview: UrlPreview) {
  29. if (preview.title == null) {
  30. visibility = GONE;
  31. } else {
  32. visibility = VISIBLE;
  33.  
  34. picasso.load(preview.image).into(imageView) // missing placeholder
  35. setTitle(preview.title)
  36. setContent(preview.description)
  37. setSource(preview.url)
  38. }
  39. }
  40.  
  41. protected fun setTitle(title: String) {
  42. titleView.text = title
  43. }
  44.  
  45. protected fun setContent(content: String) {
  46. contentView.text = content
  47. }
  48.  
  49. protected fun setSource(source: String) {
  50. sourceView.text = source
  51. }
  52. }
  53.  
  54.  
  55.  
  56. <?xml version="1.0" encoding="utf-8"?>
  57. <RelativeLayout
  58. style="@style/Feed.CardView"
  59. xmlns:android="http://schemas.android.com/apk/res/android"
  60. xmlns:app="http://schemas.android.com/apk/res-auto"
  61. xmlns:tools="http://schemas.android.com/tools"
  62. android:layout_width="match_parent"
  63. android:layout_height="130dp"
  64. android:layout_marginBottom="6dp"
  65. android:layout_marginLeft="6dp"
  66. android:layout_marginRight="6dp"
  67. android:layout_marginTop="6dp">
  68.  
  69. <ImageView
  70. android:id="@+id/iv_url_preview"
  71. android:layout_width="130dp"
  72. android:layout_height="130dp"
  73. android:layout_marginRight="12dp"
  74. android:scaleType="centerCrop"/>
  75.  
  76. <RelativeLayout
  77. android:layout_width="match_parent"
  78. android:layout_height="wrap_content"
  79. android:layout_alignBaseline="@+id/iv_url_preview"
  80. android:layout_marginBottom="12dp"
  81. android:layout_marginLeft="12dp"
  82. android:layout_marginTop="12dp"
  83. android:layout_toRightOf="@+id/iv_url_preview">
  84.  
  85. <com.devspark.robototextview.widget.RobotoTextView
  86. android:id="@+id/tv_preview_title"
  87. android:layout_width="wrap_content"
  88. android:layout_height="wrap_content"
  89. android:textColor="@color/h19_black_light"
  90. android:textSize="@dimen/text_size_small"
  91. app:typeface="roboto_light"
  92. tools:text="Oppenheim, 35 finally makes Tour dream a reality"/>
  93.  
  94. <com.devspark.robototextview.widget.RobotoTextView
  95. android:id="@+id/tv_preview_body"
  96. android:layout_width="match_parent"
  97. android:layout_height="wrap_content"
  98. android:layout_above="@+id/tv_preview_source"
  99. android:layout_below="@+id/tv_preview_title"
  100. android:ellipsize="end"
  101. android:gravity="center_vertical"
  102. android:maxLines="2"
  103. android:textColor="@color/h19_black_medium"
  104. android:textSize="13sp"
  105. tools:text="As Rob Oppenheim stood behind the scoring area at Sawgrass Golf Club, we could hardly wait."/>
  106.  
  107. <com.devspark.robototextview.widget.RobotoTextView
  108. android:id="@+id/tv_preview_source"
  109. style="@style/Caption"
  110. android:layout_width="wrap_content"
  111. android:layout_height="wrap_content"
  112. android:layout_alignParentBottom="true"
  113. tools:text="golfchannel.com"/>
  114. </RelativeLayout>
  115.  
  116.  
  117. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement