Skip to content

Commit

Permalink
add header, footer sample
Browse files Browse the repository at this point in the history
  • Loading branch information
sjjeong committed Feb 20, 2020
1 parent ed4c600 commit 8820e15
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import androidx.lifecycle.ViewModel
import com.dino.simplerecyclerview.ItemClickListener
import com.dino.simplerecyclerview.model.BaseVectorAssetItem
import com.dino.simplerecyclerview.model.VectorAsset
import kotlin.random.Random

class MvvmViewModel : ViewModel(), ItemClickListener {

val vectorAssetItems = ObservableField<List<BaseVectorAssetItem>>()

val selectedItem = ObservableField<BaseVectorAssetItem>()

val randomNumer = ObservableField<Long>(0)

init {
createNewItem()
}
Expand All @@ -22,6 +25,7 @@ class MvvmViewModel : ViewModel(), ItemClickListener {
.map { it.toItem() }
.toMutableList()
.shuffled())
randomNumer.set(Random.nextLong(1000))
}

override fun onClick(item: BaseVectorAssetItem) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_mvp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3"
bind:dino_eventHolder="@{eventHolder}"
bind:dino_footerItemLayout="@{@layout/item_footer}"
bind:dino_itemLayout="@{@layout/item_vector_asset}"
bind:dino_itemSpace="@{`8dp`}"
bind:dino_items="@{items}"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/layout/activity_mvvm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.StaggeredGridLayoutManager"
app:spanCount="3"
bind:dino_vm="@{vm}"
bind:dino_footerItem="@{vm.randomNumer}"
bind:dino_footerItemLayout="@{@layout/item_footer}"
bind:dino_headerItem="@{vm.randomNumer}"
bind:dino_headerItemLayout="@{@layout/item_header}"
bind:dino_itemLayout="@{@layout/item_vector_asset}"
bind:dino_itemSpace="@{`8dp`}"
bind:dino_items="@{vm.vectorAssetItems}"
bind:dino_vm="@{vm}"
tools:itemCount="10"
tools:listitem="@layout/item_vector_asset" />

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_normal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
bind:dino_eventHolder="@{eventHolder}"
bind:dino_headerItemLayout="@{@layout/item_header}"
bind:dino_itemLayout="@{@layout/item_vector_asset}"
bind:dino_itemSpace="@{@dimen/space}"
bind:dino_items="@{items}"
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/res/layout/item_footer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

<variable
name="item"
type="Long" />

</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{String.format(`footer %d`, item)}"
android:textSize="20dp" />

</LinearLayout>
</layout>
24 changes: 24 additions & 0 deletions app/src/main/res/layout/item_header.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

<variable
name="item"
type="Long" />

</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{String.format(`header %d`, item)}"
android:textSize="20dp" />

</LinearLayout>
</layout>

0 comments on commit 8820e15

Please sign in to comment.