-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
741 additions
and
10 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
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
28 changes: 28 additions & 0 deletions
28
app/src/main/java/me/donnie/app/databinding/ItemDb1Delegate.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,28 @@ | ||
package me.donnie.app.databinding; | ||
|
||
import me.donnie.adapter.databinding.delegate.ItemViewDelegate; | ||
import me.donnie.app.R; | ||
|
||
/** | ||
* @author donnieSky | ||
* @created_at 2017/7/31. | ||
* @description | ||
*/ | ||
|
||
public class ItemDb1Delegate implements ItemViewDelegate<StringViewModel, me.donnie.app.databinding.ViewDbItem1Binding> { | ||
@Override | ||
public int getItemViewLayoutId() { | ||
return R.layout.view_db_item_1; | ||
} | ||
|
||
@Override | ||
public boolean isForViewType(StringViewModel item, int position) { | ||
return item.getTxt().equals("2"); | ||
} | ||
|
||
@Override | ||
public void convert(me.donnie.app.databinding.ViewDbItem1Binding binding, StringViewModel stringViewModel, int position) { | ||
binding.setViewModel(stringViewModel); | ||
binding.executePendingBindings(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/me/donnie/app/databinding/ItemDb2Delegate.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,28 @@ | ||
package me.donnie.app.databinding; | ||
|
||
import me.donnie.adapter.databinding.delegate.ItemViewDelegate; | ||
import me.donnie.app.R; | ||
|
||
/** | ||
* @author donnieSky | ||
* @created_at 2017/7/31. | ||
* @description | ||
*/ | ||
|
||
public class ItemDb2Delegate implements ItemViewDelegate<StringViewModel, me.donnie.app.databinding.ViewDbItem2Binding> { | ||
@Override | ||
public int getItemViewLayoutId() { | ||
return R.layout.view_db_item_2; | ||
} | ||
|
||
@Override | ||
public boolean isForViewType(StringViewModel item, int position) { | ||
return item.getTxt().equals("3"); | ||
} | ||
|
||
@Override | ||
public void convert(me.donnie.app.databinding.ViewDbItem2Binding binding, StringViewModel stringViewModel, int position) { | ||
binding.setViewModel(stringViewModel); | ||
binding.executePendingBindings(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/me/donnie/app/databinding/ItemDbDefaultDelegate.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,29 @@ | ||
package me.donnie.app.databinding; | ||
|
||
import me.donnie.adapter.databinding.delegate.ItemViewDelegate; | ||
import me.donnie.app.R; | ||
|
||
/** | ||
* @author donnieSky | ||
* @created_at 2017/7/31. | ||
* @description | ||
*/ | ||
|
||
public class ItemDbDefaultDelegate implements ItemViewDelegate<StringViewModel, ViewDbItemBinding> { | ||
@Override | ||
public int getItemViewLayoutId() { | ||
return R.layout.view_db_item; | ||
} | ||
|
||
@Override | ||
public boolean isForViewType(StringViewModel item, int position) { | ||
return !item.getTxt().equals("2") && | ||
!item.getTxt().equals("3"); | ||
} | ||
|
||
@Override | ||
public void convert(ViewDbItemBinding binding, StringViewModel stringViewModel, int position) { | ||
binding.setViewModel(stringViewModel); | ||
binding.executePendingBindings(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/me/donnie/app/databinding/StringViewModel.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,24 @@ | ||
package me.donnie.app.databinding; | ||
|
||
import android.databinding.BaseObservable; | ||
import android.databinding.Bindable; | ||
|
||
/** | ||
* @author donnieSky | ||
* @created_at 2017/7/31. | ||
* @description | ||
*/ | ||
|
||
public class StringViewModel extends BaseObservable { | ||
|
||
private String txt; | ||
|
||
public StringViewModel(String txt) { | ||
this.txt = txt; | ||
} | ||
|
||
@Bindable | ||
public String getTxt() { | ||
return txt; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/me/donnie/app/databinding/TestBindingAdapter.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,32 @@ | ||
package me.donnie.app.databinding; | ||
|
||
import me.donnie.adapter.BaseViewHolder; | ||
import me.donnie.adapter.databinding.BaseBindingAdapter; | ||
import me.donnie.app.R; | ||
|
||
/** | ||
* @author donnieSky | ||
* @created_at 2017/7/31. | ||
* @description | ||
*/ | ||
|
||
public class TestBindingAdapter extends BaseBindingAdapter<StringViewModel, ViewDbItemBinding, BaseViewHolder> { | ||
|
||
public TestBindingAdapter() { | ||
super(R.layout.view_db_item); | ||
} | ||
|
||
/*@Override | ||
protected void convert(BaseBindHolder<ViewDbItemBinding> holder, StringViewModel model, int position) { | ||
StringViewModel viewModel = getItem(position); | ||
ViewDbItemBinding itemBinding = holder.binding; | ||
itemBinding.setViewModel(viewModel); | ||
itemBinding.executePendingBindings(); | ||
}*/ | ||
|
||
@Override | ||
protected void convert(ViewDbItemBinding binding, StringViewModel stringViewModel, int position) { | ||
binding.setViewModel(stringViewModel); | ||
binding.executePendingBindings(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/me/donnie/app/databinding/TextMultiDbAdapter.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,21 @@ | ||
package me.donnie.app.databinding; | ||
|
||
import me.donnie.adapter.BaseViewHolder; | ||
import me.donnie.adapter.databinding.MultiItemBindingAdapter; | ||
|
||
/** | ||
* @author donnieSky | ||
* @created_at 2017/7/31. | ||
* @description | ||
*/ | ||
|
||
public class TextMultiDbAdapter extends MultiItemBindingAdapter<StringViewModel, BaseViewHolder> { | ||
|
||
public TextMultiDbAdapter() { | ||
super(null); | ||
|
||
addItemViewDelegate(new ItemDbDefaultDelegate()); | ||
addItemViewDelegate(new ItemDb1Delegate()); | ||
addItemViewDelegate(new ItemDb2Delegate()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout | ||
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"> | ||
|
||
<data> | ||
<variable | ||
name="viewModel" | ||
type="me.donnie.app.databinding.StringViewModel"/> | ||
</data> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="100dp" | ||
android:background="?attr/selectableItemBackground" | ||
android:gravity="center_vertical" | ||
android:orientation="horizontal" | ||
android:padding="20dp"> | ||
|
||
<ImageView | ||
android:id="@+id/img" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@mipmap/ic_launcher"/> | ||
|
||
<TextView | ||
android:id="@+id/txt" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="20dp" | ||
android:text="@{viewModel.txt}" | ||
android:textColor="@android:color/black" | ||
android:textSize="20sp"/> | ||
|
||
|
||
</LinearLayout> | ||
</layout> |
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,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout | ||
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"> | ||
|
||
<data> | ||
<variable | ||
name="viewModel" | ||
type="me.donnie.app.databinding.StringViewModel"/> | ||
</data> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="100dp" | ||
android:background="?attr/selectableItemBackground" | ||
android:gravity="center_vertical" | ||
android:orientation="horizontal" | ||
android:padding="20dp"> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="test"/> | ||
|
||
<TextView | ||
android:id="@+id/txt1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="20dp" | ||
android:text="@{viewModel.txt}" | ||
android:textColor="@android:color/black" | ||
android:textSize="20sp"/> | ||
|
||
</LinearLayout> | ||
</layout> |
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,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout | ||
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"> | ||
|
||
<data> | ||
<variable | ||
name="viewModel" | ||
type="me.donnie.app.databinding.StringViewModel"/> | ||
</data> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="100dp" | ||
android:background="?attr/selectableItemBackground" | ||
android:gravity="center_vertical" | ||
android:orientation="horizontal" | ||
android:padding="20dp"> | ||
|
||
<TextView | ||
android:id="@+id/txt3" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/colorPrimary" | ||
android:gravity="center" | ||
android:text="@{viewModel.txt}" | ||
android:textColor="@android:color/white" | ||
android:textSize="30sp"/> | ||
|
||
</LinearLayout> | ||
</layout> |
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.