[英]ionic 2 create adapter like android?
Since 1 week i have started with ionic2 and angular2 , because i wanted to develop for android and ios at the same time. 从1周开始,我开始使用ionic2和angular2,因为我想同时为android和ios开发。 I have written a Chat application for android in Java and now i would like to write this application new in Ionic2.
我已经用Java编写了一个适用于Android的聊天应用程序,现在我想在Ionic2中编写此应用程序。 But i have one problem , namely the adapter.
但我有一个问题,即适配器。 I have in Java an Adapter like this
我在Java中有这样的适配器
public class ChatFirebaseAdapter extends FirebaseRecyclerAdapter<ChatModel, ChatFirebaseAdapter.MyChatViewHolder> {
private static final int RIGHT_MSG = 0;
private static final int RIGHT_MSG_LOW = 7;
private static final int LEFT_MSG = 1;
private static final int LEFT_MSG_LOW = 6;
private static final int RIGHT_MSG_IMG = 2;
private static final int LEFT_MSG_IMG = 3;
public ChatFirebaseAdapter(DatabaseReference ref, String nameUser, String IdUser, ClickListenerChatFirebase mClickListenerChatFirebase, Context context, ContentResolver cr, String id) {
super(ChatModel.class, R.layout.item_message_left, ChatFirebaseAdapter.MyChatViewHolder.class, ref);
this.nameUser = nameUser;
this.idUser = IdUser;
this.mClickListenerChatFirebase = mClickListenerChatFirebase;
this.context = context;
this.cr = cr;
this.groupID = id;
}
@Override
public MyChatViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
if (viewType == RIGHT_MSG) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_right, parent, false);
return new MyChatViewHolder(view);
} else if (viewType == LEFT_MSG) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_left_single, parent, false);
return new MyChatViewHolder(view);
} else if (viewType == RIGHT_MSG_IMG) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_right_img, parent, false);
return new MyChatViewHolder(view);
} else if (viewType == LEFT_MSG_IMG) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_left_img, parent, false);
return new MyChatViewHolder(view);
} else if (viewType == RIGHT_EMJI) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_right_emji, parent, false);
return new MyChatViewHolder(view);
} else if (viewType == RIGHT_MSG_LOW) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_right_low, parent, false);
return new MyChatViewHolder(view);
} else {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_messages_left_low, parent, false);
return new MyChatViewHolder(view);
}
}
And populate viewholder and so on.. 并填充观察者等等。
And i use a Model : 我用一个Model:
public class ChatModel {
private String id;
private String user;
private String username;
private String userphoto;
private boolean send;
private boolean delivered;
private boolean seen;
private boolean isEmji;
private String userModel;
private String message;
private String timeStamp;
private FileModel file;
private MapModel mapModel;
public ChatModel() {
}
public ChatModel(String senderID, String message, String timeStamp, FileModel file, boolean send, boolean delivered , boolean seen ,String ID , String username , String userphoto , Boolean isEmji) {
this.userModel = senderID;
this.message = message;
this.timeStamp = timeStamp;
this.file = file;
this.send = send;
this.id = ID;
this.username = username;
this.userphoto = userphoto;
this.isEmji = isEmji;
this.delivered = delivered;
this.seen = seen;
}
public ChatModel(String senderID, String timeStamp, MapModel mapModel, boolean send, boolean delivered , boolean seen , String ID , String username , String userphoto , Boolean isEmji) {
this.userModel = senderID;
this.timeStamp = timeStamp;
this.mapModel = mapModel;
this.send = send;
this.id = ID;
this.username = username;
this.userphoto = userphoto;
this.isEmji = isEmji;
this.delivered = delivered;
this.seen = seen;
} ....
On Android I create a new Instance and apply the adapter : 在Android上,我创建一个新实例并应用适配器:
final ListUserFirebaseAdapter firebaseAdapter = new ListUserFirebaseAdapter(mFirebaseDatabaseReference.child("users/" + id + "/Chats/").orderByChild("lastTimeStamp").getRef(), name, id , getActivity() ,this , getContext());
rvListMessage.setAdapter(firebaseAdapter);
How can i now do this on ionic 2 ? 我现在如何在ionic 2上执行此操作? I cannot find any suggestion on the Internet :(
我在互联网上找不到任何建议:(
Hopefully you can help me :) (Sry for my bad english i´m from germany :|) 希望你能帮助我:)(对不起我的英语不好,我来自德国:|)
MFG Cem MFG Cem
FirebaseUI is available for Android, iOS and a more limited version for the (plain JavaScript) web. FirebaseUI可用于Android,iOS和(普通JavaScript)网络的更受限版本。 There is no FirebaseUI library for Angular2.
Angular2没有FirebaseUI库。 It also wouldn't make a lot of sense, since the underlying model of Angular2 is quite different from the models of iOS and Android.
这也没有多大意义,因为Angular2的基础模型与iOS和Android的模型完全不同。
But you can use AngularFire2 , which is the equally official library for Angular2. 但是您可以使用AngularFire2 ,它是Angular2的同等官方库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.