Skip to content

Commit

Permalink
feat(0.9.6): 添加详情demo,调整数据绑定Holder manager
Browse files Browse the repository at this point in the history
Signed-off-by: free46000 <[email protected]>
  • Loading branch information
free46000 committed Apr 23, 2017
1 parent ea93654 commit 0cc7d13
Show file tree
Hide file tree
Showing 20 changed files with 431 additions and 26 deletions.
2 changes: 1 addition & 1 deletion demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
compile project(':library')
compile 'org.androidannotations:androidannotations-api:4.2.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
testCompile 'junit:junit:4.12'
annotationProcessor 'org.androidannotations:androidannotations:4.2.0'
}
3 changes: 3 additions & 0 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<activity android:name=".PanelActivity_"/>
<activity android:name=".DataBindActivity_"/>
<activity android:name=".InputActivity_"/>
<activity android:name=".UserInfoActivity_"/>
<activity android:name=".EmptyAndErrorActivity_">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.freelib.multiitem.demo;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import org.androidannotations.annotations.EActivity;

@EActivity(R.layout.layout_recycler)
public class EmptyAndErrorActivity extends AppCompatActivity {

public static void startActivity(Context context) {
// EmptyAndErrorActivity_.
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.freelib.multiitem.demo;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -48,6 +49,8 @@ protected void initViews() {
() -> DataBindActivity.startActivity(this)));
adapter.addDataItem(new MainBean(getString(R.string.input_title),
() -> InputActivity.startActivity(this)));
adapter.addDataItem(new MainBean(getString(R.string.user_info_title),
() -> UserInfoActivity.startActivity(this)));

adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.freelib.multiitem.demo;

import android.content.Context;
import android.databinding.ViewDataBinding;
import android.icu.text.UnicodeSet;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.freelib.multiitem.adapter.BaseItemAdapter;
import com.freelib.multiitem.adapter.holder.DataBindViewHolderManager;
import com.freelib.multiitem.demo.bean.ImageBean;
import com.freelib.multiitem.demo.bean.ImageTextBean;
import com.freelib.multiitem.demo.bean.ItemInfo;
import com.freelib.multiitem.demo.bean.TextBean;
import com.freelib.multiitem.demo.bean.UserBean;
import com.freelib.multiitem.demo.viewholder.ImageAndTextManager;
import com.freelib.multiitem.demo.viewholder.ImageViewManager;
import com.freelib.multiitem.demo.viewholder.TextViewManager;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

@EActivity(R.layout.layout_recycler)
public class UserInfoActivity extends AppCompatActivity {
@ViewById(R.id.recyclerView)
protected RecyclerView recyclerView;

public static void startActivity(Context context) {
UserInfoActivity_.intent(context).start();
}

@AfterViews
protected void initViews() {
setTitle(R.string.user_info_title);

UserBean userBean = getUserBean();

recyclerView.setLayoutManager(new LinearLayoutManager(this));
//初始化adapter
BaseItemAdapter adapter = new BaseItemAdapter();
//为UserBean数据源注册数据绑定View Holder Manager管理类
adapter.register(ItemInfo.class, new DataBindViewHolderManager<>(
R.layout.item_image_text_data_bind, BR.itemData));
recyclerView.setAdapter(adapter);

List<ItemInfo> list = new ArrayList<>(5);
list.add(new ItemInfo("名字", userBean.getName()));
list.add(new ItemInfo("性别", userBean.getSex()));
list.add(new ItemInfo("年龄", userBean.getAge()));
list.add(new ItemInfo("城市", userBean.getAddr()));
list.add(new ItemInfo("介绍", userBean.getInfo()));
adapter.setDataItems(list);
}


private UserBean getUserBean() {
UserBean userBean = new UserBean();
userBean.setName("张三");
userBean.setSex("男");
userBean.setInfo("简单介绍");
userBean.setAddr("中国北京");
userBean.setAge("26岁");
return userBean;
}

}
30 changes: 30 additions & 0 deletions demo/src/main/java/com/freelib/multiitem/demo/bean/ItemInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.freelib.multiitem.demo.bean;

/**
* Created by free46000 on 2017/4/22.
*/
public class ItemInfo {
private String name;
private String value;

public ItemInfo(String name, String value) {
this.name = name;
this.value = value;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
53 changes: 53 additions & 0 deletions demo/src/main/java/com/freelib/multiitem/demo/bean/UserBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.freelib.multiitem.demo.bean;

/**
* Created by free46000 on 2017/4/22.
*/
public class UserBean {
private String name;
private String sex;
private String info;
private String age;
private String addr;


public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public String getInfo() {
return info;
}

public void setInfo(String info) {
this.info = info;
}

public String getAge() {
return age;
}

public void setAge(String age) {
this.age = age;
}

public String getAddr() {
return addr;
}

public void setAddr(String addr) {
this.addr = addr;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package com.freelib.multiitem.demo.input;

import android.support.annotation.NonNull;
import android.support.v4.text.TextUtilsCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.freelib.multiitem.adapter.holder.BaseViewHolder;
import com.freelib.multiitem.demo.R;
import com.freelib.multiitem.item.BaseItemInput;

import static android.R.attr.value;
import static android.R.id.edit;

/**
* ItemEdit
* Created by free46000 on 2017/4/12.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import com.freelib.multiitem.demo.R;
import com.freelib.multiitem.demo.bean.TextBean;

import static android.R.attr.data;

/**
* @author free46000 2017/03/17
* @version v1.0
Expand Down
47 changes: 47 additions & 0 deletions demo/src/main/res/layout/item_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="itemData"
type="com.freelib.multiitem.demo.bean.ItemInfo"/>
</data>

<android.support.constraint.ConstraintLayout
android:id="@+id/content_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
>


<TextView
android:id="@+id/name_txt"
app:layout_constraintLeft_toLeftOf="@id/content_lay"
app:layout_constraintTop_toTopOf="@id/content_lay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{itemData.name}"
android:textColor="@android:color/black"
android:textSize="@dimen/text_medium"
tools:text="name"
/>

<TextView
android:id="@+id/value_txt"
app:layout_constraintLeft_toRightOf="@id/name_txt"
app:layout_constraintRight_toRightOf="@id/content_lay"
app:layout_constraintTop_toTopOf="@id/name_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{itemData.value}"
android:textColor="@android:color/black"
android:textSize="@dimen/text_medium"
tools:text="value"
/>

</android.support.constraint.ConstraintLayout>
</layout>
34 changes: 34 additions & 0 deletions demo/src/main/res/layout/layout_empty_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
>

<TextView
android:id="@+id/tip_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/handler_btn"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="xin xi"
/>

<Button
android:id="@+id/handler_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tip_txt"
tools:text="xin xi"
/>
</android.support.constraint.ConstraintLayout>


1 change: 1 addition & 0 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<string name="panel_title">跨Recycler拖动面板界面演示</string>
<string name="data_bind_title">DataBinding使用演示</string>
<string name="input_title">录入表单演示</string>
<string name="user_info_title">用户详情演示</string>

<string name="loading_more">加载中...</string>
<string name="load_all">加载完成</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.freelib.multiitem.adapter.holder;

import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

/**
* ViewHolder的管理类,默认采用{@link BaseViewHolder}的实现
* <p>
* Created by free46000 on 2017/3/16.
*/
public abstract class BaseItemState<T extends BaseItemState> extends ViewHolderManager<T, BaseViewHolder> {
@Override
public abstract void onBindViewHolder(BaseViewHolder holder, T t);

@NonNull
@Override
public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent) {
BaseViewHolder viewHolder = new BaseViewHolder(getItemView(parent));
onCreateViewHolder(viewHolder);
return viewHolder;
}

/**
* {@link #onCreateViewHolder}
*/
protected void onCreateViewHolder(@NonNull BaseViewHolder holder) {
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.freelib.multiitem.adapter.holder;

import android.view.ViewGroup;

import com.freelib.multiitem.adapter.holder.BaseViewHolder;
import com.freelib.multiitem.adapter.holder.ViewHolderManager;

import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

/**
* ViewHolder的管理类,默认采用{@link BaseViewHolder}的实现
* ViewHolder鐨勭®$悊绫伙紝榛樿®ら噰鐢▄@link BaseViewHolder}鐨勫疄鐜°
* <p>
* Created by free46000 on 2017/3/16.
*/
Expand All @@ -28,4 +33,4 @@ public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent) {
protected void onCreateViewHolder(@NonNull BaseViewHolder holder) {
}

}
}
Loading

0 comments on commit 0cc7d13

Please sign in to comment.