-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
demo/src/main/java/com/freelib/multiitem/demo/ChatActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
demo/src/main/java/com/freelib/multiitem/demo/bean/MessageBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
demo/src/main/java/com/freelib/multiitem/demo/viewholder/MessageViewManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|