Skip to content

Commit

Permalink
feat(0.9.1): 添加消息item xml布局
Browse files Browse the repository at this point in the history
  • Loading branch information
free46000 committed Mar 20, 2017
1 parent 75c5a14 commit d255a51
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 0 deletions.
1 change: 1 addition & 0 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</activity>
<activity android:name=".MultiItemActivity_"/>
<activity android:name=".ItemClickActivity_"/>
<activity android:name=".ChatActivity_"/>
</application>

</manifest>
53 changes: 53 additions & 0 deletions demo/src/main/java/com/freelib/multiitem/demo/ChatActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.freelib.multiitem.demo;

import android.content.Context;
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.demo.bean.ImageBean;
import com.freelib.multiitem.demo.bean.ImageTextBean;
import com.freelib.multiitem.demo.bean.MessageBean;
import com.freelib.multiitem.demo.bean.TextBean;
import com.freelib.multiitem.demo.viewholder.ImageAndTextManager;
import com.freelib.multiitem.demo.viewholder.ImageViewManager;
import com.freelib.multiitem.demo.viewholder.MessageViewManager;
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 ChatActivity extends AppCompatActivity {
@ViewById(R.id.recyclerView)
protected RecyclerView recyclerView;

public static void startChatActivity(Context context) {
ChatActivity_.intent(context).start();
}

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

recyclerView.setLayoutManager(new LinearLayoutManager(this));
//初始化adapter
BaseItemAdapter adapter = new BaseItemAdapter();
//为XXBean数据源注册XXManager管理类
adapter.register(MessageBean.class, new MessageViewManager());
recyclerView.setAdapter(adapter);
List<Object> list = new ArrayList<>();
for (int i = 0; i < 20; i++) {
list.add(new TextBean("AAA" + i));
list.add(new ImageBean(R.drawable.img1));
list.add(new ImageTextBean(R.drawable.img2, "BBB" + i));
}

adapter.setDataItems(list);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.freelib.multiitem.demo.bean;

/**
* 消息实体
* Created by free46000 on 2017/3/20.
*/
public class MessageBean {
private String message;
private String sender;

public String getMessage() {
return message;
}

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

public String getSender() {
return sender;
}

public void setSender(String sender) {
this.sender = sender;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.freelib.multiitem.demo.viewholder;

import android.support.annotation.NonNull;
import android.widget.TextView;

import com.freelib.multiitem.adapter.holder.BaseViewHolder;
import com.freelib.multiitem.adapter.holder.BaseViewHolderManager;
import com.freelib.multiitem.demo.R;
import com.freelib.multiitem.demo.bean.MessageBean;

/**
* @author free46000 2017/03/17
*/
public class MessageViewManager extends BaseViewHolderManager<MessageBean> {


@Override
public void onBindViewHolder(@NonNull BaseViewHolder holder, @NonNull MessageBean data) {
TextView textView = getView(holder, R.id.text);
textView.setText(data.getMessage());
}

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

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions demo/src/main/res/layout/item_chat_receive.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/message_bubble_receive"
android:paddingBottom="12dp"
android:paddingLeft="20dp"
android:paddingRight="12dp"
android:paddingTop="12dp"
android:textColor="@android:color/white"
android:textSize="@dimen/text_medium"
tools:text="嗨,在吗?"/>
</LinearLayout>

22 changes: 22 additions & 0 deletions demo/src/main/res/layout/item_chat_send.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/message_bubble_send"
android:paddingBottom="12dp"
android:paddingLeft="12dp"
android:paddingRight="20dp"
android:paddingTop="12dp"
android:textColor="@android:color/black"
android:textSize="@dimen/text_medium"
tools:text="嗨,在吗?"/>
</RelativeLayout>

0 comments on commit d255a51

Please sign in to comment.