从1周开始我已经开始使用ionic2和angular2,因为我想同时为android和ios开发。我已经用Java编写了一个用于android的聊天应用程序,现在我想在Ionic2中编写这个新的应用程序。 但我有一个问题,即适配器。我在Java中有这样的适配器
import { inject } from 'aurelia-dependency-injection';
import { Redirect } from 'aurelia-router';
import { AuthService } from "aurelia-authentication";
import { StateStore } from "./StateStore";
@inject(AuthService, StateStore)
export class SaveNavStep {
authService: AuthService;
commonState: StateStore;
constructor(authService: AuthService, commonState: StateStore) {
this.authService = authService;
this.commonState = commonState;
}
run(routingContext, next) {
const isLoggedIn = this.authService.authenticated;
const loginRoute = this.authService.config.loginRoute;
if (routingContext.getAllInstructions().some(route => route.config.auth === true)) {
if (!isLoggedIn) {
this.commonState.postLoginNavInstr = routingContext;
return next.cancel(new Redirect(loginRoute));
}
} else if (isLoggedIn && routingContext.getAllInstructions().some(route => route.fragment === loginRoute)) {
return next.cancel(new Redirect(this.authService.config.loginRedirect));
}
return next();
}
}
填充视图等等..
我使用的是模型:
login() {
var redirectUri = '#/defaultRedirectUri';
if (this.commonState.postLoginNavInstr) {
redirectUri = this.routing.router.generate(this.commonState.postLoginNavInstr.config.name,
this.commonState.postLoginNavInstr.params,
{ replace: true });
}
var credentials = {
username: this.userName,
password: this.password,
grant_type: "password"
};
this.routing.auth.login(credentials,
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } },
redirectUri
).catch(e => {
this.dialogService.open({
viewModel: InfoDialog,
model: ExceptionHelpers.exceptionToString(e)
});
});
};
在Android上我创建了一个新的实例并应用了适配器:
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);
}
}
我现在如何在离子2上做到这一点?我在互联网上找不到任何建议:(
希望你能帮助我:) (我的英语不好,我来自德国:|)
MFG Cem
答案 0 :(得分:0)
FirebaseUI适用于Android,iOS和(纯JavaScript)网站的更有限版本。 Angular2没有FirebaseUI库。它也没有多大意义,因为Angular2的底层模型完全与iOS和Android的模型不同。
但你可以使用AngularFire2,这是Angular2的同等官方库。