Skip to content

Commit

Permalink
supplement
Browse files Browse the repository at this point in the history
supplement
  • Loading branch information
goldze committed Dec 1, 2018
1 parent e3e7cb2 commit abacdde
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.goldze.work.ui.viewmodel;

import android.databinding.ObservableField;
import android.support.annotation.NonNull;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.ItemViewModel;

/**
* Created by goldze on 2017/7/17.
*/

public class WorkItemViewModel extends ItemViewModel {
public ObservableField<String> text = new ObservableField<>();

public WorkItemViewModel(@NonNull BaseViewModel viewModel, String text) {
super(viewModel);
this.text.set(text);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.goldze.work.ui.viewmodel;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;

import com.goldze.work.R;
import com.goldze.work.BR;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
* Created by goldze on 2018/6/21.
Expand All @@ -13,4 +19,16 @@ public class WorkViewModel extends BaseViewModel {
public WorkViewModel(@NonNull Application application) {
super(application);
}

@Override
public void onCreate() {
super.onCreate();
for (int i = 0; i < 10; i++) {
observableList.add(new WorkItemViewModel(this, "条目" + i));
}
}
//给RecyclerView添加ObservableList
public ObservableList<WorkItemViewModel> observableList = new ObservableArrayList<>();
//给RecyclerView添加ItemBinding
public ItemBinding<WorkItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.grid_work);
}
19 changes: 14 additions & 5 deletions module-work/src/main/res/layout/fragment_work.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:binding="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="viewModel"
type="com.goldze.work.ui.viewmodel.WorkViewModel" />

<import type="me.tatarka.bindingcollectionadapter2.LayoutManagers" />

<import type="me.goldze.mvvmhabit.binding.viewadapter.recyclerview.LineManagers" />
</data>

<LinearLayout
Expand All @@ -15,10 +20,14 @@
android:gravity="center"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="工作组件"
android:textColor="@color/textColor" />
android:divider="@android:color/transparent"
android:dividerHeight="0dip"
binding:itemBinding="@{viewModel.itemBinding}"
binding:items="@{viewModel.observableList}"
binding:lineManager="@{LineManagers.both()}"
binding:layoutManager="@{LayoutManagers.grid(4)}" />
</LinearLayout>
</layout>
28 changes: 28 additions & 0 deletions module-work/src/main/res/layout/grid_work.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:binding="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="viewModel"
type="com.goldze.work.ui.viewmodel.WorkItemViewModel" />

</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/appBackColor"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:src="@mipmap/ic_launcher"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:text="@{viewModel.text}"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</layout>

0 comments on commit abacdde

Please sign in to comment.