-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add binding adapter to load images. Add data binding to recycler view
adapter. Add 2-way data binding to superHero edition.
- Loading branch information
1 parent
4ab6265
commit 667bf7d
Showing
12 changed files
with
139 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/karumi/jetpack/superheroes/common/BindingAdapters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.karumi.jetpack.superheroes.common | ||
|
||
import android.widget.ImageView | ||
import androidx.databinding.BindingAdapter | ||
import com.squareup.picasso.Picasso | ||
|
||
@BindingAdapter("imageUrl") | ||
fun setImageUrl(view: ImageView, url: String?) { | ||
if (url != null) { | ||
Picasso.get().load(url).fit().centerCrop().fit().into(view) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
app/src/main/java/com/karumi/jetpack/superheroes/ui/utils/PicassoUtils.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 8 additions & 33 deletions
41
app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,18 @@ | ||
package com.karumi.jetpack.superheroes.ui.view.adapter | ||
|
||
import android.view.View | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.karumi.jetpack.superheroes.R | ||
import com.karumi.jetpack.superheroes.databinding.SuperHeroRowBinding | ||
import com.karumi.jetpack.superheroes.domain.model.SuperHero | ||
import com.karumi.jetpack.superheroes.ui.presenter.SuperHeroesPresenter | ||
import com.karumi.jetpack.superheroes.ui.utils.setImageBackground | ||
import com.karumi.jetpack.superheroes.ui.presenter.SuperHeroesListener | ||
|
||
class SuperHeroViewHolder( | ||
itemView: View, | ||
private val presenter: SuperHeroesPresenter | ||
) : RecyclerView.ViewHolder(itemView) { | ||
|
||
private val photoImageView: ImageView = itemView.findViewById(R.id.iv_super_hero_photo) | ||
private val nameTextView: TextView = itemView.findViewById(R.id.tv_super_hero_name) | ||
private val avengersBadgeView: View = itemView.findViewById(R.id.iv_avengers_badge) | ||
private val binding: SuperHeroRowBinding, | ||
private val listener: SuperHeroesListener | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun render(superHero: SuperHero) { | ||
hookListeners(superHero) | ||
renderSuperHeroPhoto(superHero.photo) | ||
renderSuperHeroName(superHero.name) | ||
renderAvengersBadge(superHero.isAvenger) | ||
} | ||
|
||
private fun hookListeners(superHero: SuperHero) { | ||
itemView.setOnClickListener { presenter.onSuperHeroClicked(superHero) } | ||
} | ||
|
||
private fun renderSuperHeroPhoto(photo: String?) { | ||
photoImageView.setImageBackground(photo) | ||
} | ||
|
||
private fun renderSuperHeroName(name: String) { | ||
nameTextView.text = name | ||
} | ||
|
||
private fun renderAvengersBadge(isAvenger: Boolean) { | ||
avengersBadgeView.visibility = if (isAvenger) View.VISIBLE else View.GONE | ||
binding.superHero = superHero | ||
binding.listener = listener | ||
binding.executePendingBindings() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.