-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from SamiraVaezi/mary_data_binding
Mary data binding
- Loading branch information
Showing
13 changed files
with
138 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/angels/pooyeshgaran/databinding/PicassoBindingAdapters.java
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,22 @@ | ||
package com.angels.pooyeshgaran.databinding; | ||
|
||
import android.content.Context; | ||
import android.widget.ImageView; | ||
import androidx.databinding.BindingAdapter; | ||
import com.angels.pooyeshgaran.R; | ||
import com.squareup.picasso.Picasso; | ||
|
||
public class PicassoBindingAdapters { | ||
|
||
@BindingAdapter("imageResource") | ||
public static void setImageResource(ImageView view, String imageUrl){ | ||
|
||
Context context = view.getContext(); | ||
|
||
Picasso.with(context) | ||
.load(imageUrl) | ||
.placeholder(R.drawable.ic_launcher_background) | ||
.error(R.drawable.ic_launcher_background) | ||
.into(view); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/angels/pooyeshgaran/databinding/UserModel.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,7 @@ | ||
package com.angels.pooyeshgaran.databinding | ||
|
||
class UserModel { | ||
|
||
lateinit var userName: String | ||
lateinit var userImage: String | ||
} |
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,18 +1,47 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent" | ||
tools:context=".MainActivity"> | ||
<layout > | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Hello World!" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
<data> | ||
<variable | ||
name="userModel" | ||
type="com.angels.pooyeshgaran.databinding.UserModel" /> | ||
<variable | ||
name="testUrl" | ||
type="String"/> | ||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/userImage" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:imageResource="@{testUrl}" | ||
android:layout_marginLeft="8dp" | ||
android:layout_marginRight="8dp" | ||
android:layout_marginTop="8dp" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintBottom_toTopOf="@+id/tvUserName"/> | ||
|
||
<TextView | ||
android:id="@+id/tvUserName" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:textAlignment="center" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/userImage" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
android:text="@{userModel.userName}"/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</layout> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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