Skip to content

Commit

Permalink
feat(0.9.6): 添加状态页辅助类,添加空白和错误状态页demo
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 0cc7d13 commit 422165d
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,89 @@
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.freelib.multiitem.adapter.BaseItemAdapter;
import com.freelib.multiitem.adapter.holder.BaseViewHolder;
import com.freelib.multiitem.demo.bean.ImageBean;
import com.freelib.multiitem.demo.bean.ImageTextBean;
import com.freelib.multiitem.demo.bean.MainBean;
import com.freelib.multiitem.demo.bean.TextBean;
import com.freelib.multiitem.demo.state.ItemEmptyAndError;
import com.freelib.multiitem.demo.viewholder.ImageAndTextManager;
import com.freelib.multiitem.demo.viewholder.ImageViewManager;
import com.freelib.multiitem.demo.viewholder.TextViewManager;
import com.freelib.multiitem.helper.StateViewHelper;
import com.freelib.multiitem.item.BaseItemState;
import com.freelib.multiitem.listener.OnItemClickListener;
import com.freelib.multiitem.listener.OnStateClickListener;

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

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

import static android.R.id.empty;
import static com.freelib.multiitem.demo.R.id.recyclerView;

@EActivity(R.layout.layout_recycler)
public class EmptyAndErrorActivity extends AppCompatActivity {
@ViewById(R.id.recyclerView)
protected RecyclerView recyclerView;
private StateViewHelper emptyViewHelper;
private StateViewHelper errorViewHelper;

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

@AfterViews
protected void initViews() {
setTitle(R.string.empty_error_title);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
//初始化adapter
BaseItemAdapter adapter = new BaseItemAdapter();
//为XXBean数据源注册XXManager管理类
adapter.register(TextBean.class, new TextViewManager());
recyclerView.setAdapter(adapter);
adapter.addDataItem(new TextBean("展示空白页"));
adapter.addDataItem(new TextBean("展示错误页"));

setOnItemClickListener(adapter);

initEmptyHelper();
initErrorHelper();
}

private void setOnItemClickListener(BaseItemAdapter adapter) {
adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(BaseViewHolder viewHolder) {
switch (viewHolder.getItemPosition()) {
case 0:
emptyViewHelper.show();
break;
case 1:
errorViewHelper.show();
break;
}
}
});
}

private void initEmptyHelper() {
BaseItemState emptyItem = new ItemEmptyAndError("列表数据为空");
emptyViewHelper = new StateViewHelper(recyclerView, emptyItem);
emptyItem.setOnStateClickListener(() -> emptyViewHelper.hide());
}

private void initErrorHelper() {
BaseItemState emptyItem = new ItemEmptyAndError("数据加载错误");
errorViewHelper = new StateViewHelper(recyclerView, emptyItem);
emptyItem.setOnStateClickListener(() -> emptyViewHelper.hide());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ protected void initViews() {
() -> InputActivity.startActivity(this)));
adapter.addDataItem(new MainBean(getString(R.string.user_info_title),
() -> UserInfoActivity.startActivity(this)));
adapter.addDataItem(new MainBean(getString(R.string.empty_error_title),
() -> EmptyAndErrorActivity.startActivity(this)));

adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void initViews() {
BaseItemAdapter adapter = new BaseItemAdapter();
//为UserBean数据源注册数据绑定View Holder Manager管理类
adapter.register(ItemInfo.class, new DataBindViewHolderManager<>(
R.layout.item_image_text_data_bind, BR.itemData));
R.layout.item_info, BR.itemData));
recyclerView.setAdapter(adapter);

List<ItemInfo> list = new ArrayList<>(5);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.freelib.multiitem.demo.state;

import android.databinding.ViewDataBinding;

import com.freelib.multiitem.demo.BR;
import com.freelib.multiitem.demo.R;
import com.freelib.multiitem.item.BaseItemState;

/**
* Created by free46000 on 2017/4/23.
*/
public class ItemEmptyAndError extends BaseItemState<ItemEmptyAndError> {
private String message;
private String btnText = "点击重试";

public ItemEmptyAndError(String message) {
this.message = message;
}

@Override
protected void onBindViewHolder(ViewDataBinding dataBinding, ItemEmptyAndError data) {
dataBinding.setVariable(BR.itemData, data);
}

@Override
protected int getItemLayoutId() {
return R.layout.layout_empty_error;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String getBtnText() {
return btnText;
}

public void setBtnText(String btnText) {
this.btnText = btnText;
}
}
25 changes: 18 additions & 7 deletions demo/src/main/res/layout/item_info.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand All @@ -20,28 +20,39 @@

<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"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
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"
app:layout_constraintLeft_toRightOf="@+id/name_txt"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/name_txt"
tools:text="value"
/>


<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="5dp"
android:background="@android:color/darker_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/name_txt"
/>
</android.support.constraint.ConstraintLayout>
</layout>
70 changes: 41 additions & 29 deletions demo/src/main/res/layout/layout_empty_error.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
<?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"
>
<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">

<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"
/>
<data>

<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>
<variable
name="itemData"
type="com.freelib.multiitem.demo.state.ItemEmptyAndError"/>
</data>

<android.support.constraint.ConstraintLayout
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"
android:text="@{itemData.message}"
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"
android:onClick="@{() -> itemData.onStateClickListener.onStateClick()}"
android:text="@{itemData.btnText}"
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>


</layout>
2 changes: 1 addition & 1 deletion demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<string name="data_bind_title">DataBinding使用演示</string>
<string name="input_title">录入表单演示</string>
<string name="user_info_title">用户详情演示</string>
<string name="empty_error_title">空白错误页演示</string>

<string name="loading_more">加载中...</string>
<string name="load_all">加载完成</string>
<string name="load_has_more">点击加载更多...</string>
<string name="load_failed">加载失败,点击重试...</string>

</resources>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.support.v7.widget.RecyclerView;

import com.freelib.multiitem.adapter.BaseItemAdapter;
import com.freelib.multiitem.adapter.holder.BaseItemState;
import com.freelib.multiitem.item.BaseItemState;

/**
* Created by free46000 on 2017/4/23.
Expand Down
Loading

0 comments on commit 422165d

Please sign in to comment.