aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-06 19:29:25 -0700
committerAllan Wang <me@allanwang.ca>2017-06-06 19:29:25 -0700
commit067ea15188f20fa268255153e35c2df732fdffee (patch)
tree87a0fcd84f37ad569ec2743ffc702a69cd59e252 /app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
parentc4e22f5512570d05178711ba90c28eb6dc288253 (diff)
downloadfrost-067ea15188f20fa268255153e35c2df732fdffee.tar.gz
frost-067ea15188f20fa268255153e35c2df732fdffee.tar.bz2
frost-067ea15188f20fa268255153e35c2df732fdffee.zip
Clean up injectors and events
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt17
1 files changed, 8 insertions, 9 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
index e0e33e79..6c5d5b6c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
@@ -1,6 +1,5 @@
package com.pitchedapps.frost.views
-import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.support.v7.widget.AppCompatTextView
import android.support.v7.widget.RecyclerView
@@ -9,24 +8,23 @@ import android.widget.ImageView
import butterknife.ButterKnife
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
-import com.bumptech.glide.load.Transformation
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.mikepenz.fastadapter.items.AbstractItem
+import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.pitchedapps.frost.R
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.utils.bindView
+import com.pitchedapps.frost.utils.toDrawable
/**
* Created by Allan Wang on 2017-06-05.
*/
-class AccountItem(val id: Long, val name: String) : AbstractItem<AccountItem, AccountItem.ViewHolder>() {
- constructor() : this(-1L, "")
- constructor(cookie: CookieModel) : this(cookie.id, cookie.name ?: "")
+class AccountItem(val cookie: CookieModel?) : AbstractItem<AccountItem, AccountItem.ViewHolder>() {
override fun getType(): Int = R.id.item_account
@@ -38,10 +36,10 @@ class AccountItem(val id: Long, val name: String) : AbstractItem<AccountItem, Ac
super.bindView(viewHolder, payloads)
with(viewHolder) {
text.visibility = View.INVISIBLE
- if (id != -1L) {
- text.text = name
+ if (cookie != null) {
+ text.text = cookie.name
val options = RequestOptions().transform(CircleCrop())
- Glide.with(itemView).load(PROFILE_PICTURE_URL(id)).apply(options).listener(object : RequestListener<Drawable> {
+ Glide.with(itemView).load(PROFILE_PICTURE_URL(cookie.id)).apply(options).listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
text.fadeIn()
return false
@@ -54,6 +52,7 @@ class AccountItem(val id: Long, val name: String) : AbstractItem<AccountItem, Ac
}).into(image)
} else {
text.visibility = View.VISIBLE
+ image.setImageDrawable(GoogleMaterial.Icon.gmd_add_circle_outline.toDrawable(itemView.context, 100))
text.text = itemView.context.getString(R.string.add_account)
//todo add plus image
}
@@ -68,7 +67,7 @@ class AccountItem(val id: Long, val name: String) : AbstractItem<AccountItem, Ac
}
}
- class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
+ class ViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
val image: ImageView by bindView(R.id.account_image)
val text: AppCompatTextView by bindView(R.id.account_text)